-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathack2_swu_decrypt.py
70 lines (57 loc) · 2.22 KB
/
ack2_swu_decrypt.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
#!/usr/bin/env python3
from Crypto.Cipher import AES
import os
import sys, getopt
def remove_padding(file_path):
with open(file_path, 'rb+') as file:
file.seek(-1, os.SEEK_END)
padding_value = ord(file.read(1))
file.seek(-padding_value, os.SEEK_END)
file.truncate()
def decrypt_aes_cbc(input_file, output_file, first_aes_key, second_aes_key, offset=32):
block_size = 16
# Convert hex keys to bytes
first_aes_key_bytes = bytes.fromhex(first_aes_key)
# Read IV from the second AES key
iv = bytes.fromhex(second_aes_key[:32])
# Create AES cipher objects
cipher = AES.new(first_aes_key_bytes, AES.MODE_CBC, iv)
with open(input_file, 'rb') as file_input:
# Seek to the specified offset
file_input.seek(offset)
with open(output_file, 'wb') as file_output:
while True:
ciphertext = file_input.read(block_size)
if not ciphertext:
break
# Decrypt the block
plaintext = cipher.decrypt(ciphertext)
file_output.write(plaintext)
# Remove padding
remove_padding(output_file)
def main(argv):
input_file_path = ''
output_file_path = ''
try:
opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="])
except getopt.GetoptError:
print ('ack2_swu_decrypt.py -i update.bin -o update.zip')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print ('ack2_swu_decrypt.py -i update.bin -o update.zip')
sys.exit()
elif opt in ("-i", "--ifile"):
input_file_path = arg
elif opt in ("-o", "--ofile"):
output_file_path = arg
print ('AnyCubic Kobra 2 BIN to SWU Converter V1.0')
print ('Input file: ', input_file_path)
print ('Output file: ', output_file_path)
first_aes_key_hex = "78B6A614B6B6E361DC84D705B7FDDA33C967DDF2970A689F8156F78EFE0B1FCE"
second_aes_key_hex = "54E37626B9A699403064111F77858049"
offset_value = 32 # Provide the offset value if needed
print ('Processing...')
decrypt_aes_cbc(input_file_path, output_file_path, first_aes_key_hex, second_aes_key_hex, offset_value)
print ('Done!')
main(sys.argv[1:])