22
33# More info, please refer to https://github.com/qilingframework/qiling/pull/765
44
5-
65from collections import deque
76from typing import Deque , Iterable , Iterator , Mapping , Tuple
87
9- from capstone import Cs , CsInsn , CS_OP_IMM , CS_OP_MEM , CS_OP_REG
8+ from capstone import Cs , CsInsn , CS_ARCH_X86 , CS_OP_IMM , CS_OP_MEM , CS_OP_REG
109from capstone .x86 import X86Op
1110from capstone .x86_const import X86_INS_LEA , X86_REG_INVALID , X86_REG_RIP
1211
1615
1716# <WORKAROUND>
1817def __uc2_workaround () -> Mapping [int , int ]:
19- """Starting from Unicron2, Unicron and Capstone Intel registers definitions are
18+ """Starting from Unicorn2, Unicorn and Capstone Intel registers definitions are
2019 no longer aligned and cannot be used interchangebly. This temporary workaround
2120 maps capstone x86 registers definitions to unicorn x86 registers definitions.
2221
@@ -47,6 +46,7 @@ def __get_trace_records(ql: Qiling, address: int, size: int, md: Cs) -> Iterator
4746 # unicorn denotes unsupported instructions by a magic size value. though these instructions
4847 # are not emulated, capstone can still parse them.
4948 if size == 0xf1f1f1f1 :
49+ # note that invalid instructions will generate a StopIteration exception here
5050 yield next (__get_trace_records (ql , address , 16 , md ))
5151 return
5252
@@ -162,8 +162,8 @@ def enable_full_trace(ql: Qiling):
162162
163163 # show trace lines in a darker color so they would be easily distinguished from
164164 # ordinary log records
165- DarkGray = "\x1b [90m "
166- Default = "\x1b [39m "
165+ faded_color = "\033 [2m "
166+ reset_color = "\033 [0m "
167167
168168 def __trace_hook (ql : Qiling , address : int , size : int ):
169169 """[internal] Trace hook callback.
@@ -172,7 +172,7 @@ def __trace_hook(ql: Qiling, address: int, size: int):
172172 for record in __get_trace_records (ql , address , size , md ):
173173 line = __to_trace_line (record , symsmap )
174174
175- ql .log .debug (f'{ DarkGray } { line } { Default } ' )
175+ ql .log .debug (f'{ faded_color } { line } { reset_color } ' )
176176
177177 ql .hook_code (__trace_hook )
178178
0 commit comments