-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathyada.py
executable file
·49 lines (41 loc) · 1.26 KB
/
yada.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
#!/usr/bin/env python3
from pathlib import Path
from utils import unpack
import sys
def main():
try:
path = Path(sys.argv[1])
except IndexError:
print("Usage: {} [path]".format(sys.argv[0]))
sys.exit(1)
with path.open('rb') as f:
header, size = unpack(f, '<4sL')
if header != b'YARA':
print('Invalid File (Bad header)')
exit()
# lookahead for newer versions
# v8 -> version: 1byte, 3.9.0 -> version: 4bytes
version = unpack(f, '<L')[0]
if version != 0x150020:
f.seek(-4, 1)
version = unpack(f, '<B')[0]
if version in [8, 11, 12]:
import v11dec as decompiler
elif version == 0x150020:
import v39dec as decompiler
else:
print('Unsupported Yara version')
exit()
dec = decompiler.decompiler(f, size)
rules = dec.parse_rules()
cnt = 0
unrecoverable = 0
for rule in rules:
o = str(rule)
cnt += 1
if 'UNRECOVERABLE_REGEXP' in o or 'DecompileError' in o or '[Unsupported]' in o:
unrecoverable += 1
print(o)
print('/* Decompile %d/%d rules */' % (cnt - unrecoverable, cnt))
if __name__ == '__main__':
main()