forked from klensy/wt-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clog_unpack.py
41 lines (31 loc) · 1.16 KB
/
clog_unpack.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
import argparse
def xxor(data, key):
d_data = bytearray(len(data))
key_length = len(key)
for i, c in enumerate(data):
d_data[i] = (c ^ key[i % key_length])
return d_data
def main():
parser = argparse.ArgumentParser(description="Decrypt *.clog files")
parser.add_argument('-i', dest='in_file', required=True,
type=argparse.FileType('rb'), help="*.clog file")
parser.add_argument('-k', dest='key_file', required=True,
type=argparse.FileType('rb'), help="file with decryption key")
parser.add_argument('-o', dest='out_file', required=True,
type=argparse.FileType('wb'), help="output file")
try:
parse_result = parser.parse_args()
except IOError, msg:
parser.error(str(msg))
exit(1)
data = bytearray(parse_result.in_file.read())
parse_result.in_file.close()
if len(data) == 0:
print "empty file"
exit(1)
key_data = bytearray(parse_result.key_file.read())
parse_result.key_file.close()
with parse_result.out_file as f:
f.write(xxor(data, key_data))
if __name__ == '__main__':
main()