diff --git a/pwndbg/aglib/disasm/arch.py b/pwndbg/aglib/disasm/arch.py index b58f2a53b..62384f3d5 100644 --- a/pwndbg/aglib/disasm/arch.py +++ b/pwndbg/aglib/disasm/arch.py @@ -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 diff --git a/pwndbg/aglib/disasm/x86.py b/pwndbg/aglib/disasm/x86.py index 284e75c72..b46309757 100644 --- a/pwndbg/aglib/disasm/x86.py +++ b/pwndbg/aglib/disasm/x86.py @@ -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)