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.
pull/1571/head^2
Disconnect3d 3 years ago committed by GitHub
parent 3ee589062c
commit e5fbefc444
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,6 +17,7 @@ class segment(gdb.Function):
return result + arg return result + arg
# TODO/FIXME: This should be defined only for x86 and x86_64
segment("fsbase") segment("fsbase")
segment("gsbase") segment("gsbase")
@ -25,6 +26,7 @@ segment("gsbase")
"Prints out the FS base address. See also $fsbase.", category=CommandCategory.REGISTER "Prints out the FS base address. See also $fsbase.", category=CommandCategory.REGISTER
) )
@pwndbg.commands.OnlyWhenRunning @pwndbg.commands.OnlyWhenRunning
@pwndbg.commands.OnlyWithArch(["i386", "x86-64"])
def fsbase() -> None: def fsbase() -> None:
""" """
Prints out the FS base address. See also $fsbase. 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 "Prints out the GS base address. See also $gsbase.", category=CommandCategory.REGISTER
) )
@pwndbg.commands.OnlyWhenRunning @pwndbg.commands.OnlyWhenRunning
@pwndbg.commands.OnlyWithArch(["i386", "x86-64"])
def gsbase() -> None: def gsbase() -> None:
""" """
Prints out the GS base address. See also $gsbase. Prints out the GS base address. See also $gsbase.

@ -194,7 +194,7 @@ class module(ModuleType):
# For GDB >= 8.x we can use get_register directly # For GDB >= 8.x we can use get_register directly
# Elsewhere we have to get the register via ptrace # 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) return get_register(regname)
# We can't really do anything if the process is remote. # We can't really do anything if the process is remote.

Loading…
Cancel
Save