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
a4a49bb9
Commit
a4a49bb9
authored
Jan 30, 2019
by
swift_gan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix call origin with android p 32bit
parent
bd2c91b1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
5 deletions
+45
-5
sandhook.cpp
hooklib/src/main/cpp/sandhook.cpp
+45
-5
No files found.
hooklib/src/main/cpp/sandhook.cpp
View file @
a4a49bb9
...
@@ -30,18 +30,35 @@ void disableCompilable(art::mirror::ArtMethod* method) {
...
@@ -30,18 +30,35 @@ void disableCompilable(art::mirror::ArtMethod* method) {
uint32_t
accessFlag
=
SandHook
::
CastArtMethod
::
accessFlag
->
get
(
method
);
uint32_t
accessFlag
=
SandHook
::
CastArtMethod
::
accessFlag
->
get
(
method
);
if
(
SDK_INT
>=
ANDROID_O2
)
{
if
(
SDK_INT
>=
ANDROID_O2
)
{
accessFlag
|=
0x02000000
;
accessFlag
|=
0x02000000
;
accessFlag
|=
0x00800000
;
}
else
{
}
else
{
accessFlag
|=
0x01000000
;
accessFlag
|=
0x01000000
;
}
}
SandHook
::
CastArtMethod
::
accessFlag
->
set
(
method
,
accessFlag
);
SandHook
::
CastArtMethod
::
accessFlag
->
set
(
method
,
accessFlag
);
}
}
void
tryDisableInline
(
art
::
mirror
::
ArtMethod
*
method
)
{
if
(
method
==
nullptr
)
return
;
if
(
SDK_INT
<
ANDROID_O
)
return
;
uint32_t
accessFlag
=
SandHook
::
CastArtMethod
::
accessFlag
->
get
(
method
);
accessFlag
&=
~
0x08000000
;
SandHook
::
CastArtMethod
::
accessFlag
->
set
(
method
,
accessFlag
);
}
void
disableInterpreterForO
(
art
::
mirror
::
ArtMethod
*
method
)
{
void
disableInterpreterForO
(
art
::
mirror
::
ArtMethod
*
method
)
{
uint32_t
accessFlag
=
SandHook
::
CastArtMethod
::
accessFlag
->
get
(
method
);
uint32_t
accessFlag
=
SandHook
::
CastArtMethod
::
accessFlag
->
get
(
method
);
accessFlag
|=
0x0100
;
accessFlag
|=
0x0100
;
SandHook
::
CastArtMethod
::
accessFlag
->
set
(
method
,
accessFlag
);
SandHook
::
CastArtMethod
::
accessFlag
->
set
(
method
,
accessFlag
);
}
}
void
disableAccessCheck
(
art
::
mirror
::
ArtMethod
*
method
)
{
uint32_t
accessFlag
=
SandHook
::
CastArtMethod
::
accessFlag
->
get
(
method
);
accessFlag
|=
0x00080000
;
SandHook
::
CastArtMethod
::
accessFlag
->
set
(
method
,
accessFlag
);
}
void
setPrivate
(
art
::
mirror
::
ArtMethod
*
method
)
{
void
setPrivate
(
art
::
mirror
::
ArtMethod
*
method
)
{
uint32_t
accessFlag
=
SandHook
::
CastArtMethod
::
accessFlag
->
get
(
method
);
uint32_t
accessFlag
=
SandHook
::
CastArtMethod
::
accessFlag
->
get
(
method
);
accessFlag
&=
~
0x1
;
accessFlag
&=
~
0x1
;
...
@@ -49,6 +66,12 @@ void setPrivate(art::mirror::ArtMethod* method) {
...
@@ -49,6 +66,12 @@ void setPrivate(art::mirror::ArtMethod* method) {
SandHook
::
CastArtMethod
::
accessFlag
->
set
(
method
,
accessFlag
);
SandHook
::
CastArtMethod
::
accessFlag
->
set
(
method
,
accessFlag
);
}
}
void
setStatic
(
art
::
mirror
::
ArtMethod
*
method
)
{
uint32_t
accessFlag
=
SandHook
::
CastArtMethod
::
accessFlag
->
get
(
method
);
accessFlag
|=
0x0008
;
SandHook
::
CastArtMethod
::
accessFlag
->
set
(
method
,
accessFlag
);
}
bool
isAbsMethod
(
art
::
mirror
::
ArtMethod
*
method
)
{
bool
isAbsMethod
(
art
::
mirror
::
ArtMethod
*
method
)
{
uint32_t
accessFlags
=
SandHook
::
CastArtMethod
::
accessFlag
->
get
(
method
);
uint32_t
accessFlags
=
SandHook
::
CastArtMethod
::
accessFlag
->
get
(
method
);
return
((
accessFlags
&
0x0400
)
!=
0
);
return
((
accessFlags
&
0x0400
)
!=
0
);
...
@@ -92,6 +115,16 @@ bool doHookWithReplacement(art::mirror::ArtMethod *originMethod,
...
@@ -92,6 +115,16 @@ bool doHookWithReplacement(art::mirror::ArtMethod *originMethod,
}
}
if
(
backupMethod
!=
nullptr
)
{
if
(
backupMethod
!=
nullptr
)
{
memcpy
(
backupMethod
,
originMethod
,
SandHook
::
CastArtMethod
::
size
);
memcpy
(
backupMethod
,
originMethod
,
SandHook
::
CastArtMethod
::
size
);
if
(
SDK_INT
>=
ANDROID_N
)
{
disableCompilable
(
backupMethod
);
}
if
(
SDK_INT
>=
ANDROID_O
)
{
disableInterpreterForO
(
backupMethod
);
}
tryDisableInline
(
backupMethod
);
disableAccessCheck
(
backupMethod
);
setPrivate
(
backupMethod
);
SandHook
::
Trampoline
::
flushCache
(
reinterpret_cast
<
Size
>
(
originMethod
),
SandHook
::
CastArtMethod
::
size
);
}
}
if
(
SDK_INT
>=
ANDROID_O
)
{
if
(
SDK_INT
>=
ANDROID_O
)
{
disableInterpreterForO
(
originMethod
);
disableInterpreterForO
(
originMethod
);
...
@@ -128,13 +161,13 @@ bool doHookWithInline(JNIEnv* env,
...
@@ -128,13 +161,13 @@ bool doHookWithInline(JNIEnv* env,
SandHook
::
Trampoline
::
flushCache
(
reinterpret_cast
<
Size
>
(
originMethod
),
SandHook
::
CastArtMethod
::
size
);
SandHook
::
Trampoline
::
flushCache
(
reinterpret_cast
<
Size
>
(
originMethod
),
SandHook
::
CastArtMethod
::
size
);
}
}
tryDisableInline
(
originMethod
);
disableAccessCheck
(
originMethod
);
SandHook
::
HookTrampoline
*
hookTrampoline
=
trampolineManager
.
installInlineTrampoline
(
originMethod
,
hookMethod
,
backupMethod
,
isNative
(
originMethod
));
SandHook
::
HookTrampoline
*
hookTrampoline
=
trampolineManager
.
installInlineTrampoline
(
originMethod
,
hookMethod
,
backupMethod
,
isNative
(
originMethod
));
if
(
hookTrampoline
==
nullptr
)
if
(
hookTrampoline
==
nullptr
)
return
false
;
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
...
@@ -148,7 +181,9 @@ bool doHookWithInline(JNIEnv* env,
...
@@ -148,7 +181,9 @@ bool doHookWithInline(JNIEnv* env,
if
(
SDK_INT
>=
ANDROID_O
)
{
if
(
SDK_INT
>=
ANDROID_O
)
{
disableInterpreterForO
(
backupMethod
);
disableInterpreterForO
(
backupMethod
);
}
}
//setPrivate(backupMethod);
tryDisableInline
(
backupMethod
);
disableAccessCheck
(
backupMethod
);
setPrivate
(
backupMethod
);
hookTrampoline
->
callOrigin
->
flushCache
(
reinterpret_cast
<
Size
>
(
backupMethod
),
SandHook
::
CastArtMethod
::
size
);
hookTrampoline
->
callOrigin
->
flushCache
(
reinterpret_cast
<
Size
>
(
backupMethod
),
SandHook
::
CastArtMethod
::
size
);
}
}
return
true
;
return
true
;
...
@@ -187,6 +222,11 @@ Java_com_swift_sandhook_SandHook_hookMethod(JNIEnv *env, jclass type, jobject or
...
@@ -187,6 +222,11 @@ Java_com_swift_sandhook_SandHook_hookMethod(JNIEnv *env, jclass type, jobject or
}
}
if
(
SDK_INT
>=
ANDROID_P
&&
BYTE_POINT
==
4
)
{
if
(
SDK_INT
>=
ANDROID_P
&&
BYTE_POINT
==
4
)
{
bool
isInterpreter
=
SandHook
::
CastArtMethod
::
entryPointQuickCompiled
->
get
(
hook
)
==
SandHook
::
CastArtMethod
::
quickToInterpreterBridge
;
if
(
isInterpreter
)
{
Size
threadId
=
getAddressFromJavaByCallMethod
(
env
,
"com/swift/sandhook/SandHook"
,
"getThreadId"
);
compileMethod
(
hook
,
reinterpret_cast
<
void
*>
(
threadId
));
}
return
static_cast
<
jboolean
>
(
doHookWithReplacement
(
origin
,
hook
,
backup
));
return
static_cast
<
jboolean
>
(
doHookWithReplacement
(
origin
,
hook
,
backup
));
}
else
if
(
isAbsMethod
(
origin
))
{
}
else
if
(
isAbsMethod
(
origin
))
{
return
static_cast
<
jboolean
>
(
doHookWithReplacement
(
origin
,
hook
,
backup
));
return
static_cast
<
jboolean
>
(
doHookWithReplacement
(
origin
,
hook
,
backup
));
...
...
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