我目前在我的Xposed模块中有这个代码:
public class Test implements IXposedHookLoadPackage, IXposedHookZygoteInit {
@Override
public void initZygote(StartupParam startupParam) throws Throwable {
XposedBridge.log("ZYGOTE INIT");
}
@Override
public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
if(lpparam.packageName.equals("com.somerandomapp")) {
XposedHelpers.findAndHookMethod(Application.class, "attach", Context.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedHelpers.findAndHookMethod("java.lang.Class", lpparam.classLoader,
"forName", String.class, boolean.class, ClassLoader.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param1) throws Throwable {
if(((String)param1.args[0]).equals("com.alibaba.wireless.security.mainplugin.SecurityGuardMainPlugin")) {
Class clazz = XposedHelpers.findClass("SecurityGuardMainPlugin", (ClassLoader)param1.args[2]);
XposedHelpers.findAndHookMethod("com.alibaba.wireless.security.a.l.a", (ClassLoader)param1.args[2], "a", clazz, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedHelpers.findAndHookMethod("com.alibaba.wireless.security.a.l.a", lpparam.classLoader, "getSecurityToken", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("Token: " + param.getResult());
}
});
}
});
}
}
});
}
});
}
}
}
我试图在运行时由app动态加载com.alibaba.wireless.security.a.l.a#a
之后挂钩方法SecurityGuardMainPlugin
。然而,我得到ClassNotFoundException
。这很奇怪,因为正如您在代码中看到的那样,在执行Class#forName
方法之后,我会检查是否已加载SecurityGuardMainPlugin
并且它似乎已经加载。
我在最后两次lpparam.classloader
电话中尝试使用findAndHookMethod
但没有运气。
任何帮助将不胜感激!
答案 0 :(得分:1)
由于您正在拦截Class.forName并假设它确实在拦截某些内容,因此您无需找到该类,您已经在param1.getResult()
中找到了该类。只需直接使用XposedBridge.hookMethod(param1.getResult(), yourHook)
即可。
另请注意,从钩子中挂钩方法通常是一种不好的做法。在注册新挂钩之前,请确保成员尚未挂钩。