mirror of
https://github.com/real-zony/ZonyLrcToolsX.git
synced 2026-11-24 03:37:47 +08:00
feat(decrypt): 支持酷狗 .kgg 格式
原先的解密依赖 MusicDecrypto.Library,它支持 ncm/qmc/kgm/kgma/kwm,但任何 版本都不支持 .kgg,这类文件会被直接拒绝。 .kgg 不是自包含的:音频用 QMC2 加密,而每个文件的 ekey 并不存放在文件里。 文件里只有偏移 0x48 处的 32 字节音频哈希;对应的 ekey 在酷狗客户端的 KGMusicV3.db(表 ShareFileItems)里,而这个数据库本身也是逐页加密的。 所以必须先读数据库: 1. 逐页解密 KGMusicV3.db(AES-128-CBC,key/IV 由主密钥和页号派生) 2. 用文件的音频哈希查出 ekey 3. 解码 ekey(TC-TEA CBC,含 V2 两段式变体) 4. 构造 QMC2 解密器(短密钥用映射表,长密钥用 RC4) 5. 按 1 MB 分块流式解密音频 6. 读解密后的头 4 个字节判断真实扩展名(fLaC / OggS / 否则 mp3) 实际后果:.kgg 只能在本机解密,因为那条 ekey 记录只有在酷狗客户端下载过 这首歌时才会写入。别人给的 .kgg 解不了。 新增内容: - Common/MusicDecryption/Kugou/ —— TcTea、EkeyDecoder、Qmc2Cipher、 KugouEkeyDatabase、KggMusicDecryptor - IKugouKeyProvider / KugouKeyProvider —— 探测数据库、缓存已解析的密钥表、 支持手动指定数据库路径 - IMusicDecryptor.ConvertMusicAsync 增加可选 CancellationToken,让大文件真的 能被中断(桌面端有"停止"按钮) - 输出先写 .part,校验字节数之后才改名,中途中断不会留下一个看起来完成 了的残缺文件 注意: - Microsoft.Data.Sqlite 会传递引入 SQLitePCLRaw.lib.e_sqlite3 2.1.11,该版本 被 NU1903 / GHSA-2m69-gcr7-jv3q 标记。显式引用 SQLitePCLRaw.bundle_e_sqlite3 3.0.5 覆盖掉它。 - e_sqlite3.dll 是原生依赖,单文件发布会把它留在 exe 外面,必须随包分发。 酷狗算法移植自 MIT 协议的 kgg-dec 参考实现,因此 THIRD-PARTY-NOTICES.md 带上原始版权与许可声明,每个移植文件头部也标了来源。
This commit is contained in:
1 parent
1c0f8e8d3a
commit
168a8e42f1
12 files changed
+1516
-8
No files matched your search
@@ -0,0 +1,45 @@
|
||||
# Third-Party Notices
|
||||
|
||||
This project contains code derived from the following MIT-licensed works.
|
||||
The MIT licence requires the copyright notice and permission notice to be
|
||||
included in all copies or substantial portions of the software, so they are
|
||||
reproduced in full below.
|
||||
|
||||
---
|
||||
|
||||
## kgg-dec — KuGou `.kgg` decryption reference implementation
|
||||
|
||||
Source: <https://github.com/lizipeng0013/kgg-dec.mirror>
|
||||
|
||||
Used by: `src/ZonyLrcTools.Common/MusicDecryption/Kugou/`
|
||||
(`TcTea.cs`, `EkeyDecoder.cs`, `Qmc2Cipher.cs`, `KugouEkeyDatabase.cs`,
|
||||
`KggMusicDecryptor.cs`)
|
||||
|
||||
The C# classes above are a port of the TC-TEA / ekey / QMC2 / KGMusicV3.db
|
||||
algorithms from that project. They were rewritten for this codebase (different
|
||||
structure, streaming I/O, cancellation support), but the cryptographic
|
||||
constants and the database page-decryption scheme originate there.
|
||||
|
||||
```
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 LSR
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
```
|
||||
Reference in new issue
Block a user