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
2209c181
Commit
2209c181
authored
Mar 04, 2019
by
swift_gan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into support_k
parents
ea2f1173
48916f5a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
93 deletions
+13
-93
sandhook.cpp
hooklib/src/main/cpp/sandhook.cpp
+0
-60
trampoline_manager.cpp
hooklib/src/main/cpp/trampoline/trampoline_manager.cpp
+2
-0
SandHook.java
hooklib/src/main/java/com/swift/sandhook/SandHook.java
+0
-30
HookWrapper.java
...src/main/java/com/swift/sandhook/wrapper/HookWrapper.java
+11
-3
No files found.
hooklib/src/main/cpp/sandhook.cpp
View file @
2209c181
...
@@ -58,53 +58,6 @@ void ensureMethodCached(art::mirror::ArtMethod *hookMethod, art::mirror::ArtMeth
...
@@ -58,53 +58,6 @@ void ensureMethodCached(art::mirror::ArtMethod *hookMethod, art::mirror::ArtMeth
}
}
}
}
void
ensureBackupMethod
(
art
::
mirror
::
ArtMethod
*
origin
,
art
::
mirror
::
ArtMethod
*
backup
)
{
if
(
origin
->
getDeclaringClassPtr
()
!=
backup
->
getDeclaringClassPtr
())
{
LOGW
(
"backup method is out to date due to Moving GC!"
);
SandHook
::
HookTrampoline
*
trampoline
=
trampolineManager
.
getHookTrampoline
(
origin
);
if
(
trampoline
==
nullptr
)
return
;
SandHook
::
StopTheWorld
stopTheWorld
;
if
(
trampoline
->
inlineJump
!=
nullptr
)
{
origin
->
backup
(
backup
);
backup
->
setQuickCodeEntry
(
trampoline
->
callOrigin
->
getCode
());
if
(
SDK_INT
>=
ANDROID_N
)
{
backup
->
disableCompilable
();
}
if
(
SDK_INT
>=
ANDROID_O
)
{
backup
->
disableInterpreterForO
();
}
if
(
!
backup
->
isStatic
())
{
backup
->
setPrivate
();
}
backup
->
tryDisableInline
();
}
else
if
(
trampoline
->
replacement
!=
nullptr
)
{
origin
->
backup
(
backup
);
if
(
trampoline
->
callOrigin
!=
nullptr
)
{
backup
->
setQuickCodeEntry
(
trampoline
->
callOrigin
->
getCode
());
}
else
{
backup
->
setQuickCodeEntry
(
trampoline
->
originCode
);
}
if
(
SDK_INT
>=
ANDROID_N
)
{
backup
->
disableCompilable
();
}
if
(
SDK_INT
>=
ANDROID_O
)
{
backup
->
disableInterpreterForO
();
}
if
(
!
backup
->
isStatic
())
{
backup
->
setPrivate
();
}
backup
->
tryDisableInline
();
}
else
{
return
;
}
backup
->
flushCache
();
}
}
bool
doHookWithReplacement
(
JNIEnv
*
env
,
bool
doHookWithReplacement
(
JNIEnv
*
env
,
art
::
mirror
::
ArtMethod
*
originMethod
,
art
::
mirror
::
ArtMethod
*
originMethod
,
art
::
mirror
::
ArtMethod
*
hookMethod
,
art
::
mirror
::
ArtMethod
*
hookMethod
,
...
@@ -264,19 +217,6 @@ Java_com_swift_sandhook_SandHook_ensureMethodCached(JNIEnv *env, jclass type, jo
...
@@ -264,19 +217,6 @@ Java_com_swift_sandhook_SandHook_ensureMethodCached(JNIEnv *env, jclass type, jo
ensureMethodCached
(
hookeMethod
,
backupMethod
);
ensureMethodCached
(
hookeMethod
,
backupMethod
);
}
}
extern
"C"
JNIEXPORT
void
JNICALL
Java_com_swift_sandhook_SandHook_ensureBackupMethod
(
JNIEnv
*
env
,
jclass
type
,
jobject
originMethod
,
jobject
backupMethod
)
{
if
(
backupMethod
==
NULL
||
originMethod
==
NULL
)
return
;
art
::
mirror
::
ArtMethod
*
origin
=
reinterpret_cast
<
art
::
mirror
::
ArtMethod
*>
(
env
->
FromReflectedMethod
(
originMethod
));
art
::
mirror
::
ArtMethod
*
backup
=
reinterpret_cast
<
art
::
mirror
::
ArtMethod
*>
(
env
->
FromReflectedMethod
(
backupMethod
));
ensureBackupMethod
(
origin
,
backup
);
}
extern
"C"
extern
"C"
JNIEXPORT
jboolean
JNICALL
JNIEXPORT
jboolean
JNICALL
Java_com_swift_sandhook_SandHook_compileMethod
(
JNIEnv
*
env
,
jclass
type
,
jobject
member
)
{
Java_com_swift_sandhook_SandHook_compileMethod
(
JNIEnv
*
env
,
jclass
type
,
jobject
member
)
{
...
...
hooklib/src/main/cpp/trampoline/trampoline_manager.cpp
View file @
2209c181
...
@@ -14,6 +14,8 @@ namespace SandHook {
...
@@ -14,6 +14,8 @@ namespace SandHook {
uint32_t
TrampolineManager
::
sizeOfEntryCode
(
mirror
::
ArtMethod
*
method
)
{
uint32_t
TrampolineManager
::
sizeOfEntryCode
(
mirror
::
ArtMethod
*
method
)
{
Code
codeEntry
=
getEntryCode
(
method
);
Code
codeEntry
=
getEntryCode
(
method
);
if
(
codeEntry
==
nullptr
||
codeEntry
<=
0
)
return
0
;
#if defined(__arm__)
#if defined(__arm__)
if
(
isThumbCode
(
reinterpret_cast
<
Size
>
(
codeEntry
)))
{
if
(
isThumbCode
(
reinterpret_cast
<
Size
>
(
codeEntry
)))
{
codeEntry
=
getThumbCodeAddress
(
codeEntry
);
codeEntry
=
getThumbCodeAddress
(
codeEntry
);
...
...
hooklib/src/main/java/com/swift/sandhook/SandHook.java
View file @
2209c181
...
@@ -172,37 +172,9 @@ public class SandHook {
...
@@ -172,37 +172,9 @@ public class SandHook {
}
}
}
}
public
static
Object
ensureBackupAndCallOriginMethod
(
Member
originMethod
,
Method
backupMethod
,
Object
thiz
,
Object
[]
args
)
throws
Throwable
{
backupMethod
.
setAccessible
(
true
);
if
(
Modifier
.
isStatic
(
originMethod
.
getModifiers
()))
{
ensureBackupMethod
(
originMethod
,
backupMethod
);
return
backupMethod
.
invoke
(
null
,
args
);
}
else
{
ensureBackupMethod
(
originMethod
,
backupMethod
);
return
backupMethod
.
invoke
(
thiz
,
args
);
}
}
public
static
void
ensureBackupMethod
(
Method
backupMethod
)
{
public
static
void
ensureBackupMethod
(
Method
backupMethod
)
{
if
(
backupMethod
==
null
)
return
;
HookWrapper
.
HookEntity
hookEntity
=
globalBackupMap
.
get
(
backupMethod
);
if
(
hookEntity
==
null
)
return
;
ensureBackupMethod
(
hookEntity
.
target
,
backupMethod
);
}
}
public
static
void
ensureBackupMethodByOrigin
(
Member
originMethod
)
{
if
(
originMethod
==
null
)
return
;
HookWrapper
.
HookEntity
hookEntity
=
globalHookEntityMap
.
get
(
originMethod
);
if
(
hookEntity
==
null
||
hookEntity
.
backup
==
null
)
return
;
ensureBackupMethod
(
originMethod
,
hookEntity
.
backup
);
}
public
static
void
resolveStaticMethod
(
Member
method
)
{
public
static
void
resolveStaticMethod
(
Member
method
)
{
//ignore result, just call to trigger resolve
//ignore result, just call to trigger resolve
if
(
method
==
null
)
if
(
method
==
null
)
...
@@ -334,8 +306,6 @@ public class SandHook {
...
@@ -334,8 +306,6 @@ public class SandHook {
public
static
native
void
ensureMethodCached
(
Method
hook
,
Method
backup
);
public
static
native
void
ensureMethodCached
(
Method
hook
,
Method
backup
);
public
static
native
void
ensureBackupMethod
(
Member
originMethod
,
Method
backupMethod
);
public
static
native
boolean
compileMethod
(
Member
member
);
public
static
native
boolean
compileMethod
(
Member
member
);
public
static
native
boolean
canGetObject
();
public
static
native
boolean
canGetObject
();
...
...
hooklib/src/main/java/com/swift/sandhook/wrapper/HookWrapper.java
View file @
2209c181
...
@@ -39,7 +39,11 @@ public class HookWrapper {
...
@@ -39,7 +39,11 @@ public class HookWrapper {
if
(
targetHookClass
==
null
)
if
(
targetHookClass
==
null
)
throw
new
HookErrorException
(
"error hook wrapper class :"
+
clazz
.
getName
());
throw
new
HookErrorException
(
"error hook wrapper class :"
+
clazz
.
getName
());
Map
<
Member
,
HookEntity
>
hookEntityMap
=
getHookMethods
(
classLoader
,
targetHookClass
,
clazz
);
Map
<
Member
,
HookEntity
>
hookEntityMap
=
getHookMethods
(
classLoader
,
targetHookClass
,
clazz
);
fillBackupMethod
(
classLoader
,
clazz
,
hookEntityMap
);
try
{
fillBackupMethod
(
classLoader
,
clazz
,
hookEntityMap
);
}
catch
(
Throwable
throwable
)
{
throw
new
HookErrorException
(
"fillBackupMethod error!"
,
throwable
);
}
for
(
HookEntity
entity:
hookEntityMap
.
values
())
{
for
(
HookEntity
entity:
hookEntityMap
.
values
())
{
SandHook
.
hook
(
entity
);
SandHook
.
hook
(
entity
);
}
}
...
@@ -82,8 +86,12 @@ public class HookWrapper {
...
@@ -82,8 +86,12 @@ public class HookWrapper {
private
static
Map
<
Member
,
HookEntity
>
getHookMethods
(
ClassLoader
classLoader
,
Class
targetHookClass
,
Class
<?>
hookWrapperClass
)
throws
HookErrorException
{
private
static
Map
<
Member
,
HookEntity
>
getHookMethods
(
ClassLoader
classLoader
,
Class
targetHookClass
,
Class
<?>
hookWrapperClass
)
throws
HookErrorException
{
Map
<
Member
,
HookEntity
>
hookEntityMap
=
new
HashMap
<>();
Map
<
Member
,
HookEntity
>
hookEntityMap
=
new
HashMap
<>();
Method
[]
methods
=
hookWrapperClass
.
getDeclaredMethods
();
Method
[]
methods
=
null
;
if
(
methods
==
null
&&
methods
.
length
==
0
)
try
{
methods
=
hookWrapperClass
.
getDeclaredMethods
();
}
catch
(
Throwable
throwable
)
{
}
if
(
methods
==
null
||
methods
.
length
==
0
)
throw
new
HookErrorException
(
"error hook wrapper class :"
+
targetHookClass
.
getName
());
throw
new
HookErrorException
(
"error hook wrapper class :"
+
targetHookClass
.
getName
());
for
(
Method
method:
methods
)
{
for
(
Method
method:
methods
)
{
HookMethod
hookMethodAnno
=
method
.
getAnnotation
(
HookMethod
.
class
);
HookMethod
hookMethodAnno
=
method
.
getAnnotation
(
HookMethod
.
class
);
...
...
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