|
|
|
@ -48,10 +48,8 @@ VariableInstructionSizeMax = {
|
|
|
|
'x86-64': 16,
|
|
|
|
'x86-64': 16,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
smart_backward_cache = collections.defaultdict(lambda: 0)
|
|
|
|
|
|
|
|
backward_cache = collections.defaultdict(lambda: 0)
|
|
|
|
backward_cache = collections.defaultdict(lambda: 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_disassembler(pc):
|
|
|
|
def get_disassembler(pc):
|
|
|
|
arch = pwndbg.arch.current
|
|
|
|
arch = pwndbg.arch.current
|
|
|
|
d = CapstoneArch[arch]
|
|
|
|
d = CapstoneArch[arch]
|
|
|
|
@ -76,8 +74,7 @@ def one(address=None):
|
|
|
|
if address is None:
|
|
|
|
if address is None:
|
|
|
|
address = pwndbg.regs.pc
|
|
|
|
address = pwndbg.regs.pc
|
|
|
|
for insn in get(address, 1):
|
|
|
|
for insn in get(address, 1):
|
|
|
|
smart_backward_cache[insn.next] = insn.address
|
|
|
|
backward_cache[insn.next] = insn.address
|
|
|
|
backward_cache[insn.address + insn.size] = insn.address
|
|
|
|
|
|
|
|
return insn
|
|
|
|
return insn
|
|
|
|
|
|
|
|
|
|
|
|
def fix(i):
|
|
|
|
def fix(i):
|
|
|
|
@ -122,22 +119,14 @@ def near(address, instructions=1):
|
|
|
|
insns.append(current)
|
|
|
|
insns.append(current)
|
|
|
|
|
|
|
|
|
|
|
|
# Now find all of the instructions moving forward.
|
|
|
|
# Now find all of the instructions moving forward.
|
|
|
|
next = current.next
|
|
|
|
insn = current
|
|
|
|
while len(insns) < 1+(2*instructions):
|
|
|
|
while insn and len(insns) < 1+(2*instructions):
|
|
|
|
insn = one(next)
|
|
|
|
# In order to avoid annoying cycles where the current instruction
|
|
|
|
if not insn:
|
|
|
|
# is a branch, which evaluates to true, and jumps back a short
|
|
|
|
break
|
|
|
|
# number of instructions.
|
|
|
|
insns.append(insn)
|
|
|
|
|
|
|
|
next = insn.next
|
|
|
|
insn = one(insn.next)
|
|
|
|
|
|
|
|
if insn:
|
|
|
|
# On a short backward jump, we may get an annoying cycle in the
|
|
|
|
insns.append(insn)
|
|
|
|
# disassembly listing, because we're reading the jump target and
|
|
|
|
|
|
|
|
# have evaluated the destination.
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# We don't want this loop to show up in the future, so force it
|
|
|
|
|
|
|
|
# to fall-through, as long as the jump destination is a small-enough
|
|
|
|
|
|
|
|
# backward jump that it also shows up in the disassembly.
|
|
|
|
|
|
|
|
if insn.address == current.address and any(i.address == next for i in insns):
|
|
|
|
|
|
|
|
next = insn.address + insn.size
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return insns
|
|
|
|
return insns
|
|
|
|
|