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.
Add report_diff user callback in Python API (open-obfuscator#49)
Extend the Python API in a way that allows users to monitor IR-level changes from individual passes. That might be useful for experimentation, validation, testing, etc. The included test shows how to configure it. Co-authored-by: Antonio Frighetto <[email protected]>
- Loading branch information
1 parent
6f7aaf3
commit c10c275
Showing
9 changed files
with
146 additions
and
8 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
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
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
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,23 @@ | ||
// REQUIRES: x86-registered-target | ||
|
||
// RUN: env OMVLL_CONFIG=%S/report_diff.py clang -target x86_64-pc-linux-gnu -fpass-plugin=%libOMVLL -O1 -S %s -o /dev/null -DNEEDS_OBFUSCATION | FileCheck %s | ||
// RUN: env OMVLL_CONFIG=%S/report_diff.py clang -target x86_64-pc-linux-gnu -fpass-plugin=%libOMVLL -O1 -S %s -o /dev/null | FileCheck --allow-empty --check-prefix=NO_REPORT %s | ||
|
||
// Make sure the report_diff function was called if the obfuscation was applied | ||
// CHECK: omvll::Arithmetic applied obfuscation | ||
// CHECK: --- original | ||
// CHECK: +++ obfuscated | ||
// CHECK: @@ | ||
// CHECK: - | ||
// CHECK: + | ||
|
||
// Make sure the report_diff function was NOT called if the obfuscation was NOT applied | ||
// NO_REPORT-NOT: omvll::Arithmetic applied obfuscation | ||
|
||
void test(char *dst, const char *src, unsigned len) { | ||
#if defined(NEEDS_OBFUSCATION) | ||
*dst = *src ^ 35; | ||
#else | ||
*dst = *src; | ||
#endif | ||
} |
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,20 @@ | ||
import omvll | ||
from difflib import unified_diff | ||
from functools import lru_cache | ||
|
||
class MyConfig(omvll.ObfuscationConfig): | ||
def __init__(self): | ||
super().__init__() | ||
def obfuscate_arithmetic(self, mod: omvll.Module, | ||
fun: omvll.Function) -> omvll.ArithmeticOpt: | ||
return omvll.ArithmeticOpt(rounds=2) | ||
def report_diff(self, pass_name: str, original: str, obfuscated: str): | ||
print(pass_name, "applied obfuscation:") | ||
diff = unified_diff(original.splitlines(), obfuscated.splitlines(), | ||
'original', 'obfuscated', lineterm='') | ||
for line in diff: | ||
print(line) | ||
|
||
@lru_cache(maxsize=1) | ||
def omvll_get_config() -> omvll.ObfuscationConfig: | ||
return MyConfig() |