This repository has been archived by the owner on Jun 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDencrypt_fix.py
106 lines (89 loc) · 3.15 KB
/
Dencrypt_fix.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
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import sys
envars = dict()
def readVarvalue(data):
length = len(data)
source = str(data, encoding="utf-8")
buffer = source[1:length - 1]
buffer = buffer.split(":~")
varname = buffer[0]
if not varname in envars:
envars[varname] = os.getenv(varname)
entity = envars[varname]
if not entity: # None value
return source
length = len(buffer)
if length > 1:
length = len(entity)
buffer = buffer[1].split(",")
start = int(buffer[0])
ended = int(buffer[1])
if start < 0:
start, ended = length + start, ended
source = entity[start: start + ended]
return source
def batchReader(data, index, length):
buffer = bytes(); source = str()
flag = False; start = 0; ended = 0
while(True):
if data[index] in [0xFF, 0xFE]: index += 1; continue
if data[index] == 0x0D and data[index + 1] == 0x0A: index += 2; break
if data[index] == 0x25: # 判断变量符号, 获取符号名
if not flag:
flag = True
start = index
else:
flag = False
ended = index + 1
buffer = data[start:ended]
source += readVarvalue(buffer)
index += 1
else:
if not flag: # 保存其他字符串
try:
buffer = data[index:index + 1]
source += str(buffer, encoding="utf-8")
index += 1
except Exception as err:
ansiByte = bytes(); ansiLen = index
while (str(buffer).find("x") >= 0):
ansiByte += buffer; ansiLen += 1
buffer = data[ansiLen:ansiLen + 1]
source += ansiByte.decode("ansi", "ignore")
index = ansiLen
else: # 保存变量内的名称
if (start + 1 == index) and ((data[index] >= 0x30 and data[index] <= 0x39) or data[index] == 0x2A):
flag = False
ended = index
buffer = data[start: ended + 1]
source += str(buffer, encoding="utf-8")
index += 1
if index >= length: break
print(source)
bufs = source.split('&@') # 解析加密变量
for var in bufs:
if var[0:4] == 'set ':
var = var[4:]
b = var.find('=')
envars[var[0:b]] = var[b+1:].replace('^^^', '^')
source += '\r\n'
return {"index": index, "source": source}
def batchDecryp(data):
result = dict(); source = str()
index = 0; length = len(data)
while (index < length):
result = batchReader(data, index, length)
index = result.get("index")
source = result.get("source")
return source
if __name__ == '__main__':
if len(sys.argv) < 2:
print("[x] Script parameter length error!")
print("[!] Usage: python dencrypt.py encrypt.bat")
exit(0)
file = open(sys.argv[1], "rb")
data = file.read(); file.close()
batchDecryp(data)
exit(0)