zoukankan      html  css  js  c++  java
  • 其它 微信DAT图片解密

    原文:https://www.cnblogs.com/xuxml/p/13946816.html

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApp1
    {
        class Program
        {
            // 原文:https://www.cnblogs.com/xuxml/p/13946816.html
            static void Main(string[] args)
            {
                DirectoryInfo dir = new DirectoryInfo("D:\2021-02\");
                FileInfo[] allFile = dir.GetFiles();
                foreach (FileInfo fInfo in allFile)
                {
                    convertFile(fInfo.FullName);
                }
            }
    
            static void convertFile(String path)
            {
                // var path = @"D:9a064413d6f5d36cfbdc7d2263dbb7bb.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, $@"D:pp.{keyValuePairs[tsc]}");
    
                FileBinaryConvertHelper.Bytes2File(newByteArray, path+$".convert.{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();
            }
        }
    }
    
    
  • 相关阅读:
    BootStrap2学习日记15----选项卡
    BootStrap2学习日记14----导航
    Google地图下载工具代码
    SqlServer 动态SQL(存储过程)中Like 传入参数无正确返回值的问题
    地球坐标-火星坐标-百度坐标及之间的转换算法 C#
    GIS基础知识
    Gps坐标有效性判定
    Gps坐标距离计算C#实现
    C# 对字段忽略模型校验
    SQL基础复习2
  • 原文地址:https://www.cnblogs.com/guxingy/p/14455423.html
Copyright © 2011-2022 走看看