-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdeobfuscator.py
50 lines (38 loc) · 1.33 KB
/
deobfuscator.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
import base64, codecs
import ast, os.path as p, time
from ast import BinOp, Assign, Constant
file = input("Path: ")
new_file_name = ''
joy = 'rot13'
destiny = ''
final = ''
magic = ''
love = ''
god = ''
with open(file, 'rb') as f:
new_file_name = "deobf_"+file.replace('.py', '')+".py"
pre_time = round(time.time() * 1000)
parsed = ast.parse(f.read().decode('utf-8'))
for node in parsed.body:
if (isinstance(node, Assign)):
node_value = node.value
name_of_constant = node.targets[0].id
if (isinstance(node_value, Constant)):
value_of_constant = node_value.value
match (name_of_constant):
case "magic":
magic = value_of_constant
case "god":
god = value_of_constant
case "destiny":
destiny = value_of_constant
case "love":
love = value_of_constant
elif (isinstance(node_value, BinOp)):
node_value = node.value
encoded_source = eval(ast.unparse(node_value)).encode('utf-8')
final = base64.b64decode(encoded_source)
with open(new_file_name, ("wb" if p.isfile(new_file_name) else "xb+")) as d:
d.write(final)
post_time = round(time.time() * 1000)
print("Complete in "+str(post_time - pre_time)+"ms")