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
c2bf39ef
Commit
c2bf39ef
authored
Jan 23, 2019
by
swift_gan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
done arm32 compat
parent
bd2a9f9a
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
36 additions
and
15 deletions
+36
-15
native-lib.cpp
app/src/main/cpp/native-lib.cpp
+22
-7
arm32.S
app/src/main/cpp/trampoline/arch/arm32.S
+2
-2
trampoline.cpp
app/src/main/cpp/trampoline/trampoline.cpp
+1
-1
trampoline.h
app/src/main/cpp/trampoline/trampoline.h
+1
-1
trampoline_manager.cpp
app/src/main/cpp/trampoline/trampoline_manager.cpp
+8
-2
ActivityHooker.java
app/src/main/java/com/swift/sandhook/ActivityHooker.java
+1
-1
MyApp.java
app/src/main/java/com/swift/sandhook/MyApp.java
+1
-1
No files found.
app/src/main/cpp/native-lib.cpp
View file @
c2bf39ef
...
@@ -77,6 +77,9 @@ bool doHookWithReplacement(art::mirror::ArtMethod *originMethod,
...
@@ -77,6 +77,9 @@ bool doHookWithReplacement(art::mirror::ArtMethod *originMethod,
SandHook
::
CastArtMethod
::
entryPointFormInterpreter
->
set
(
originMethod
,
entryPointFormInterpreter
);
SandHook
::
CastArtMethod
::
entryPointFormInterpreter
->
set
(
originMethod
,
entryPointFormInterpreter
);
}
}
hookTrampoline
->
replacement
->
flushCache
(
reinterpret_cast
<
Size
>
(
originMethod
),
SandHook
::
CastArtMethod
::
size
);
hookTrampoline
->
replacement
->
flushCache
(
reinterpret_cast
<
Size
>
(
originMethod
),
SandHook
::
CastArtMethod
::
size
);
return
true
;
}
else
{
return
false
;
}
}
}
}
...
@@ -94,19 +97,33 @@ bool doHookWithInline(JNIEnv* env,
...
@@ -94,19 +97,33 @@ bool doHookWithInline(JNIEnv* env,
}
}
SandHook
::
HookTrampoline
*
hookTrampoline
=
trampolineManager
.
installInlineTrampoline
(
originMethod
,
hookMethod
,
backupMethod
);
SandHook
::
HookTrampoline
*
hookTrampoline
=
trampolineManager
.
installInlineTrampoline
(
originMethod
,
hookMethod
,
backupMethod
);
if
(
hookTrampoline
==
nullptr
)
return
false
;
void
*
entryPointFormInterpreter
=
SandHook
::
CastArtMethod
::
entryPointFormInterpreter
->
get
(
hookMethod
);
if
(
entryPointFormInterpreter
!=
NULL
)
{
SandHook
::
CastArtMethod
::
entryPointFormInterpreter
->
set
(
originMethod
,
entryPointFormInterpreter
);
}
hookTrampoline
->
inlineSecondory
->
flushCache
(
reinterpret_cast
<
Size
>
(
hookMethod
),
SandHook
::
CastArtMethod
::
size
);
hookTrampoline
->
inlineSecondory
->
flushCache
(
reinterpret_cast
<
Size
>
(
hookMethod
),
SandHook
::
CastArtMethod
::
size
);
if
(
hookTrampoline
->
callOrigin
!=
nullptr
)
{
if
(
hookTrampoline
->
callOrigin
!=
nullptr
)
{
//backup
//backup
memcpy
(
backupMethod
,
originMethod
,
SandHook
::
CastArtMethod
::
size
);
memcpy
(
backupMethod
,
originMethod
,
SandHook
::
CastArtMethod
::
size
);
SandHook
::
CastArtMethod
::
entryPointQuickCompiled
->
set
(
backupMethod
,
hookTrampoline
->
callOrigin
->
getCode
());
Code
callOriginCode
=
hookTrampoline
->
callOrigin
->
getCode
();
if
(
hookTrampoline
->
callOrigin
->
isThumCode
())
{
callOriginCode
=
hookTrampoline
->
callOrigin
->
getThumbCodePcAddress
(
callOriginCode
);
}
SandHook
::
CastArtMethod
::
entryPointQuickCompiled
->
set
(
backupMethod
,
callOriginCode
);
if
(
SDK_INT
>=
ANDROID_N
)
{
if
(
SDK_INT
>=
ANDROID_N
)
{
disableCompilable
(
backupMethod
);
disableCompilable
(
backupMethod
);
}
}
if
(
SDK_INT
>=
ANDROID_O
)
{
if
(
SDK_INT
>=
ANDROID_O
)
{
disableInterpreterForO
(
backupMethod
);
disableInterpreterForO
(
backupMethod
);
}
}
hookTrampoline
->
callOrigin
->
flushCache
(
reinterpret_cast
<
Size
>
(
backupMethod
),
SandHook
::
CastArtMethod
::
size
);
hookTrampoline
->
callOrigin
->
flushCache
(
reinterpret_cast
<
Size
>
(
backupMethod
),
SandHook
::
CastArtMethod
::
size
);
}
}
return
true
;
}
}
extern
"C"
extern
"C"
...
@@ -134,19 +151,17 @@ Java_com_swift_sandhook_SandHook_hookMethod(JNIEnv *env, jclass type, jobject or
...
@@ -134,19 +151,17 @@ Java_com_swift_sandhook_SandHook_hookMethod(JNIEnv *env, jclass type, jobject or
if
(
SDK_INT
>=
ANDROID_N
)
{
if
(
SDK_INT
>=
ANDROID_N
)
{
Size
threadId
=
getAddressFromJavaByCallMethod
(
env
,
"com/swift/sandhook/SandHook"
,
"getThreadId"
);
Size
threadId
=
getAddressFromJavaByCallMethod
(
env
,
"com/swift/sandhook/SandHook"
,
"getThreadId"
);
if
(
compileMethod
(
origin
,
reinterpret_cast
<
void
*>
(
threadId
))
&&
SandHook
::
CastArtMethod
::
entryPointQuickCompiled
->
get
(
origin
)
!=
SandHook
::
CastArtMethod
::
quickToInterpreterBridge
)
{
if
(
compileMethod
(
origin
,
reinterpret_cast
<
void
*>
(
threadId
))
&&
SandHook
::
CastArtMethod
::
entryPointQuickCompiled
->
get
(
origin
)
!=
SandHook
::
CastArtMethod
::
quickToInterpreterBridge
)
{
doHookWithInline
(
env
,
origin
,
hook
,
backup
);
return
static_cast
<
jboolean
>
(
doHookWithInline
(
env
,
origin
,
hook
,
backup
)
);
}
else
{
}
else
{
doHookWithReplacement
(
origin
,
hook
,
backup
);
return
static_cast
<
jboolean
>
(
doHookWithReplacement
(
origin
,
hook
,
backup
)
);
}
}
}
else
{
}
else
{
doHookWithReplacement
(
origin
,
hook
,
backup
);
return
static_cast
<
jboolean
>
(
doHookWithReplacement
(
origin
,
hook
,
backup
)
);
}
}
}
else
{
}
else
{
doHookWithInline
(
env
,
origin
,
hook
,
backup
);
return
static_cast
<
jboolean
>
(
doHookWithInline
(
env
,
origin
,
hook
,
backup
)
);
}
}
return
JNI_TRUE
;
}
}
extern
"C"
extern
"C"
...
...
app/src/main/cpp/trampoline/arch/arm32.S
View file @
c2bf39ef
...
@@ -96,11 +96,11 @@ origin_code_t:
...
@@ -96,11 +96,11 @@ origin_code_t:
//4 byte
//4 byte
ldr RegT, addr_origin_art_method_t
ldr RegT, addr_origin_art_method_t
//4 byte
//4 byte
add RegT, RegT, #
8
add RegT, RegT, #
36
//4 byte
//4 byte
ldr RegT, [RegT]
ldr RegT, [RegT]
//4 byte
//4 byte
add RegT, RegT,
SIZE_JUMP
add RegT, RegT,
#8
//2 byte
//2 byte
mov pc, RegT
mov pc, RegT
nop
nop
...
...
app/src/main/cpp/trampoline/trampoline.cpp
View file @
c2bf39ef
...
@@ -73,7 +73,7 @@ namespace SandHook {
...
@@ -73,7 +73,7 @@ namespace SandHook {
#if defined(__arm__)
#if defined(__arm__)
Code32Bit
offset32
;
Code32Bit
offset32
;
offset32
.
code
=
offSet
;
offset32
.
code
=
offSet
;
unsigned
char
offsetOP
=
isBigEnd
()
?
offset32
.
op
.
op
4
:
offset32
.
op
.
op1
;
unsigned
char
offsetOP
=
isBigEnd
()
?
offset32
.
op
.
op
2
:
offset32
.
op
.
op1
;
tweakOpImm
(
OFFSET_INLINE_OP_OFFSET_CODE
,
offsetOP
);
tweakOpImm
(
OFFSET_INLINE_OP_OFFSET_CODE
,
offsetOP
);
#endif
#endif
}
}
...
...
app/src/main/cpp/trampoline/trampoline.h
View file @
c2bf39ef
...
@@ -172,7 +172,7 @@ namespace SandHook {
...
@@ -172,7 +172,7 @@ namespace SandHook {
if
(
isBigEnd
())
{
if
(
isBigEnd
())
{
code32Bit
.
op
.
op4
=
imm
;
code32Bit
.
op
.
op4
=
imm
;
}
else
{
}
else
{
code32Bit
.
op
.
op
1
=
imm
;
code32Bit
.
op
.
op
3
=
imm
;
}
}
codeCopy
(
reinterpret_cast
<
Code
>
(
&
code32Bit
.
code
),
codeOffset
,
4
);
codeCopy
(
reinterpret_cast
<
Code
>
(
&
code32Bit
.
code
),
codeOffset
,
4
);
}
}
...
...
app/src/main/cpp/trampoline/trampoline_manager.cpp
View file @
c2bf39ef
...
@@ -120,8 +120,14 @@ namespace SandHook {
...
@@ -120,8 +120,14 @@ namespace SandHook {
if
(
callOriginTrampolineSpace
==
0
)
if
(
callOriginTrampolineSpace
==
0
)
goto
label_error
;
goto
label_error
;
callOriginTrampoline
->
setExecuteSpace
(
callOriginTrampolineSpace
);
callOriginTrampoline
->
setExecuteSpace
(
callOriginTrampolineSpace
);
callOriginTrampoline
->
setOriginMethod
(
reinterpret_cast
<
unsigned
char
*>
(
originMethod
));
callOriginTrampoline
->
setOriginMethod
(
reinterpret_cast
<
Code
>
(
originMethod
));
callOriginTrampoline
->
setOriginCode
(
inlineHookTrampoline
->
getCallOriginCode
());
Code
originCode
=
nullptr
;
if
(
callOriginTrampoline
->
isThumCode
())
{
originCode
=
callOriginTrampoline
->
getThumbCodePcAddress
(
inlineHookTrampoline
->
getCallOriginCode
());
}
else
{
originCode
=
inlineHookTrampoline
->
getCallOriginCode
();
}
callOriginTrampoline
->
setOriginCode
(
originCode
);
hookTrampoline
->
callOrigin
=
callOriginTrampoline
;
hookTrampoline
->
callOrigin
=
callOriginTrampoline
;
}
}
...
...
app/src/main/java/com/swift/sandhook/ActivityHooker.java
View file @
c2bf39ef
...
@@ -16,7 +16,7 @@ public class ActivityHooker {
...
@@ -16,7 +16,7 @@ public class ActivityHooker {
@MethodParams
(
Bundle
.
class
)
@MethodParams
(
Bundle
.
class
)
public
static
void
onCreate
(
Activity
thiz
,
Bundle
bundle
)
{
public
static
void
onCreate
(
Activity
thiz
,
Bundle
bundle
)
{
Log
.
e
(
"ActivityHooker"
,
"hooked success "
+
thiz
);
Log
.
e
(
"ActivityHooker"
,
"hooked success "
+
thiz
);
//
onCreateBackup(thiz, bundle);
onCreateBackup
(
thiz
,
bundle
);
}
}
@HookMethodBackup
(
"onCreate"
)
@HookMethodBackup
(
"onCreate"
)
...
...
app/src/main/java/com/swift/sandhook/MyApp.java
View file @
c2bf39ef
...
@@ -9,7 +9,7 @@ public class MyApp extends Application {
...
@@ -9,7 +9,7 @@ public class MyApp extends Application {
public
void
onCreate
()
{
public
void
onCreate
()
{
super
.
onCreate
();
super
.
onCreate
();
try
{
try
{
SandHook
.
addHookClass
(
Activity
Hooker
.
class
);
SandHook
.
addHookClass
(
LogHooker
.
class
,
ActivityHooker
.
class
,
Object
Hooker
.
class
);
}
catch
(
HookErrorException
e
)
{
}
catch
(
HookErrorException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
...
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