From 04b209925a938f57f2fe677bf9331dd41b2c7eb6 Mon Sep 17 00:00:00 2001 From: Disconnect3d Date: Thu, 29 May 2025 14:48:40 +0200 Subject: [PATCH] fix: show "x" when the condition instruction will not be taken (#3027) * fix: show "x" when the condition instruction will not be taken Fixes #3025 * Update disasm.py * Update disasm.py * Update disasm.py * Fix X marker in cross-arch tests (aarch64, riscv64) --- pwndbg/color/disasm.py | 5 ++++- tests/qemu-tests/tests/user/test_aarch64.py | 2 +- tests/qemu-tests/tests/user/test_riscv64.py | 8 ++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pwndbg/color/disasm.py b/pwndbg/color/disasm.py index 29d118df0..a0ae16ab4 100644 --- a/pwndbg/color/disasm.py +++ b/pwndbg/color/disasm.py @@ -13,6 +13,7 @@ from pwndbg.color import ColorConfig from pwndbg.color import ColorParamSpec from pwndbg.color import ljust_colored from pwndbg.color import strip +from pwndbg.color.message import off from pwndbg.color.message import on c = ColorConfig( @@ -41,8 +42,10 @@ def one_instruction(ins: PwndbgInstruction) -> str: # If we know the conditional is taken, mark it as taken. if ins.condition == InstructionCondition.TRUE or ins.is_conditional_jump_taken: asm = on("✔ ") + asm + elif ins.condition == InstructionCondition.FALSE: + asm = off("✘ ") + asm else: - asm = " " + asm + asm = f" {asm}" return asm diff --git a/tests/qemu-tests/tests/user/test_aarch64.py b/tests/qemu-tests/tests/user/test_aarch64.py index f89b04d5a..7a9ed54bd 100644 --- a/tests/qemu-tests/tests/user/test_aarch64.py +++ b/tests/qemu-tests/tests/user/test_aarch64.py @@ -219,7 +219,7 @@ def test_aarch64_conditional_jump_output(qemu_assembly_run): " 0x1010140 ✔ tbnz w2, #3, D \n" " ↓\n" " 0x1010148 cmp x2, x3 0xa - 0x0 CPSR => 0x20000000 [ n z C v q pan il d a i f el:0 sp ]\n" - " 0x101014c b.eq E \n" + " 0x101014c ✘ b.eq E \n" " \n" " 0x1010150 nop \n" " 0x1010154 ✔ b.ne F \n" diff --git a/tests/qemu-tests/tests/user/test_riscv64.py b/tests/qemu-tests/tests/user/test_riscv64.py index cf4d7261a..016480f25 100644 --- a/tests/qemu-tests/tests/user/test_riscv64.py +++ b/tests/qemu-tests/tests/user/test_riscv64.py @@ -185,12 +185,12 @@ def test_riscv64_jumps(qemu_assembly_run): "───────────────────────[ DISASM / rv64 / set emulate on ]───────────────────────\n" " ► 0x1001158 <_start> c.li t0, 4 T0 => 4\n" " 0x100115a <_start+2> c.li t1, 5 T1 => 5\n" - " 0x100115c <_start+4> beq t0, t1, 6 \n" + " 0x100115c <_start+4> ✘ beq t0, t1, 6 \n" " \n" " 0x1001160 <_start+8> c.nop \n" " 0x1001162 ✔ bne t0, t2, 6 \n" " ↓\n" - " 0x1001168 blt t0, t3, 6 \n" + " 0x1001168 ✘ blt t0, t3, 6 \n" " \n" " 0x100116c c.nop \n" " 0x100116e ✔ bge t0, t4, 6 \n" @@ -215,12 +215,12 @@ def test_riscv64_jumps(qemu_assembly_run): "LEGEND: STACK | HEAP | CODE | DATA | WX | RODATA\n" "───────────────────────[ DISASM / rv64 / set emulate on ]───────────────────────\n" " 0x100115a <_start+2> c.li t1, 5 T1 => 5\n" - " 0x100115c <_start+4> beq t0, t1, 6 \n" + " 0x100115c <_start+4> ✘ beq t0, t1, 6 \n" " \n" " 0x1001160 <_start+8> c.nop \n" " 0x1001162 ✔ bne t0, t2, 6 \n" " ↓\n" - " 0x1001168 blt t0, t3, 6 \n" + " 0x1001168 ✘ blt t0, t3, 6 \n" " \n" " ► 0x100116c c.nop \n" " 0x100116e ✔ bge t0, t4, 6 \n"