-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbinbase.py
More file actions
executable file
·38 lines (28 loc) · 1.11 KB
/
binbase.py
File metadata and controls
executable file
·38 lines (28 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""Get the base address of the loaded binary"""
import gdb
import re
from pathname import PathName
from mappingparser import MappingsParser
class NotFoundException(Exception):
def __init__(self, msg):
super(NotFoundException, self).__init__(msg)
def get_exe():
info_proc = gdb.execute('info proc', to_string=True)
for line in info_proc.splitlines():
match = re.match('^exe = \'(.*)\'$', line)
if match:
return match.group(1)
raise NotFoundException('Error parsing \'info proc\', executable not found.')
class BinBase(gdb.Function):
"""Print the base address of a loaded object (the main executable if none is given)"""
def __init__(self):
super(BinBase, self).__init__('base')
def invoke(self, exe=None):
exe = exe.string() if exe else get_exe()
exe = PathName(exe)
maps = MappingsParser().maps
for mapping in maps:
if mapping.pathname and mapping.pathname == exe:
return mapping.start_addr
raise NotFoundException('No entry found for {} in /proc/{}/maps'.format(exe, get_pid()))
BinBase()