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
67982050
Commit
67982050
authored
Mar 21, 2019
by
swift_gan
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
8aa1f24a
64575661
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
162 additions
and
32 deletions
+162
-32
build.gradle
build.gradle
+1
-1
sandhook.cpp
hooklib/src/main/cpp/sandhook.cpp
+134
-24
SandHook.java
hooklib/src/main/java/com/swift/sandhook/SandHook.java
+6
-6
SandHookConfig.java
hooklib/src/main/java/com/swift/sandhook/SandHookConfig.java
+21
-1
No files found.
build.gradle
View file @
67982050
...
...
@@ -30,7 +30,7 @@ ext {
userOrg
=
'ganyao114'
groupId
=
'com.swift.sandhook'
repoName
=
'SandHook'
publishVersion
=
'3.
0.2
'
publishVersion
=
'3.
2.0
'
desc
=
'android art hook'
website
=
'https://github.com/ganyao114/SandHook'
licences
=
[
'Apache-2.0'
]
...
...
hooklib/src/main/cpp/sandhook.cpp
View file @
67982050
...
...
@@ -3,6 +3,7 @@
#include "includes/trampoline_manager.h"
#include "includes/hide_api.h"
#include "includes/cast_compiler_options.h"
#include "includes/log.h"
SandHook
::
TrampolineManager
trampolineManager
;
...
...
@@ -17,21 +18,6 @@ enum HookMode {
HookMode
gHookMode
=
AUTO
;
extern
"C"
JNIEXPORT
jboolean
JNICALL
Java_com_swift_sandhook_SandHook_initNative
(
JNIEnv
*
env
,
jclass
type
,
jint
sdk
,
jboolean
debug
)
{
// TODO
SDK_INT
=
sdk
;
DEBUG
=
debug
;
initHideApi
(
env
);
SandHook
::
CastArtMethod
::
init
(
env
);
SandHook
::
CastCompilerOptions
::
init
(
env
);
trampolineManager
.
init
(
SandHook
::
CastArtMethod
::
entryPointQuickCompiled
->
getOffset
());
return
JNI_TRUE
;
}
void
ensureMethodCached
(
art
::
mirror
::
ArtMethod
*
hookMethod
,
art
::
mirror
::
ArtMethod
*
backupMethod
)
{
if
(
SDK_INT
>=
ANDROID_P
)
return
;
...
...
@@ -144,6 +130,22 @@ bool doHookWithInline(JNIEnv* env,
return
true
;
}
extern
"C"
JNIEXPORT
jboolean
JNICALL
Java_com_swift_sandhook_SandHook_initNative
(
JNIEnv
*
env
,
jclass
type
,
jint
sdk
,
jboolean
debug
)
{
// TODO
SDK_INT
=
sdk
;
DEBUG
=
debug
;
initHideApi
(
env
);
SandHook
::
CastArtMethod
::
init
(
env
);
SandHook
::
CastCompilerOptions
::
init
(
env
);
trampolineManager
.
init
(
SandHook
::
CastArtMethod
::
entryPointQuickCompiled
->
getOffset
());
return
JNI_TRUE
;
}
extern
"C"
JNIEXPORT
jint
JNICALL
Java_com_swift_sandhook_SandHook_hookMethod
(
JNIEnv
*
env
,
jclass
type
,
jobject
originMethod
,
...
...
@@ -319,24 +321,132 @@ Java_com_swift_sandhook_SandHook_disableVMInline(JNIEnv *env, jclass type) {
extern
"C"
JNIEXPORT
void
JNICALL
Java_com_swift_sandhook_test_TestClass_jni_1test
(
JNIEnv
*
env
,
jobject
instance
)
{
Java_com_swift_sandhook_ClassNeverCall_neverCallNative
(
JNIEnv
*
env
,
jobject
instance
)
{
int
a
=
1
+
1
;
int
b
=
a
+
1
;
}
extern
"C"
JNIEXPORT
void
JNICALL
Java_com_swift_sandhook_ClassNeverCall_neverCallNative
(
JNIEnv
*
env
,
jobject
instance
)
{
Java_com_swift_sandhook_ClassNeverCall_neverCallNative2
(
JNIEnv
*
env
,
jobject
instance
)
{
int
a
=
4
+
3
;
int
b
=
9
+
6
;
}
// TODO
extern
"C"
JNIEXPORT
void
JNICALL
Java_com_swift_sandhook_test_TestClass_jni_1test
(
JNIEnv
*
env
,
jobject
instance
)
{
int
a
=
1
+
1
;
int
b
=
a
+
1
;
}
static
JNINativeMethod
jniSandHook
[]
=
{
{
"initNative"
,
"(IZ)Z"
,
(
void
*
)
Java_com_swift_sandhook_SandHook_initNative
},
{
"hookMethod"
,
"(Ljava/lang/reflect/Member;Ljava/lang/reflect/Method;Ljava/lang/reflect/Method;I)I"
,
(
void
*
)
Java_com_swift_sandhook_SandHook_hookMethod
},
{
"ensureMethodCached"
,
"(Ljava/lang/reflect/Method;Ljava/lang/reflect/Method;)V"
,
(
void
*
)
Java_com_swift_sandhook_SandHook_ensureMethodCached
},
{
"compileMethod"
,
"(Ljava/lang/reflect/Member;)Z"
,
(
void
*
)
Java_com_swift_sandhook_SandHook_compileMethod
},
{
"deCompileMethod"
,
"(Ljava/lang/reflect/Member;Z)Z"
,
(
void
*
)
Java_com_swift_sandhook_SandHook_deCompileMethod
},
{
"getObjectNative"
,
"(JJ)Ljava/lang/Object;"
,
(
void
*
)
Java_com_swift_sandhook_SandHook_getObjectNative
},
{
"canGetObject"
,
"()Z"
,
(
void
*
)
Java_com_swift_sandhook_SandHook_canGetObject
},
{
"setHookMode"
,
"(I)V"
,
(
void
*
)
Java_com_swift_sandhook_SandHook_setHookMode
},
{
"setInlineSafeCheck"
,
"(Z)V"
,
(
void
*
)
Java_com_swift_sandhook_SandHook_setInlineSafeCheck
},
{
"skipAllSafeCheck"
,
"(Z)V"
,
(
void
*
)
Java_com_swift_sandhook_SandHook_skipAllSafeCheck
},
{
"is64Bit"
,
"()Z"
,
(
void
*
)
Java_com_swift_sandhook_SandHook_is64Bit
},
{
"disableVMInline"
,
"()Z"
,
(
void
*
)
Java_com_swift_sandhook_SandHook_disableVMInline
}
};
static
JNINativeMethod
jniNeverCall
[]
=
{
{
"neverCallNative"
,
"()V"
,
(
void
*
)
Java_com_swift_sandhook_ClassNeverCall_neverCallNative
},
{
"neverCallNative2"
,
"()V"
,
(
void
*
)
Java_com_swift_sandhook_ClassNeverCall_neverCallNative2
}
};
static
bool
registerNativeMethods
(
JNIEnv
*
env
,
const
char
*
className
,
JNINativeMethod
*
jniMethods
,
int
methods
)
{
jclass
clazz
=
env
->
FindClass
(
className
);
if
(
clazz
==
NULL
)
{
return
false
;
}
return
env
->
RegisterNatives
(
clazz
,
jniMethods
,
methods
)
>=
0
;
}
extern
"C"
JNIEXPORT
void
JNICALL
Java_com_swift_sandhook_ClassNeverCall_neverCallNative2
(
JNIEnv
*
env
,
jobject
instance
)
{
int
a
=
4
+
3
;
int
b
=
9
+
6
;
JNIEXPORT
jint
JNICALL
JNI_OnLoad
(
JavaVM
*
vm
,
void
*
reserved
)
{
const
char
*
CLASS_SAND_HOOK
=
"com/swift/sandhook/SandHook"
;
const
char
*
CLASS_NEVER_CALL
=
"com/swift/sandhook/ClassNeverCall"
;
int
jniMethodSize
=
sizeof
(
JNINativeMethod
);
JNIEnv
*
env
=
NULL
;
if
(
vm
->
GetEnv
((
void
**
)
&
env
,
JNI_VERSION_1_6
)
!=
JNI_OK
)
{
return
-
1
;
}
if
(
!
registerNativeMethods
(
env
,
CLASS_SAND_HOOK
,
jniSandHook
,
sizeof
(
jniSandHook
)
/
jniMethodSize
))
{
return
-
1
;
}
if
(
!
registerNativeMethods
(
env
,
CLASS_NEVER_CALL
,
jniNeverCall
,
sizeof
(
jniNeverCall
)
/
jniMethodSize
))
{
return
-
1
;
}
LOGW
(
"JNI Loaded"
);
return
JNI_VERSION_1_6
;
}
\ No newline at end of file
hooklib/src/main/java/com/swift/sandhook/SandHook.java
View file @
67982050
...
...
@@ -40,11 +40,7 @@ public class SandHook {
public
static
int
testAccessFlag
;
static
{
if
(
SandHookConfig
.
libSandHookPath
==
null
||
SandHookConfig
.
libSandHookPath
.
length
()
==
0
)
{
System
.
loadLibrary
(
"sandhook"
);
}
else
{
System
.
load
(
SandHookConfig
.
libSandHookPath
);
}
SandHookConfig
.
libLoader
.
loadLib
();
init
();
}
...
...
@@ -259,7 +255,11 @@ public class SandHook {
if
(
artMethodClass
!=
null
)
return
true
;
try
{
artMethodClass
=
Class
.
forName
(
"java.lang.reflect.ArtMethod"
);
if
(
SandHookConfig
.
initClassLoader
==
null
)
{
artMethodClass
=
Class
.
forName
(
"java.lang.reflect.ArtMethod"
);
}
else
{
artMethodClass
=
Class
.
forName
(
"java.lang.reflect.ArtMethod"
,
true
,
SandHookConfig
.
initClassLoader
);
}
return
true
;
}
catch
(
ClassNotFoundException
e
)
{
return
false
;
...
...
hooklib/src/main/java/com/swift/sandhook/SandHookConfig.java
View file @
67982050
package
com
.
swift
.
sandhook
;
import
android.annotation.SuppressLint
;
import
android.os.Build
;
import
com.swift.sandhook.lib.BuildConfig
;
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
;
public
volatile
static
ClassLoader
initClassLoader
;
public
volatile
static
String
libSandHookPath
;
public
volatile
static
LibLoader
libLoader
=
new
LibLoader
()
{
@SuppressLint
(
"UnsafeDynamicallyLoadedCode"
)
@Override
public
void
loadLib
()
{
if
(
SandHookConfig
.
libSandHookPath
==
null
)
{
System
.
loadLibrary
(
"sandhook"
);
}
else
{
System
.
load
(
SandHookConfig
.
libSandHookPath
);
}
}
};
public
interface
LibLoader
{
void
loadLib
();
}
}
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