forked from airbus-seclab/elfesteem
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbinary.py
More file actions
executable file
·67 lines (62 loc) · 2.13 KB
/
binary.py
File metadata and controls
executable file
·67 lines (62 loc) · 2.13 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#! /usr/bin/env python
# Generic container for all binary types known by elfesteem,
# with auto-recognition of the binary type.
import sys, os
sys.path.insert(1, os.path.abspath(sys.path[0]+'/..'))
from elfesteem.elf_init import ELF
from elfesteem.pe_init import PE, COFF
from elfesteem.minidump_init import Minidump
from elfesteem.macho import MACHO
from elfesteem.rprc import RPRC
class UnknownFormat(object):
def __init__(self, raw):
self.raw = raw
architecture = 'UNKNOWN'
entrypoint = -1
sections = ()
symbols = ()
dynsyms = ()
class virt_stub(object):
max_addr = lambda _:-1
virt = virt_stub()
class BINARY(object):
def __init__(self, raw):
for container in ELF, PE, Minidump, MACHO, RPRC, COFF:
try:
self.e = container(raw)
break
except ValueError:
pass
except AssertionError:
pass
else:
self.e = UnknownFormat(raw)
container = property(lambda _:_.e.__class__.__name__)
architecture = property(lambda _:_.e.architecture)
entrypoint = property(lambda _:_.e.entrypoint)
max_addr = property(lambda _:_.e.virt.max_addr())
sections = property(lambda _:_.e.sections)
symbols = property(lambda _:_.e.symbols)
dynsyms = property(lambda _:_.e.dynsyms)
if __name__ == "__main__":
for file in sys.argv[1:]:
print("File: %s"%file)
fd = open(file, 'rb')
try:
raw = fd.read()
finally:
fd.close()
e = BINARY(raw)
print(" container %s" % e.container)
print(" architecture %s" % e.architecture)
print(" entrypoint %#x" % e.entrypoint)
print(" max address %#x" % e.max_addr)
print(" %d sections:" % len(e.sections))
for sect in e.sections:
print(" %s" % sect)
print(" %d symbols:" % len(e.symbols))
for symbol in e.symbols:
print(" %s" % symbol)
print(" %d dynamic symbols:" % len(e.dynsyms))
for symbol in e.dynsyms:
print(" %s" % symbol)