本文参考于https://www.cnblogs.com/KMBlog/p/6877752.html
大神破解了酷狗缓存文件kgtemp的加密解密方式,遂用python实现之。
kugou.py
# coding:utf-8
import os
import sys
key = [0xAC, 0xEC, 0xDF, 0x57]
def crack_file(argv):
filename = argv[0]
new_name = argv[1]
file = open(filename, "rb")
file.seek(1024, os.SEEK_SET) # 偏移量1024
changed_file = open(new_name, 'wb+') # 以二进制追加写的方式打开
try:
b = file.read(4) # 一次读4个字节 type(b) --> 'bytes'
while(b):
for num,i in enumerate(b):
h = i >> 4 # type(i) --> int
l = i & 0xf
kh = key[num] >> 4
kl = key[num] & 0xf
y = l ^ kl
y = (h ^ kh ^ y) << 4 | y
temp = bytes([y]) # 将int转为bytes
changed_file.write(temp)
b = file.read(4)
except Exception as e:
print(e)
else:
print("成功")
finally:
file.close()
changed_file.close()
if __name__ == "__main__":
crack_file(sys.argv[1:])
运行方式python3中运行 python kugou.py 要转换的文件名 新名字
检查新文件的MD5值,看是否和原文件的名字一样
import hashlib
filename = "xxxx"
with open(filename, 'rb') as f:
md5obj = hashlib.md5()
md5obj.update(f.read())
hash = md5obj.hexdigest()
print(hash)
注:
- 关于int转bytes问题见https://stackoverflow.com/questions/21017698/converting-int-to-bytes-in-python-3
- python二进制读写见http://blog.youkuaiyun.com/lesky/article/details/5727473
如
import struct
temp = struct.pack("B", 12) # 将int转为bytes