微信.dat文件转为.jpg

微信.dat文件转为.jpg

今天在清理电脑微信数据时发现微信的WeChat Files\wxid_xxxx\FileStorage\MsgAttach目录,这个目录是微信按照联系人或群聊生成的数据文件夹,其中Image文件夹里保存了聊天记录的图片,但是文件后缀是.dat,修改后缀为.jpg仍然无法查看,应该是经过了加密,经过查询找到了一个用js脚本转换的方法,代码如下:

let fs = require('fs');
let path = require('path');
let async = require('async');

let base = 0xFF;
let next = 0xD8;
let gifA = 0x47;
let gifB = 0x49;
let pngA = 0x89;
let pngB = 0x50;
//指定扫描文件夹
let scanDir = 'C:\\xxx\\xxx\\xxx\\xxx\\';
//指定输出路径
let imgDir = 'C:\\xxx\\xxx\\xxx\\xxx\\xxx\\';

let files = fs.readdirSync(scanDir);
var arr = [];
files.forEach(function(item){
    if(path.extname(item) == '.dat'){
        arr.push(item);
    }
})
async.mapLimit(arr,50,function(item,cb){
    convert(item,cb);
},function(){
    process.exit(0);
})
//convert
function convert(item,cb){
    let absPath =path.join(scanDir,item);
    let imgPath = path.join(imgDir,item+'.jpg');
    fs.readFile(absPath,(err,content)=>{
        if(err){
            console.log(err);
            cb(err);
        }
        let firstV = content[0],
            nextV = content[1],
            jT = firstV ^ base,
            jB = nextV ^ next,
            gT = firstV ^ gifA,
            gB = nextV ^ gifB,
            pT = firstV ^ pngA,
            pB = nextV ^ pngB;
        var v = firstV ^ base;
        if(jT == jB){
            v = jT;
        }else if(gT == gB){
            v = gT;
        }else if(pT == pB){
            v = pT;
        }
        let bb = content.map(br=>{
            return br ^ v
        })
        fs.writeFileSync(imgPath,bb)
        cb(null);
    })
}
  • 代码运行时需要node.js环境
  • 还需要安装async模块
npm install async

代码cv自:电脑微信dat文件怎么转换成jpg?

新手上路,如有错误欢迎指正

你可能感兴趣的:(微信,javascript,node.js)