-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgdb_utils.py
37 lines (31 loc) · 959 Bytes
/
gdb_utils.py
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
#!/usr/bin/env python3
import os
import string
import random
'''
return a random string of the given size
'''
def getRandomString(size: int) -> str:
charset = string.ascii_letters + string.digits
return ''.join(random.choices(charset, k=size))
'''
return a default charset
'''
def getCharset() -> str:
return string.ascii_letters + string.digits + "@*{}+=$%^][() _-.?!"
'''
return the entry point address of the given binary
note: this creates a temporary file in the current working directory
'''
def getEntry(filename: str) -> int:
size = 6
tmpfilename = './gdbpython_tempfile_' + getRandomString(size)
# the actual command to parse `readelf` output
mycmd = f"readelf -h {filename}"
mycmd += "| grep 'Entry point'"
mycmd += "| tr -s ' '"
mycmd += "| cut -d ' ' -f 5"
os.system(f'{mycmd} > {tmpfilename}')
entry = open(tmpfilename, 'r').read()[:-1]
os.system(f'rm -f {tmpfilename}')
return entry