88import cmd
99
1010from qiling import Qiling
11- from qiling .const import QL_ARCH , QL_VERBOSE
11+ from qiling .const import QL_OS , QL_ARCH , QL_VERBOSE
1212from qiling .debugger import QlDebugger
1313
1414from .utils import setup_context_render , setup_branch_predictor , SnapshotManager , run_qdb_script
@@ -34,6 +34,7 @@ def __init__(self, ql: Qiling, init_hook: str = "", rr: bool = False, script: st
3434 self ._saved_reg_dump = None
3535 self ._script = script
3636 self .bp_list = {}
37+ self .mark_list = {}
3738
3839 self .rr = SnapshotManager (ql ) if rr else None
3940 self .mm = setup_memory_Manager (ql )
@@ -72,7 +73,10 @@ def bp_handler(ql, address, size, bp_list):
7273
7374 self .ql .hook_code (bp_handler , self .bp_list )
7475
75- if init_hook and self .ql .loader .entry_point != init_hook :
76+ if self .ql .os .type == QL_OS .BLOB :
77+ self .ql .loader .entry_point = self .ql .loader .load_address
78+
79+ elif init_hook and self .ql .loader .entry_point != init_hook :
7680 self .do_breakpoint (init_hook )
7781
7882 self .cur_addr = self .ql .loader .entry_point
@@ -348,13 +352,63 @@ def do_context(self, *args) -> None:
348352 self .render .context_stack ()
349353 self .render .context_asm ()
350354
355+ def do_jump (self , address , * args ) -> None :
356+ """
357+ seek to where ever valid location you want
358+ """
359+
360+ symbol , addr = None , None
361+ try :
362+ addr = int (address , 0 )
363+ except :
364+ symbol = address
365+
366+ if symbol :
367+ addr = self .mark_list .get (symbol , None )
368+
369+ if self .ql .mem .is_mapped (addr , 4 ):
370+ qdb_print (QDB_MSG .INFO , f"seek to 0x{ addr :08x} ..." )
371+ self .cur_addr = addr
372+ self .do_context ()
373+
374+ else :
375+ qdb_print (QDB_MSG .ERROR , f"the address to be seeked isn't mapped" )
376+
377+ def do_mark (self , args ):
378+ """
379+ mark a user specified address as a symbol
380+ """
381+
382+ args = args .split ()
383+ if len (args ) == 1 :
384+ try :
385+ tmp = int (args [0 ], 0 )
386+ except :
387+ tmp = args [0 ]
388+
389+ if type (tmp ) is str :
390+ symbol = tmp
391+ else :
392+ address = tmp
393+
394+ else :
395+ symbol , address = args
396+
397+ if symbol :
398+ addr = self .cur_addr if address is None else int (address , 0 )
399+ self .mark_list .update ({symbol : addr })
400+ qdb_print (QDB_MSG .INFO , f"mark symbol '{ symbol } ' at address: 0x{ addr :08x} ..." )
401+ else :
402+ qdb_print (QDB_MSG .ERROR , "symbol should not be empty ..." )
403+
351404 def do_show (self , * args ) -> None :
352405 """
353406 show some runtime information
354407 """
355408
356409 self .ql .mem .show_mapinfo ()
357410 qdb_print (QDB_MSG .INFO , f"Breakpoints: { [hex (addr ) for addr in self .bp_list .keys ()]} " )
411+ qdb_print (QDB_MSG .INFO , f"Marked symbol: { [{key :hex (val )} for key ,val in self .mark_list .items ()]} " )
358412 if self .rr :
359413 qdb_print (QDB_MSG .INFO , f"Snapshots: { len ([st for st in self .rr .layers if isinstance (st , self .rr .DiffedState )])} " )
360414
@@ -401,6 +455,8 @@ def do_EOF(self, *args) -> None:
401455 do_r = do_run
402456 do_s = do_step_in
403457 do_n = do_step_over
458+ do_j = do_jump
459+ do_m = do_mark
404460 do_q = do_quit
405461 do_x = do_examine
406462 do_p = do_backward
0 commit comments