99from qiling import *
1010from qiling .exception import *
1111from qiling .const import QL_VERBOSE
12+ from qiling .const import QL_INTERCEPT , QL_CALL_BLOCK , QL_VERBOSE
13+ from qiling .os .const import STRING
1214
1315class QNXTest (unittest .TestCase ):
1416 def test_arm_qnx_static (self ):
@@ -20,7 +22,56 @@ def test_arm_qnx_static(self):
2022
2123 def test_arm_qnx_sqrt (self ):
2224 ql = Qiling (["../examples/rootfs/arm_qnx/bin/hello_sqrt" ], "../examples/rootfs/arm_qnx" , verbose = QL_VERBOSE .DEBUG )
23- ql .run ()
25+ ql .run ()
26+
27+ def test_set_api_arm_qnx_sqrt (self ):
28+ self .set_api_puts_onenter = False
29+ self .set_api_puts_onexit = False
30+ self .set_api_printf_onenter = False
31+ self .set_api_printf_onexit = False
32+
33+ def my_puts_onenter (ql : Qiling ):
34+ params = ql .os .resolve_fcall_params ({'s' : STRING })
35+
36+ print (f'puts("{ params ["s" ]} ")' )
37+ self .set_api_puts_onenter = True
38+ return QL_CALL_BLOCK
39+
40+ def my_puts_onexit (ql : Qiling ):
41+ print (f'after puts' )
42+ self .set_api_puts_onexit = True
43+ return QL_CALL_BLOCK
44+
45+ def my_printf_onenter (ql : Qiling ):
46+ params = ql .os .resolve_fcall_params ({'s' : STRING })
47+
48+ print (f'printf("{ params ["s" ]} ")' )
49+ self .set_api_printf_onenter = True
50+ return QL_CALL_BLOCK
51+
52+ def my_printf_onexit (ql : Qiling ):
53+ print (f'after printf' )
54+ self .set_api_printf_onexit = True
55+ return QL_CALL_BLOCK
56+
57+ ql = Qiling (["../examples/rootfs/arm_qnx/bin/hello_sqrt" ], "../examples/rootfs/arm_qnx" , verbose = QL_VERBOSE .DEBUG )
58+ ql .set_api ('puts' , my_puts_onenter , QL_INTERCEPT .ENTER )
59+ ql .set_api ('printf' , my_printf_onenter , QL_INTERCEPT .ENTER )
60+
61+ # ql.set_api('puts', my_puts_onexit, QL_INTERCEPT.EXIT)
62+ ql .set_api ('printf' , my_printf_onexit , QL_INTERCEPT .EXIT )
63+
64+ ql .run ()
65+
66+ self .assertEqual (False , self .set_api_puts_onenter )
67+ self .assertEqual (False , self .set_api_puts_onexit )
68+ self .assertEqual (True , self .set_api_printf_onenter )
69+ self .assertEqual (True , self .set_api_printf_onexit )
70+
71+ del self .set_api_puts_onenter
72+ del self .set_api_puts_onexit
73+ del self .set_api_printf_onenter
74+ del self .set_api_printf_onexit
2475
2576if __name__ == "__main__" :
2677 unittest .main ()
0 commit comments