Commit 5ac8c414 authored by swift_gan's avatar swift_gan

wrap callOrigin

parent 02ff063d
...@@ -165,13 +165,13 @@ public class SandHook { ...@@ -165,13 +165,13 @@ public class SandHook {
ensureMethodDeclaringClass(hookEntity.target, backupMethod); ensureMethodDeclaringClass(hookEntity.target, backupMethod);
} }
public static boolean ensureBackupDelaringClassByOrigin(Member originMethod) { public static void ensureBackupDelaringClassByOrigin(Member originMethod) {
if (originMethod == null) if (originMethod == null)
return false; return;
HookWrapper.HookEntity hookEntity = globalHookEntityMap.get(originMethod); HookWrapper.HookEntity hookEntity = globalHookEntityMap.get(originMethod);
if (hookEntity == null || hookEntity.backup == null) if (hookEntity == null || hookEntity.backup == null)
return false; return;
return ensureMethodDeclaringClass(originMethod, hookEntity.backup); ensureMethodDeclaringClass(originMethod, hookEntity.backup);
} }
...@@ -286,7 +286,7 @@ public class SandHook { ...@@ -286,7 +286,7 @@ public class SandHook {
public static native void ensureMethodCached(Method hook, Method backup); public static native void ensureMethodCached(Method hook, Method backup);
public static native boolean ensureMethodDeclaringClass(Member originMethod, Method backupMethod); public static native void ensureMethodDeclaringClass(Member originMethod, Method backupMethod);
@FunctionalInterface @FunctionalInterface
public interface HookModeCallBack { public interface HookModeCallBack {
......
...@@ -210,8 +210,8 @@ public class HookerDexMaker { ...@@ -210,8 +210,8 @@ public class HookerDexMaker {
} else { } else {
generateBackupMethod(); generateBackupMethod();
} }
generateHookMethod();
generateCallBackupMethod(); generateCallBackupMethod();
generateHookMethod();
ClassLoader loader; ClassLoader loader;
if (TextUtils.isEmpty(mDexDirPath)) { if (TextUtils.isEmpty(mDexDirPath)) {
...@@ -284,7 +284,7 @@ public class HookerDexMaker { ...@@ -284,7 +284,7 @@ public class HookerDexMaker {
Local<Member> method = code.newLocal(memberTypeId); Local<Member> method = code.newLocal(memberTypeId);
Map<TypeId, Local> resultLocals = createResultLocals(code); Map<TypeId, Local> resultLocals = createResultLocals(code);
MethodId<?, ?> errLogMethod = TypeId.get(DexLog.class).getMethod(TypeId.get(Void.TYPE), "printCallOriginError", TypeId.get(Member.class)); MethodId<?, ?> errLogMethod = TypeId.get(DexLog.class).getMethod(TypeId.get(Void.TYPE), "printCallOriginError", memberTypeId);
//very very important!!!!!!!!!!! //very very important!!!!!!!!!!!
...@@ -309,7 +309,7 @@ public class HookerDexMaker { ...@@ -309,7 +309,7 @@ public class HookerDexMaker {
private void generateBackupAndCallOriginCheckMethod() { private void generateBackupAndCallOriginCheckMethod() {
mBackupMethodId = mHookerTypeId.getMethod(mReturnTypeId, METHOD_NAME_BACKUP, mParameterTypeIds); mBackupMethodId = mHookerTypeId.getMethod(mReturnTypeId, METHOD_NAME_BACKUP, mParameterTypeIds);
mSandHookCallOriginMethodId = TypeId.get(ErrorCatch.class).getMethod(TypeId.get(Object.class), "callOriginError", memberTypeId, methodTypeId, TypeId.get(Object.class), TypeId.get(Object[].class)); mSandHookCallOriginMethodId = TypeId.get(ErrorCatch.class).getMethod(TypeId.get(Object.class), "callOriginError", memberTypeId, methodTypeId, TypeId.get(Object.class), TypeId.get(Object[].class));
MethodId<?, ?> errLogMethod = TypeId.get(DexLog.class).getMethod(TypeId.get(Void.TYPE), "printCallOriginError", TypeId.get(Member.class)); MethodId<?, ?> errLogMethod = TypeId.get(DexLog.class).getMethod(TypeId.get(Void.TYPE), "printCallOriginError", methodTypeId);
Code code = mDexMaker.declare(mBackupMethodId, Modifier.PUBLIC | Modifier.STATIC); Code code = mDexMaker.declare(mBackupMethodId, Modifier.PUBLIC | Modifier.STATIC);
...@@ -398,9 +398,20 @@ public class HookerDexMaker { ...@@ -398,9 +398,20 @@ public class HookerDexMaker {
mCallBackupMethodId = mHookerTypeId.getMethod(mReturnTypeId, METHOD_NAME_CALL_BACKUP, mParameterTypeIds); mCallBackupMethodId = mHookerTypeId.getMethod(mReturnTypeId, METHOD_NAME_CALL_BACKUP, mParameterTypeIds);
Code code = mDexMaker.declare(mCallBackupMethodId, Modifier.PUBLIC | Modifier.STATIC); Code code = mDexMaker.declare(mCallBackupMethodId, Modifier.PUBLIC | Modifier.STATIC);
// just call backup and return its result // just call backup and return its result
Local localOrigin = code.newLocal(memberTypeId);
Local localBackup = code.newLocal(methodTypeId);
Local[] allArgsLocals = createParameterLocals(code); Local[] allArgsLocals = createParameterLocals(code);
Map<TypeId, Local> resultLocals = createResultLocals(code); Map<TypeId, Local> resultLocals = createResultLocals(code);
code.sget(mMethodFieldId, localOrigin);
code.sget(mBackupMethodFieldId, localBackup);
MethodId methodId = TypeId.get(SandHook.class).getMethod(TypeId.get(Void.TYPE), "ensureMethodDeclaringClass", memberTypeId, methodTypeId);
code.invokeStatic(methodId, null, localOrigin, localBackup);
if (mReturnTypeId.equals(TypeId.VOID)) { if (mReturnTypeId.equals(TypeId.VOID)) {
code.invokeStatic(mBackupMethodId, null, allArgsLocals); code.invokeStatic(mBackupMethodId, null, allArgsLocals);
code.returnVoid(); code.returnVoid();
...@@ -579,12 +590,12 @@ public class HookerDexMaker { ...@@ -579,12 +590,12 @@ public class HookerDexMaker {
} }
// get pre-created Local with a matching typeId // get pre-created Local with a matching typeId
if (mReturnTypeId.equals(TypeId.VOID)) { if (mReturnTypeId.equals(TypeId.VOID)) {
code.invokeStatic(mBackupMethodId, null, allArgsLocals); code.invokeStatic(mCallBackupMethodId, null, allArgsLocals);
// TODO maybe keep preset result to do some magic? // TODO maybe keep preset result to do some magic?
code.invokeVirtual(setResultMethodId, null, param, nullObj); code.invokeVirtual(setResultMethodId, null, param, nullObj);
} else { } else {
Local returnedResult = resultLocals.get(mReturnTypeId); Local returnedResult = resultLocals.get(mReturnTypeId);
code.invokeStatic(mBackupMethodId, returnedResult, allArgsLocals); code.invokeStatic(mCallBackupMethodId, returnedResult, allArgsLocals);
// save returnedResult to resultObj as a Object // save returnedResult to resultObj as a Object
autoBoxIfNecessary(code, resultObj, returnedResult); autoBoxIfNecessary(code, resultObj, returnedResult);
// save resultObj to param // save resultObj to param
...@@ -665,11 +676,11 @@ public class HookerDexMaker { ...@@ -665,11 +676,11 @@ public class HookerDexMaker {
// call backup and return // call backup and return
code.mark(noHookReturn); code.mark(noHookReturn);
if (mReturnTypeId.equals(TypeId.VOID)) { if (mReturnTypeId.equals(TypeId.VOID)) {
code.invokeStatic(mBackupMethodId, null, allArgsLocals); code.invokeStatic(mCallBackupMethodId, null, allArgsLocals);
code.returnVoid(); code.returnVoid();
} else { } else {
Local result = resultLocals.get(mReturnTypeId); Local result = resultLocals.get(mReturnTypeId);
code.invokeStatic(mBackupMethodId, result, allArgsLocals); code.invokeStatic(mCallBackupMethodId, result, allArgsLocals);
code.returnValue(result); code.returnValue(result);
} }
} }
......
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