-
Notifications
You must be signed in to change notification settings - Fork 6
/
wic.py
64 lines (54 loc) · 1.55 KB
/
wic.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
import traceback
try:
# wechat image convert
import binascii
# first need two file to find rule
trans = 'color_trans.dat'
sheet = 'color_sheet.jpg'
binfile = open(trans, 'rb')
a = binfile.read()
hex_trans = binascii.b2a_hex(a)
binfile = open(sheet, 'rb')
a = binfile.read()
hex_sheet = binascii.b2a_hex(a)
rule = [0] * 256
flag = [False] * 256
for i in range(len(hex_trans) // 2):
hex_t = hex_trans[2 * i:2 * (i + 1)]
hex_s = hex_sheet[2 * i:2 * (i + 1)]
int_t = int(hex_t, 16)
int_s = int(hex_s, 16)
if flag[int_t] == False:
rule[int_t] = int_s
flag[int_t] = True
if flag.count(True) == 256:
break
# second convert dat file
in_file = 'in.dat'
out_file = 'out.jpg'
binfile = open(in_file, 'rb')
a = binfile.read()
binfile.close()
hex_in = binascii.b2a_hex(a)
out_ret = ''
for i in range(len(hex_in) // 2):
hex_t = hex_in[2 * i:2 * (i + 1)]
int_t = int(hex_t, 16)
int_ret = rule[int_t]
if int_ret > 15:
hex_ret = hex(int_ret)[2:]
else:
hex_ret = '0' + hex(int_ret)[2:]
out_ret += hex_ret
hex_file = bytes.fromhex(out_ret)
binfile = open(out_file, 'wb')
binfile.write(hex_file)
binfile.close()
print(u'转换成功')
except Exception as e:
print('Exception Info')
print('-' * 10)
print('traceback.format_exc():')
print(traceback.format_exc())
print('-' * 10)
input(u'按任意键退出\n')