From e5fbefc4444a566f54ca2c96d21b67eef9fd15d2 Mon Sep 17 00:00:00 2001 From: Disconnect3d Date: Thu, 9 Feb 2023 09:48:14 +0100 Subject: [PATCH] Fix #1572: fsbase/gsbase commands on x86 32-bit archs (#1575) Before this fix, when we compiled a 32-bit prgoram a 'Bad register' bug would show up on `fsbase` and `gsbase` commands. Also, those commands weren't protected to not be executed on another archs, which this commit fixes. Additionally, this commit introduces 4 tests: ``` test_commands_segments[gsbase-gosample.x64] PASSED test_commands_segments[gsbase-gosample.x86] PASSED test_commands_segments[fsbase-gosample.x64] PASSED test_commands_segments[fsbase-gosample.x86] PASSED ``` Two of those tests, the ones with x86 binaries, applied without other changes would fail. --- pwndbg/commands/segments.py | 3 +++ pwndbg/gdblib/regs.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pwndbg/commands/segments.py b/pwndbg/commands/segments.py index 620cb8d55..1a648e20a 100644 --- a/pwndbg/commands/segments.py +++ b/pwndbg/commands/segments.py @@ -17,6 +17,7 @@ class segment(gdb.Function): return result + arg +# TODO/FIXME: This should be defined only for x86 and x86_64 segment("fsbase") segment("gsbase") @@ -25,6 +26,7 @@ segment("gsbase") "Prints out the FS base address. See also $fsbase.", category=CommandCategory.REGISTER ) @pwndbg.commands.OnlyWhenRunning +@pwndbg.commands.OnlyWithArch(["i386", "x86-64"]) def fsbase() -> None: """ Prints out the FS base address. See also $fsbase. @@ -36,6 +38,7 @@ def fsbase() -> None: "Prints out the GS base address. See also $gsbase.", category=CommandCategory.REGISTER ) @pwndbg.commands.OnlyWhenRunning +@pwndbg.commands.OnlyWithArch(["i386", "x86-64"]) def gsbase() -> None: """ Prints out the GS base address. See also $gsbase. diff --git a/pwndbg/gdblib/regs.py b/pwndbg/gdblib/regs.py index 8aba8aba6..d6eb84348 100644 --- a/pwndbg/gdblib/regs.py +++ b/pwndbg/gdblib/regs.py @@ -194,7 +194,7 @@ class module(ModuleType): # For GDB >= 8.x we can use get_register directly # Elsewhere we have to get the register via ptrace - if get_register == gdb79_get_register: + if pwndbg.gdblib.arch.current == "x86-64" and get_register == gdb79_get_register: return get_register(regname) # We can't really do anything if the process is remote.