Question

I am trying to use Xposed on Android to hook onto an Android resource, in particular, Webview's loadUrl. The code below hooks onto loadUrl and if successful, prints a message onto the log.

findAndHookMethod("com.example.webview.MainActivity", lpparam.classLoader, "android.webkit.WebView.loadUrl", new XC_MethodHook() {
        @Override
        protected void afterHookedMethod(MethodHookParam param) throws Throwable {
            XposedBridge.log("we are in loadurl!");
        }

However, doing so throws an error:

java.lang.NoSuchMethodError: android.webkit.WebView#android.webkit.WebView.loadUrl()#exact

Is it even possible to hook onto Android resources with xposed?

Était-ce utile?

La solution 2

It doesn't find the method because you didn't specify the method arguments. The Xposed helper function is trying to find a loadUrl method with no arguments which does not exist.

Looking at webView there are the following signatures:

  • loadUrl(String url)
  • loadUrl(String url, Map additionalHttpHeaders).

I haven't tested but this should work:

try {
    Method loadUrl1 = android.webkit.WebView.class.getDeclaredMethod("loadUrl", String.class);

    Method loadUrl2 = android.webkit.WebView.class.getDeclaredMethod("loadUrl", String.class, Map.class);

    XposedBridge.hookMethod(loadUrl1, new XC_MethodHook() { /* your code here*/});
    XposedBridge.hookMethod(loadUrl2, new XC_MethodHook() { /* your code here*/});

} catch (NoSuchMethodException e) { ... }

Or even with the same API you were using:

findAndHookMethod(classname, classloader, methodName, **ARGUMENTS[]**, xc_hook)

Also, did you mean class name "android.webkit.WebView" and method "loadUrl"?

Good luck

Autres conseils

You could use simply "hookAllMethods"

XposedBridge.hookAllMethods("com.example.webview.MainActivity", "loadUrl", new XC_MethodHook() {
        @Override
        protected void afterHookedMethod(MethodHookParam param) throws Throwable {
            XposedBridge.log("we are in loadurl!");
        }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top