I'm developing an Android app that has to be obfuscated for security reasons. Some classes and fields that are obfuscated by R8 are used in my C++ code, so of course the obfuscation step breaks this part of the code.
My question is, since I don't want to just keep those classes and fields unobfuscated, how can I script an automatic modification of the C++ code based on the mapping.txt
that is output by R8?
More specifically, the issues I'm facing while trying to tackle this problem are the following:
mapping.txt
file, so how can I reorder the tasks or work around this problemAny help would be appreciated.
Here is the spark of an idea, up to you to see if it is workable:
mapping.txt
of a build and remove everything except the parts needed by your JNI code.-applymapping
option in all subsequent builds. This will keep the JNI symbols obfuscated but stable. Other symbols will still be randomly obfuscated.m
table in the following function:inline constexpr const char * mapping(const char* in) {
std::pair<const char *, const char *> m[] = {
{"important/class","a"},
{"important/other/class", "a.b"},
};
for (const auto& [normal, obfuscated]: m) {
if (!strcmp(normal, in)) return obfuscated;
}
return "ERROR";
}
mapping("foo")
anywhere you need to reference a class, field or type name.In a brief experiment the compiler completely inlined and eliminated the mapping
function, leaving only the obfuscated type in place.