-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathdump_symbols.py
More file actions
executable file
·43 lines (32 loc) · 1.08 KB
/
Copy pathdump_symbols.py
File metadata and controls
executable file
·43 lines (32 loc) · 1.08 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
38
39
40
41
42
43
import lief
import platform
import sys
from logzero import logger
libs = sys.argv[-1].split(';')
exported_symbols = []
# lief <0.14 uses lief.EXE_FORMATS; 0.14+ uses lief.Binary.FORMATS
FORMATS = getattr(lief, 'EXE_FORMATS', None) or lief.Binary.FORMATS
for lib in libs:
lib = lib.strip()
if not lib:
raise RuntimeError(f'{lib!r} was an empty string')
logger.info(f'Analyzing {lib}')
p = lief.parse(lib)
if p is None:
raise RuntimeError(f'lief.parse failed for {lib!r}')
format = p.format
if format == FORMATS.ELF:
name = "freebsd" if platform.system() == "FreeBSD" else "linux"
for s in p.exported_symbols:
exported_symbols.append(f'{s.name}\n')
elif format == FORMATS.MACHO:
name = "mac"
for s in p.symbols:
if s.raw_type>1:
exported_symbols.append(f'{s.name}\n')
else:
name = "win"
for s in p.exported_functions:
exported_symbols.append(f'{s.name}\n')
with open(f'symbols_mangled_{name}.dat','w') as f:
f.writelines(exported_symbols)