Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
S
SandHook
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
SandHook
Commits
1ca453e2
Commit
1ca453e2
authored
Apr 15, 2019
by
swift_gan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tweak code
parent
99c556c2
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
31 deletions
+58
-31
HookBlackList.java
...main/java/com/swift/sandhook/blacklist/HookBlackList.java
+20
-11
Unsafe.java
hooklib/src/main/java/com/swift/sandhook/utils/Unsafe.java
+3
-5
XposedCompat.java
...in/java/com/swift/sandhook/xposedcompat/XposedCompat.java
+16
-2
HookMethodEntity.java
...wift/sandhook/xposedcompat/hookstub/HookMethodEntity.java
+6
-7
DynamicBridge.java
.../swift/sandhook/xposedcompat/methodgen/DynamicBridge.java
+11
-4
DexLog.java
...in/java/com/swift/sandhook/xposedcompat/utils/DexLog.java
+2
-2
No files found.
hooklib/src/main/java/com/swift/sandhook/blacklist/HookBlackList.java
View file @
1ca453e2
...
@@ -9,19 +9,18 @@ public class HookBlackList {
...
@@ -9,19 +9,18 @@ public class HookBlackList {
public
static
Set
<
String
>
methodBlackList
=
new
HashSet
<>();
public
static
Set
<
String
>
methodBlackList
=
new
HashSet
<>();
public
static
Set
<
Class
>
classBlackList
=
new
HashSet
<>();
public
static
Set
<
Class
>
classBlackList
=
new
HashSet
<>();
public
static
Set
<
String
>
methodUseInHookBridge
=
new
HashSet
<>();
public
static
Set
<
String
>
methodUseInHookStub
=
new
HashSet
<>();
static
{
static
{
methodBlackList
.
add
(
"java.lang.reflect.Member.getDeclaringClass"
);
methodBlackList
.
add
(
"java.lang.reflect.Method.invoke"
);
methodBlackList
.
add
(
"java.lang.reflect.Method.invoke"
);
methodBlackList
.
add
(
"java.lang.Class.getDeclaredField"
);
methodBlackList
.
add
(
"java.util.Map.get"
);
methodUseInHookBridge
.
add
(
"java.lang.reflect.Member.getDeclaringClass"
);
methodBlackList
.
add
(
"java.util.concurrent.ConcurrentHashMap.get"
);
methodUseInHookBridge
.
add
(
"java.lang.Class.getDeclaredField"
);
methodBlackList
.
add
(
"java.lang.reflect.AccessibleObject.setAccessible"
);
methodUseInHookBridge
.
add
(
"java.lang.reflect.InvocationTargetException.getCause"
);
methodBlackList
.
add
(
"java.lang.reflect.Member.getModifiers"
);
methodBlackList
.
add
(
"java.lang.reflect.InvocationTargetException.getCause"
);
methodUseInHookStub
.
add
(
"java.lang.Object.equals"
);
methodBlackList
.
add
(
"java.lang.reflect.Method.hashCode"
);
methodUseInHookStub
.
add
(
"java.lang.Class.isPrimitive"
);
methodBlackList
.
add
(
"java.lang.reflect.Class.getName"
);
methodBlackList
.
add
(
"java.lang.String.hashCode"
);
methodBlackList
.
add
(
"java.lang.String.length"
);
}
}
public
final
static
boolean
canNotHook
(
Member
origin
)
{
public
final
static
boolean
canNotHook
(
Member
origin
)
{
...
@@ -31,4 +30,14 @@ public class HookBlackList {
...
@@ -31,4 +30,14 @@ public class HookBlackList {
return
methodBlackList
.
contains
(
name
);
return
methodBlackList
.
contains
(
name
);
}
}
public
final
static
boolean
canNotHookByBridge
(
Member
origin
)
{
String
name
=
origin
.
getDeclaringClass
().
getName
()
+
"."
+
origin
.
getName
();
return
methodUseInHookBridge
.
contains
(
name
);
}
public
final
static
boolean
canNotHookByStub
(
Member
origin
)
{
String
name
=
origin
.
getDeclaringClass
().
getName
()
+
"."
+
origin
.
getName
();
return
methodUseInHookStub
.
contains
(
name
);
}
}
}
hooklib/src/main/java/com/swift/sandhook/utils/Unsafe.java
View file @
1ca453e2
...
@@ -18,6 +18,8 @@ package com.swift.sandhook.utils;
...
@@ -18,6 +18,8 @@ package com.swift.sandhook.utils;
import
android.util.Log
;
import
android.util.Log
;
import
com.swift.sandhook.HookLog
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
...
@@ -75,7 +77,6 @@ public final class Unsafe {
...
@@ -75,7 +77,6 @@ public final class Unsafe {
try
{
try
{
return
(
int
)
arrayBaseOffsetMethod
.
invoke
(
unsafe
,
cls
);
return
(
int
)
arrayBaseOffsetMethod
.
invoke
(
unsafe
,
cls
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
Log
.
w
(
TAG
,
e
);
return
0
;
return
0
;
}
}
}
}
...
@@ -85,7 +86,6 @@ public final class Unsafe {
...
@@ -85,7 +86,6 @@ public final class Unsafe {
try
{
try
{
return
(
int
)
arrayIndexScaleMethod
.
invoke
(
unsafe
,
cls
);
return
(
int
)
arrayIndexScaleMethod
.
invoke
(
unsafe
,
cls
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
Log
.
w
(
TAG
,
e
);
return
0
;
return
0
;
}
}
}
}
...
@@ -95,7 +95,6 @@ public final class Unsafe {
...
@@ -95,7 +95,6 @@ public final class Unsafe {
try
{
try
{
return
(
int
)
getIntMethod
.
invoke
(
unsafe
,
array
,
offset
);
return
(
int
)
getIntMethod
.
invoke
(
unsafe
,
array
,
offset
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
Log
.
w
(
TAG
,
e
);
return
0
;
return
0
;
}
}
}
}
...
@@ -105,7 +104,6 @@ public final class Unsafe {
...
@@ -105,7 +104,6 @@ public final class Unsafe {
try
{
try
{
return
(
long
)
getLongMethod
.
invoke
(
unsafe
,
array
,
offset
);
return
(
long
)
getLongMethod
.
invoke
(
unsafe
,
array
,
offset
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
Log
.
w
(
TAG
,
e
);
return
0
;
return
0
;
}
}
}
}
...
@@ -119,7 +117,7 @@ public final class Unsafe {
...
@@ -119,7 +117,7 @@ public final class Unsafe {
return
0xffffffff
L
&
getInt
(
array
,
arrayBaseOffset
(
objectArrayClass
));
return
0xffffffff
L
&
getInt
(
array
,
arrayBaseOffset
(
objectArrayClass
));
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
Log
.
w
(
TAG
,
e
);
HookLog
.
e
(
"get object address error"
,
e
);
return
-
1
;
return
-
1
;
}
}
}
}
...
...
xposedcompat/src/main/java/com/swift/sandhook/xposedcompat/XposedCompat.java
View file @
1ca453e2
...
@@ -16,6 +16,8 @@ import de.robv.android.xposed.XposedBridge;
...
@@ -16,6 +16,8 @@ import de.robv.android.xposed.XposedBridge;
import
de.robv.android.xposed.XposedInit
;
import
de.robv.android.xposed.XposedInit
;
import
de.robv.android.xposed.callbacks.XC_LoadPackage
;
import
de.robv.android.xposed.callbacks.XC_LoadPackage
;
import
static
com
.
swift
.
sandhook
.
xposedcompat
.
utils
.
DexMakerUtils
.
MD5
;
public
class
XposedCompat
{
public
class
XposedCompat
{
public
static
File
cacheDir
;
public
static
File
cacheDir
;
...
@@ -79,10 +81,22 @@ public class XposedCompat {
...
@@ -79,10 +81,22 @@ public class XposedCompat {
}
}
}
}
public
static
File
getCacheDir
()
{
if
(
cacheDir
==
null
)
{
if
(
context
==
null
)
{
context
=
ApplicationUtils
.
currentApplication
();
}
if
(
context
!=
null
)
{
cacheDir
=
new
File
(
context
.
getCacheDir
(),
MD5
(
processName
!=
null
?
processName
:
ProcessUtils
.
getProcessName
(
context
)));
}
}
return
cacheDir
;
}
public
static
boolean
clearCache
()
{
public
static
boolean
clearCache
()
{
try
{
try
{
FileUtils
.
delete
(
cacheDir
);
FileUtils
.
delete
(
getCacheDir
()
);
cacheDir
.
mkdirs
();
getCacheDir
()
.
mkdirs
();
return
true
;
return
true
;
}
catch
(
Throwable
throwable
)
{
}
catch
(
Throwable
throwable
)
{
return
false
;
return
false
;
...
...
xposedcompat/src/main/java/com/swift/sandhook/xposedcompat/hookstub/HookMethodEntity.java
View file @
1ca453e2
...
@@ -16,10 +16,13 @@ public class HookMethodEntity {
...
@@ -16,10 +16,13 @@ public class HookMethodEntity {
public
Class
[]
parType
;
public
Class
[]
parType
;
public
Class
retType
;
public
Class
retType
;
public
boolean
isStatic
;
public
HookMethodEntity
(
Member
origin
,
Method
hook
,
Method
backup
)
{
public
HookMethodEntity
(
Member
origin
,
Method
hook
,
Method
backup
)
{
this
.
origin
=
origin
;
this
.
origin
=
origin
;
this
.
hook
=
hook
;
this
.
hook
=
hook
;
this
.
backup
=
backup
;
this
.
backup
=
backup
;
this
.
isStatic
=
Modifier
.
isStatic
(
origin
.
getModifiers
());
}
}
public
Object
[]
getArgs
(
long
...
addresses
)
{
public
Object
[]
getArgs
(
long
...
addresses
)
{
...
@@ -28,7 +31,7 @@ public class HookMethodEntity {
...
@@ -28,7 +31,7 @@ public class HookMethodEntity {
if
(
parType
==
null
||
parType
.
length
==
0
)
if
(
parType
==
null
||
parType
.
length
==
0
)
return
new
Object
[
0
];
return
new
Object
[
0
];
int
argStart
=
0
;
int
argStart
=
0
;
if
(!
isStatic
()
)
{
if
(!
isStatic
)
{
argStart
=
1
;
argStart
=
1
;
}
}
Object
[]
args
=
new
Object
[
parType
.
length
];
Object
[]
args
=
new
Object
[
parType
.
length
];
...
@@ -43,7 +46,7 @@ public class HookMethodEntity {
...
@@ -43,7 +46,7 @@ public class HookMethodEntity {
return
new
long
[
0
];
return
new
long
[
0
];
long
[]
addresses
;
long
[]
addresses
;
int
argStart
=
0
;
int
argStart
=
0
;
if
(!
isStatic
()
)
{
if
(!
isStatic
)
{
argStart
=
1
;
argStart
=
1
;
addresses
=
new
long
[
oldAddress
.
length
+
1
];
addresses
=
new
long
[
oldAddress
.
length
+
1
];
addresses
[
0
]
=
oldAddress
[
0
];
addresses
[
0
]
=
oldAddress
[
0
];
...
@@ -57,7 +60,7 @@ public class HookMethodEntity {
...
@@ -57,7 +60,7 @@ public class HookMethodEntity {
}
}
public
Object
getThis
(
long
address
)
{
public
Object
getThis
(
long
address
)
{
if
(
isStatic
()
)
if
(
isStatic
)
return
null
;
return
null
;
return
SandHook
.
getObject
(
address
);
return
SandHook
.
getObject
(
address
);
}
}
...
@@ -86,8 +89,4 @@ public class HookMethodEntity {
...
@@ -86,8 +89,4 @@ public class HookMethodEntity {
return
origin
instanceof
Constructor
;
return
origin
instanceof
Constructor
;
}
}
public
boolean
isStatic
()
{
return
Modifier
.
isStatic
(
origin
.
getModifiers
());
}
}
}
xposedcompat/src/main/java/com/swift/sandhook/xposedcompat/methodgen/DynamicBridge.java
View file @
1ca453e2
...
@@ -3,6 +3,7 @@ package com.swift.sandhook.xposedcompat.methodgen;
...
@@ -3,6 +3,7 @@ package com.swift.sandhook.xposedcompat.methodgen;
import
android.os.Trace
;
import
android.os.Trace
;
import
com.swift.sandhook.SandHook
;
import
com.swift.sandhook.SandHook
;
import
com.swift.sandhook.blacklist.HookBlackList
;
import
com.swift.sandhook.wrapper.HookWrapper
;
import
com.swift.sandhook.wrapper.HookWrapper
;
import
com.swift.sandhook.xposedcompat.XposedCompat
;
import
com.swift.sandhook.xposedcompat.XposedCompat
;
import
com.swift.sandhook.xposedcompat.hookstub.HookMethodEntity
;
import
com.swift.sandhook.xposedcompat.hookstub.HookMethodEntity
;
...
@@ -23,7 +24,7 @@ import de.robv.android.xposed.XposedBridge;
...
@@ -23,7 +24,7 @@ import de.robv.android.xposed.XposedBridge;
public
final
class
DynamicBridge
{
public
final
class
DynamicBridge
{
private
static
HookMaker
h
ookMaker
=
XposedCompat
.
useNewCallBackup
?
new
HookerDexMakerNew
()
:
new
HookerDexMaker
();
private
static
HookMaker
defaultH
ookMaker
=
XposedCompat
.
useNewCallBackup
?
new
HookerDexMakerNew
()
:
new
HookerDexMaker
();
private
static
final
AtomicBoolean
dexPathInited
=
new
AtomicBoolean
(
false
);
private
static
final
AtomicBoolean
dexPathInited
=
new
AtomicBoolean
(
false
);
private
static
File
dexDir
;
private
static
File
dexDir
;
...
@@ -46,7 +47,7 @@ public final class DynamicBridge {
...
@@ -46,7 +47,7 @@ public final class DynamicBridge {
try
{
try
{
if
(
dexPathInited
.
compareAndSet
(
false
,
true
))
{
if
(
dexPathInited
.
compareAndSet
(
false
,
true
))
{
try
{
try
{
String
fixedAppDataDir
=
XposedCompat
.
cacheDir
.
getAbsolutePath
();
String
fixedAppDataDir
=
XposedCompat
.
getCacheDir
()
.
getAbsolutePath
();
dexDir
=
new
File
(
fixedAppDataDir
,
"/sandxposed/"
);
dexDir
=
new
File
(
fixedAppDataDir
,
"/sandxposed/"
);
if
(!
dexDir
.
exists
())
if
(!
dexDir
.
exists
())
dexDir
.
mkdirs
();
dexDir
.
mkdirs
();
...
@@ -57,13 +58,19 @@ public final class DynamicBridge {
...
@@ -57,13 +58,19 @@ public final class DynamicBridge {
Trace
.
beginSection
(
"SandHook-Xposed"
);
Trace
.
beginSection
(
"SandHook-Xposed"
);
long
timeStart
=
System
.
currentTimeMillis
();
long
timeStart
=
System
.
currentTimeMillis
();
HookMethodEntity
stub
=
null
;
HookMethodEntity
stub
=
null
;
if
(
XposedCompat
.
useInternalStub
)
{
if
(
XposedCompat
.
useInternalStub
&&
!
HookBlackList
.
canNotHookByStub
(
hookMethod
)
&&
!
HookBlackList
.
canNotHookByBridge
(
hookMethod
)
)
{
stub
=
HookStubManager
.
getHookMethodEntity
(
hookMethod
,
additionalHookInfo
);
stub
=
HookStubManager
.
getHookMethodEntity
(
hookMethod
,
additionalHookInfo
);
}
}
if
(
stub
!=
null
)
{
if
(
stub
!=
null
)
{
SandHook
.
hook
(
new
HookWrapper
.
HookEntity
(
hookMethod
,
stub
.
hook
,
stub
.
backup
,
false
));
SandHook
.
hook
(
new
HookWrapper
.
HookEntity
(
hookMethod
,
stub
.
hook
,
stub
.
backup
,
false
));
entityMap
.
put
(
hookMethod
,
stub
);
entityMap
.
put
(
hookMethod
,
stub
);
}
else
{
}
else
{
HookMaker
hookMaker
;
if
(
HookBlackList
.
canNotHookByBridge
(
hookMethod
))
{
hookMaker
=
new
HookerDexMaker
();
}
else
{
hookMaker
=
defaultHookMaker
;
}
hookMaker
.
start
(
hookMethod
,
additionalHookInfo
,
hookMaker
.
start
(
hookMethod
,
additionalHookInfo
,
XposedCompat
.
classLoader
,
dexDir
==
null
?
null
:
dexDir
.
getAbsolutePath
());
XposedCompat
.
classLoader
,
dexDir
==
null
?
null
:
dexDir
.
getAbsolutePath
());
hookedInfo
.
put
(
hookMethod
,
hookMaker
.
getCallBackupMethod
());
hookedInfo
.
put
(
hookMethod
,
hookMaker
.
getCallBackupMethod
());
...
@@ -76,7 +83,7 @@ public final class DynamicBridge {
...
@@ -76,7 +83,7 @@ public final class DynamicBridge {
}
}
public
static
void
clearOatFile
()
{
public
static
void
clearOatFile
()
{
String
fixedAppDataDir
=
XposedCompat
.
cacheDir
.
getAbsolutePath
();
String
fixedAppDataDir
=
XposedCompat
.
getCacheDir
()
.
getAbsolutePath
();
File
dexOatDir
=
new
File
(
fixedAppDataDir
,
"/sandxposed/oat/"
);
File
dexOatDir
=
new
File
(
fixedAppDataDir
,
"/sandxposed/oat/"
);
if
(!
dexOatDir
.
exists
())
if
(!
dexOatDir
.
exists
())
return
;
return
;
...
...
xposedcompat/src/main/java/com/swift/sandhook/xposedcompat/utils/DexLog.java
View file @
1ca453e2
...
@@ -2,7 +2,7 @@ package com.swift.sandhook.xposedcompat.utils;
...
@@ -2,7 +2,7 @@ package com.swift.sandhook.xposedcompat.utils;
import
android.util.Log
;
import
android.util.Log
;
import
com.swift.sandhook.
SandHookConfi
g
;
import
com.swift.sandhook.
HookLo
g
;
import
java.lang.reflect.Member
;
import
java.lang.reflect.Member
;
...
@@ -11,7 +11,7 @@ public class DexLog {
...
@@ -11,7 +11,7 @@ public class DexLog {
public
static
final
String
TAG
=
"SandXposed"
;
public
static
final
String
TAG
=
"SandXposed"
;
public
static
boolean
DEBUG
=
SandHookConfi
g
.
DEBUG
;
public
static
boolean
DEBUG
=
HookLo
g
.
DEBUG
;
public
static
int
v
(
String
s
)
{
public
static
int
v
(
String
s
)
{
return
Log
.
v
(
TAG
,
s
);
return
Log
.
v
(
TAG
,
s
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment