Last active
June 30, 2019 12:38
-
-
Save hc0d3r/8a5686c9ba2a562a0cd07a8aa6e030fb to your computer and use it in GitHub Desktop.
gdb script to set a breakpoint in the entry-point, works with PIE, non-PIE, and stripped binaries
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
import gdb | |
import re | |
class entryPoint(gdb.Command): | |
def __init__(self): | |
super(entryPoint, self).__init__("start-ep", gdb.COMMAND_BREAKPOINTS) | |
def invoke(self, arg, from_tty): | |
output = gdb.execute('starti '+arg, False, True) | |
ep = self.get_entry_point() | |
if ep and ep != self.current_ip(): | |
gdb.Breakpoint("*{}".format(hex(ep)), gdb.BP_BREAKPOINT, 0, True, True) | |
gdb.execute('c') | |
else: | |
print(output) | |
def get_entry_point(self): | |
auxv = gdb.execute('info auxv', False, True) | |
ep = 0 | |
try: | |
ep = int(re.findall(r'.*AT_ENTRY.*0x(\w+)', auxv)[0], 16) | |
except: | |
pass | |
return ep | |
def current_ip(self): | |
ip = gdb.parse_and_eval("$pc") | |
return int(ip.cast(gdb.lookup_type('long'))) | |
entryPoint() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment