From a2704c90045e0659dd6328f6caac3d85d8344c8e Mon Sep 17 00:00:00 2001 From: Angelo942 <52466998+Angelo942@users.noreply.github.com> Date: Sat, 30 Dec 2023 16:45:02 +0000 Subject: [PATCH] Support 64 bit return value for stub (#1034) The `return (int) X` command in gdb only sets the 4 lowest bytes of the return register. For example if `rax` was `-1`, a `return int 0` would leave us with `0xffffffff000000` instead of `0x0`. This patch makes `StubBreakpoint` check for the register size and executes `return (int)` or `return (long)` accordingly. --- gef.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gef.py b/gef.py index 2e7a785fd..cec269c16 100644 --- a/gef.py +++ b/gef.py @@ -4147,7 +4147,8 @@ def __init__(self, func: str, retval: Optional[int]) -> None: return def stop(self) -> bool: - gdb.execute(f"return (unsigned int){self.retval:#x}") + size = "long" if gef.arch.ptrsize == 8 else "int" + gdb.execute(f"return (unsigned {size}){self.retval:#x}") ok(f"Ignoring call to '{self.func}' " f"(setting return value to {self.retval:#x})") return False