2025年3月19日 星期三 甲辰(龙)年 月十八 设为首页 加入收藏
rss
您当前的位置:首页 > 计算机 > 编程开发 > Other

nodejs实现电脑版微信dat文件批量转化为jpg图片

时间:03-27来源:作者:点击数:79

微信聊天的图片都是以.dat格式保存下载的,搜了下网上的资料,只找到了python代码的实现,

这里用nodejs实现了一下。

新版电脑微信存储图片位置:

.\FileStorage\MsgAttach\d793770e32c06bd55098717dff82c5a6\Image

旧版电脑微信存储图片位置:

.\FileStorage\Image\

Nodejs实现批量转换:

  • const fs = require('fs')
  • const path = require('path')
  • const base = 0xFF
  • const next = 0xD8
  • const gifA = 0x47
  • const gifB = 0x49
  • const pngA = 0x89
  • const pngB = 0x50
  • //扫描路劲
  • const filePath = 'E:/Image/2022-11'
  • //转化后输出图片的路径
  • const outPath = 'E:/vxphoto/'
  • //读取目录下所有.dat文件
  • const files = fs.readdirSync(filePath)
  • const datArry = []
  • files.forEach(function (item) {
  • if (path.extname(item) == '.dat') {
  • datArry.push(item);
  • }
  • })
  • // 将所有.dat文件依次转化为.jpg文件,输出路径为上面的outPath
  • for (let i = 0; i < datArry.length; i++) {
  • convert(datArry[i])
  • process.stdout.write(`${i + 1}/${datArry.length} \r`)
  • }
  • //.dat转化为.jpg图片
  • function convert (item) {
  • let absPath = path.join(filePath, item);
  • let imgPath = path.join(outPath, item + '.jpg');
  • fs.readFile(absPath, (_err, content) => {
  • if (content?.length) {
  • let firstV = content[0]
  • let nextV = content[1]
  • let jT = firstV ^ base
  • let jB = nextV ^ next
  • let gT = firstV ^ gifA
  • let gB = nextV ^ gifB
  • let pT = firstV ^ pngA
  • let pB = nextV ^ pngB
  • let 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)
  • }
  • })
  • }
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门