From 0d2e488edf42df74dc594414bec7dc267b7c5f6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Damien?= Date: Tue, 17 Mar 2026 20:03:43 +0100 Subject: [PATCH] string: obfuscate all byte arrays with alignment of 1 - Remove null-terminated check in `encodeStringDataArray`. - Filter globals to only obfuscate those with an alignment of 1. Not doing that lead to crashes of the compiler. - Use `isString()` instead of `isCString()` to include more byte arrays. --- string/StringObfuscation.cpp | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/string/StringObfuscation.cpp b/string/StringObfuscation.cpp index ca15028..69537f0 100644 --- a/string/StringObfuscation.cpp +++ b/string/StringObfuscation.cpp @@ -28,15 +28,6 @@ ConstantDataArray *StringObfuscatorPass::encodeStringDataArray(LLVMContext &ctx, const char *str, size_t size, uint8_t key) { - // Check this is a valid string (not containing zeros) - if (str[size - 1] == '\0') { - if (strnlen(str, size) != size - 1) - return nullptr; - } else { - if (strnlen(str, size) != size) - return nullptr; - } - // Encode the data char *encodedStr = (char *)malloc(size); for (unsigned int i = 0; i < size; i++) { @@ -94,10 +85,11 @@ bool StringObfuscatorPass::encodeAllStrings(Module &M) { // For each global variable for (GlobalVariable &gv : M.globals()) { - if (!gv.isConstant() // constant - || !gv.hasInitializer() // unitialized - || gv.hasExternalLinkage() // external - || gv.getSection() == "llvm.metadata") { // Intrinsic Global Variables + if (!gv.isConstant() // constant + || !gv.hasInitializer() // unitialized + || gv.hasExternalLinkage() // external + || gv.getAlign().valueOrOne().value() != 1 // align == 1 + || gv.getSection() == "llvm.metadata") { // Intrinsic Global Variables //|| gv.getSection().find("__objc_methname") != string::npos) { // TODO : // is this necessary ? continue; @@ -109,7 +101,7 @@ bool StringObfuscatorPass::encodeAllStrings(Module &M) { // Encode the value and update the variable if (isa(initializer)) { // Global variable auto array = cast(initializer); - if (array->isCString()) { + if (array->isString()) { encodeGlobalString(ctx, &gv, array); } } else if (isa(initializer)) { // Variable in a struct @@ -118,7 +110,7 @@ bool StringObfuscatorPass::encodeAllStrings(Module &M) { auto operand = cs->getOperand(i); if (isa(operand)) { auto array = cast(operand); - if (array->isCString()) { + if (array->isString()) { encodeStructString(ctx, &gv, cs, array, i); } }