Commit 0aab93f2 authored by swift_gan's avatar swift_gan Committed by swift_gan

fix logic of resolve dex cache

parent 2beba56b
......@@ -88,8 +88,8 @@ public class SandHook {
throw new HookErrorException("method <" + entity.target.getName() + "> has been hooked!");
resolveStaticMethod(target);
if (backup != null) {
resolveStaticMethod(backup);
resolveStaticMethod(backup);
if (backup != null && entity.resolveDexCache) {
SandHookMethodResolver.resolveMethod(hook, backup);
}
if (target instanceof Method) {
......@@ -179,6 +179,8 @@ public class SandHook {
public static void resolveStaticMethod(Member method) {
//ignore result, just call to trigger resolve
if (method == null)
return;
try {
if (method instanceof Method && Modifier.isStatic(method.getModifiers())) {
((Method) method).setAccessible(true);
......
......@@ -389,6 +389,7 @@ public class HookWrapper {
public Method backup;
public boolean hookIsStub = false;
public boolean resolveDexCache = true;
public Class[] pars;
public int hookMode;
......@@ -403,6 +404,13 @@ public class HookWrapper {
this.backup = backup;
}
public HookEntity(Member target, Method hook, Method backup, boolean resolveDexCache) {
this.target = target;
this.hook = hook;
this.backup = backup;
this.resolveDexCache = resolveDexCache;
}
public boolean isCtor() {
return target instanceof Constructor;
}
......
......@@ -63,7 +63,7 @@ public final class DynamicBridge {
stub = HookStubManager.getHookMethodEntity(hookMethod);
}
if (stub != null) {
SandHook.hook(new HookWrapper.HookEntity(hookMethod, stub.hook, stub.backup));
SandHook.hook(new HookWrapper.HookEntity(hookMethod, stub.hook, stub.backup, false));
entityMap.put(hookMethod, stub);
} else {
dexMaker.start(hookMethod, additionalHookInfo,
......
......@@ -13,6 +13,7 @@ import com.android.dx.Local;
import com.android.dx.MethodId;
import com.android.dx.TypeId;
import com.swift.sandhook.SandHook;
import com.swift.sandhook.SandHookMethodResolver;
import com.swift.sandhook.wrapper.HookWrapper;
import com.swift.sandhook.xposedcompat.XposedCompat;
import com.swift.sandhook.xposedcompat.utils.DexLog;
......@@ -229,6 +230,7 @@ public class HookerDexMaker {
mBackupMethod = mHookClass.getMethod(METHOD_NAME_BACKUP, mActualParameterTypes);
mCallBackupMethod = mHookClass.getMethod(METHOD_NAME_CALL_BACKUP, mActualParameterTypes);
SandHook.resolveStaticMethod(mCallBackupMethod);
SandHookMethodResolver.resolveMethod(mCallBackupMethod, mBackupMethod);
SandHook.compileMethod(mCallBackupMethod);
mHookClass.getMethod(METHOD_NAME_SETUP, Member.class, Method.class, XposedBridge.AdditionalHookInfo.class).invoke(null, mMember, mBackupMethod, mHookInfo);
return new HookWrapper.HookEntity(mMember, mHookMethod, mBackupMethod);
......
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