zoukankan      html  css  js  c++  java
  • 【Tools】将微信DAT图片加密文件转化为图片

     var path = @"E:68b2dab36844e760f17f4cde1d9742fb.dat";
                byte[] byteArray = FileBinaryConvertHelper.File2Bytes(path);
    
                Dictionary<byte, string> keyValuePairs = new Dictionary<byte, string>();
                keyValuePairs.Add(0xFF, "jpg");
                keyValuePairs.Add(0x89, "png");
                keyValuePairs.Add(0x47, "gif");
    
                byte sc = new byte();
                byte tsc = new byte();
                if ((byteArray[0] ^ 0xFF) == (byteArray[1] ^ 0xD8))
                {
                    tsc = 0xFF;
                    sc = BitConverter.GetBytes(byteArray[0] ^ 0xFF)[0];
                }
    
                if ((byteArray[0] ^ 0x89) == (byteArray[1] ^ 0x50))
                {
                    tsc = 0x89;
                    sc = BitConverter.GetBytes(byteArray[0] ^ 0x89)[0];
                }
    
                if ((byteArray[0] ^ 0x47) == (byteArray[1] ^ 0x49))
                {
                    tsc = 0x47;
                    sc = BitConverter.GetBytes(byteArray[0] ^ 0x47)[0];
                }
    
                var lsNewbyte = new List<byte>();
                foreach (var item in byteArray)
                {
                    var newByte = BitConverter.GetBytes(item ^ sc);
                    lsNewbyte.Add(newByte[0]);
                }
                var newByteArray = lsNewbyte.ToArray();
    
                FileBinaryConvertHelper.Bytes2File(newByteArray, $@"E:pp.{keyValuePairs[tsc]}");
     public class FileBinaryConvertHelper
        {
            public static byte[] File2Bytes(string path)
            {
                if (!System.IO.File.Exists(path))
                {
                    return new byte[0];
                }
    
                FileInfo fi = new FileInfo(path);
                byte[] buff = new byte[fi.Length];
    
                FileStream fs = fi.OpenRead();
                fs.Read(buff, 0, Convert.ToInt32(fs.Length));
                fs.Close();
    
                return buff;
            }
    
            public static void Bytes2File(byte[] buff, string savepath)
            {
                if (System.IO.File.Exists(savepath))
                {
                    System.IO.File.Delete(savepath);
                }
    
                FileStream fs = new FileStream(savepath, FileMode.CreateNew);
                BinaryWriter bw = new BinaryWriter(fs);
                bw.Write(buff, 0, buff.Length);
                bw.Close();
                fs.Close();
            }
        }
  • 相关阅读:
    XP IIS COM+ 应用程序无法打开
    SQL 连接字符串
    WebSocket
    一个很详细的web.xml讲解
    Maven+SpringMVC+SpringFox+Swagger整合示例
    poj 1691 Painting A Board (DFS/状态压缩DP)
    poj 3373 Changing Digits (DFS+剪枝)
    hdu 1171 Big Event in HDU (母函数)
    鸽巢定理
    poj 1724 ROADS
  • 原文地址:https://www.cnblogs.com/xuxml/p/13946816.html
Copyright © 2011-2022 走看看