-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrr_decode.py
286 lines (221 loc) · 7.62 KB
/
rr_decode.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import sys
def decode_b0747746(enc_data):
print('[!] Type [b0747746] is detected!')
print('[+] Decoding...')
dec_data = []
xor_key = 1219836524
for i in range(len(enc_data)):
for _ in range(7):
x0 = (xor_key & 0x20000000) == 0x20000000
x1 = (xor_key & 8) == 8
x2 = xor_key & 1
x3 = 1 + (x0 ^ x1 ^ x2)
xor_key = ((xor_key + xor_key) + x3) & 0xFFFFFFFF
dec_data.append(int.from_bytes(enc_data[i], "little") ^ (xor_key % 256))
return dec_data
def decode_b25a6f00(enc_data):
print('[!] Type [b25a6f00] is detected!')
print('[+] Decoding...')
dec_data = []
for i in range(len(enc_data)):
if i % 2 == 0:
dec_data.append(int.from_bytes(enc_data[i], "little") ^ 0xff)
else:
dec_data.append(int.from_bytes(enc_data[i], "little"))
return dec_data
def decode_b2a66dff(enc_data):
print('[!] Type [b2a66dff] is detected!')
print('[+] Decoding...')
dec_data = []
for i in range(len(enc_data)):
dec_data.append(int.from_bytes(enc_data[i], "little") ^ 0xfc)
dec_data[0] = 0x4d
dec_data[2] = 0x90
return dec_data
def decode_f2a32072(enc_data):
print('[!] Type [f2a32072] is detected!')
print('[+] Decoding...')
dec_data = []
xor_key = 2079624803
for i in range(len(enc_data)):
for _ in range(7):
x0 = (xor_key & 0x40000000) == 0x40000000
x1 = (xor_key & 8) == 8
x2 = xor_key & 1
x3 = x0 ^ x1 ^ x2
xor_key = ((xor_key + xor_key) + x3) & 0xFFFFFFFF
dec_data.append(int.from_bytes(enc_data[i], "little") ^ (xor_key % 256))
return dec_data
def decode_b2a46eff(enc_data):
print('[!] Type [b2a46eff] is detected!')
print('[+] Decoding...')
dec_data = []
for i in range(len(enc_data)):
dec_data.append(int.from_bytes(enc_data[i], "little") ^ 0xff)
dec_data[1] = 0x5a
dec_data[2] = 0x90
return dec_data
def decode_a9a46efe(enc_data):
print('[!] Type [a9a46efe] is detected!')
print('[+] Decoding...')
dec_data = []
for i in range(len(enc_data)):
dec_data.append(((int.from_bytes(enc_data[i], "little") ^ 0x7b) + 0x7b) % 256)
return dec_data
def decode_945fdad8(enc_data):
print('[!] Type [945fdad8] is detected!')
print('[+] Decoding...')
dec_data = []
xor_key = 1387678300
for i in range(len(enc_data)):
for _ in range(7):
x0 = (xor_key & 0x20000000) == 0x20000000
x1 = (xor_key & 8) == 8
x2 = xor_key & 1
x3 = 1 + (x0 ^ x1 ^ x2)
xor_key = ((xor_key + xor_key) + x3) & 0xFFFFFFFF
dec_data.append(int.from_bytes(enc_data[i], "little") ^ (xor_key % 256))
return dec_data
def decode_95a2748e(enc_data):
print('[!] Type [95a2748e] is detected!')
print('[+] Decoding...')
dec_data = []
xor_key = 1404390492
for i in range(len(enc_data)):
for _ in range(7):
x0 = (xor_key & 0x20000000) == 0x20000000
x1 = (xor_key & 8) == 8
x2 = xor_key & 1
x3 = 1 + (x0 ^ x1 ^ x2)
xor_key = ((xor_key + xor_key) + x3) & 0xFFFFFFFF
dec_data.append(int.from_bytes(enc_data[i], "little") ^ (xor_key % 256))
return dec_data
def rc4_ksa(key):
x = 0
y = 0
s = list(range(256))
for i in range(0x100):
y = (key[x % len(key)] + s[i] + y) & 0xff
s[i], s[y] = s[y], s[i]
x += 1
return s
def rc4_prga(enc_data, s):
x = 0
y = 0
for i in range(len(enc_data)):
x = (x + 1) & 0xff
y = (s[x] + y) & 0xff
s[x], s[y] = s[y], s[x]
enc_data[i] = int.from_bytes(enc_data[i], "little") ^ s[(s[x] + s[y]) & 0xff]
return bytes(enc_data)
def decode_4da2ee67(enc_data):
print('[!] Type [4da2ee67] is detected!')
print('[+] Decoding...')
key = bytearray(b"123456")
s = rc4_ksa(key)
dec_data = rc4_prga(enc_data, s)
return dec_data
def decode_8291706f(enc_data):
print('[!] Type [8291706f] is detected!')
print('[+] Decoding...')
key = bytearray(b"2YlK77")
s = rc4_ksa(key)
dec_data = rc4_prga(enc_data, s)
return dec_data
def decode_614a860c(enc_data):
print('[!] Type [614a860c] is detected!')
print('[+] Decoding...')
key = bytearray(b"923hrg")
s = rc4_ksa(key)
dec_data = rc4_prga(enc_data, s)
return dec_data
def decode_0f7850ba(enc_data):
print('[!] Type [614a860c] is detected!')
print('[+] Decoding...')
key = bytearray(b"c34H4y")
s = rc4_ksa(key)
dec_data = rc4_prga(enc_data, s)
return dec_data
def decode_8291986f(enc_data):
print('[!] Type [8291986f] is detected!')
print('[+] Decoding...')
key = bytearray(b"2YlK77")
s = rc4_ksa(key)
dec_data = rc4_prga(enc_data, s)
return dec_data
def decode_2333f765(enc_data):
print('[!] Type [2333f765] is detected!')
print('[+] Decoding...')
key = bytearray(b"nigerdi")
dec_data = []
for i in range(len(enc_data)):
dec_data.append(int.from_bytes(enc_data[i], "little") ^ key[i % len(key)])
return dec_data
def main():
args = sys.argv
if len(args) != 3:
print('[!] Usage: "' + args[0] + ' [Input] [Output]"')
sys.exit(-1)
signature = [
[0xb0, 0x74, 0x77, 0x46],
[0xb2, 0x5a, 0x6f, 0x00],
[0xb2, 0xa6, 0x6d, 0xff],
[0xf2, 0xa3, 0x20, 0x72],
[0xb2, 0xa4, 0x6e, 0xff],
[0xa9, 0xa4, 0x6e, 0xfe],
[0x94, 0x5f, 0xda, 0xd8],
[0x95, 0xa2, 0x74, 0x8e],
[0x4d, 0xa2, 0xee, 0x67],
[0x82, 0x91, 0x70, 0x6f],
[0x61, 0x4a, 0x86, 0x0c],
[0x0f, 0x78, 0x50, 0xba],
[0x82, 0x91, 0x98, 0x6f],
[0x23, 0x33, 0xf7, 0x65]
]
enc_data = []
with open(args[1], 'rb') as f:
while True:
byte = f.read(1)
if byte:
enc_data.append(byte)
else:
break
header = enc_data[:4]
for i in range(4):
header[i] = int.from_bytes(header[i], 'little')
if header == signature[0]:
dec_data = decode_b0747746(enc_data)
elif header == signature[1]:
dec_data = decode_b25a6f00(enc_data)
elif header == signature[2]:
dec_data = decode_b2a66dff(enc_data)
elif header == signature[3]:
dec_data = decode_f2a32072(enc_data)
elif header == signature[4]:
dec_data = decode_b2a46eff(enc_data)
elif header == signature[5]:
dec_data = decode_a9a46efe(enc_data)
elif header == signature[6]:
dec_data = decode_945fdad8(enc_data)
elif header == signature[7]:
dec_data = decode_95a2748e(enc_data)
elif header == signature[8]:
dec_data = decode_4da2ee67(enc_data)
elif header == signature[9]:
dec_data = decode_8291706f(enc_data)
elif header == signature[10]:
dec_data = decode_614a860c(enc_data)
elif header == signature[11]:
dec_data = decode_0f7850ba(enc_data)
elif header == signature[12]:
dec_data = decode_8291986f(enc_data)
elif header == signature[13]:
dec_data = decode_2333f765(enc_data)
else:
print('[!] Error: Unknown Format')
sys.exit(-1)
print('[!] Complete!')
with open(args[2], 'wb') as f:
f.write(bytearray(dec_data))
if __name__ == '__main__':
main()