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
6e652fbf
Commit
6e652fbf
authored
Mar 20, 2019
by
swift_gan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tweak compile switcher
parent
2de02441
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
19 deletions
+29
-19
utils.h
hooklib/src/main/cpp/includes/utils.h
+2
-0
sandhook.cpp
hooklib/src/main/cpp/sandhook.cpp
+0
-7
hide_api.cpp
hooklib/src/main/cpp/utils/hide_api.cpp
+13
-8
utils.cpp
hooklib/src/main/cpp/utils/utils.cpp
+14
-0
SandHook.java
hooklib/src/main/java/com/swift/sandhook/SandHook.java
+0
-4
No files found.
hooklib/src/main/cpp/includes/utils.h
View file @
6e652fbf
...
...
@@ -20,6 +20,8 @@ extern "C" {
jint
getIntFromJava
(
JNIEnv
*
env
,
const
char
*
className
,
const
char
*
fieldName
);
bool
getBooleanFromJava
(
JNIEnv
*
env
,
const
char
*
className
,
const
char
*
fieldName
);
bool
munprotect
(
size_t
addr
,
size_t
len
);
bool
flushCacheExt
(
Size
addr
,
Size
len
);
...
...
hooklib/src/main/cpp/sandhook.cpp
View file @
6e652fbf
...
...
@@ -8,7 +8,6 @@ SandHook::TrampolineManager trampolineManager;
extern
"C"
int
SDK_INT
=
0
;
extern
"C"
bool
DEBUG
=
false
;
extern
"C"
volatile
bool
COMPILER
=
true
;
enum
HookMode
{
AUTO
=
0
,
...
...
@@ -318,12 +317,6 @@ 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 @
6e652fbf
...
...
@@ -5,9 +5,9 @@
#include "../includes/arch.h"
#include "../includes/elf_util.h"
#include "../includes/log.h"
#include "../includes/utils.h"
extern
int
SDK_INT
;
extern
bool
COMPILER
;
extern
"C"
{
...
...
@@ -30,10 +30,12 @@ extern "C" {
const
char
*
art_lib_path
;
const
char
*
jit_lib_path
;
JavaVM
*
jvm
;
void
initHideApi
(
JNIEnv
*
env
)
{
env
->
GetJavaVM
(
&
jvm
);
if
(
BYTE_POINT
==
8
)
{
art_lib_path
=
"/system/lib64/libart.so"
;
jit_lib_path
=
"/system/lib64/libart-compiler.so"
;
...
...
@@ -97,8 +99,15 @@ extern "C" {
}
bool
canCompile
()
{
JNIEnv
*
env
;
jvm
->
GetEnv
(
reinterpret_cast
<
void
**>
(
&
env
),
JNI_VERSION_1_6
);
return
getBooleanFromJava
(
env
,
"com/swift/sandhook/SandHookConfig"
,
"compiler"
);
}
bool
compileMethod
(
void
*
artMethod
,
void
*
thread
)
{
if
(
!
COMPILER
)
return
false
;
if
(
!
canCompile
()
)
return
false
;
if
(
SDK_INT
>=
ANDROID_Q
)
{
if
(
jitCompileMethodQ
==
nullptr
)
{
return
false
;
...
...
@@ -133,11 +142,7 @@ extern "C" {
if
(
addWeakGlobalRef
==
nullptr
)
return
NULL
;
JavaVM
*
vm
;
env
->
GetJavaVM
(
&
vm
);
jobject
object
=
addWeakGlobalRef
(
vm
,
thread
,
address
);
jobject
object
=
addWeakGlobalRef
(
jvm
,
thread
,
address
);
if
(
object
==
NULL
)
return
NULL
;
...
...
hooklib/src/main/cpp/utils/utils.cpp
View file @
6e652fbf
...
...
@@ -48,6 +48,20 @@ extern "C" {
return
env
->
GetStaticIntField
(
clazz
,
id
);
}
bool
getBooleanFromJava
(
JNIEnv
*
env
,
const
char
*
className
,
const
char
*
fieldName
)
{
jclass
clazz
=
env
->
FindClass
(
className
);
if
(
clazz
==
NULL
)
{
printf
(
"find class error !"
);
return
false
;
}
jfieldID
id
=
env
->
GetStaticFieldID
(
clazz
,
fieldName
,
"Z"
);
if
(
id
==
NULL
)
{
printf
(
"find field error !"
);
return
false
;
}
return
env
->
GetStaticBooleanField
(
clazz
,
id
);
}
bool
munprotect
(
size_t
addr
,
size_t
len
)
{
long
pagesize
=
sysconf
(
_SC_PAGESIZE
);
unsigned
alignment
=
(
unsigned
)
((
unsigned
long
long
)
addr
%
pagesize
);
...
...
hooklib/src/main/java/com/swift/sandhook/SandHook.java
View file @
6e652fbf
...
...
@@ -52,7 +52,6 @@ public class SandHook {
initTestOffset
();
initThreadPeer
();
SandHookMethodResolver
.
init
();
enableCompiler
(
SandHookConfig
.
compiler
);
return
initNative
(
SandHookConfig
.
SDK_INT
,
SandHookConfig
.
DEBUG
);
}
...
...
@@ -320,9 +319,6 @@ 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
);
...
...
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