Android R: add hooker for new method signature

com.android.server.SystemServer#startBootstrapServices(com.android.server.utils.TimingsTraceAndSlog)
This commit is contained in:
solohsu 2020-08-01 23:48:10 +08:00
parent 1a7957e2ad
commit 6b7c8e4942
14 changed files with 118 additions and 12 deletions

View File

@ -1,7 +1,7 @@
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
compileSdkVersion androidCompileSdkVersion.toInteger()
defaultConfig {
minSdkVersion 26

View File

@ -0,0 +1,28 @@
package com.elderdrivers.riru.edxp._hooker.yahfa;
import com.elderdrivers.riru.common.KeepMembers;
import com.elderdrivers.riru.edxp._hooker.impl.StartBootstrapServices;
import de.robv.android.xposed.XC_MethodHook;
public class StartBootstrapServicesHooker11 implements KeepMembers {
public static String className = "com.android.server.SystemServer";
public static String methodName = "startBootstrapServices";
public static String methodSig = "(Lcom/android/server/utils/TimingsTraceAndSlog;)V";
public static void hook(Object systemServer, Object traceAndSlog) throws Throwable {
final XC_MethodHook methodHook = new StartBootstrapServices();
final XC_MethodHook.MethodHookParam param = new XC_MethodHook.MethodHookParam();
param.thisObject = systemServer;
param.args = new Object[]{traceAndSlog};
methodHook.callBeforeHookedMethod(param);
if (!param.returnEarly) {
backup(systemServer, traceAndSlog);
}
methodHook.callAfterHookedMethod(param);
}
public static void backup(Object systemServer, Object traceAndSlog) {
}
}

View File

@ -2,9 +2,18 @@ package com.elderdrivers.riru.edxp.entry.yahfa;
import com.elderdrivers.riru.common.KeepMembers;
import com.elderdrivers.riru.edxp._hooker.yahfa.StartBootstrapServicesHooker;
import com.elderdrivers.riru.edxp._hooker.yahfa.StartBootstrapServicesHooker11;
import com.elderdrivers.riru.edxp.util.Versions;
public class SysInnerHookInfo implements KeepMembers {
public static Class<?> getSysInnerHookerClass() {
return Versions.hasR() ?
StartBootstrapServicesHooker11.class :
StartBootstrapServicesHooker.class;
}
public static String[] hookItemNames = {
StartBootstrapServicesHooker.class.getName()
getSysInnerHookerClass().getName()
};
}

View File

@ -21,6 +21,7 @@ import com.elderdrivers.riru.edxp.entry.yahfa.SysBootstrapHookInfo;
import com.elderdrivers.riru.edxp.entry.yahfa.SysInnerHookInfo;
import com.elderdrivers.riru.edxp.entry.yahfa.WorkAroundHookInfo;
import com.elderdrivers.riru.edxp.util.Utils;
import com.elderdrivers.riru.edxp.util.Versions;
import java.util.concurrent.atomic.AtomicBoolean;
@ -127,9 +128,13 @@ public abstract class BaseRouter implements Router {
public void startSystemServerHook() {
ClassLoader classLoader = BaseRouter.class.getClassLoader();
if (useXposedApi) {
StartBootstrapServices sbsHooker = new StartBootstrapServices();
Object[] paramTypesAndCallback = Versions.hasR() ?
new Object[]{"com.android.server.utils.TimingsTraceAndSlog", sbsHooker} :
new Object[]{sbsHooker};
XposedHelpers.findAndHookMethod(StartBootstrapServicesHooker.className,
SystemMain.systemServerCL,
StartBootstrapServicesHooker.methodName, new StartBootstrapServices());
StartBootstrapServicesHooker.methodName, paramTypesAndCallback);
} else {
HookMain.doHookDefault(
classLoader,

View File

@ -0,0 +1,10 @@
package com.elderdrivers.riru.edxp.util;
import android.os.Build;
public class Versions {
public static boolean hasR() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.R;
}
}

View File

@ -37,7 +37,7 @@ ext {
}
android {
compileSdkVersion 28
compileSdkVersion androidCompileSdkVersion.toInteger()
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion

View File

@ -4,7 +4,7 @@ sourceCompatibility = "7"
targetCompatibility = "7"
android {
compileSdkVersion 28
compileSdkVersion androidCompileSdkVersion.toInteger()
defaultConfig {
applicationId "com.elderdrivers.riru.edxp.sandhook"

View File

@ -2,13 +2,22 @@ package com.elderdrivers.riru.edxp.sandhook.entry;
import com.elderdrivers.riru.common.KeepMembers;
import com.elderdrivers.riru.edxp.sandhook.hooker.StartBootstrapServicesHooker;
import com.elderdrivers.riru.edxp.sandhook.hooker.StartBootstrapServicesHooker11;
import com.elderdrivers.riru.edxp.util.Versions;
public class SysInnerHookInfo implements KeepMembers {
public static Class<?> getSysInnerHookerClass() {
return Versions.hasR() ?
StartBootstrapServicesHooker11.class :
StartBootstrapServicesHooker.class;
}
public static String[] hookItemNames = {
StartBootstrapServicesHooker.class.getName()
getSysInnerHookerClass().getName()
};
public static Class[] hookItems = {
StartBootstrapServicesHooker.class
getSysInnerHookerClass()
};
}

View File

@ -0,0 +1,43 @@
package com.elderdrivers.riru.edxp.sandhook.hooker;
import com.elderdrivers.riru.common.KeepMembers;
import com.elderdrivers.riru.edxp._hooker.impl.StartBootstrapServices;
import com.swift.sandhook.SandHook;
import com.swift.sandhook.annotation.HookMethod;
import com.swift.sandhook.annotation.HookMethodBackup;
import com.swift.sandhook.annotation.HookReflectClass;
import com.swift.sandhook.annotation.Param;
import com.swift.sandhook.annotation.SkipParamCheck;
import com.swift.sandhook.annotation.ThisObject;
import java.lang.reflect.Method;
import de.robv.android.xposed.XC_MethodHook;
@HookReflectClass("com.android.server.SystemServer")
public class StartBootstrapServicesHooker11 implements KeepMembers {
public static String className = "com.android.server.SystemServer";
public static String methodName = "startBootstrapServices";
public static String methodSig = "(Lcom/android/server/utils/TimingsTraceAndSlog;)V";
@HookMethodBackup("startBootstrapServices")
@SkipParamCheck
static Method backup;
@HookMethod("startBootstrapServices")
public static void hook(@ThisObject Object systemServer, @Param("com.android.server.utils.TimingsTraceAndSlog") Object traceAndSlog) throws Throwable {
final XC_MethodHook methodHook = new StartBootstrapServices();
final XC_MethodHook.MethodHookParam param = new XC_MethodHook.MethodHookParam();
param.thisObject = systemServer;
param.args = new Object[]{traceAndSlog};
methodHook.callBeforeHookedMethod(param);
if (!param.returnEarly) {
backup(systemServer, traceAndSlog);
}
methodHook.callAfterHookedMethod(param);
}
public static void backup(Object systemServer, Object traceAndSlog) throws Throwable {
SandHook.callOriginByBackup(backup, systemServer, traceAndSlog);
}
}

View File

@ -4,7 +4,7 @@ sourceCompatibility = "7"
targetCompatibility = "7"
android {
compileSdkVersion 28
compileSdkVersion androidCompileSdkVersion.toInteger()
defaultConfig {
applicationId "com.elderdrivers.riru.edxp.whale"

View File

@ -4,7 +4,7 @@ sourceCompatibility = "7"
targetCompatibility = "7"
android {
compileSdkVersion 28
compileSdkVersion androidCompileSdkVersion.toInteger()
defaultConfig {
applicationId "com.elderdrivers.riru.edxp.yahfa"

View File

@ -1 +1,3 @@
android.enableR8=false
android.enableR8=false
androidCompileSdkVersion=30

View File

@ -3,7 +3,7 @@ import com.android.builder.core.BuilderConstants
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
compileSdkVersion androidCompileSdkVersion.toInteger()
}
task makeStubJar(type: Jar){

View File

@ -1,7 +1,7 @@
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
compileSdkVersion androidCompileSdkVersion.toInteger()
buildToolsVersion '28.0.3'
defaultConfig {