fix disasm.one() to be called without an address (#189)

This brings back the functionality to call disasm.one() without
and target address. As a default value the current regs.pc is
selected.
Fix the disasm.near() call to not pass None to disasm.one() when
the backward cache misses, otherwise it wrongly falls back to
the regs.pc value (which near() is not supposed to do in its
context).
pull/194/head
Levente Polyak 9 years ago committed by Zach Riggle
parent d277918670
commit 52c1c0655c

@ -101,10 +101,10 @@ def get_one_instruction(address):
return ins return ins
def one(address=None): def one(address=None):
if address is None or not pwndbg.memory.peek(address):
return None
if address is None: if address is None:
address = pwndbg.regs.pc address = pwndbg.regs.pc
if not pwndbg.memory.peek(address):
return None
for insn in get(address, 1): for insn in get(address, 1):
backward_cache[insn.next] = insn.address backward_cache[insn.next] = insn.address
return insn return insn
@ -163,10 +163,12 @@ def near(address, instructions=1, emulate=False):
# before, which were followed by this one. # before, which were followed by this one.
needle = address needle = address
insns = [] insns = []
insn = one(backward_cache[current.address]) cached = backward_cache[current.address]
insn = one(cached) if cached else None
while insn is not None and len(insns) < instructions: while insn is not None and len(insns) < instructions:
insns.append(insn) insns.append(insn)
insn = one(backward_cache[insn.address]) cached = backward_cache[insn.address]
insn = one(cached) if cached else None
insns.reverse() insns.reverse()
insns.append(current) insns.append(current)

Loading…
Cancel
Save