77
88sys .path .append ('..' )
99
10- from qiling import Qiling
1110from qiling .const import QL_VERBOSE
12- from qiling .extensions .r2 import R2Qiling
11+ from qiling .extensions .r2 import R2Qiling as Qiling
1312
1413
1514
1615if __name__ == "__main__" :
17- # a program obfuscated by OLLVM CFF flatten, which should print 4 when argv[1] is 1
16+ # a program obfuscated by OLLVM control flow graph flatten, which should print 4 when argv[1] is 1
1817 # see source code at examples/src/linux/fla_test.c
19- ql = R2Qiling (['rootfs/x86_linux/bin/test_fla_argv' , '1' ], 'rootfs/x86_linux' , verbose = QL_VERBOSE .DEFAULT )
18+ ql = Qiling (['rootfs/x86_linux/bin/test_fla_argv' , '1' ], 'rootfs/x86_linux' , verbose = QL_VERBOSE .DEFAULT )
19+ ctx = ql .save ()
2020 r2 = ql .r2
21- # now we can use r2 parsed symbol name instead of address
21+ # now we can use r2 parsed symbol name instead of address to get function
2222 fcn = r2 .get_fcn ('target_function' )
23- print ( fcn )
23+ # de-flatten the target function, ql code will be patched
2424 r2 .deflat (fcn )
25+ # run the de-flattened program, it should print 4 as expected
2526 ql .run ()
26- r2 .shell ()
27+ # get a r2-like interactive shell to reverse engineering target_function
28+ r2 .shell ('target_function' )
29+ # run `pdf` in r2 shell to print disassembly of target_function
30+ # we should see many patched NOP instructions
31+
32+ print ('restore the original program' )
33+ ql .restore (ctx )
34+ r2 = ql .r2
35+ # the program is still obfuscated
36+ r2 .shell ('target_function' )
0 commit comments