skylot / jadx

Dex to Java decompiler
Apache License 2.0
40.86k stars 4.8k forks source link

How to fetch the "real" class for some method? #1218

Closed impvd closed 3 years ago

impvd commented 3 years ago

I just decompiled an app with Jadx-gui, and here're the target code that I wanna hook with Xposed:

package androidx.appcompat.widget;

class SuggestionsAdapter extends ResourceCursorAdapter implements View.OnClickListener {
   public Cursor getSearchManagerSuggestions(SearchableInfo searchableInfo, String str, int i) {
  ...
  }
}

With the xposed code:

val target = lpparam?.classLoader?.loadClass("androidx.appcompat.widget.SuggestionsAdapter")
        XposedHelpers.findAndHookMethod(target, "getSearchManagerSuggestions", object : XC_MethodHook() {

            override fun afterHookedMethod(param: MethodHookParam?) {
                val cursor = param!!.thisObject as Cursor
                if (cursor.moveToFirst()) {
                    val candidateCnt = cursor.columnCount
                    XposedBridge.log("Loaded app: $candidateCnt")
                }
            }
        })

But there's error in log:

 EdXposed-Bridge: java.lang.ClassNotFoundException: Didn't find class "androidx.appcompat.widget.SuggestionsAdapter" on path: DexPathList[[zip file "/system/framework/com.android.location.provider.jar", zip file "/system/framework/services.jar", zip file "/system/framework/ethernet-service.jar", zip file "/system/framework/oneplus-services.jar", zip file "/system/framework/oneplus-wifi-service.jar", zip file "/apex/com.android.permission/javalib/service-permission.jar", zip file "/apex/com.android.wifi/javalib/service-wifi.jar", zip file "/apex/com.android.ipsec/javalib/android.net.ipsec.ike.jar"],nativeLibraryDirectories=[/system/lib64, /system/system_ext/lib64, /system/lib64, /system/system_ext/lib64]]

It should be something like com.targetapp.somepath1.somepath2.SuggestionsAdapter, but I am not sure how to find it.

jpstotz commented 3 years ago

When Jadx renames a class then a comment is added containing the original class name. Therefore the class name to hook should be really androidx.appcompat.widget.SuggestionsAdapter.

The packageName of the app absolutely has nothing to do with the class name.

Your Xposed code is just a fragment. Have you made sure to only run your Xposed plugin for the app you want to modify? Otherwise it will be executed in other apps as well and if they don't contain the class androidx.appcompat.widget.SuggestionsAdapter you will get that error message.

As I don't see an problem in Jadx addressed in this issue I am closing it. If you have problems developing an Xposed plugin you may better create a question on https://Stackoverflow.com containing the minimum working code of your plugin.

impvd commented 3 years ago

@jpstotz Awesome thanks, I just debug it again and logged more details.

07-29 22:04:55.002  4529  4529 E EdXposed-Bridge: java.lang.NoSuchMethodError: androidx.appcompat.widget.SuggestionsAdapter#getSearchManagerSuggestions()#exact

You are right, the class exists. And it seems that I just need to debug the xposed module.