-
Notifications
You must be signed in to change notification settings - Fork 21
/
decrypter.py
56 lines (50 loc) · 1.7 KB
/
decrypter.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
import marshal, struct, sys, time, py_compile, traceback, fupy, os
def unpack_pyc(filename):
f = open(filename, "rb")
magic = f.read(4)
unixtime = struct.unpack("L", f.read(4))[0]
timestamp = time.asctime(time.localtime(unixtime))
code = marshal.load(f)
f.close()
return filename, magic, unixtime, timestamp, code
def mydecomp(decrypted_name,decompyled_name):
indent_pattern = ' ' * 4
pydec = fupy.PythonDecompiler(decrypted_name)
dump = pydec.decompile(indent = indent_pattern)
output = open(decompyled_name, "w")
output.write(dump)
output.close()
def mydecrypt(code,decrypted_name,decompyled_name):
with open(decrypted_name, 'wb') as fc:
fc.write(py_compile.MAGIC)
py_compile.wr_long(fc, long(time.time()))
marshal.dump(code, fc)
fc.flush()
fc.seek(0, 0)
mydecomp(decrypted_name,decompyled_name)
def do(name):
pname = os.path.dirname(os.path.abspath(__file__))+"\\"+name
crypted_name = pname + ".pyc"
decrypted_name = pname + "___decrypt.pyc"
decompyled_name = pname + "___decrypt.py"
sys.path.append(os.path.dirname(pname))
try:
cur_module = __import__(os.path.basename(pname))
filename, magic, unixtime, timestamp, code = unpack_pyc(crypted_name)
mydecrypt(code,decrypted_name,decompyled_name)
except:
traceback.print_exc(file=sys.stdout)
exc_traceback = sys.exc_info()[2]
trkobj = exc_traceback
while(trkobj.tb_next is not None):
trkobj = trkobj.tb_next
code = trkobj.tb_frame.f_code
mydecrypt(code,decrypted_name,decompyled_name)
first = True
for file in sys.argv:
if first:
first = False
continue
pythonFolder = os.path.dirname(os.path.abspath(__file__))
modulePath = file.replace(pythonFolder+'\\',"")
do(os.path.splitext(modulePath)[0])