Skip to content

Commit 1f5e113

Browse files
committed
revise command do_start
1 parent 31c79b0 commit 1f5e113

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

qiling/debugger/qdb/qdb.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,22 @@ def __init__(self: QlQdb, ql: Qiling, init_hook: str = "", rr: bool = False) ->
3333

3434
super().__init__()
3535

36+
self.dbg_hook(init_hook)
37+
38+
def dbg_hook(self: QlQdb, init_hook: str):
39+
40+
# self.ql.loader.entry_point # ld.so
41+
# self.ql.loader.elf_entry # .text of binary
42+
43+
if init_hook:
44+
init_hook = parse_int(init_hook)
45+
46+
self.set_breakpoint(init_hook, is_temp=True)
47+
3648
self.cur_addr = self.ql.loader.entry_point
49+
self._init_state = self.ql.save()
3750

38-
self.do_start()
51+
self.do_context()
3952
self.interactive()
4053

4154
@property
@@ -72,6 +85,7 @@ def _bp_handler(self: QlQdb, *args) -> None:
7285
print(f"{color.CYAN}[+] hit breakpoint at 0x{self.cur_addr:08x}{color.END}")
7386
bp.hitted = True
7487

88+
self.ql.stop()
7589
self.do_context()
7690

7791
def _save(self: QlQdb, *args) -> None:
@@ -147,7 +161,7 @@ def emptyline(self: QlQdb, *args) -> None:
147161

148162
def do_run(self: QlQdb, *args) -> None:
149163
"""
150-
launching qiling instance
164+
launch qiling instance
151165
"""
152166

153167
self._run()
@@ -173,7 +187,7 @@ def do_backward(self: QlQdb, *args) -> None:
173187
self._restore()
174188
self.do_context()
175189

176-
def do_step(self: QlQdb, *args) -> Optional[bool, None]:
190+
def do_step(self: QlQdb, *args) -> Optional[bool]:
177191
"""
178192
execute one instruction at a time
179193
"""
@@ -202,7 +216,7 @@ def do_step(self: QlQdb, *args) -> Optional[bool, None]:
202216

203217
def set_breakpoint(self: QlQdb, address: int, is_temp: bool = False) -> None:
204218
"""
205-
internal function for placing breakpoints
219+
internal function for placing breakpoint
206220
"""
207221

208222
bp = TempBreakpoint(address) if is_temp else Breakpoint(address)
@@ -221,14 +235,10 @@ def del_breakpoint(self: QlQdb, bp: Union[Breakpoint, TempBreakpoint]) -> None:
221235

222236
def do_start(self: QlQdb, address: str = "", *args) -> None:
223237
"""
224-
move current context to ql.loader.entry_point
238+
restore qiling instance context to initial state
225239
"""
226240

227-
self.cur_addr = self.ql.loader.entry_point # ld.so
228-
# self.cur_addr = self.ql.loader.elf_entry # .text of binary
229-
230-
# need a proper method for this
231-
# self.ql.restore(self._init_state)
241+
self.ql.restore(self._init_state)
232242

233243
self.do_context()
234244

0 commit comments

Comments
 (0)