Correct instruction.condition for emulated conditional branches (#3030)

pull/3023/head^2
OBarronCS 7 months ago committed by GitHub
parent a8d9df243d
commit 8206735af2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -27,6 +27,7 @@ from pwndbg.aglib.disasm.instruction import FORWARD_JUMP_GROUP
from pwndbg.aglib.disasm.instruction import EnhancedOperand
from pwndbg.aglib.disasm.instruction import InstructionCondition
from pwndbg.aglib.disasm.instruction import PwndbgInstruction
from pwndbg.aglib.disasm.instruction import boolean_to_instruction_condition
from pwndbg.lib.arch import PWNDBG_SUPPORTED_ARCHITECTURES_TYPE
# Emulator currently requires GDB, and we only use it here for type checking.
@ -695,6 +696,20 @@ class DisassemblyAssistant:
# Only bother doing the symbol lookup if this is a jump
instruction.target_string = MemoryColor.get_address_or_symbol(instruction.target)
# Now that we have determined the target, if it was a conditional branch,
# go back and correct the instruction condition to reflect the branch decision of the emulator
# in case we didn't manually determine the condition.
if (
jump_emu
and instruction.condition == InstructionCondition.UNDETERMINED
and instruction.is_conditional_jump
):
# At this point we know the emulator was used to determine
# the conditional branch
instruction.condition = boolean_to_instruction_condition(
instruction.is_conditional_jump_taken
)
if (
instruction.operands
and instruction.operands[0].before_value

@ -324,12 +324,9 @@ class X86DisassemblyAssistant(pwndbg.aglib.disasm.arch.DisassemblyAssistant):
if instruction.id in (X86_INS_JMP, X86_INS_RET, X86_INS_CALL):
return InstructionCondition.UNDETERMINED
# We can't reason about anything except the current instruction
if instruction.address != pwndbg.aglib.regs.pc:
return InstructionCondition.UNDETERMINED
efl = pwndbg.aglib.regs.eflags
efl = self._read_register_name(instruction, "eflags", emu)
if efl is None:
# We can't reason about the value of flags register
return InstructionCondition.UNDETERMINED
cf = efl & (1 << 0)

Loading…
Cancel
Save