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 <jni.h>
#include <unistd.h> #include <unistd.h>
#include <algorithm>
#include <random> #include <random>
#include <unordered_map> #include <unordered_map>
#include <sys/mman.h> #include <sys/mman.h>
@ -60,27 +61,43 @@ Java_org_lsposed_lspd_service_ObfuscationManager_getObfuscatedSignature(JNIEnv *
return env->NewStringUTF(obfuscated_signature.c_str()); return env->NewStringUTF(obfuscated_signature.c_str());
} }
static auto& chrs = "abcdefghijklmnopqrstuvwxyz" auto regen = []() {
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"; static auto& chrs = "abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
thread_local static std::mt19937 rg{std::random_device{}()}; thread_local static std::mt19937 rg{std::random_device{}()};
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> pick(0, sizeof(chrs) - 2);
thread_local static std::uniform_int_distribution<std::string::size_type> choose_slash(0, 10); thread_local static std::uniform_int_distribution<std::string::size_type> choose_slash(0, 10);
size_t length = old_signature.size(); std::string out;
obfuscated_signature.reserve(length); size_t length = old_signature.size();
obfuscated_signature += "L"; out.reserve(length);
out += "L";
for (size_t i = 1; i < length; i++) { for (size_t i = 1; i < length; i++) {
if (choose_slash(rg) > 8 && // 80% alphabet + 20% slashes 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 != 1 && // the first character should not be slash
i != length - 1) { // and the last character i != length - 1) { // and the last character
obfuscated_signature += "/"; out += "/";
} else { } 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()); LOGD("ObfuscationManager.getObfuscatedSignature: %s", obfuscated_signature.c_str());
return env->NewStringUTF(obfuscated_signature.c_str()); return env->NewStringUTF(obfuscated_signature.c_str());
} }