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
c3e36683
Commit
c3e36683
authored
Mar 20, 2019
by
swift_gan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add compiler switcher
parent
b1fa5c26
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
11 deletions
+27
-11
art_method.cpp
hooklib/src/main/cpp/art/art_method.cpp
+2
-0
sandhook.cpp
hooklib/src/main/cpp/sandhook.cpp
+18
-11
hide_api.cpp
hooklib/src/main/cpp/utils/hide_api.cpp
+2
-0
SandHook.java
hooklib/src/main/java/com/swift/sandhook/SandHook.java
+4
-0
SandHookConfig.java
hooklib/src/main/java/com/swift/sandhook/SandHookConfig.java
+1
-0
No files found.
hooklib/src/main/cpp/art/art_method.cpp
View file @
c3e36683
...
...
@@ -28,6 +28,8 @@ void ArtMethod::disableInterpreterForO() {
}
void
ArtMethod
::
disableCompilable
()
{
if
(
SDK_INT
<
ANDROID_N
)
return
;
uint32_t
accessFlag
=
getAccessFlags
();
if
(
SDK_INT
>=
ANDROID_O2
)
{
accessFlag
|=
0x02000000
;
...
...
hooklib/src/main/cpp/sandhook.cpp
View file @
c3e36683
...
...
@@ -8,6 +8,7 @@ SandHook::TrampolineManager trampolineManager;
extern
"C"
int
SDK_INT
=
0
;
extern
"C"
bool
DEBUG
=
false
;
extern
"C"
volatile
bool
COMPILER
=
true
;
enum
HookMode
{
AUTO
=
0
,
...
...
@@ -64,13 +65,13 @@ bool doHookWithReplacement(JNIEnv* env,
art
::
mirror
::
ArtMethod
*
hookMethod
,
art
::
mirror
::
ArtMethod
*
backupMethod
)
{
hookMethod
->
compile
(
env
);
if
(
!
hookMethod
->
compile
(
env
))
{
hookMethod
->
disableCompilable
();
}
if
(
backupMethod
!=
nullptr
)
{
originMethod
->
backup
(
backupMethod
);
if
(
SDK_INT
>=
ANDROID_N
)
{
backupMethod
->
disableCompilable
();
}
backupMethod
->
disableCompilable
();
backupMethod
->
disableInterpreterForO
();
backupMethod
->
tryDisableInline
();
if
(
!
backupMethod
->
isStatic
())
{
...
...
@@ -79,13 +80,11 @@ bool doHookWithReplacement(JNIEnv* env,
backupMethod
->
flushCache
();
}
if
(
SDK_INT
>=
ANDROID_N
)
{
originMethod
->
disableCompilable
();
hookMethod
->
disableCompilable
();
hookMethod
->
flushCache
();
}
originMethod
->
tryDisableInline
();
originMethod
->
disableCompilable
();
hookMethod
->
disableCompilable
();
hookMethod
->
flushCache
();
originMethod
->
tryDisableInline
();
originMethod
->
disableInterpreterForO
();
SandHook
::
HookTrampoline
*
hookTrampoline
=
trampolineManager
.
installReplacementTrampoline
(
originMethod
,
hookMethod
,
backupMethod
);
...
...
@@ -112,7 +111,9 @@ bool doHookWithInline(JNIEnv* env,
art
::
mirror
::
ArtMethod
*
backupMethod
)
{
//fix >= 8.1
hookMethod
->
compile
(
env
);
if
(
!
hookMethod
->
compile
(
env
))
{
hookMethod
->
disableCompilable
();
}
if
(
SDK_INT
>=
ANDROID_N
)
{
originMethod
->
disableCompilable
();
...
...
@@ -317,6 +318,12 @@ Java_com_swift_sandhook_SandHook_disableVMInline(JNIEnv *env, jclass type) {
return
static_cast
<
jboolean
>
(
disableJitInline
(
compilerOptions
));
}
extern
"C"
JNIEXPORT
void
JNICALL
Java_com_swift_sandhook_SandHook_enableCompiler
(
JNIEnv
*
env
,
jclass
type
,
jboolean
enable
)
{
COMPILER
=
enable
;
}
extern
"C"
JNIEXPORT
void
JNICALL
Java_com_swift_sandhook_test_TestClass_jni_1test
(
JNIEnv
*
env
,
jobject
instance
)
{
...
...
hooklib/src/main/cpp/utils/hide_api.cpp
View file @
c3e36683
...
...
@@ -7,6 +7,7 @@
#include "../includes/log.h"
extern
int
SDK_INT
;
extern
bool
COMPILER
;
extern
"C"
{
...
...
@@ -97,6 +98,7 @@ extern "C" {
}
bool
compileMethod
(
void
*
artMethod
,
void
*
thread
)
{
if
(
!
COMPILER
)
return
false
;
if
(
SDK_INT
>=
ANDROID_Q
)
{
if
(
jitCompileMethodQ
==
nullptr
)
{
return
false
;
...
...
hooklib/src/main/java/com/swift/sandhook/SandHook.java
View file @
c3e36683
...
...
@@ -52,6 +52,7 @@ public class SandHook {
initTestOffset
();
initThreadPeer
();
SandHookMethodResolver
.
init
();
enableCompiler
(
SandHookConfig
.
compiler
);
return
initNative
(
SandHookConfig
.
SDK_INT
,
SandHookConfig
.
DEBUG
);
}
...
...
@@ -319,6 +320,9 @@ public class SandHook {
public
static
native
boolean
disableVMInline
();
//compile error when in zygote process
public
static
native
void
enableCompiler
(
boolean
enable
);
@FunctionalInterface
public
interface
HookModeCallBack
{
int
hookMode
(
Member
originMethod
);
...
...
hooklib/src/main/java/com/swift/sandhook/SandHookConfig.java
View file @
c3e36683
...
...
@@ -8,4 +8,5 @@ public class SandHookConfig {
public
volatile
static
int
SDK_INT
=
Build
.
VERSION
.
SDK_INT
;
public
volatile
static
String
libSandHookPath
;
public
volatile
static
boolean
DEBUG
=
BuildConfig
.
DEBUG
;
public
volatile
static
boolean
compiler
=
true
;
}
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