Commit f6cf74a2 authored by swift_gan's avatar swift_gan

add jni test case

parent ff86d7a9
...@@ -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:
......
...@@ -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 + "");
......
...@@ -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();
} }
......
...@@ -20,4 +20,6 @@ public class TestClass { ...@@ -20,4 +20,6 @@ public class TestClass {
b++; b++;
} }
public native void jni_test();
} }
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);
}
}
...@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment