Skip to content

Commit

Permalink
Support 64 bit return value for stub (#1034)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Angelo942 committed Dec 30, 2023
1 parent 5cc4ef2 commit a2704c9
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion gef.py
Expand Up @@ -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
Expand Down

0 comments on commit a2704c9

Please sign in to comment.