|
6 | 6 | import sys |
7 | 7 | from typing import Any, Iterable, Optional, Callable, Mapping, Sequence, TextIO, Tuple |
8 | 8 |
|
| 9 | +from unicorn import UcError |
| 10 | + |
9 | 11 | from qiling import Qiling |
10 | 12 | from qiling.const import QL_OS, QL_INTERCEPT, QL_OS_POSIX |
11 | 13 | from qiling.os.const import STRING, WSTRING, GUID |
@@ -202,36 +204,39 @@ def find_containing_image(self, pc): |
202 | 204 | if image.base <= pc < image.end: |
203 | 205 | return image |
204 | 206 |
|
| 207 | + # os main method; derivatives must implement one of their own |
| 208 | + def run(self) -> None: |
| 209 | + raise NotImplementedError |
| 210 | + |
205 | 211 | def stop(self): |
206 | 212 | if self.ql.multithread: |
207 | 213 | self.thread_management.stop() |
208 | 214 | else: |
209 | 215 | self.ql.emu_stop() |
210 | 216 |
|
211 | 217 | def emu_error(self): |
212 | | - self.ql.log.error("\n") |
213 | | - |
| 218 | + self.ql.log.error(f'CPU Context:') |
214 | 219 | for reg in self.ql.reg.register_mapping: |
215 | 220 | if isinstance(reg, str): |
216 | | - REG_NAME = reg |
217 | | - REG_VAL = self.ql.reg.read(reg) |
218 | | - self.ql.log.error("%s\t:\t 0x%x" % (REG_NAME, REG_VAL)) |
219 | | - |
220 | | - self.ql.log.error("\n") |
221 | | - self.ql.log.error("PC = 0x%x" % (self.ql.reg.arch_pc)) |
222 | | - containing_image = self.find_containing_image(self.ql.reg.arch_pc) |
223 | | - if containing_image: |
224 | | - offset = self.ql.reg.arch_pc - containing_image.base |
225 | | - self.ql.log.error(" (%s+0x%x)" % (containing_image.path, offset)) |
226 | | - else: |
227 | | - self.ql.log.info("\n") |
228 | | - self.ql.mem.show_mapinfo() |
| 221 | + self.ql.log.error(f'{reg}\t: {self.ql.reg.read(reg):#x}') |
| 222 | + |
| 223 | + pc = self.ql.reg.arch_pc |
229 | 224 |
|
230 | 225 | try: |
231 | | - buf = self.ql.mem.read(self.ql.reg.arch_pc, 8) |
232 | | - self.ql.log.error("%r" % ([hex(_) for _ in buf])) |
| 226 | + data = self.ql.mem.read(pc, size=8) |
| 227 | + except UcError: |
| 228 | + pc_info = ' (unreachable)' |
| 229 | + else: |
| 230 | + self.ql.log.error('Hexdump:') |
| 231 | + self.ql.log.error(data.hex(' ')) |
| 232 | + |
| 233 | + self.ql.log.error('Disassembly:') |
| 234 | + self.ql.arch.utils.disassembler(self.ql, pc, 64) |
| 235 | + |
| 236 | + containing_image = self.find_containing_image(pc) |
| 237 | + pc_info = f' ({containing_image.path} + {pc - containing_image.base:#x})' if containing_image else '' |
| 238 | + finally: |
| 239 | + self.ql.log.error(f'PC = {pc:#0{self.ql.pointersize * 2 + 2}x}{pc_info}\n') |
233 | 240 |
|
234 | | - self.ql.log.info("\n") |
235 | | - self.utils.disassembler(self.ql, self.ql.reg.arch_pc, 64) |
236 | | - except: |
237 | | - self.ql.log.error("Error: PC(0x%x) Unreachable" % self.ql.reg.arch_pc) |
| 241 | + self.ql.log.info(f'Memory map:') |
| 242 | + self.ql.mem.show_mapinfo() |
0 commit comments