在上一篇我们留下问题:handleLoadPackage如何生效即在何时被执行。本篇我们会对Xposed学习一中的操作步骤剖析背后原理。
先看XposedBridge.class的main:
1 private static void main(String[] args) { 2 String startClassName = getStartClassName(); 3 ...... 4 if(initNative()) { 5 if(startClassName == null) { 6 initXbridgeZygote(); 7 } 8 // 读取/data/data/de.robv.android.xposed.installer/conf/modules.list内容,存储着模块apk的地址, 9 // 内容:/data/app/com.jason.learnxposed-2.apk 10 // 加载模块loadModule(APK,startClassName) 11 loadModules(startClassName); 12 } 13 ...... 14 if(startClassName == null) { 15 ZygoteInit.main(args); 16 } else { 17 RuntimeInit.main(args); 18 } 20 }
main中分两步:loadModules;2 init。loadModules简单先分析这个
private static void loadModule(String apk, String startClassName) { ...... PathClassLoader mcl = new PathClassLoader(apk, BOOTCLASSLOADER); InputStream is = mcl.getResourceAsStream("assets/xposed_init"); // 读取apk的assets/xposed_init内容,Xposed学习一中的第五步 if(is == null) { log("assets/xposed_init not found in the APK"); } else { BufferedReader moduleClassesReader = new BufferedReader(new InputStreamReader(is)); ...... if(startClassName == null) { if(moduleInstance instanceof IXposedHookZygoteInit) { StartupParam param = new StartupParam(); param.modulePath = apk; ((IXposedHookZygoteInit)moduleInstance).initZygote(param); } if(moduleInstance instanceof IXposedHookLoadPackage) { hookLoadPackage(new Wrapper((IXposedHookLoadPackage)moduleInstance)); } if(moduleInstance instanceof IXposedHookInitPackageResources) { hookInitPackageResources(new de.robv.android.xposed.IXposedHookInitPackageResources.Wrapper((IXposedHookInitPackageResources)moduleInstance)); } } else if(moduleInstance instanceof IXposedHookCmdInit) { de.robv.android.xposed.IXposedHookCmdInit.StartupParam param1 = new de.robv.android.xposed.IXposedHookCmdInit.StartupParam(); param1.modulePath = apk; param1.startClassName = startClassName; ((IXposedHookCmdInit)moduleInstance).initCmdApp(param1); } ...... } } }
简单说下loadModule中步骤,1.读取Xposed_init文本里的内容,里面是我们的类名。我们可以在一个模块中写好几个功能的类,但请注意一定要将类全名字符串写到Xposed_init里且每个类字符串为一行。
时间: 2024-09-28 20:30:42