From 24914c22e289e7f390ef69b46b5502abfb490888 Mon Sep 17 00:00:00 2001 From: bluesadi Date: Mon, 1 Jan 2024 09:44:31 +0000 Subject: [PATCH] Refine caching mechanism of MBAObfuscation --- llvm/lib/Transforms/Obfuscation/MBAUtils.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Transforms/Obfuscation/MBAUtils.cpp b/llvm/lib/Transforms/Obfuscation/MBAUtils.cpp index 0a544019f..35e05ee97 100644 --- a/llvm/lib/Transforms/Obfuscation/MBAUtils.cpp +++ b/llvm/lib/Transforms/Obfuscation/MBAUtils.cpp @@ -35,9 +35,12 @@ static int8_t truthTables[15][4] = { int64_t *MBAUtils::generateLinearMBA(int numExprs) { #ifdef USE_CACHE static std::queue cached_coeffs; - if (cached_coeffs.size() && cryptoutils->get_range(10) < 8) { + if (cached_coeffs.size() && cryptoutils->get_range(100) < 80) { int64_t *coeffs = cached_coeffs.front(); cached_coeffs.pop(); + int64_t *coeffs_copy = new int64_t[15]; + std::copy(coeffs, coeffs + 15, coeffs_copy); + cached_coeffs.push(coeffs_copy); return coeffs; } #endif @@ -77,11 +80,9 @@ int64_t *MBAUtils::generateLinearMBA(int numExprs) { } delete[] exprs; #ifdef USE_CACHE - if (cached_coeffs.size() < 10) { - int64_t *coeffs_copy = new int64_t[15]; - std::copy(coeffs, coeffs + 15, coeffs_copy); - cached_coeffs.push(coeffs_copy); - } + int64_t *coeffs_copy = new int64_t[15]; + std::copy(coeffs, coeffs + 15, coeffs_copy); + cached_coeffs.push(coeffs_copy); #endif return coeffs; }