喜歡聽歌.突然發現酷狗裏面的歌手背景圖片都還不錯.憑印象找到了路徑
C:\Users\***\AppData\Roaming\KuGou8\SingerImg(win7)
發現裏面有很多內容.關閉kugou.全部刪光.再開,點要聽的歌,發現文件 ***.kg
試着用N種圖片打開方式和格式,都打不開.
發現SingerRes.xml.肯定是這裏
在網上找到這個東東
可惜我不喜歡用別人的玩意(特別是沒有源碼)
用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