美文网首页
微信聊天记录Dat文件使用python解码,输出图片

微信聊天记录Dat文件使用python解码,输出图片

作者: Ganson2019 | 来源:发表于2022-07-07 17:01 被阅读0次

    Ref: https://blog.csdn.net/wujinmei/article/details/116073984

    import os

    path=r'your dat files path'

    dat文件保存的位置

    def imageDecode(fpath,fn):
    dat_read = open(fpath, "rb")
    out=fpath+".png"
    #png格式前面是89504E47
    #jpg格式前面是FFD8FFE0
    #gif格式前面是47494638
    filetype="png"
    first2=dat_read.read(2)
    #先取前面的两位
    #print(hex(first2[0]))
    xor=0x00
    png1=int(str(hex(first2[0])),16) ^ 0x89
    png2=int(str(hex(first2[1])),16) ^ 0x50
    if png1==png2:
    xor=png1
    filetype="png"
    else:
    jpg1=int(str(hex(first2[0])),16) ^ 0xFF
    jpg2=int(str(hex(first2[1])),16) ^ 0xD8
    if jpg1==jpg2:
    filetype="jpg"
    xor=jpg1
    out=fpath+".jpg"
    else:
    gif1=int(str(hex(first2[0])),16) ^ 0x47
    gif2=int(str(hex(first2[1])),16) ^ 0x49
    if gif1==gif2:
    filetype="gif"
    xor=gif1
    out=fpath+".gif"
    if xor>0x00:
    png_write = open(out, "wb")
    if filetype=="png":
    png_write.write(bytes([0x89]))
    png_write.write(bytes([0x50]))
    elif filetype=="jpg":
    png_write.write(bytes([0xFF]))
    png_write.write(bytes([0xD8]))
    elif filetype=="gif":
    png_write.write(bytes([0x47]))
    png_write.write(bytes([0x49]))
    for now in dat_read:
    for nowByte in now:
    newByte = nowByte ^ int(str(hex(xor)),16)
    png_write.write(bytes([newByte]))
    png_write.close()
    dat_read.close()
    def findFile(f):
    fsinfo = os.listdir(f)
    for fn in fsinfo:
    temp_path = os.path.join(f, fn)
    if not os.path.isdir(temp_path):
    if fn[-4:]==".dat":
    print('文件路径: {}' .format(temp_path))
    imageDecode(temp_path,fn)
    #os.remove(temp_path) #删除原dat文件
    else:
    findFile(temp_path)

    findFile(path)

    相关文章

      网友评论

          本文标题:微信聊天记录Dat文件使用python解码,输出图片

          本文链接:https://www.haomeiwen.com/subject/dwepbrtx.html