mercredi 25 mars 2020

Completely hide use of PackageManager in the generated code

Analyzing the apk with Android Studio, in classes.dex every call to native methods aren't obfuscated, also for explicit Class identifier, e.g.:

.line 3
    invoke-virtual {p1}, Landroid/content/Context;->getPackageManager()Landroid/content/pm/PackageManager;
invoke-virtual {p1}, Landroid/content/Context;->getPackageName()Ljava/lang/String;
...

I'm writing a code to access PackageManager via reflection, in order to make harder the work to find its use in the generated code.

This is a portion of code that works in my Android application:

import static com.example.test.Utils.getPackageManagerViaReflection;
...

public class MainActivity extends AppCompatActivity {
    ...

    @Override
    protected void onResume() {
        super.onResume();

        PackageManager packageManagerViaReflection = getPackageManagerViaReflection(this, this);
        ...
    }

    ...
}

The method:

public static PackageManager getPackageManagerViaReflection(Context context, Object callerObj) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    String getPM = new String(Base64.decode("Z2V0UGFja2FnZU1hbmFnZXI=\n", 0));
    Method gpmMethod = context.getClass().getMethod(getPM);
    Object gpmObject = gpmMethod.invoke(callerObj);

    if(gpmObject instanceof PackageManager) {
        return (PackageManager) gpmObject;
    }

    return null;
}

How to completely hide the text PackageManager in the cast (PackageManager) and in instanceof PackageManager?

Thanks a lot!





Aucun commentaire:

Enregistrer un commentaire