-
Notifications
You must be signed in to change notification settings - Fork 10
/
report.py
214 lines (178 loc) · 4.95 KB
/
report.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
## fufluns - Copyright 2019-2021 - deroad
import threading
import json
import time
import os
from utils import dk
PERMISSION_NAME='name'
PERMISSION_DESC='description'
ISSUE_TBL_NAME='issue'
ISSUE_TBL_DESC='description'
ISSUE_TBL_SEVR='severity'
STRINGS_TBL_OFFSET='offset'
STRINGS_TBL_DATA ='data'
STRINGS_TBL_TYPE ='type'
STRINGS_TBL_FILE ='filename'
BINDETAILS_DETAILS_LIBRARIES='libraries'
BINDETAILS_DETAILS_CLASSES='classes'
BINDETAILS_DETAILS_HASHES='hashes'
def bin_methods(c):
return [dk(x, 'name', '(null)') for x in dk(c, 'methods', [])]
class BinDetails(object):
"""Contains the details of the binary, like hashes, etc.."""
def __init__(self):
super(BinDetails, self).__init__()
self._details = {
BINDETAILS_DETAILS_LIBRARIES: [],
BINDETAILS_DETAILS_CLASSES: [],
BINDETAILS_DETAILS_HASHES: []
}
self.lock = threading.Lock()
def libraries(self, data):
self.lock.acquire()
old = self._details[BINDETAILS_DETAILS_LIBRARIES]
old.extend(data)
self._details[BINDETAILS_DETAILS_LIBRARIES] = sorted(set(old))
self.lock.release()
def classes(self, filename, data):
self.lock.acquire()
dc = []
for c in data:
dc.append({
'filename': filename,
'name': dk(c, 'classname', "(null)"),
'super': dk(c, 'super'),
'address': dk(c, 'addr', 0),
'methods': bin_methods(c),
})
self._details[BINDETAILS_DETAILS_CLASSES].extend(dc)
self.lock.release()
def hashes(self, filename, data):
data['filename'] = filename
self.lock.acquire()
self._details[BINDETAILS_DETAILS_HASHES].append(data)
self.lock.release()
def json(self):
self.lock.acquire()
ret = json.dumps(self._details)
self.lock.release()
return ret
class Permissions(object):
"""Class used to list all the permissions requested by the mobile application"""
def __init__(self):
super(Permissions, self).__init__()
self.perms = []
self.lock = threading.Lock()
def add(self, name, description):
self.lock.acquire()
self.perms.append({
PERMISSION_NAME: name,
PERMISSION_DESC: description
})
self.lock.release()
def json(self):
self.lock.acquire()
ret = json.dumps(self.perms)
self.lock.release()
return ret
class Issues(object):
"""Issues linked to the binary"""
def __init__(self):
super(Issues, self).__init__()
self.issues = []
self.lock = threading.Lock()
def add(self, detail, description, severity):
self.lock.acquire()
self.issues.append({
ISSUE_TBL_NAME: detail,
ISSUE_TBL_DESC: description,
ISSUE_TBL_SEVR: severity,
})
self.lock.release()
def json(self):
self.lock.acquire()
ret = json.dumps(self.issues)
self.lock.release()
return ret
class SourceCode(object):
"""SourceCode found in the binary"""
def __init__(self):
super(SourceCode, self).__init__()
self.files = []
self.lock = threading.Lock()
def add(self, filename):
self.lock.acquire()
if filename not in self.files:
self.files.append(filename)
self.lock.release()
def json(self):
self.lock.acquire()
ret = json.dumps(self.files)
self.lock.release()
return ret
class Strings(object):
"""Strings linked to the binary"""
def __init__(self):
super(Strings, self).__init__()
self.strings = []
self.lock = threading.Lock()
def add(self, filename, stype, offset, string):
self.lock.acquire()
self.strings.append({
STRINGS_TBL_DATA: string,
STRINGS_TBL_FILE: filename,
STRINGS_TBL_TYPE: stype,
STRINGS_TBL_OFFSET: offset,
})
self.lock.release()
def json(self):
self.lock.acquire()
ret = json.dumps(self.strings)
self.lock.release()
return ret
class Extra(object):
"""Extra interesting stuff that can be added"""
def __init__(self):
super(Extra, self).__init__()
self.extra = {}
self.lock = threading.Lock()
def add(self, key, string):
self.lock.acquire()
self.extra[key] = string
self.lock.release()
def add_text_file(self, filename):
basename = os.path.basename(filename)
with open(filename, 'r', errors='replace') as fp:
self.add(basename, "".join(fp.readlines()))
def json(self):
self.lock.acquire()
ret = json.dumps(self.extra)
self.lock.release()
return ret
class WebLogger(object):
"""Class used to creat loggin features via web interface."""
def __init__(self):
super(WebLogger, self).__init__()
self.logs = []
self.lock = threading.Lock()
def error(self, message):
self.lock.acquire()
self.logs.append({"timestamp": time.time(), "log": message, "type": "error"})
self.lock.release()
def warning(self, message):
self.lock.acquire()
self.logs.append({"timestamp": time.time(), "log": message, "type": "warning"})
self.lock.release()
def notify(self, message):
self.lock.acquire()
self.logs.append({"timestamp": time.time(), "log": message, "type": "notify"})
self.lock.release()
def info(self, message):
self.lock.acquire()
self.logs.append({"timestamp": time.time(), "log": message, "type": "info"})
self.lock.release()
def json(self):
self.lock.acquire()
ret = json.dumps(self.logs)
self.lock.release()
return ret