Commit 4cbbcb53 authored by swift_gan's avatar swift_gan

add test case

parent 779037e4
...@@ -12,6 +12,7 @@ import android.view.Menu; ...@@ -12,6 +12,7 @@ import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.Toast; import android.widget.Toast;
import com.swift.sandhook.test.TestClass;
import com.swift.sandhook.wrapper.HookErrorException; import com.swift.sandhook.wrapper.HookErrorException;
import com.swift.sandhook.wrapper.HookWrapper; import com.swift.sandhook.wrapper.HookWrapper;
...@@ -54,6 +55,14 @@ public class MainActivity extends AppCompatActivity { ...@@ -54,6 +55,14 @@ public class MainActivity extends AppCompatActivity {
// Example of a call to a native method // Example of a call to a native method
TextView tv = (TextView) findViewById(R.id.sample_text); TextView tv = (TextView) findViewById(R.id.sample_text);
TestClass str = new TestClass(1);
str.add1();
str.add2();
Log.e("dd", str.a + "");
} }
public static Field getField(Class topClass, String fieldName) throws NoSuchFieldException { public static Field getField(Class topClass, String fieldName) throws NoSuchFieldException {
......
...@@ -2,10 +2,11 @@ package com.swift.sandhook; ...@@ -2,10 +2,11 @@ package com.swift.sandhook;
import android.app.Application; import android.app.Application;
import com.swift.sandhook.test.ActivityHooker; import com.swift.sandhook.testHookers.ActivityHooker;
import com.swift.sandhook.test.CustmizeHooker; import com.swift.sandhook.testHookers.CtrHook;
import com.swift.sandhook.test.LogHooker; import com.swift.sandhook.testHookers.CustmizeHooker;
import com.swift.sandhook.test.ObjectHooker; import com.swift.sandhook.testHookers.LogHooker;
import com.swift.sandhook.testHookers.ObjectHooker;
import com.swift.sandhook.wrapper.HookErrorException; import com.swift.sandhook.wrapper.HookErrorException;
public class MyApp extends Application { public class MyApp extends Application {
...@@ -13,7 +14,7 @@ public class MyApp extends Application { ...@@ -13,7 +14,7 @@ public class MyApp extends Application {
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
try { try {
SandHook.addHookClass(LogHooker.class, CustmizeHooker.class, ActivityHooker.class, ObjectHooker.class); SandHook.addHookClass(CtrHook.class, LogHooker.class, CustmizeHooker.class, ActivityHooker.class, ObjectHooker.class);
} catch (HookErrorException e) { } catch (HookErrorException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
package com.swift.sandhook.test;
public class TestClass {
public int a = 1;
int b = 2;
public TestClass(int a) {
this.a = a + 1;
}
public void add1 () {
a++;
b++;
}
public void add2 () {
a++;
b++;
}
}
package com.swift.sandhook.test; package com.swift.sandhook.testHookers;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
......
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;
import com.swift.sandhook.wrapper.MethodParams;
@HookClass(TestClass.class)
public class CtrHook {
@HookMethod
@MethodParams(int.class)
public static void onCtr(TestClass thiz, int a) {
Log.e("TestClassHook", "TestClass(int) been hooked");
onCtrBackup(thiz, a);
}
@HookMethodBackup
@MethodParams(int.class)
public static void onCtrBackup(TestClass thiz, int a) {
onCtrBackup(thiz, a);
}
@HookMethod("add1")
public static void onAdd1(TestClass thiz) {
Log.e("TestClassHook", "add1 been hooked");
onAdd1Backup(thiz);
}
@HookMethodBackup("add1")
public static void onAdd1Backup(TestClass thiz) {
onAdd1Backup(thiz);
}
@HookMethod("add2")
public static void onAdd2(TestClass thiz) {
Log.e("TestClassHook", "add2 been hooked");
onAdd2Backup(thiz);
}
@HookMethodBackup("add2")
public static void onAdd2Backup(TestClass thiz) {
onAdd2Backup(thiz);
}
}
package com.swift.sandhook.test; package com.swift.sandhook.testHookers;
import android.util.Log; import android.util.Log;
......
package com.swift.sandhook.test; package com.swift.sandhook.testHookers;
import android.util.Log; import android.util.Log;
......
package com.swift.sandhook.test; package com.swift.sandhook.testHookers;
import android.util.Log; import android.util.Log;
......
...@@ -64,8 +64,8 @@ x22 - x28 貌似可以使用 ...@@ -64,8 +64,8 @@ x22 - x28 貌似可以使用
#if defined(__aarch64__) #if defined(__aarch64__)
#define Reg0 x24 #define Reg0 x23
#define Reg1 x25 #define Reg1 x24
#define RegMethod x0 #define RegMethod x0
FUNCTION_START(REPLACEMENT_HOOK_TRAMPOLINE) FUNCTION_START(REPLACEMENT_HOOK_TRAMPOLINE)
......
...@@ -45,7 +45,6 @@ public class SandHookMethodResolver { ...@@ -45,7 +45,6 @@ public class SandHookMethodResolver {
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
} }
} }
......
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