blacklist java keywords

This commit is contained in:
kotori0 2022-02-02 18:45:20 +08:00 committed by LoveSy
parent 581810401d
commit f254576934
1 changed files with 34 additions and 17 deletions

View File

@ -23,6 +23,7 @@
#include <jni.h>
#include <unistd.h>
#include <algorithm>
#include <random>
#include <unordered_map>
#include <sys/mman.h>
@ -60,6 +61,7 @@ Java_org_lsposed_lspd_service_ObfuscationManager_getObfuscatedSignature(JNIEnv *
return env->NewStringUTF(obfuscated_signature.c_str());
}
auto regen = []() {
static auto& chrs = "abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
@ -67,20 +69,35 @@ Java_org_lsposed_lspd_service_ObfuscationManager_getObfuscatedSignature(JNIEnv *
thread_local static std::uniform_int_distribution<std::string::size_type> pick(0, sizeof(chrs) - 2);
thread_local static std::uniform_int_distribution<std::string::size_type> choose_slash(0, 10);
std::string out;
size_t length = old_signature.size();
obfuscated_signature.reserve(length);
obfuscated_signature += "L";
out.reserve(length);
out += "L";
for (size_t i = 1; i < length; i++) {
if (choose_slash(rg) > 8 && // 80% alphabet + 20% slashes
obfuscated_signature[i - 1] != '/' && // slashes could not stick together
out[i - 1] != '/' && // slashes could not stick together
i != 1 && // the first character should not be slash
i != length - 1) { // and the last character
obfuscated_signature += "/";
out += "/";
} else {
obfuscated_signature += chrs[pick(rg)];
out += chrs[pick(rg)];
}
}
return out;
};
auto contains_keyword = [](std::string_view s) -> bool {
for (const auto &i: {"do", "if", "for", "int", "new", "try"}) {
if (s.find(i) != std::string::npos) return true;
}
return false;
};
do {
obfuscated_signature = regen();
} while (contains_keyword(obfuscated_signature));
LOGD("ObfuscationManager.getObfuscatedSignature: %s", obfuscated_signature.c_str());
return env->NewStringUTF(obfuscated_signature.c_str());
}