fix(emulate): let `emulate` works on unicorn-1.0.2rc1 ~ unicorn-1.0.2

pull/914/head
veritas501 5 years ago committed by Disconnect3d
parent 87da998fce
commit 5389eb668d

@ -214,16 +214,14 @@ def near(address, instructions=1, emulate=False, show_prev_insns=True):
if address == pc and emulate: if address == pc and emulate:
emu = pwndbg.emu.emulator.Emulator() emu = pwndbg.emu.emulator.Emulator()
# For whatever reason, the first instruction is emulated twice.
# Skip the first one here.
emu.single_step()
# Now find all of the instructions moving forward. # Now find all of the instructions moving forward.
# #
# At this point, we've already added everything *BEFORE* the requested address, # At this point, we've already added everything *BEFORE* the requested address,
# and the instruction at 'address'. # and the instruction at 'address'.
insn = current insn = current
total_instructions = 1 + (2*instructions) total_instructions = 1 + (2*instructions)
last_emu_target = None
target_candidate = address
while insn and len(insns) < total_instructions: while insn and len(insns) < total_instructions:
target = insn.target target = insn.target
@ -236,7 +234,14 @@ def near(address, instructions=1, emulate=False, show_prev_insns=True):
# If we initialized the emulator and emulation is still enabled, we can use it # If we initialized the emulator and emulation is still enabled, we can use it
# to figure out the next instruction. # to figure out the next instruction.
if emu: if emu:
target_candidate, size_candidate = emu.single_step() # For whatever reason, the first instruction is emulated twice on
# unicorn-1.0.2rc1~unicorn-1.0.2rc3, but not on >= unicorn-1.0.2rc4.
# If the address is equal with the last one, skip it
last_emu_target = target_candidate
while last_emu_target == target_candidate:
target_candidate, size_candidate = emu.single_step()
if not target_candidate:
break
if None not in (target_candidate, size_candidate): if None not in (target_candidate, size_candidate):
target = target_candidate target = target_candidate

Loading…
Cancel
Save