@@ -340,7 +340,7 @@ def _find_thread(self, thread_id):
340
340
thread = self ._minidump .threads .threads [i ]
341
341
if thread .ThreadId == thread_id :
342
342
return thread
343
- raise Exception (f"Thread 0x { thread_id :x } ({ thread_id } ) not found!" )
343
+ raise Exception (f"Thread { hex ( thread_id ) } ({ thread_id } ) not found!" )
344
344
345
345
def debug (self , message : str ):
346
346
if self ._debug :
@@ -419,7 +419,7 @@ def _setup_memory(self):
419
419
seg : minidump .MinidumpMemorySegment
420
420
for seg in self ._minidump .memory_segments_64 .memory_segments :
421
421
emu_addr = seg .start_virtual_address & self .addr_mask
422
- self .debug (f"initialize base: 0x { emu_addr :x } , size: 0x { seg .size :x } " )
422
+ self .debug (f"initialize base: { hex ( emu_addr ) } , size: { hex ( seg .size ) } " )
423
423
memory .move (seg .start_virtual_address )
424
424
assert memory .current_position == seg .start_virtual_address
425
425
data = memory .read (seg .size )
@@ -508,11 +508,11 @@ def _setup_pebteb(self, thread):
508
508
if self .wow64 :
509
509
self .memory .set_region_info (self .peb - PAGE_SIZE , "WoW64 PEB" , size = PAGE_SIZE )
510
510
511
- self .info (f"TEB: 0x { self .teb :x } , PEB: 0x { self .peb :x } " )
512
- self .info (f" ConsoleHandle: 0x { self .console_handle :x } " )
513
- self .info (f" StandardInput: 0x { self .stdin_handle :x } " )
514
- self .info (f" StandardOutput: 0x { self .stdout_handle :x } " )
515
- self .info (f" StandardError: 0x { self .stderr_handle :x } " )
511
+ self .info (f"TEB: { hex ( self .teb ) } , PEB: { hex ( self .peb ) } " )
512
+ self .info (f" ConsoleHandle: { hex ( self .console_handle ) } " )
513
+ self .info (f" StandardInput: { hex ( self .stdin_handle ) } " )
514
+ self .info (f" StandardOutput: { hex ( self .stdout_handle ) } " )
515
+ self .info (f" StandardError: { hex ( self .stderr_handle ) } " )
516
516
517
517
process_heaps = []
518
518
for i in range (0 , min (number_of_heaps , 0x1000 )):
@@ -785,7 +785,7 @@ def _setup_syscalls(self):
785
785
syscalls .append ((export .address , export .name ))
786
786
elif export .name == "Wow64Transition" :
787
787
patch_addr = self .read_ptr (export .address )
788
- self .info (f"Patching Wow64Transition: { export .address :x } -> { patch_addr :x } " )
788
+ self .info (f"Patching Wow64Transition: { hex ( export .address ) } -> { hex ( patch_addr ) } " )
789
789
# See: https://opcode0x90.wordpress.com/2007/05/18/kifastsystemcall-hook/
790
790
# mov edx, esp; sysenter; ret
791
791
KiFastSystemCall = b"\x8B \xD4 \x0F \x34 \x90 \x90 \xC3 "
@@ -921,7 +921,7 @@ def handle_exception(self):
921
921
922
922
csp = self .regs .csp - allocation_size
923
923
self .write (csp , allocation_size * b"\x69 " ) # fill stuff with 0x69 for debugging
924
- self .info (f"old csp: { self .regs .csp :x } , new csp: { csp :x } " )
924
+ self .info (f"old csp: { hex ( self .regs .csp ) } , new csp: { hex ( csp ) } " )
925
925
context_size = ctypes .sizeof (context_type )
926
926
context = context_type .from_buffer (self .read (csp , context_size ))
927
927
context .ContextFlags = context_flags
@@ -1011,12 +1011,12 @@ def start(self, begin, end=0xffffffffffffffff, count=0) -> None:
1011
1011
1012
1012
if self .exception .type == ExceptionType .Terminate :
1013
1013
if self .exit_code is not None :
1014
- self .info (f"exit code: { self .exit_code :x } " )
1014
+ self .info (f"exit code: { hex ( self .exit_code ) } " )
1015
1015
break
1016
1016
1017
1017
try :
1018
1018
emu_begin = self .handle_exception ()
1019
- except :
1019
+ except Exception :
1020
1020
traceback .print_exc ()
1021
1021
self .error (f"exception during exception handling (stack overflow?)" )
1022
1022
break
@@ -1039,12 +1039,12 @@ def start(self, begin, end=0xffffffffffffffff, count=0) -> None:
1039
1039
emu_until = 0xffffffffffffffff
1040
1040
emu_count = self .exception .tb_icount + 1
1041
1041
1042
- self .info (f"emu_start({ emu_begin :x } , { emu_until :x } , { emu_count } )" )
1042
+ self .info (f"emu_start({ hex ( emu_begin ) } , { hex ( emu_until ) } , { emu_count } )" )
1043
1043
self .kill_me = None
1044
1044
self ._uc .emu_start (emu_begin , until = emu_until , count = emu_count )
1045
- self .info (f'emulation finished, cip = { self .regs .cip :x } ' )
1045
+ self .info (f'emulation finished, cip = { hex ( self .regs .cip ) } ' )
1046
1046
if self .exit_code is not None :
1047
- self .info (f"exit code: { self .exit_code :x } " )
1047
+ self .info (f"exit code: { hex ( self .exit_code ) } " )
1048
1048
break
1049
1049
except UcError as err :
1050
1050
if self .kill_me is not None and type (self .kill_me ) is not UcError :
@@ -1053,7 +1053,7 @@ def start(self, begin, end=0xffffffffffffffff, count=0) -> None:
1053
1053
# Handle the exception outside of the except handler
1054
1054
continue
1055
1055
else :
1056
- self .error (f'error: { err } , cip = { self .regs .cip :x } ' )
1056
+ self .error (f'error: { err } , cip = { hex ( self .regs .cip ) } ' )
1057
1057
traceback .print_exc ()
1058
1058
break
1059
1059
@@ -1062,7 +1062,7 @@ def stop(self, exit_code=None) -> None:
1062
1062
self .exit_code = None
1063
1063
if exit_code is not None :
1064
1064
self .exit_code = int (exit_code )
1065
- except :
1065
+ except Exception :
1066
1066
traceback .print_exc ()
1067
1067
self .error ("Invalid type passed to exit_code!" )
1068
1068
self ._uc .emu_stop ()
@@ -1204,7 +1204,7 @@ def load_dll(self, file_name: str, file_data: bytes):
1204
1204
1205
1205
def _hook_code_exception (uc : Uc , address , size , dp : Dumpulator ):
1206
1206
try :
1207
- dp .info (f"exception step: { address :x } [{ size } ]" )
1207
+ dp .info (f"exception step: { hex ( address ) } [{ size } ]" )
1208
1208
ex = dp .exception
1209
1209
ex .step_count += 1
1210
1210
if ex .step_count >= ex .tb_icount :
@@ -1220,7 +1220,7 @@ def _hook_mem(uc: Uc, access, address, size, value, dp: Dumpulator):
1220
1220
1221
1221
fetch_accesses = [UC_MEM_FETCH , UC_MEM_FETCH_PROT , UC_MEM_FETCH_UNMAPPED ]
1222
1222
if access == UC_MEM_FETCH_UNMAPPED and address >= FORCE_KILL_ADDR - 0x10 and address <= FORCE_KILL_ADDR + 0x10 and dp .kill_me is not None :
1223
- dp .error (f"forced exit memory operation { access } of { address :x } [{ size :x } ] = { value :X } " )
1223
+ dp .error (f"forced exit memory operation { access } of { hex ( address ) } [{ hex ( size ) } ] = { hex ( value ) } " )
1224
1224
return False
1225
1225
if dp .exception .final and access in fetch_accesses :
1226
1226
dp .info (f"fetch from { hex (address )} [{ size } ] already reported" )
@@ -1245,11 +1245,11 @@ def _hook_mem(uc: Uc, access, address, size, value, dp: Dumpulator):
1245
1245
final = dp .trace or dp .exception .code_hook_h is not None
1246
1246
info = "final" if final else "initial"
1247
1247
if access == UC_MEM_READ_UNMAPPED :
1248
- dp .error (f"{ info } unmapped read from { address :x } [{ size :x } ], cip = { dp .regs .cip :x } , exception: { exception } " )
1248
+ dp .error (f"{ info } unmapped read from { hex ( address ) } [{ hex ( size ) } ], cip = { hex ( dp .regs .cip ) } , exception: { exception } " )
1249
1249
elif access == UC_MEM_WRITE_UNMAPPED :
1250
- dp .error (f"{ info } unmapped write to { address :x } [{ size :x } ] = { value :x } , cip = { dp .regs .cip :x } " )
1250
+ dp .error (f"{ info } unmapped write to { hex ( address ) } [{ hex ( size ) } ] = { hex ( value ) } , cip = { hex ( dp .regs .cip ) } " )
1251
1251
elif access == UC_MEM_FETCH_UNMAPPED :
1252
- dp .error (f"{ info } unmapped fetch of { address :x } [{ size :x } ], cip = { dp .regs .rip :x } , cs = { dp .regs .cs :x } " )
1252
+ dp .error (f"{ info } unmapped fetch of { hex ( address ) } [{ hex ( size ) } ], cip = { hex ( dp .regs .rip ) } , cs = { hex ( dp .regs .cs ) } " )
1253
1253
else :
1254
1254
names = {
1255
1255
UC_MEM_READ : "UC_MEM_READ" , # Memory is read from
@@ -1263,7 +1263,7 @@ def _hook_mem(uc: Uc, access, address, size, value, dp: Dumpulator):
1263
1263
UC_MEM_FETCH_PROT : "UC_MEM_FETCH_PROT" , # Fetch from non-executable, but mapped, memory
1264
1264
UC_MEM_READ_AFTER : "UC_MEM_READ_AFTER" , # Memory is read from (successful access)
1265
1265
}
1266
- dp .error (f"{ info } unsupported access { names .get (access , str (access ))} of { address :x } [{ size :x } ] = { value :X } , cip = { dp .regs .cip :x } " )
1266
+ dp .error (f"{ info } unsupported access { names .get (access , str (access ))} of { hex ( address ) } [{ hex ( size ) } ] = { hex ( value ) } , cip = { hex ( dp .regs .cip ) } " )
1267
1267
1268
1268
if final :
1269
1269
# Make sure this is the same exception we expect
@@ -1360,14 +1360,14 @@ def _hook_code(uc: Uc, address, size, dp: Dumpulator):
1360
1360
elif module :
1361
1361
address_name = " " + module
1362
1362
1363
- line = f"0x { address :x } { address_name } |"
1363
+ line = f"{ hex ( address ) } { address_name } |"
1364
1364
if instr is not None :
1365
1365
line += instr .mnemonic
1366
1366
if instr .op_str :
1367
1367
line += " "
1368
1368
line += instr .op_str
1369
1369
for reg in _get_regs (instr ):
1370
- line += f"|{ reg } =0x { dp .regs .__getattr__ (reg ):x } "
1370
+ line += f"|{ reg } ={ hex ( dp .regs .__getattr__ (reg )) } "
1371
1371
if instr .mnemonic in {"syscall" , "sysenter" }:
1372
1372
line += f"|sequence_id=[{ dp .sequence_id } ]"
1373
1373
else :
@@ -1440,7 +1440,7 @@ def _hook_interrupt(uc: Uc, number, dp: Dumpulator):
1440
1440
description = interrupt_names [number ]
1441
1441
else :
1442
1442
description = f"IRQ { number - 32 } "
1443
- dp .error (f"interrupt { number } ({ description } ), cip = { dp .regs .cip :x } , cs = { dp .regs .cs :x } " )
1443
+ dp .error (f"interrupt { number } ({ description } ), cip = { hex ( dp .regs .cip ) } , cs = { hex ( dp .regs .cs ) } " )
1444
1444
1445
1445
# There should not be an exception active
1446
1446
assert dp .exception .type == ExceptionType .NoException
@@ -1519,7 +1519,7 @@ def syscall_arg(index):
1519
1519
dp .exception = status
1520
1520
raise dp .raise_kill (UcError (UC_ERR_EXCEPTION )) from None
1521
1521
else :
1522
- dp .info (f"status = { status :x } " )
1522
+ dp .info (f"status = { hex ( status ) } " )
1523
1523
dp .regs .cax = status
1524
1524
if dp .x64 :
1525
1525
dp .regs .rcx = dp .regs .cip + 2
@@ -1560,7 +1560,7 @@ def _hook_invalid(uc: Uc, dp: Dumpulator):
1560
1560
if dp .kill_me :
1561
1561
dp .error (f"terminating emulation..." )
1562
1562
return False
1563
- dp .error (f"invalid instruction at { address :x } " )
1563
+ dp .error (f"invalid instruction at { hex ( address ) } " )
1564
1564
try :
1565
1565
code = dp .read (address , 15 )
1566
1566
instr = next (dp .cs .disasm (code , address , 1 ))
0 commit comments