微信的dat文件转图片 java

  • 想了解更多的朋友可参考链接:超链接
  • 代码已经取了前两位与FF进行了异或,直接运行即可
import java.io.*;

public class ConvertDat {
    public static void main(String[] args) throws Exception {
        String srcPath = "F:/";//源文件路径
        String outPath = "F:/";//解码后输出路径

        File file = new File(srcPath);
        File[] files = file.listFiles(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                return name.endsWith(".dat");
            }
        });
        assert files != null;
        for (File f : files) {
            InputStream in = new FileInputStream(f);
            int read = in.read();
            int xorResult = read ^ 0xFF;
            in = new FileInputStream(f);//重新获取输入流
            OutputStream out = new FileOutputStream(outPath + f.getName()
                    .replace(".dat", ".png"));
            byte[] buffer = new byte[1024];
            int r;
            byte[] outBuffer = new byte[1024];
            while ((r = in.read(buffer)) > 0) {
                for (int i = 0; i < r; i++) {
                    byte b = buffer[i];
                    int c = b ^ xorResult;//与计算出的结果异或
                    Byte aByte = (byte) c;
                    outBuffer[i] = aByte;
                }
                out.write(outBuffer, 0, r);
                out.flush();
            }
            in.close();
            out.close();
        }
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值