Skip to content

Commit 942daa1

Browse files
committed
Re-organize os emu_error
1 parent f83e4f6 commit 942daa1

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

qiling/loader/loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
Image = NamedTuple('Image', (('base', int), ('end', int), ('path', str)))
1111

12-
class QlLoader():
12+
class QlLoader:
1313
def __init__(self, ql: Qiling):
1414
self.ql = ql
1515
self.env = self.ql.env

qiling/os/os.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import sys
77
from typing import Any, Iterable, Optional, Callable, Mapping, Sequence, TextIO, Tuple
88

9+
from unicorn import UcError
10+
911
from qiling import Qiling
1012
from qiling.const import QL_OS, QL_INTERCEPT, QL_OS_POSIX
1113
from qiling.os.const import STRING, WSTRING, GUID
@@ -213,29 +215,28 @@ def stop(self):
213215
self.ql.emu_stop()
214216

215217
def emu_error(self):
216-
self.ql.log.error("\n")
217-
218+
self.ql.log.error(f'CPU Context:')
218219
for reg in self.ql.reg.register_mapping:
219220
if isinstance(reg, str):
220-
REG_NAME = reg
221-
REG_VAL = self.ql.reg.read(reg)
222-
self.ql.log.error("%s\t:\t 0x%x" % (REG_NAME, REG_VAL))
223-
224-
self.ql.log.error("\n")
225-
self.ql.log.error("PC = 0x%x" % (self.ql.reg.arch_pc))
226-
containing_image = self.find_containing_image(self.ql.reg.arch_pc)
227-
if containing_image:
228-
offset = self.ql.reg.arch_pc - containing_image.base
229-
self.ql.log.error(" (%s+0x%x)" % (containing_image.path, offset))
230-
else:
231-
self.ql.log.info("\n")
232-
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
233224

234225
try:
235-
buf = self.ql.mem.read(self.ql.reg.arch_pc, 8)
236-
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')
237240

238-
self.ql.log.info("\n")
239-
self.utils.disassembler(self.ql, self.ql.reg.arch_pc, 64)
240-
except:
241-
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

Comments
 (0)