Commit f6cf74a2 authored by swift_gan's avatar swift_gan

add jni test case

parent ff86d7a9
......@@ -17,6 +17,7 @@ Android ART Hook
- Static Methods
- Constructors
- System Methods
- JNI Methods
if you must hook an abstract method:
......
......@@ -60,6 +60,8 @@ public class MainActivity extends AppCompatActivity {
str.add1();
str.add2();
str.jni_test();
Log.e("dd", str.a + "");
......
......@@ -5,6 +5,7 @@ import android.app.Application;
import com.swift.sandhook.testHookers.ActivityHooker;
import com.swift.sandhook.testHookers.CtrHook;
import com.swift.sandhook.testHookers.CustmizeHooker;
import com.swift.sandhook.testHookers.JniHooker;
import com.swift.sandhook.testHookers.LogHooker;
import com.swift.sandhook.testHookers.ObjectHooker;
import com.swift.sandhook.wrapper.HookErrorException;
......@@ -14,7 +15,7 @@ public class MyApp extends Application {
public void onCreate() {
super.onCreate();
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) {
e.printStackTrace();
}
......
......@@ -20,4 +20,6 @@ public class TestClass {
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
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));
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