记一个小软件的开发

来源:互联网 发布:d2d网络 编辑:程序博客网 时间:2024/06/05 10:59

喜欢听歌.突然发现酷狗里面的歌手背景图片都还不错.凭印象找到了路径

C:\Users\***\AppData\Roaming\KuGou8\SingerImg(win7)

发现里面有很多内容.关闭kugou.全部删光.再开,点要听的歌,发现文件 ***.kg

试着用N种图片打开方式和格式,都打不开.

发现SingerRes.xml.肯定是这里

在网上找到这个东东

img

可惜我不喜欢用别人的玩意(特别是没有源码)

用UE打开.kg文件.发现前面几行里面有 jpeg quality=80 这种字符

没看出头绪.再用UE打开2张JPG图片,发现都是以  FF D8 FF E0....这种开头.

再去kg文件里面看到了.于是知道怎么做了.

本来想简单点直接复制二进制出来的.可惜好像行不通.于是只能写代码.

最近在学Python.想试试,去网上找了下Python操作二进制文件.好像很麻烦.

于是先用.net实现,等学到Python文件操作再用Py实现一遍

软件界面


多的不说.上代码

public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        List<string> m_singer_name_string_list = new List<string>();        List<string> m_img_name_string_list = new List<string>();        string m_path = "";        string m_suffix_all = ".krs.kg!";        string m_suffix = ".krs";        private void Form1_Load(object sender, EventArgs error)        {            this.FormBorderStyle = FormBorderStyle.FixedSingle;            //win7酷狗写真krs文件路径:C:\Users\你的用户名\AppData\Roaming\Kugou7\SingerImg            //xp酷狗写真krs文件路径:C:\Documents and Settings\你的用户名\Application Data\Kugou7\SingerImg            Version ver = System.Environment.OSVersion.Version;            //Version compareToVersion = new Version("6.2");            string strClient = "";            if (ver.Major == 5 && ver.Minor == 1)            {                strClient = "Win XP";            }            else if (ver.Major == 6 && ver.Minor == 0)            {                strClient = "Win Vista";            }            else if (ver.Major == 6 && ver.Minor == 1)            {                strClient = "Win 7";            }            else if (ver.Major == 6 && ver.Minor == 2)            {                strClient = "Win 8";            }            else if (ver.Major == 5 && ver.Minor == 0)            {                strClient = "Win 2000";            }            else            {                strClient = "未知";            }            string m_system_dir = System.Environment.SystemDirectory.Split(':')[0];            string userName = System.Environment.UserName;            if (strClient == "Win 7" || strClient == "Win 8")                m_path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData);            else if (strClient == "Win XP")                m_path = m_system_dir + @":\Documents and Settings\" + userName + @"\Application Data\";            if (Directory.GetDirectories(m_path, "kugou*").Length > 0)                m_path = Directory.GetDirectories(m_path, "kugou*")[0] + @"\SingerImg\";            FileStream m_file_stream = null;            string m_xml_string;            try            {                m_file_stream = File.OpenRead(m_path + "SingerRes.xml");                byte[] m_byte = new byte[m_file_stream.Length];                m_file_stream.Read(m_byte, 0, (int)m_file_stream.Length);                m_file_stream.Close();                m_xml_string = System.Text.Encoding.Unicode.GetString(m_byte);                Regex reg = new Regex(@"\s<([\u0391-\uFFE5]{0,20}|[\u0020-\u007A]{0,20})\s\S{20,23}\sResourceHash=\S(\w{32})\S\s");                MatchCollection matches = reg.Matches(m_xml_string);                foreach (Match match in matches)                {                    m_singer_name_string_list.Add(match.Groups[1].Value.Replace(" ", " "));                    m_img_name_string_list.Add(match.Groups[2].Value);                }                for (int i = 0; i < m_img_name_string_list.Count; i++)                {                    if (!File.Exists(m_path + m_img_name_string_list[i] + m_suffix))                    {                        m_img_name_string_list.RemoveAt(i);                        m_singer_name_string_list.RemoveAt(i);                        i--;                    }                    else m_img_name_string_list[i] += m_suffix;                }                lb_singer_name.DataSource = m_singer_name_string_list;            }            catch (Exception ex)            {                MessageBox.Show(ex.ToString());            }            finally            {                m_file_stream.Dispose();            }            //MessageBox.Show(strClient);        }        List<byte[]> m_img_read_byte = new List<byte[]>();        SaveFileDialog m_save_file_dialog = new SaveFileDialog();        int m_old_index = -1;        private void lb_singer_name_SelectedIndexChanged(object sender, EventArgs e)        {            if (lb_singer_name.SelectedIndex != m_old_index)            {                m_old_index = lb_singer_name.SelectedIndex;                PbBoxListClass.GetPbBoxList().m_pb_list.Clear();                m_flp_list.Controls.Clear();                ImgRead m_imgread = new ImgRead();                int m_index = lb_singer_name.SelectedIndex;                m_img_read_byte = m_imgread.ImgReadString(m_path, m_img_name_string_list[m_index], m_singer_name_string_list[m_index]);                for (int i = 0; i < m_img_read_byte.Count; i++)                {                    MemoryStream ms = new MemoryStream(m_img_read_byte[i]);                    Image img = Image.FromStream(ms, false);                    ms.Close();                    PictureBox pb = new PictureBox();                    pb.MouseEnter += new System.EventHandler(OnMouseEnter_PicBox);                    pb.MouseClick += new System.Windows.Forms.MouseEventHandler(OnMouseClick_PicBox);                    pb.Image = img;                    pb.SizeMode = PictureBoxSizeMode.Zoom;                    if (img.Width < 200)                    {                        pb.Width = img.Width;                        pb.Height = img.Height;                    }                    else                    {                        pb.Width = 300;                        pb.Height = 300 * img.Height / img.Width;                    }                    PbBoxListClass.GetPbBoxList().m_pb_list.Add(pb);                    m_flp_list.Controls.Add(pb);                }            }        }        protected void OnMouseEnter_PicBox(object sender, EventArgs e)        {            //MessageBox.Show("In");            m_flp_list.Focus();            base.OnMouseEnter(e);        }        protected void OnMouseClick_PicBox(object sender, System.Windows.Forms.MouseEventArgs e)        {            int m_index = PbBoxListClass.GetPbBoxList().m_pb_list.IndexOf((PictureBox)sender);            string singer_name = m_singer_name_string_list[lb_singer_name.SelectedIndex];            m_save_file_dialog.FileName = singer_name + (m_index + 1);            m_save_file_dialog.AddExtension = true;            m_save_file_dialog.CheckPathExists = true;            m_save_file_dialog.DefaultExt = ".jpg";            m_save_file_dialog.ValidateNames = true;            m_save_file_dialog.OverwritePrompt = true;            m_save_file_dialog.Filter = "(*.jpg)|*.jpg";            m_save_file_dialog.Title = "保存图片";            m_save_file_dialog.RestoreDirectory = false;            if (m_save_file_dialog.ShowDialog() == DialogResult.OK)            {                string localFilePath = m_save_file_dialog.FileName; //获得文件路径                 string fileNameExt = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1); //获取文件名,不带路径                FileStream fs = File.Create(localFilePath);                fs.Write(m_img_read_byte[m_index], 0, m_img_read_byte[m_index].Length);                fs.Dispose();                //MessageBox.Show("保存成功" + localFilePath);            }            m_flp_list.Focus();            base.OnMouseClick(e);        }        private void linkLabel_getAll_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)        {            if (lb_singer_name.SelectedIndex > 0)            {                string singer_name = m_singer_name_string_list[lb_singer_name.SelectedIndex];                m_save_file_dialog.FileName = singer_name;                m_save_file_dialog.AddExtension = true;                m_save_file_dialog.CheckPathExists = true;                m_save_file_dialog.DefaultExt = ".jpg";                m_save_file_dialog.ValidateNames = true;                m_save_file_dialog.OverwritePrompt = true;                m_save_file_dialog.Filter = "(*.jpg)|*.jpg";                m_save_file_dialog.Title = "保存图片";                m_save_file_dialog.RestoreDirectory = false;                if (m_save_file_dialog.ShowDialog() == DialogResult.OK)                {                    string localFilePath = m_save_file_dialog.FileName;                     string FilePath = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));                    for (int i = 0; i < m_img_read_byte.Count; i++)                    {                        FileStream fs = File.Create(FilePath + "\\" + singer_name + (i + 1) + ".jpg");                        fs.Write(m_img_read_byte[i], 0, m_img_read_byte[i].Length);                        fs.Dispose();                    }                    MessageBox.Show("成功保存至" + FilePath);                }                m_flp_list.Focus();            }        }    }    public class ImgRead    {        string m_img_path;        string m_img_name;        string m_encode;        public ImgRead()        {        }        public List<byte[]> ImgReadString(string img_path, string img_name_and_suffix, string singer_name)        {            List<byte[]> m_result = new List<byte[]>();            m_img_path = img_path;            m_img_name = img_name_and_suffix;            try            {                FileStream m_file_stream = File.OpenRead(m_img_path + m_img_name);                byte[] m_byte = new byte[m_file_stream.Length];                m_file_stream.Read(m_byte, 0, (int)m_file_stream.Length);                //result = System.Text.Encoding.ASCII.GetString(m_byte);                List<int> m_start_pos_list = new List<int>();                List<int> m_end_pos_list = new List<int>();                for (int i = 0; i < m_byte.Length; i++)                {                    if (m_byte[i] == 0xFF && m_byte[i + 1] == 0xD8 && m_byte[i + 2] == 0xFF && m_byte[i + 3] == 0xE0                        && m_byte[i + 4] == 0x00 && m_byte[i + 5] == 0x10 && m_byte[i + 6] == 0x4A && m_byte[i + 7] == 0x46)                    {                        m_start_pos_list.Add(i);                        m_end_pos_list.Add(i - 1);                    }                }                m_end_pos_list.RemoveAt(0);                m_end_pos_list.Add(m_byte.Length - 1);                for (int i = 0; i < m_start_pos_list.Count; i++)                {                    byte[] m_write_byte = new byte[m_end_pos_list[i] - m_start_pos_list[i]];                    for (int j = 0; j < m_write_byte.Length; j++)                    {                        m_write_byte[j] = m_byte[j + m_start_pos_list[i]];                    }                    m_result.Add(m_write_byte);                }            }            catch (Exception ex)            {                MessageBox.Show(ex.ToString());            }            finally            {            }            return m_result;        }    }

链接: 我在这里!!!

密码: 305t

0 0
原创粉丝点击