Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds `$rebase(offset)` gdbfunction that can be used to set up a breakpoint over an offset from program image base. Also changed a bit the pwndbg banner displayed at startup.
- Loading branch information
1 parent
81d4c53
commit 109889d
Showing
6 changed files
with
97 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Put all new things related to gdb in this module. | ||
""" | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
|
||
import pwndbg.gdbutils.functions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Put all functions defined for gdb in here. | ||
This file might be changed into a module in the future. | ||
""" | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
|
||
import functools | ||
|
||
import gdb | ||
|
||
import pwndbg.elf | ||
|
||
functions = [] | ||
|
||
|
||
def GdbFunction(only_when_running=False): | ||
return functools.partial(_GdbFunction, only_when_running=only_when_running) | ||
|
||
|
||
class _GdbFunction(gdb.Function): | ||
def __init__(self, func, only_when_running): | ||
self.name = func.__name__ | ||
self.func = func | ||
self.only_when_running = only_when_running | ||
|
||
functions.append(self) | ||
|
||
super(_GdbFunction, self).__init__(self.name) | ||
|
||
functools.update_wrapper(self, func) | ||
self.__doc__ = func.__doc__ | ||
|
||
def invoke(self, *args): | ||
if self.only_when_running and not pwndbg.elf.exe(): | ||
# Returning empty string is a workaround that we can't stop e.g. `break *$rebase(offset)` | ||
# Thx to that, gdb will print out 'evaluation of this expression requires the target program to be active' | ||
return '' | ||
|
||
return self.func(*args) | ||
|
||
def __call__(self, *args): | ||
return self.invoke(*args) | ||
|
||
|
||
@GdbFunction(only_when_running=True) | ||
def rebase(addr): | ||
"""Return rebased address.""" | ||
base = pwndbg.elf.exe().address | ||
return base + int(addr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters