forked from open-obfuscator/o-mvll
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not try opaque constants when handling infinite loops
We should not break the correctness of the program, even when the compiler may be able to remove infinite loops with no side-effects. As constants get reconstructed with a stack-allocated variable, do not conceal loop-variant constants when possibly in presence of infinite loops; this otherwise could lead to stack-overflow issues. Fixes: open-obfuscator#39.
- Loading branch information
1 parent
c45fe12
commit 6030d75
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
25 changes: 25 additions & 0 deletions
25
src/test/passes/opaque-constants/opaque-constants-infinite-loop.ll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |