rovo89 / Xposed

The native part of the Xposed framework (mainly the modified app_process binary).
Other
7.39k stars 1.47k forks source link

How can i start my application when i have hooked a function in another application? #223

Open qxtqxt96 opened 7 years ago

qxtqxt96 commented 7 years ago

In my class which implements IXposedHookLoadPackage, i try

findAndHookMethod(Camera.class, "startPreview", new XC_MethodHook() {
                @Override
                protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                    super.beforeHookedMethod(param);

                }
            });

So when i have hooked this function in a test application, i want to start my application which includes this class. How can i do it ?

wanam commented 7 years ago

You can send an Intent to your app.

aviraxp commented 7 years ago

You may need to get a context. Try to get system context by hooking.

wanam commented 7 years ago

@TonyQi1996 You can use something like this https://github.com/wanam/YouTubeAdAway/blob/master/src/ma/wanam/youtubeadaway/Xposed.java#L44 to get a context.

qxtqxt96 commented 7 years ago

@wanam Thanks very much. Now i try doing that. ( I deleted my comment just now which mentioned you. Because i wanted to revoice my ideas. And suddenly i saw your respones. Thank you for your rapid answers.)

qxtqxt96 commented 7 years ago

@wanam I made it. Is that a system context? But there is a new problem after starting my activity. When i click "back", it can't back to the application which includes the hooked method. The method is still hooked and my activity is started. Whether the problem is the hooked method?

 findAndHookMethod(Camera.class, "startPreview", new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                super.beforeHookedMethod(param);

                try {
                        if (context == null) {
                            Object activityThread = XposedHelpers.callStaticMethod(
                                    XposedHelpers.findClass("android.app.ActivityThread", null), "currentActivityThread");
                            context = (Context) XposedHelpers.callMethod(activityThread, "getSystemContext");
                        }
                        if (context != null ) {
                            Intent intent = new Intent();
                            intent.setClassName("com.xys.zxinglib", "com.xys.zxinglib.ScanQRCodeActivity");
                            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            context.startActivity(intent);
                        }
                } catch (Throwable t) {
                    XposedBridge.log(t);
                }
            }
        });
wanam commented 7 years ago

Take a look at Android doc, this flag "FLAG_ACTIVITY_NEW_TASK" clears history stack, try "FLAG_ACTIVITY_CLEAR_TOP".