Commit 59726be9 authored by swift_gan's avatar swift_gan

tweak demo

parent 23b25448
...@@ -4,6 +4,7 @@ import android.app.Activity; ...@@ -4,6 +4,7 @@ import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import com.swift.sandhook.SandHook;
import com.swift.sandhook.annotation.HookClass; import com.swift.sandhook.annotation.HookClass;
import com.swift.sandhook.annotation.HookMethod; import com.swift.sandhook.annotation.HookMethod;
import com.swift.sandhook.annotation.HookMethodBackup; import com.swift.sandhook.annotation.HookMethodBackup;
...@@ -24,28 +25,15 @@ public class ActivityHooker { ...@@ -24,28 +25,15 @@ public class ActivityHooker {
@HookMethod("onCreate") @HookMethod("onCreate")
@MethodParams(Bundle.class) @MethodParams(Bundle.class)
public static void onCreate(Activity thiz, Bundle bundle) { public static void onCreate(Activity thiz, Bundle bundle) throws Throwable {
Log.e("ActivityHooker", "hooked onCreate success " + thiz); Log.e("ActivityHooker", "hooked onCreate success " + thiz);
onCreateBackup(thiz, bundle); SandHook.callOriginByBackup(onCreateBackup, thiz, bundle);
}
@HookMethodBackup("onCreate")
@MethodParams(Bundle.class)
public static void onCreateBackup(Activity thiz, Bundle bundle) {
//invoke self to kill inline
onCreateBackup(thiz, bundle);
} }
@HookMethod("onPause") @HookMethod("onPause")
public static void onPause(@ThisObject Activity thiz) { public static void onPause(@ThisObject Activity thiz) throws Throwable {
Log.e("ActivityHooker", "hooked onPause success " + thiz); Log.e("ActivityHooker", "hooked onPause success " + thiz);
onPauseBackup(thiz); SandHook.callOriginByBackup(onPauseBackup, thiz);
}
@HookMethodBackup("onPause")
public static void onPauseBackup(@ThisObject Activity thiz) {
//invoke self to kill inline
onPauseBackup(thiz);
} }
} }
...@@ -2,54 +2,50 @@ package com.swift.sandhook.testHookers; ...@@ -2,54 +2,50 @@ package com.swift.sandhook.testHookers;
import android.util.Log; import android.util.Log;
import com.swift.sandhook.SandHook;
import com.swift.sandhook.annotation.HookClass; import com.swift.sandhook.annotation.HookClass;
import com.swift.sandhook.annotation.HookMethod; import com.swift.sandhook.annotation.HookMethod;
import com.swift.sandhook.annotation.HookMethodBackup; import com.swift.sandhook.annotation.HookMethodBackup;
import com.swift.sandhook.annotation.HookMode; import com.swift.sandhook.annotation.HookMode;
import com.swift.sandhook.annotation.SkipParamCheck;
import com.swift.sandhook.annotation.ThisObject; import com.swift.sandhook.annotation.ThisObject;
import com.swift.sandhook.test.TestClass; import com.swift.sandhook.test.TestClass;
import java.lang.reflect.Method;
@HookClass(TestClass.class) @HookClass(TestClass.class)
public class CtrHook { public class CtrHook {
@HookMethodBackup
@SkipParamCheck
static Method ctrbackup;
@HookMethodBackup("add1")
@SkipParamCheck
static Method add1backup;
@HookMethodBackup("add2")
@SkipParamCheck
static Method add2backup;
@HookMethod @HookMethod
public static void onCtr(@ThisObject TestClass thiz, int a) { public static void onCtr(@ThisObject TestClass thiz, int a) throws Throwable {
Log.e("TestClassHook", "TestClass(int) been hooked"); Log.e("TestClassHook", "TestClass(int) been hooked");
onCtrBackup(thiz, a); SandHook.callOriginByBackup(ctrbackup, thiz, a);
}
@HookMethodBackup
public static void onCtrBackup(@ThisObject TestClass thiz, int a) {
onCtrBackup(thiz, a);
} }
@HookMethod("add1") @HookMethod("add1")
@HookMode(HookMode.INLINE) @HookMode(HookMode.INLINE)
public static void onAdd1(TestClass thiz) { public static void onAdd1(TestClass thiz) throws Throwable {
Log.e("TestClassHook", "add1 been hooked"); Log.e("TestClassHook", "add1 been hooked");
try { SandHook.callOriginByBackup(add1backup, thiz);
onAdd1Backup(thiz);
} catch (Exception e) {
e.printStackTrace();
}
}
@HookMethodBackup("add1")
public static void onAdd1Backup(TestClass thiz) {
onAdd1Backup(thiz);
} }
@HookMethod("add2") @HookMethod("add2")
public static void onAdd2(TestClass thiz) { public static void onAdd2(TestClass thiz) throws Throwable {
Log.e("TestClassHook", "add2 been hooked"); SandHook.callOriginByBackup(add2backup, thiz);
onAdd2Backup(thiz);
} }
@HookMethodBackup("add2")
public static void onAdd2Backup(TestClass thiz) {
onAdd2Backup(thiz);
}
} }
...@@ -3,31 +3,29 @@ package com.swift.sandhook.testHookers; ...@@ -3,31 +3,29 @@ package com.swift.sandhook.testHookers;
import android.os.Build; import android.os.Build;
import android.util.Log; import android.util.Log;
import com.swift.sandhook.annotation.HookMode; import com.swift.sandhook.SandHook;
import com.swift.sandhook.annotation.ThisObject;
import com.swift.sandhook.test.TestClass;
import com.swift.sandhook.annotation.HookClass; import com.swift.sandhook.annotation.HookClass;
import com.swift.sandhook.annotation.HookMethod; import com.swift.sandhook.annotation.HookMethod;
import com.swift.sandhook.annotation.HookMethodBackup; import com.swift.sandhook.annotation.HookMethodBackup;
import com.swift.sandhook.annotation.SkipParamCheck;
import com.swift.sandhook.annotation.ThisObject;
import com.swift.sandhook.test.TestClass;
import java.lang.reflect.Method;
@HookClass(TestClass.class) @HookClass(TestClass.class)
public class JniHooker { public class JniHooker {
@HookMethodBackup("jni_test")
@SkipParamCheck
static Method backup;
@HookMethod("jni_test") @HookMethod("jni_test")
@HookMode(HookMode.INLINE) public static void onJni(@ThisObject TestClass thiz) throws Throwable {
public static int onJni(@ThisObject TestClass thiz) {
Log.e("JniHooker", "hooked success "); Log.e("JniHooker", "hooked success ");
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
return onJniBackup(thiz); SandHook.callOriginByBackup(backup, thiz);
} else {
//can not call jni origin in 4.4 tmp
return 0;
} }
} }
@HookMethodBackup("jni_test")
public static int onJniBackup(@ThisObject TestClass thiz) {
return onJniBackup(thiz);
}
} }
...@@ -2,25 +2,26 @@ package com.swift.sandhook.testHookers; ...@@ -2,25 +2,26 @@ package com.swift.sandhook.testHookers;
import android.util.Log; import android.util.Log;
import com.swift.sandhook.SandHook;
import com.swift.sandhook.annotation.HookClass; import com.swift.sandhook.annotation.HookClass;
import com.swift.sandhook.annotation.HookMethod; import com.swift.sandhook.annotation.HookMethod;
import com.swift.sandhook.annotation.HookMethodBackup; import com.swift.sandhook.annotation.HookMethodBackup;
import com.swift.sandhook.annotation.HookMode;
import com.swift.sandhook.annotation.Param; import com.swift.sandhook.annotation.Param;
import com.swift.sandhook.annotation.SkipParamCheck;
import java.lang.reflect.Method;
@HookClass(Log.class) @HookClass(Log.class)
public class LogHooker { public class LogHooker {
@HookMethodBackup("w")
@SkipParamCheck
static Method backup;
@HookMethod("w") @HookMethod("w")
@HookMode(HookMode.INLINE) public static int onCreate(String tag, @Param("java.lang.String") Object msg) throws Throwable {
public static int onCreate(String tag, @Param("java.lang.String") Object msg) {
Log.e("LogHooker", "hooked success " + tag); Log.e("LogHooker", "hooked success " + tag);
return onCreateBackup(tag, msg); return (int) SandHook.callOriginByBackup(backup, null, tag, msg);
}
@HookMethodBackup("w")
public static int onCreateBackup(String tag, @Param("java.lang.String") Object msg) {
return onCreateBackup(tag, msg);
} }
} }
...@@ -3,20 +3,28 @@ package com.swift.sandhook.testHookers; ...@@ -3,20 +3,28 @@ package com.swift.sandhook.testHookers;
import android.app.Activity; import android.app.Activity;
import android.util.Log; import android.util.Log;
import com.swift.sandhook.SandHook;
import com.swift.sandhook.annotation.HookClass; import com.swift.sandhook.annotation.HookClass;
import com.swift.sandhook.annotation.HookMethod; import com.swift.sandhook.annotation.HookMethod;
import com.swift.sandhook.annotation.HookMethodBackup; import com.swift.sandhook.annotation.HookMethodBackup;
import com.swift.sandhook.annotation.Param; import com.swift.sandhook.annotation.Param;
import com.swift.sandhook.annotation.SkipParamCheck;
import com.swift.sandhook.annotation.ThisObject; import com.swift.sandhook.annotation.ThisObject;
import com.swift.sandhook.test.TestClass; import com.swift.sandhook.test.TestClass;
import java.lang.reflect.Method;
@HookClass(TestClass.class) @HookClass(TestClass.class)
public class NewAnnotationApiHooker { public class NewAnnotationApiHooker {
@HookMethodBackup("testNewHookApi")
@SkipParamCheck
static Method backup;
@HookMethod("testNewHookApi") @HookMethod("testNewHookApi")
public static void onTestNewHookApi(@ThisObject TestClass thiz, @Param("com.swift.sandhook.MainActivity") Activity activity, int a) { public static void onTestNewHookApi(@ThisObject TestClass thiz, @Param("com.swift.sandhook.MainActivity") Activity activity, int a) throws Throwable {
Log.e("TestClassHook", "testNewHookApi been hooked"); Log.e("TestClassHook", "testNewHookApi been hooked");
onTestNewHookApiBackup(thiz, activity, a); SandHook.callOriginByBackup(backup, thiz, activity, a);
} }
@HookMethodBackup("testNewHookApi") @HookMethodBackup("testNewHookApi")
......
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