-
Notifications
You must be signed in to change notification settings - Fork 2
/
PEDataObject.py
53 lines (41 loc) · 1.77 KB
/
PEDataObject.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from DataObject import DataObject
import pefile
class PESection():
def __init__(self, name, address, virtual_size, raw_size):
self.Name = name
self.VirtualAddress = address
self.VirtualSize = virtual_size
self.RawSize = raw_size
def printSection(self):
print("Section Name: {}\n\tVirtual Address: {}\n\tVirtual Size: {}\n\tRaw Size: {} ".format(self.Name,
self.VirtualAddress,
self.VirtualSize,
self.RawSize))
class PEDataObject(DataObject):
def __init__(self, path):
DataObject.__init__(self, path)
self.pe = pefile.PE(path)
self.signature = hex(self.pe.NT_HEADERS.Signature)
self.magic = hex(self.pe.DOS_HEADER.e_magic)
self.dlls = []
for entry in self.pe.DIRECTORY_ENTRY_IMPORT:
self.dlls.append(entry.dll.decode('utf-8'))
self.sections = []
for section in self.pe.sections:
self.sections.append(
PESection(section.Name.decode('utf-8'), hex(section.VirtualAddress), hex(section.Misc_VirtualSize),
hex(section.SizeOfRawData)))
def printPEDataObject(self):
print(self.magic)
print(self.signature)
print(self.dlls)
for section in self.sections:
section.printSection()
"""
def __main__():
path = input("Enter path to file: ")
o = PEDataObject(path)
o.printDataObject()
o.printPEDataObject()
__main__()
"""