-
Notifications
You must be signed in to change notification settings - Fork 10
/
deobfuscate.py
50 lines (43 loc) · 1.19 KB
/
deobfuscate.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 binascii
import os
# by Unleqitq
def deobf(line: str) -> str:
name0, val0 = line.split("=")
index = name0.index("[")
name = eval(name0[index+1:-1])
try:
val = eval(val0)
if (type(val)==str):
return name+"='"+val.replace("\\", "\\\\").replace("'", "\\'").replace("\n","\\n")+"'"
if (type(val)==int or type(val) == float or type(val) == bool):
return name+"="+str(val)
except:pass
return name+"="+val0
variables = {}
variableNames = []
lines = []
with open("vars.py") as file:
lines = file.read().split("\n")
try:os.remove("vars.py")
except:pass
with open("vars.py", "a") as file:
for line in lines:
try:
file.write(deobf(line)+"\n")
except:
file.write(line+"\n")
with open("vars.py") as file:
lines = file.read().split("\n")
for line in lines:
try:
name, val = line.split("=", 1)
variables[name] = val
variableNames.append(name)
except:pass
variableNames.sort(key=len, reverse=True)
with open("code.py") as file:
code = file.read()
for name in variableNames:
code = code.replace(name, variables[name])
with open("out.py", 'w') as file:
file.write(code)