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
f6cf74a2
Commit
f6cf74a2
authored
Jan 26, 2019
by
swift_gan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add jni test case
parent
ff86d7a9
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
1 deletion
+38
-1
README.md
README.md
+1
-0
MainActivity.java
app/src/main/java/com/swift/sandhook/MainActivity.java
+2
-0
MyApp.java
app/src/main/java/com/swift/sandhook/MyApp.java
+2
-1
TestClass.java
app/src/main/java/com/swift/sandhook/test/TestClass.java
+2
-0
JniHooker.java
...c/main/java/com/swift/sandhook/testHookers/JniHooker.java
+24
-0
native-lib.cpp
hooklib/src/main/cpp/native-lib.cpp
+7
-0
No files found.
README.md
View file @
f6cf74a2
...
@@ -17,6 +17,7 @@ Android ART Hook
...
@@ -17,6 +17,7 @@ Android ART Hook
-
Static Methods
-
Static Methods
-
Constructors
-
Constructors
-
System Methods
-
System Methods
-
JNI Methods
if you must hook an abstract method:
if you must hook an abstract method:
...
...
app/src/main/java/com/swift/sandhook/MainActivity.java
View file @
f6cf74a2
...
@@ -60,6 +60,8 @@ public class MainActivity extends AppCompatActivity {
...
@@ -60,6 +60,8 @@ public class MainActivity extends AppCompatActivity {
str
.
add1
();
str
.
add1
();
str
.
add2
();
str
.
add2
();
str
.
jni_test
();
Log
.
e
(
"dd"
,
str
.
a
+
""
);
Log
.
e
(
"dd"
,
str
.
a
+
""
);
...
...
app/src/main/java/com/swift/sandhook/MyApp.java
View file @
f6cf74a2
...
@@ -5,6 +5,7 @@ import android.app.Application;
...
@@ -5,6 +5,7 @@ import android.app.Application;
import
com.swift.sandhook.testHookers.ActivityHooker
;
import
com.swift.sandhook.testHookers.ActivityHooker
;
import
com.swift.sandhook.testHookers.CtrHook
;
import
com.swift.sandhook.testHookers.CtrHook
;
import
com.swift.sandhook.testHookers.CustmizeHooker
;
import
com.swift.sandhook.testHookers.CustmizeHooker
;
import
com.swift.sandhook.testHookers.JniHooker
;
import
com.swift.sandhook.testHookers.LogHooker
;
import
com.swift.sandhook.testHookers.LogHooker
;
import
com.swift.sandhook.testHookers.ObjectHooker
;
import
com.swift.sandhook.testHookers.ObjectHooker
;
import
com.swift.sandhook.wrapper.HookErrorException
;
import
com.swift.sandhook.wrapper.HookErrorException
;
...
@@ -14,7 +15,7 @@ public class MyApp extends Application {
...
@@ -14,7 +15,7 @@ public class MyApp extends Application {
public
void
onCreate
()
{
public
void
onCreate
()
{
super
.
onCreate
();
super
.
onCreate
();
try
{
try
{
SandHook
.
addHookClass
(
CtrHook
.
class
,
LogHooker
.
class
,
CustmizeHooker
.
class
,
ActivityHooker
.
class
,
ObjectHooker
.
class
);
SandHook
.
addHookClass
(
CtrHook
.
class
,
LogHooker
.
class
,
CustmizeHooker
.
class
,
ActivityHooker
.
class
,
ObjectHooker
.
class
,
JniHooker
.
class
);
}
catch
(
HookErrorException
e
)
{
}
catch
(
HookErrorException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
...
app/src/main/java/com/swift/sandhook/test/TestClass.java
View file @
f6cf74a2
...
@@ -20,4 +20,6 @@ public class TestClass {
...
@@ -20,4 +20,6 @@ public class TestClass {
b
++;
b
++;
}
}
public
native
void
jni_test
();
}
}
app/src/main/java/com/swift/sandhook/testHookers/JniHooker.java
0 → 100644
View file @
f6cf74a2
package
com
.
swift
.
sandhook
.
testHookers
;
import
android.util.Log
;
import
com.swift.sandhook.test.TestClass
;
import
com.swift.sandhook.wrapper.HookClass
;
import
com.swift.sandhook.wrapper.HookMethod
;
import
com.swift.sandhook.wrapper.HookMethodBackup
;
@HookClass
(
TestClass
.
class
)
public
class
JniHooker
{
@HookMethod
(
"jni_test"
)
public
static
int
onJni
(
TestClass
thiz
)
{
Log
.
e
(
"JniHooker"
,
"hooked success "
);
return
onJniBackup
(
thiz
);
}
@HookMethodBackup
(
"jni_test"
)
public
static
int
onJniBackup
(
TestClass
thiz
)
{
return
onJniBackup
(
thiz
);
}
}
hooklib/src/main/cpp/native-lib.cpp
View file @
f6cf74a2
...
@@ -181,4 +181,11 @@ Java_com_swift_sandhook_SandHook_ensureMethodCached(JNIEnv *env, jclass type, jo
...
@@ -181,4 +181,11 @@ Java_com_swift_sandhook_SandHook_ensureMethodCached(JNIEnv *env, jclass type, jo
art
::
mirror
::
ArtMethod
*
hookeMethod
=
reinterpret_cast
<
art
::
mirror
::
ArtMethod
*>
(
env
->
FromReflectedMethod
(
hook
));
art
::
mirror
::
ArtMethod
*
hookeMethod
=
reinterpret_cast
<
art
::
mirror
::
ArtMethod
*>
(
env
->
FromReflectedMethod
(
hook
));
art
::
mirror
::
ArtMethod
*
backupMethod
=
backup
==
NULL
?
nullptr
:
reinterpret_cast
<
art
::
mirror
::
ArtMethod
*>
(
env
->
FromReflectedMethod
(
backup
));
art
::
mirror
::
ArtMethod
*
backupMethod
=
backup
==
NULL
?
nullptr
:
reinterpret_cast
<
art
::
mirror
::
ArtMethod
*>
(
env
->
FromReflectedMethod
(
backup
));
ensureMethodCached
(
hookeMethod
,
backupMethod
);
ensureMethodCached
(
hookeMethod
,
backupMethod
);
}
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
;
}
}
\ No newline at end of file
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