44#
55
66from qiling .utils import ql_get_module_function
7- from qiling .const import QL_ARCH
87
98from .context import Context
109from .arch import ArchCORTEX_M , ArchARM , ArchMIPS , ArchX86
@@ -66,36 +65,43 @@ def get_fmt(self, text):
6665 def fmt_unpack (self , bs : bytes , sz : int ) -> int :
6766 return {
6867 1 : lambda x : x [0 ],
69- 2 : self .ql . unpack16 ,
70- 4 : self .ql . unpack32 ,
71- 8 : self .ql . unpack64 ,
68+ 2 : self .unpack16 ,
69+ 4 : self .unpack32 ,
70+ 8 : self .unpack64 ,
7271 }.get (sz )(bs )
7372
7473 def parse (self , line : str ):
75- args = line .split ()
74+
75+ # test case
76+ # x/wx address
77+ # x/i address
78+ # x $sp
79+ # x $sp +0xc
80+ # x $sp+0xc
81+ # x $sp + 0xc
7682
7783 if line .startswith ("/" ): # followed by format letter and size letter
7884
7985 fmt , * rest = line .strip ("/" ).split ()
8086
81- rest = "" .join (rest )
82-
8387 fmt = self .get_fmt (fmt )
8488
85- elif len (args ) == 1 : # only address
86- rest = args [0 ]
87- fmt = self .DEFAULT_FMT
88-
8989 else :
90- rest = args
90+ args = line .split ()
91+ rest = args [0 ] if len (args ) == 1 else args
92+ fmt = self .DEFAULT_FMT
9193
9294 if (regs_dict := getattr (self , "regs_need_swapped" , None )):
93- for old_reg , new_reg in regs_dict .items ():
94- rest = rest .replace (old_reg , new_reg )
95+ for each in rest :
96+ if each in regs_dict :
97+
98+ # for simple calculation with register and address
99+ new_line = rest
95100
96- # for supporting addition of register with constant value
97- elems = rest .split ("+" )
98- elems = [elem .strip ("$" ) for elem in elems ]
101+ # substitue register name with real value
102+ for each_reg in filter (lambda r : len (r ) == 3 , self .ql .reg .register_mapping .keys ()):
103+ if each_reg in new_line :
104+ new_line = re .sub (each_reg , hex (self .read_reg (each_reg )), new_line )
99105
100106 items = []
101107
@@ -117,7 +123,6 @@ def parse(self, line: str):
117123 if line :
118124 print (f"0x{ line .address :x} : { line .mnemonic } \t { line .op_str } " )
119125
120- print ()
121126
122127 else :
123128 lines = 1 if ct <= 4 else math .ceil (ct / 4 )
@@ -143,6 +148,6 @@ def parse(self, line: str):
143148 ft = ft .lower () if ft in ("x" , "o" , "b" , "d" ) else ft .lower ().replace ("t" , "b" ).replace ("a" , "x" )
144149 print (f"{ prefix } { data :{pad }{ft }} \t " , end = "" )
145150
146- print ()
151+ print ()
147152
148153 return True
0 commit comments