Xposed:如何在App启动时获取Context

时间:2018-05-13 10:39:29

标签: android hook xposed

我尝试挂钩所有应用程序,如何获得应用程序的上下文。

我试过

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);
}

对于某些应用,它有效,我怎样才能获得所有上下文?

1 个答案:

答案 0 :(得分:0)

尝试:

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