c#解密pc微信图片

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace wechat_image
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folder = new FolderBrowserDialog();
            folder.Description = "选择目录";
            if (folder.ShowDialog() == DialogResult.OK)
            {
                //文件夹路径
                string folderPath = folder.SelectedPath;
                textBox1.Text = folderPath;
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folder = new FolderBrowserDialog();
            folder.Description = "选择目录";
            if (folder.ShowDialog() == DialogResult.OK)
            {
                //文件夹路径
                string folderPath = folder.SelectedPath;
                textBox2.Text = folderPath;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == string.Empty || textBox2.Text == string.Empty)
            {
                return;
            }
            progressBar1.Visible = true;
            List fileList = new List();
            var files = Directory.GetFiles(textBox1.Text, "*.dat");
            foreach (var file in files)
                fileList.Add(file);
            int i=1,j = 0;
            foreach (var file in fileList)
            {
                j++;
                if(j > fileList.Count/100*i)
                {
                    i++;
                }
                xor_datfile(file);
                if (i <= 100)
                {
                    progressBar1.Value = i;
                }
                Delay(10);
            }     

        }

        private void xor_datfile(string filepath)
        {
            string filename = System.IO.Path.GetFileName(filepath);

            byte[] oldfile = FileContent(filepath);
            byte[] newfile = new byte[oldfile.Length];

            byte key = (byte)(oldfile[0] ^ 0xFF);
            if((oldfile[1] ^ key) == 0xD8)
            {
                for (int i = 0; i < oldfile.Length; i++)
                {
                    newfile[i] = (byte)(oldfile[i] ^ key);
                }
                FileStream fs = new FileStream(textBox2.Text+"\\"+filename+".jpg", FileMode.Create);
                fs.Write(newfile, 0, newfile.Length);
                fs.Close();
            }
            else
            {
                key = (byte)(oldfile[0] ^ 0x89);
                for (int i = 0; i < oldfile.Length; i++)
                {
                    newfile[i] = (byte)(oldfile[i] ^ key);
                }
                FileStream fs = new FileStream(textBox2.Text + "\\"+filename + ".png", FileMode.Create);
                fs.Write(newfile, 0, newfile.Length);
                fs.Close();
            }
        }

        private byte[] FileContent(string fileName)
        {
            using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
            {
                try
                {
                    byte[] buffur = new byte[fs.Length];
                    fs.Read(buffur, 0, (int)fs.Length);
                    return buffur;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }

        public static void Delay(int mm)//输入需要延迟的毫秒数

        {

            DateTime current = DateTime.Now;

            while (current.AddMilliseconds(mm) > DateTime.Now)

            {

                Application.DoEvents();

            }

            return;

        }
    }
}

golang参考

func decImg(imgPath string) {
	var jpg = true
	buff, err := ioutil.ReadFile(imgPath)
	if err != nil {
		fmt.Println(err)
		return
	}
	key := buff[0] ^ 0xFF
	var buff2 = make([]byte, len(buff))
	if buff[1] != 0xD8 ^ key {
		key = buff[0] ^ 0x89
		jpg = false
	}
	for i := 0; i< len(buff); i++ {
		buff2[i] = buff[i] ^ key
	}
	if(jpg) {
		ioutil.WriteFile(os.Args[1] + ".jpg", buff2, 777)
	} else {
		ioutil.WriteFile(os.Args[1] + ".png", buff2, 777)
	}
	
}
上一篇:android – 尝试将图片保存到尚未创建的特定图片文件夹中


下一篇:redis5.0.8 安装教程