-
Notifications
You must be signed in to change notification settings - Fork 2
/
tlsparser.py
executable file
·37 lines (30 loc) · 1.01 KB
/
tlsparser.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 python
__VERSION__ = '1.0'
import os
import immlib
import pefile
class FileNotExistError(Exception):
def __init__(self):
self.message = "file is not existent"
class ObjectNotInitError(Exception):
def __init__(self):
self.message = "object is not initialized"
class TLSParser:
def __init__(self, fileName):
if(os.path.isfile(fileName)):
self.fileName = fileName
self.callback_functions = []
self.pe = pefile.PE(fileName)
else:
raise FileNotExistError
def parse(self):
if(isinstance(self.pe, pefile.PE)):
idx = 0
self.callback_functions = []
callback_array_rva = self.pe.DIRECTORY_ENTRY_TLS.struct.AddressOfCallBacks - self.pe.OPTIONAL_HEADER.ImageBase
while self.pe.get_dword_from_data(self.pe.get_data(callback_array_rva + 4 * idx, 4), 0):
self.callback_functions.append(self.pe.get_dword_from_data(self.pe.get_data(callback_array_rva + 4 * idx, 4), 0))
idx += 1
return self.callback_functions
else:
raise ObjectNotInitError