Merge remote-tracking branch 'origin/sandhook' into sandhook

This commit is contained in:
swift_gan 2019-03-30 10:35:42 +08:00
commit a956dd2a47
6 changed files with 40 additions and 8 deletions

View File

@ -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.2.8' implementation 'com.swift.sandhook:hooklib:3.3.4'
compileOnly project(':dexmaker') compileOnly project(':dexmaker')
} }

View File

@ -30,6 +30,7 @@ public class Router {
private static volatile AtomicBoolean bootstrapHooked = new AtomicBoolean(false); private static volatile AtomicBoolean bootstrapHooked = new AtomicBoolean(false);
static boolean useSandHook = false;
public static void prepare(boolean isSystem) { public static void prepare(boolean isSystem) {
// this flag is needed when loadModules // this flag is needed when loadModules
@ -61,7 +62,7 @@ public class Router {
} }
Router.startBootstrapHook(isSystem); Router.startBootstrapHook(isSystem);
XposedInit.initForZygote(isSystem); XposedInit.initForZygote(isSystem);
SandHookConfig.compiler = !isSystem; //SandHookConfig.compiler = !isSystem;
} catch (Throwable t) { } catch (Throwable t) {
Utils.logE("error during Xposed initialization", t); Utils.logE("error during Xposed initialization", t);
XposedBridge.disableHooks = true; XposedBridge.disableHooks = true;
@ -81,18 +82,46 @@ public class Router {
Utils.logD("startBootstrapHook starts: isSystem = " + isSystem); Utils.logD("startBootstrapHook starts: isSystem = " + isSystem);
ClassLoader classLoader = XposedBridge.BOOTCLASSLOADER; ClassLoader classLoader = XposedBridge.BOOTCLASSLOADER;
if (isSystem) { if (isSystem) {
if (useSandHook) {
XposedCompat.addHookers(classLoader, SysBootstrapHookInfo.hookItems); XposedCompat.addHookers(classLoader, SysBootstrapHookInfo.hookItems);
} else { } else {
HookMain.doHookDefault(
Router.class.getClassLoader(),
classLoader,
SysBootstrapHookInfo.class.getName());
}
} else {
if (useSandHook) {
XposedCompat.addHookers(classLoader, AppBootstrapHookInfo.hookItems); XposedCompat.addHookers(classLoader, AppBootstrapHookInfo.hookItems);
} else {
HookMain.doHookDefault(
Router.class.getClassLoader(),
classLoader,
AppBootstrapHookInfo.class.getName());
}
} }
} }
public static void startSystemServerHook() { public static void startSystemServerHook() {
if (useSandHook) {
XposedCompat.addHookers(SystemMainHooker.systemServerCL, SysInnerHookInfo.hookItems); XposedCompat.addHookers(SystemMainHooker.systemServerCL, SysInnerHookInfo.hookItems);
} else {
HookMain.doHookDefault(
Router.class.getClassLoader(),
SystemMainHooker.systemServerCL,
SysInnerHookInfo.class.getName());
}
} }
public static void startWorkAroundHook() { public static void startWorkAroundHook() {
if (useSandHook) {
XposedCompat.addHookers(XposedBridge.BOOTCLASSLOADER, WorkAroundHookInfo.hookItems); XposedCompat.addHookers(XposedBridge.BOOTCLASSLOADER, WorkAroundHookInfo.hookItems);
} else {
HookMain.doHookDefault(
Router.class.getClassLoader(),
XposedBridge.BOOTCLASSLOADER,
WorkAroundHookInfo.class.getName());
}
} }
public static void onEnterChildProcess() { public static void onEnterChildProcess() {

View File

@ -314,7 +314,6 @@ public class HookStubManager {
try { try {
((XC_MethodHook) snapshot[afterIdx]).callAfterHookedMethod(param); ((XC_MethodHook) snapshot[afterIdx]).callAfterHookedMethod(param);
} catch (Throwable t) { } catch (Throwable t) {
XposedBridge.log(t);
if (lastThrowable == null) if (lastThrowable == null)
param.setResult(lastResult); param.setResult(lastResult);
else else
@ -384,7 +383,6 @@ public class HookStubManager {
try { try {
((XC_MethodHook) snapshot[afterIdx]).callAfterHookedMethod(param); ((XC_MethodHook) snapshot[afterIdx]).callAfterHookedMethod(param);
} catch (Throwable t) { } catch (Throwable t) {
XposedBridge.log(t);
if (lastThrowable == null) if (lastThrowable == null)
param.setResult(lastResult); param.setResult(lastResult);
else else

View File

@ -1,10 +1,12 @@
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.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;
@ -124,6 +126,9 @@ 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.