首页
社区
课程
招聘
[求助]xposed hook方法
发表于: 2015-7-3 09:55 14837

[求助]xposed hook方法

2015-7-3 09:55
14837
public class Tutoria implements IXposedHookLoadPackage{

        @Override
        public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
                // TODO 自动生成的方法存根
                if(!lpparam.packageName.equals("x.x.x"))
                        return;
               
                XposedBridge.log("Loaded app:"+lpparam.packageName+">>>>>>>>>>>>>");
                findAndHookMethod("x.x.x.x.x.x.x", lpparam.classLoader, "JA", new XC_MethodHook() {
                @Override
                protected void afterHookedMethod(MethodHookParam param)
                                throws Throwable {
                        // TODO 自动生成的方法存根
                       
                        Toast.makeText(null, ">>>>", Toast.LENGTH_LONG).show();
                        super.afterHookedMethod(param);
                }
                });
               
               
        }

}
需要hook的那个方法的类是动态载入的,就产生了这样的错误提示
Loaded app:x.x.x>>>>>>>>>>>>>
de.robv.android.xposed.XposedHelpers$ClassNotFoundError: java.lang.ClassNotFoundException: x.x.x.x.x.x.x
        at de.robv.android.xposed.XposedHelpers.findClass(XposedHelpers.java:52)
        at de.robv.android.xposed.XposedHelpers.findAndHookMethod(XposedHelpers.java:136)
        at dev.robv.android.xposed.mods.tutorial.Tutoria.handleLoadPackage(Tutoria.java:17)
        at de.robv.android.xposed.IXposedHookLoadPackage$Wrapper.handleLoadPackage(IXposedHookLoadPackage.java:20)
        at de.robv.android.xposed.callbacks.XC_LoadPackage.call(XC_LoadPackage.java:34)
        at de.robv.android.xposed.callbacks.XCallback.callAll(XCallback.java:70)
        at de.robv.android.xposed.XposedBridge$1.beforeHookedMethod(XposedBridge.java:208)
        at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:611)
        at android.app.ActivityThread.handleBindApplication(Native Method)
        at android.app.ActivityThread.access$1500(ActivityThread.java:136)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1279)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5032)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
        at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
        at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException:
x.x.x.x.x.x.x
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:251)
        at external.org.apache.commons.lang3.ClassUtils.getClass(ClassUtils.java:823)
        at de.robv.android.xposed.XposedHelpers.findClass(XposedHelpers.java:50)
        ... 19 more
Caused by: java.lang.NoClassDefFoundError: x.x.x.x.x.x.x
        ... 23 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "x.x.x.x.x.x.x" on path: DexPathList[[zip file "/data/app/x.x.x.x.x.x.x-2.apk"],nativeLibraryDirectories=[/data/app-lib/x.x.x.x.x.x.x-2, /vendor/lib, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
        ... 23 more

后来我将代码改为hook启动类的oncreate方法

public class Tutoria implements IXposedHookLoadPackage{

        @Override
        public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
                // TODO 自动生成的方法存根
                if(!lpparam.packageName.equals("x.x.x"))
                        return;
               
                XposedBridge.log("Loaded app:"+lpparam.packageName+">>>>>>>>>>>>>");
                findAndHookMethod("x.x.x.x.LauncherUI", lpparam.classLoader, "onCreate", new XC_MethodHook() {
                @Override
                protected void afterHookedMethod(MethodHookParam param)
                                throws Throwable {
                        // TODO 自动生成的方法存根
                       
                        Toast.makeText(null, ">>>>", Toast.LENGTH_LONG).show();
                        super.afterHookedMethod(param);
                }
                });
               
               
        }

}
又产生了新的错误提示
Loaded app:x.x.x>>>>>>>>>>>>>
java.lang.NoSuchMethodError: x.x.x.x.Launcher#onCreate()#exact
        at de.robv.android.xposed.XposedHelpers.findMethodExact(XposedHelpers.java:179)
        at de.robv.android.xposed.XposedHelpers.findAndHookMethod(XposedHelpers.java:129)
        at de.robv.android.xposed.XposedHelpers.findAndHookMethod(XposedHelpers.java:136)
        at dev.robv.android.xposed.mods.tutorial.Tutoria.handleLoadPackage(Tutoria.java:18)
        at de.robv.android.xposed.IXposedHookLoadPackage$Wrapper.handleLoadPackage(IXposedHookLoadPackage.java:20)
        at de.robv.android.xposed.callbacks.XC_LoadPackage.call(XC_LoadPackage.java:34)
        at de.robv.android.xposed.callbacks.XCallback.callAll(XCallback.java:70)
        at de.robv.android.xposed.XposedBridge$1.beforeHookedMethod(XposedBridge.java:208)
        at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:611)
        at android.app.ActivityThread.handleBindApplication(Native Method)
        at android.app.ActivityThread.access$1500(ActivityThread.java:136)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1279)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5032)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
        at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
        at dalvik.system.NativeStart.main(Native Method)

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (2)
雪    币: 22
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
hook方法有问题 oncreat方法有参数Bundle
xposed 要注意方法的参数
findAndHookMethod("x.x.x.x.LauncherUI", lpparam.classLoader, "onCreate",Bundle.class ,new XC_MethodHook() {.......}
2015-7-6 10:55
0
雪    币: 3
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
十分感谢
2015-7-7 19:30
0
游客
登录 | 注册 方可回帖
返回
//