@
des 嗯,现在写出文件后文件大小对了,但是。。。貌似解密失败?
$buf = file_get_contents('photo.dat');
$buf = unpack('C*', $buf);
$magic = $buf[1] ^ 0xff;
$photo = array_map(function($b){return pack('H', $b ^ $magic);}, $buf);
$b = file_put_contents('photo.jpg', $photo);
这是正确解密的 Python 代码
def _decode_pc_dat(self, datfile):
with open(datfile, 'rb') as f:
buf = bytearray(f.read())
magic = 0xff ^ list(buf)[0] if buf else 0x00
imgfile = re.sub(r'.dat$', '.jpg', datfile)
with open(imgfile, 'wb') as f:
newbuf = bytearray([b ^ magic for b in list(buf)])
f.write(newbuf)