Merge pull request #214 from ElderDrivers/sandhook
SandHook: sync code from sandhook
This commit is contained in:
commit
162338f69b
|
|
@ -24,7 +24,7 @@ dependencies {
|
||||||
compileOnly files("libs/framework-stub.jar")
|
compileOnly files("libs/framework-stub.jar")
|
||||||
implementation project(':edxp-common')
|
implementation project(':edxp-common')
|
||||||
implementation project(':xposed-bridge')
|
implementation project(':xposed-bridge')
|
||||||
implementation 'com.swift.sandhook:hooklib:3.4.2'
|
implementation 'com.swift.sandhook:hooklib:3.5.6'
|
||||||
compileOnly project(':dexmaker')
|
compileOnly project(':dexmaker')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -296,7 +296,7 @@ public class HookStubManager {
|
||||||
long[] newArgs = entity.getArgsAddress(stubArgs, param.args);
|
long[] newArgs = entity.getArgsAddress(stubArgs, param.args);
|
||||||
param.setResult(entity.getResult(callOrigin.call(newArgs)));
|
param.setResult(entity.getResult(callOrigin.call(newArgs)));
|
||||||
} else {
|
} else {
|
||||||
param.setResult(SandHook.callOriginMethod(originMethod, thiz, param.args));
|
param.setResult(SandHook.callOriginMethod(originMethod, entity.backup, thiz, param.args));
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
param.setThrowable(e);
|
param.setThrowable(e);
|
||||||
|
|
@ -337,7 +337,7 @@ public class HookStubManager {
|
||||||
Object[] snapshot = additionalHookInfo.callbacks.getSnapshot();
|
Object[] snapshot = additionalHookInfo.callbacks.getSnapshot();
|
||||||
|
|
||||||
if (snapshot == null || snapshot.length == 0) {
|
if (snapshot == null || snapshot.length == 0) {
|
||||||
return SandHook.callOriginMethod(origin, thiz, args);
|
return SandHook.callOriginMethod(origin, backup, thiz, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
XC_MethodHook.MethodHookParam param = new XC_MethodHook.MethodHookParam();
|
XC_MethodHook.MethodHookParam param = new XC_MethodHook.MethodHookParam();
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
package com.swift.sandhook.xposedcompat.methodgen;
|
package com.swift.sandhook.xposedcompat.methodgen;
|
||||||
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.os.Trace;
|
import android.os.Trace;
|
||||||
|
|
||||||
import com.swift.sandhook.SandHook;
|
import com.swift.sandhook.SandHook;
|
||||||
import com.swift.sandhook.SandHookConfig;
|
import com.swift.sandhook.SandHookConfig;
|
||||||
import com.swift.sandhook.annotation.HookMode;
|
import com.swift.sandhook.blacklist.HookBlackList;
|
||||||
import com.swift.sandhook.wrapper.HookWrapper;
|
import com.swift.sandhook.wrapper.HookWrapper;
|
||||||
import com.swift.sandhook.xposedcompat.XposedCompat;
|
import com.swift.sandhook.xposedcompat.XposedCompat;
|
||||||
import com.swift.sandhook.xposedcompat.hookstub.HookMethodEntity;
|
import com.swift.sandhook.xposedcompat.hookstub.HookMethodEntity;
|
||||||
|
|
@ -28,7 +27,7 @@ import de.robv.android.xposed.XposedBridge;
|
||||||
public final class SandHookXposedBridge {
|
public final class SandHookXposedBridge {
|
||||||
|
|
||||||
private static final Map<Member, Method> hookedInfo = new ConcurrentHashMap<>();
|
private static final Map<Member, Method> hookedInfo = new ConcurrentHashMap<>();
|
||||||
private static HookMaker hookMaker = XposedCompat.useNewCallBackup ? new HookerDexMakerNew() : new HookerDexMaker();
|
private static HookMaker defaultHookMaker = XposedCompat.useNewCallBackup ? new HookerDexMakerNew() : new HookerDexMaker();
|
||||||
private static final AtomicBoolean dexPathInited = new AtomicBoolean(false);
|
private static final AtomicBoolean dexPathInited = new AtomicBoolean(false);
|
||||||
private static File dexDir;
|
private static File dexDir;
|
||||||
|
|
||||||
|
|
@ -63,18 +62,24 @@ public final class SandHookXposedBridge {
|
||||||
Trace.beginSection("SandXposed");
|
Trace.beginSection("SandXposed");
|
||||||
long timeStart = System.currentTimeMillis();
|
long timeStart = System.currentTimeMillis();
|
||||||
HookMethodEntity stub = null;
|
HookMethodEntity stub = null;
|
||||||
if (XposedCompat.useInternalStub) {
|
if (XposedCompat.useInternalStub && !HookBlackList.canNotHookByStub(hookMethod) && !HookBlackList.canNotHookByBridge(hookMethod)) {
|
||||||
stub = HookStubManager.getHookMethodEntity(hookMethod, additionalHookInfo);
|
stub = HookStubManager.getHookMethodEntity(hookMethod, additionalHookInfo);
|
||||||
}
|
}
|
||||||
if (stub != null) {
|
if (stub != null) {
|
||||||
SandHook.hook(new HookWrapper.HookEntity(hookMethod, stub.hook, stub.backup, false));
|
SandHook.hook(new HookWrapper.HookEntity(hookMethod, stub.hook, stub.backup, false));
|
||||||
entityMap.put(hookMethod, stub);
|
entityMap.put(hookMethod, stub);
|
||||||
} else {
|
} else {
|
||||||
|
HookMaker hookMaker;
|
||||||
|
if (HookBlackList.canNotHookByBridge(hookMethod)) {
|
||||||
|
hookMaker = new HookerDexMaker();
|
||||||
|
} else {
|
||||||
|
hookMaker = defaultHookMaker;
|
||||||
|
}
|
||||||
hookMaker.start(hookMethod, additionalHookInfo,
|
hookMaker.start(hookMethod, additionalHookInfo,
|
||||||
hookMethod.getDeclaringClass().getClassLoader(), dexDir == null ? null : dexDir.getAbsolutePath());
|
hookMethod.getDeclaringClass().getClassLoader(), dexDir == null ? null : dexDir.getAbsolutePath());
|
||||||
hookedInfo.put(hookMethod, hookMaker.getCallBackupMethod());
|
hookedInfo.put(hookMethod, hookMaker.getCallBackupMethod());
|
||||||
}
|
}
|
||||||
DexLog.d("hook method <" + hookMethod.toString() + "> cost " + (System.currentTimeMillis() - timeStart) + " ms, by " + (stub != null ? "internal stub." : "dex maker"));
|
DexLog.d("hook method <" + hookMethod.toString() + "> cost " + (System.currentTimeMillis() - timeStart) + " ms, by " + (stub != null ? "internal stub" : "dex maker"));
|
||||||
Trace.endSection();
|
Trace.endSection();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
DexLog.e("error occur when hook method <" + hookMethod.toString() + ">", e);
|
DexLog.e("error occur when hook method <" + hookMethod.toString() + ">", e);
|
||||||
|
|
@ -126,9 +131,6 @@ public final class SandHookXposedBridge {
|
||||||
@Override
|
@Override
|
||||||
public void loadLib() {
|
public void loadLib() {
|
||||||
//do it in loadDexAndInit
|
//do it in loadDexAndInit
|
||||||
if (SandHookConfig.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
SandHook.setHookMode(HookMode.REPLACE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
SandHookConfig.DEBUG = true;
|
SandHookConfig.DEBUG = true;
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue