rovo89 / XposedBridge

The Java part of the Xposed framework.
3.88k stars 1.1k forks source link

Can't Hook Two Package Name #240

Open aldyjrz opened 6 years ago

aldyjrz commented 6 years ago

Hello Xposed / Mr Rovo

I can't hook two application.. this is my example code

 public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam)
            throws Throwable
    {

        if (lpparam.packageName.equals(pkg1){
             methodhook1();
}
     if (lpparam.packageName.equals(pkg2){
             methodhook2();
}
}
MPeti1 commented 6 years ago

It doesn't seem to be a valid hook. Here is an example how it's working:

`@Override public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam) throws Throwable { XposedBridge.log(LOG_TAG + "Hooking package " + lpparam.packageName);

    if (lpparam.packageName.equals("com.myapp.MyActivity")) {
        XposedBridge.log("I'm in my app!");

        XposedHelpers.findAndHookMethod("com.myapp.MyActivity", lpparam.classLoader, "onCreate", Bundle.class, new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                super.beforeHookedMethod(param);

                XposedBridge.log("My app's MainActivity is starting!");
            }
        });
    }
}`

Aaaand while i was writing this answer I understood what's the problem with my module! Thanks! :D

Unfortunatelly it seems GitHub's "Insert code" is not bug free, but you can have a look at the tutorial here, and if you learned that you can have a look here at the API reference. And here is a tip: if you have some problem you can Google it because SO and GitHub is full of questions and answers about Xposed :D