diff --git a/src/passes/opaque-constants/OpaqueConstants.cpp b/src/passes/opaque-constants/OpaqueConstants.cpp index 199826a0..ff9e6032 100644 --- a/src/passes/opaque-constants/OpaqueConstants.cpp +++ b/src/passes/opaque-constants/OpaqueConstants.cpp @@ -267,6 +267,9 @@ PreservedAnalyses OpaqueConstants::run(Module &M, } for (BasicBlock& BB : F) { + // Don't try opaque constants when potentially handling infinite loops. + if (is_contained(successors(&BB), &BB)) + continue; Changed |= runOnBasicBlock(BB, inserted); } } diff --git a/src/test/passes/opaque-constants/config_all.py b/src/test/passes/opaque-constants/config_all.py new file mode 100644 index 00000000..67fa7982 --- /dev/null +++ b/src/test/passes/opaque-constants/config_all.py @@ -0,0 +1,12 @@ +import omvll +from functools import lru_cache + +class MyConfig(omvll.ObfuscationConfig): + def __init__(self): + super().__init__() + def obfuscate_constants(self, mod: omvll.Module, func: omvll.Function): + return True + +@lru_cache(maxsize=1) +def omvll_get_config() -> omvll.ObfuscationConfig: + return MyConfig() diff --git a/src/test/passes/opaque-constants/opaque-constants-infinite-loop.ll b/src/test/passes/opaque-constants/opaque-constants-infinite-loop.ll new file mode 100644 index 00000000..959ab266 --- /dev/null +++ b/src/test/passes/opaque-constants/opaque-constants-infinite-loop.ll @@ -0,0 +1,25 @@ +; RUN: env OMVLL_CONFIG=%S/config_all.py clang -target aarch64-linux-android -fno-legacy-pass-manager -fpass-plugin=%libOMVLL -O0 -S -emit-llvm %s -o - | FileCheck %s --check-prefix=O0 +; RUN: env OMVLL_CONFIG=%S/config_all.py clang -target aarch64-linux-android -fno-legacy-pass-manager -fpass-plugin=%libOMVLL -O1 -S -emit-llvm %s -o - | FileCheck %s --check-prefix=O1 +; RUN: env OMVLL_CONFIG=%S/config_all.py clang -target arm64-apple-ios -fno-legacy-pass-manager -fpass-plugin=%libOMVLL -O0 -S -emit-llvm %s -o - | FileCheck %s --check-prefix=O0 +; RUN: env OMVLL_CONFIG=%S/config_all.py clang -target arm64-apple-ios -fno-legacy-pass-manager -fpass-plugin=%libOMVLL -O1 -S -emit-llvm %s -o - | FileCheck %s --check-prefix=O1 + +define void @opaque_infinite_loop() { +; O0-LABEL: @opaque_infinite_loop +; O0: loop +; O0: %loaded_i = load i32, i32* %i, align 4 +; O0-NEXT: %add = add nsw i32 %loaded_i, 1 +; O0-NEXT: store i32 %add, i32* %i, align 4 +; O0-NEXT: br label %loop +; O1-LABEL: @opaque_infinite_loop +; O1: loop +; O1: br label %loop +entry: + %i = alloca i32, align 4 + store i32 0, i32* %i, align 4 + br label %loop +loop: ; preds = %loop, %entry + %loaded_i = load i32, i32* %i, align 4 + %add = add nsw i32 %loaded_i, 1 + store i32 %add, i32* %i, align 4 + br label %loop +}