Skip to content

Commit 1d7968e

Browse files
committed
revised a bit MemoryManager
1 parent 5db3944 commit 1d7968e

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

qiling/debugger/qdb/branch_predictor/branch_predictor_x86.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def generic_visit(self, node):
127127
prophecy.where = eval(new_line)
128128

129129
elif line.op_str in self.ql.reg.register_mapping:
130-
prophecy.where = getattr(self.ql.reg, line.op_str)
130+
prophecy.where = self.ql.reg.read(line.op_str)
131131

132132
else:
133133
prophecy.where = read_int(line.op_str)

qiling/debugger/qdb/context.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def __init__(self, ql):
2323
self.unpack = ql.unpack
2424
self.unpack16 = ql.unpack16
2525
self.unpack32 = ql.unpack32
26+
self.unpack64 = ql.unpack64
2627

2728
@property
2829
def cur_addr(self):

qiling/debugger/qdb/memory.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#
55

66
from qiling.utils import ql_get_module_function
7-
from qiling.const import QL_ARCH
87

98
from .context import Context
109
from .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

Comments
 (0)