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();
        }
    }

 

 posted on 2020-11-09 08:37  絆τ  阅读(1193)  评论(0编辑  收藏  举报