简体   繁体   English

Xposed 无法挂钩 getInstalledApplications

[英]Xposed can't hook getInstalledApplications

I wanted to hook getInstalledApplications and getInstalledPackages to monitor if the app use this method to get my appliactionlist.我想挂钩 getInstalledApplications 和 getInstalledPackages 来监控应用程序是否使用此方法来获取我的应用程序列表。
My code:我的代码:

XposedHelpers.findAndHookMethod(

                    android.content.pm.PackageManager.class.getName(),
                    lpparam.classLoader,
                    "getInstalledApplications",
                    new XC_MethodHook() {
                        @Override
                        protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                            XposedBridge.log("getInstalledApplications()");
                            Log.d("HookLogin", "getInstalledApplications()");
                        }
                    });

And I got this error: Xposed: java.lang.NoSuchMethodError: android.content.pm.PackageManager#getInstalledApplications()#exact Then I googled and found I should use android.app.ApplicationPackageManager ,and I changed my code: And I got this error: Xposed: java.lang.NoSuchMethodError: android.content.pm.PackageManager#getInstalledApplications()#exact Then I googled and found I should use android.app.ApplicationPackageManager ,and I changed my code:

     XposedHelpers.findAndHookMethod(

                    "android.app.ApplicationPackageManager",
                    lpparam.classLoader,
                    "getInstalledPackages",
                    new XC_MethodHook() {
                        @Override
                        protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                            XposedBridge.log("getInstalledPackages()");
                            Log.d("HookLogin", "getInstalledPackages()");
                        }
                    });

But i still got NoSuchMethodError,this time it is:但我仍然得到 NoSuchMethodError,这次是:

Xposed: java.lang.NoSuchMethodError: android.app.ApplicationPackageManager#getInstalledApplications()#exact

I'm confused now, how should I hook the method getInstalledPackages .我现在很困惑,我应该如何挂钩方法getInstalledPackages

Both code versions have one major problem:两种代码版本都有一个主要问题:

Your hook can not work because you are trying to hook a method that does not exist: You are trying to hook the method getInstalledApplications() but that method does not exist, only the method [getInstalledApplications(int)][1] does exist and can be hooked.您的挂钩无法工作,因为您试图挂钩一个不存在的方法:您正在尝试挂钩方法getInstalledApplications()但该方法不存在,只有方法[getInstalledApplications(int)][1]确实存在并且可以上钩。

You alerady notived that android.content.pm.PackageManager is an abstract class and the method getInstalledApplications(int) is abstract, too.您已经注意到android.content.pm.PackageManager是一个抽象 class 方法getInstalledApplications(int)也是抽象的。 As Xposed can not hook abstract Methods and Interfaces you have to specify the class that that actually implements the method getInstalledApplications(int) .由于 Xposed 不能挂钩抽象方法和接口,您必须指定实际实现方法getInstalledApplications(int)的 class 。

The actual implementation of PackageManager is located in class android.app.ApplicationPackageManager as you already found out. PackageManager 的实际实现位于 class android.app.ApplicationPackageManager中,正如您已经发现的那样。

Therefore the correct hooking code is:因此正确的挂钩代码是:

XposedHelpers.findAndHookMethod(
    "android.app.ApplicationPackageManager",
    lpparam.classLoader,
    "getInstalledPackages", 
    int.class, // this line has been added as the getInstalledPackages method has one int parameter
    new XC_MethodHook() {
    @Override
    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
        XposedBridge.log("getInstalledPackages()");
            Log.d("HookLogin", "getInstalledPackages()");
        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM