Add ins.target enhancement for resolving jmp and call targets

pull/23/merge
Zach Riggle 10 years ago
parent ec2f6cc935
commit db7a57744a

@ -93,16 +93,23 @@ class DisassemblyAssistant(object):
if instruction.condition in (True, None):
next_addr = self.next(instruction)
instruction.target = None
if next_addr is None:
next_addr = instruction.address + instruction.size
instruction.target = self.next(instruction, call=True)
instruction.next = next_addr & pwndbg.arch.ptrmask
def next(self, instruction):
if instruction.target is None:
instruction.target = instruction.next
def next(self, instruction, call=False):
"""
Architecture-specific hook point for enhance_next.
"""
if CS_GRP_JUMP not in instruction.groups:
if CS_GRP_JUMP not in instruction.groups \
and (not call or (CS_GRP_CALL not in instruction.groups)):
return None
# At this point, all operands have been resolved.
@ -111,11 +118,14 @@ class DisassemblyAssistant(object):
return None
# Memory operands must be dereferenced
addr = instruction.operands[0].int
op = instruction.operands[0]
addr = op.int
if addr:
addr &= pwndbg.arch.ptrmask
if instruction.operands[0].type == CS_OP_MEM:
if op.type == CS_OP_MEM:
addr = int(pwndbg.memory.poi(pwndbg.typeinfo.ppvoid, addr))
if op.type == CS_OP_REG:
addr = self.register(instruction, op)
return addr

@ -100,10 +100,10 @@ class DisassemblyAssistant(pwndbg.disasm.arch.DisassemblyAssistant):
return instruction.address + instruction.size
def next(self, instruction):
def next(self, instruction, call=False):
# Only enhance 'ret'
if X86_INS_RET != instruction.id or len(instruction.operands) > 1:
return super(DisassemblyAssistant, self).next(instruction)
return super(DisassemblyAssistant, self).next(instruction, call)
# Stop disassembling at RET if we won't know where it goes to
if instruction.address != pwndbg.regs.pc:

Loading…
Cancel
Save