Enable instruction-level tracing. Trace line will be emitted for each instruction before it gets executed. The info includes static data along with the relevant registers state and symbols resolving. Args: ql: qiling instance
(ql: Qiling)
| 143 | return f'{insn.address:08x} | {insn.bytes.hex():24s} {insn.mnemonic:10} {operands:56s} | {reads}' |
| 144 | |
| 145 | def enable_full_trace(ql: Qiling): |
| 146 | """Enable instruction-level tracing. |
| 147 | |
| 148 | Trace line will be emitted for each instruction before it gets executed. The info |
| 149 | includes static data along with the relevant registers state and symbols resolving. |
| 150 | |
| 151 | Args: |
| 152 | ql: qiling instance |
| 153 | """ |
| 154 | |
| 155 | # enable detailed disassembly info |
| 156 | md = ql.arch.disassembler |
| 157 | md.detail = True |
| 158 | |
| 159 | assert md.arch == CS_ARCH_X86, 'currently available only for intel architecture' |
| 160 | |
| 161 | # if available, use symbols map to resolve memory accesses |
| 162 | symsmap = getattr(ql.loader, 'symsmap', {}) |
| 163 | |
| 164 | # show trace lines in a darker color so they would be easily distinguished from |
| 165 | # ordinary log records |
| 166 | faded_color = "\033[2m" |
| 167 | reset_color = "\033[0m" |
| 168 | |
| 169 | def __trace_hook(ql: Qiling, address: int, size: int): |
| 170 | """[internal] Trace hook callback. |
| 171 | """ |
| 172 | |
| 173 | for record in __get_trace_records(ql, address, size, md): |
| 174 | line = __to_trace_line(record, symsmap) |
| 175 | |
| 176 | ql.log.debug(f'{faded_color}{line}{reset_color}') |
| 177 | |
| 178 | ql.hook_code(__trace_hook) |
| 179 | |
| 180 | def enable_history_trace(ql: Qiling, nrecords: int): |
| 181 | """Enable instruction-level tracing in history mode. |