kgtemp文件转mp3工具
kgtemp文件是酷我音乐软件的缓存文件,本文从技术层面探讨如何解密该文件为mp3文件,并通过读取ID3信息来重命名。
备注:针对老版本的酷我音乐生效,新版本不支持!!!
kgtemp解密#
kgtemp文件前1024个字节是固定的包头信息,解密方案详细可以参见(http://www.cnblogs.com/KMBlog/p/6877752.html):
class Program
{
static void Main(string[] args)
{
byte[] key={0xAC,0xEC,0xDF,0x57};
using (var input = new FileStream(@"E:\KuGou\Temp\236909b6016c6e98365e5225f488dd7a.kgtemp", FileMode.Open, FileAccess.Read))
{
var output = File.OpenWrite(@"d:\test.mp3");//输出文件
input.Seek(1024, SeekOrigin.Begin);//跳过1024字节的包头
byte[] buffer = new byte[key.Length];
int length;
while((length=input.Read(buffer,0,buffer.Length))>0)
{
for(int i=0;i<length;i++)
{
var k = key[i];
var kh = k >> 4;
var kl = k & 0xf;
var b = buffer[i];
var low = b & 0xf ^ kl;//解密后的低4位
var high = (b >> 4) ^ kh ^ low & 0xf;//解密后的高4位
buffer[i] = (byte)(high << 4 | low);
}
output.Write(buffer, 0, length);
}
output.Close();
}
Console.WriteLine("按任意键退出...");
Console.ReadKey();
}
}
这样解密出来就是mp3文件了
读取ID3信息#
解密出来的文件还需要手动命名,不是很方便,可以读取ID3V1信息重命名文件。
ID3V1比较简单,它是存放在MP3文件的末尾,用16进制的编辑器打开一个MP3文件,查看其末尾的128个顺序存放字节,数据结构定义如下:
char Header3; /标签头必须是"TAG"否则认为没有标签/
char Title[30]; /标题/
char Artist[30]; /作者/
char Album[30]; /专集/
char Year4; /出品年代/
char Comment[30]; /备注/
char Genre; /类型,流派/
解析代码比较简单,注意中文歌曲用GBK编码就可以了:
private static Mp3Info FormatMp3Info(byte[] Info, System.Text.Encoding Encoding)
{
Mp3Info myMp3Info = new Mp3Info();
string str = null;
int i;
int position = 0主要代码jia,; //循环的起始值
int currentIndex = 0; //Info的当前索引值
//获取TAG标识
for (i = currentIndex; i < currentIndex + 3; i++)
{
str = str + (char)Info[i];
position++;
}
currentIndex = position;
myMp3Info.identify = str;
//获取歌名
str = null;
byte[] bytTitle = new byte[30]; //将歌名部分读到一个单独的数组中
int j = 0;
for (i = currentIndex; i < currentIndex + 30; i++)
{
bytTitle[j] = Info[i];
position++;
j++;
}
currentIndex = position;
myMp3Info.Title = ByteToString(bytTitle, Encoding);
//获取歌手名
str = null;
j = 0;
byte[] bytArtist = new byte[30]; //将歌手名部分读到一个单独的数组中
for (i = currentIndex; i < currentIndex + 30; i++)
{
bytArtist[j] = Info[i];
position++;
j++;
}
currentIndex = position;
myMp3Info.Artist = ByteToString(bytArtist, Encoding);
//获取唱片名
str = null;
j = 0;
byte[] bytAlbum = new byte[30]; //将唱片名部分读到一个单独的数组中
for (i = currentIndex; i < currentIndex + 30; i++)
{
bytAlbum[j] = Info[i];
position++;
j++;
}
currentIndex = position;
myMp3Info.Album = ByteToString(bytAlbum, Encoding);
//获取年
str = null;
j = 0;
byte[] bytYear = new byte[4]; //将年部分读到一个单独的数组中
for (i = currentIndex; i < currentIndex + 4; i++)
{
bytYear[j] = Info[i];
position++;
j++;
}
currentIndex = position;
myMp3Info.Year = ByteToString(bytYear, Encoding);
//获取注释
str = null;
j = 0;
byte[] bytComment = new byte[28]; //将注释部分读到一个单独的数组中
for (i = currentIndex; i < currentIndex + 25; i++)
{
bytComment[j] = Info[i];
position++;
j++;
}
currentIndex = position;
myMp3Info.Comment = ByteToString(bytComment, Encoding);
//以下获取保留位
myMp3Info.reserved1 = (char)Info[++position];
myMp3Info.reserved2 = (char)Info[++position];
myMp3Info.reserved3 = (char)Info[++position];
//
return myMp3Info;
}
转换小工具#
写了一个小工具,来进行转换
下载地址:https://pan.baidu.com/s/1o7FIsPk
PS:上面只读取了IDV1,部分歌曲可能不存在
可以下载@缤纷 提供的程序,增加了ID3V2的支持:
https://files.cnblogs.com/files/gxlxzys/kgtemp文件转mp3工具.zip
关注作者
作者: JadePeng
出处:https://www.cnblogs.com/xiaoqi/p/8085563.html
版权:本文采用「署名-非商业性使用-相同方式共享 4.0 国际(欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接) 」知识共享许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了