2

I try to hook all of apps, how can I get an App's Context.

I tried

try {
    Class<?> ContextClass = XposedHelpers.findClass("android.content.ContextWrapper", lpp.classLoader);
    XposedHelpers.findAndHookMethod(ContextClass, "getApplicationContext", new XC_MethodHook() {
        @Override
        protected void afterHookedMethod(MethodHookParam param) throws Throwable {
            super.afterHookedMethod(param);

            if(applicationContext != null){
                return;
            }
            applicationContext = (Context) param.getResult();
            init();
        }
    });
} catch (Throwable t) {
    XposedBridge.log("error" + t);
}

For some Apps, it works, how can I get all Context?

Leon
  • 21
  • 2
  • Possible duplicate of [How to get Context through hooking in android](https://stackoverflow.com/questions/28059264/how-to-get-context-through-hooking-in-android) – matfax Sep 17 '18 at 10:44

1 Answers1

0

try it:

findAndHookMethod(
                "android.content.ContextWrapper", loader, "attachBaseContext",
                Context::class.java, object : XC_MethodHook() {
            override fun afterHookedMethod(param: MethodHookParam) {
                callback(param.thisObject as? Application ?: return)
            }
        })
gallonyin
  • 131
  • 5