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
| import os import binascii
title_flags = {"JPG":b"\xff\xd8\xff", "PNG":b"\x89\x50\x4e\x47", "BMP":b"\x42\x4d", "GIF":b"\x47\x49\x46\x38", "ZIP":b"\x50\x4b\x03\x04", "RAR":b"\x52\x61\x72\x21", "AVI":b"\x41\x56\x49\x20"}
def image_decode(in_path,out_path): """ 解密dat文件 param: in_path: 输入文件路径 + 文件名 out_path: 输出路径 + 输入文件名 ret: None """ dat_read = open(in_path, "rb") out_file= out_path + ".png" png_write = open(out_file, "wb") flag = 1 xor_flag = 0 for now in dat_read: if flag == 1: file_flag = int.from_bytes(now[0:2],byteorder="big",signed=False) for k in title_flags.keys(): t_f = title_flags[k][0:2] t_f = int.from_bytes(t_f,byteorder="big",signed=False) f_type0 = t_f ^ file_flag f_type = hex(f_type0) f_type1 = f_type[2:4] f_type2 = f_type[4:6] if f_type1 == f_type2: xor_flag = f_type0 % 256 flag = 0 for nowByte in now: newByte = nowByte ^ xor_flag png_write.write(bytes([newByte])) dat_read.close() png_write.close() def main(): in_path = r"C:\Users\Public\temp\keli.dat" file_name = in_path.split("\\")[-1:][0] out_path = "C:\\Users\\Public\\" + file_name image_decode(in_path, out_path) if __name__ == "__main__": main()
|