mercredi 20 juin 2018

How do I set proxy on WebView now that Chromium is obfuscating class names?

I've been using a solution similar to the answer proposed here to set a WebView proxy. However, it appears that chromium started obfuscating class names, so identifying the broadcast receiver by reflection using the class name is no longer possible with newer chromium versions.

A solution that I thought about is to invoke onReceive on ALL broadcast receivers in the current app-context.

This is not an ideal solution, because it may have unwanted side effects by invoking the wrong receivers.

Is there a better way to do this? Thanks

Building on the previous answer, my solution would look something like this:

    Class applictionCls = Class.forName(applicationClassName);
    Field loadedApkField = applictionCls.getField("mLoadedApk");
    loadedApkField.setAccessible(true);
    Object loadedApk = loadedApkField.get(appContext);
    Class loadedApkCls = Class.forName("android.app.LoadedApk");
    Field receiversField = loadedApkCls.getDeclaredField("mReceivers");
    receiversField.setAccessible(true);
    ArrayMap receivers = (ArrayMap) receiversField.get(loadedApk);
    ArrayMap contextReceivers = (ArrayMap) receivers.get(appContext);
    for (Object rec : contextReceivers.keySet()) {
        Class clazz = rec.getClass();

        Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class);
        Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION);
        try {
            onReceiveMethod.invoke(rec, appContext, intent);
        } catch (Exception e) {
            // oops, couldn't invoke this receiver
        }
    }





Aucun commentaire:

Enregistrer un commentaire