Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
24bfc9e603 | ||
![]() |
b6886b7001 | ||
![]() |
dd965688a9 | ||
![]() |
f9543965b6 | ||
![]() |
e7b86a4779 | ||
![]() |
c3756bb3b3 | ||
![]() |
4d5d70f4b6 | ||
![]() |
e31eb9c1f1 | ||
![]() |
f64fa71b1e | ||
![]() |
181a3c402f | ||
![]() |
4c4e4061f5 | ||
![]() |
2526adcab0 | ||
![]() |
f2ea85bae9 | ||
![]() |
c07d55565d | ||
![]() |
71a8d9fab7 | ||
![]() |
7233fdc707 | ||
![]() |
0d119094df | ||
![]() |
1f804e1037 | ||
![]() |
77d9ca4ba8 | ||
![]() |
8f3c74c100 | ||
![]() |
29c27bbfd9 |
@@ -10,7 +10,7 @@ steps:
|
||||
- name: installDependencies
|
||||
image: node:lts
|
||||
commands:
|
||||
- npm ci --verbose --registry=https://registry.npm.taobao.org
|
||||
- npm ci --registry=https://registry.npm.taobao.org
|
||||
|
||||
- name: build
|
||||
image: node:lts
|
||||
|
47
README.md
47
README.md
@@ -1,30 +1,39 @@
|
||||
# Unlock Music 音乐解锁
|
||||
- Unlock encrypted music file in browser.
|
||||
- 在浏览器中解锁加密的音乐文件。
|
||||
- unlock-music项目是以学习和技术研究的初衷创建的。
|
||||
- 由于存在可能的法律风险以及滥用风险,不再提供Demo服务。
|
||||
|
||||
- unlock-music项目是以学习和技术研究的初衷创建的,修改、再分发时请遵循[License](https://github.com/ix64/unlock-music/blob/master/LICENSE)
|
||||
- 由于存在可能的法律风险以及滥用风险,不再提供Demo服务;Unlock Music的CLI版本正在开发中。
|
||||
- [其他测试版工具](https://github.com/ix64/unlock-music/wiki/%E5%85%B6%E4%BB%96%E9%9F%B3%E4%B9%90%E6%A0%BC%E5%BC%8F%E5%B7%A5%E5%85%B7)
|
||||
|
||||
[](https://ci.ixarea.com/ix64/unlock-music)
|
||||
|
||||
# Features
|
||||
- [x] Unlock in browser 在浏览器中解锁
|
||||
- [x] QQMusic Format QQ音乐格式 (.qmc0/.qmc2/.qmc3/.qmcflac/.qmcogg/.tkm)
|
||||
- [x] MooMusic Format Moo音乐格式 ([.bkcmp3/.bkcflac](https://github.com/ix64/unlock-music/issues/11))
|
||||
- [x] QQMusic Tm Format QQ音乐Tm格式 (.tm0/.tm2/.tm3/.tm6)
|
||||
- [x] QQMusic New Format QQ音乐新格式 (Experimental 实验性支持)
|
||||
# 特性
|
||||
## 支持的格式
|
||||
- [x] QQ音乐 (.qmc0/.qmc2/.qmc3/.qmcflac/.qmcogg/[.tkm](https://github.com/ix64/unlock-music/issues/9))
|
||||
- [x] Moo音乐格式 ([.bkcmp3/.bkcflac](https://github.com/ix64/unlock-music/issues/11))
|
||||
- [x] QQ音乐Tm格式 (.tm0/.tm2/.tm3/.tm6)
|
||||
- [x] QQ音乐新格式 (实验性支持)
|
||||
- [x] .mflac
|
||||
- [x] .mgg
|
||||
- [x] Netease Format 网易云音乐格式 (.ncm)
|
||||
- [x] Drag and Drop 拖放文件
|
||||
- [x] Play instantly 在线播放
|
||||
- [x] Batch unlocking 批量解锁
|
||||
- [x] Progressive Web App 渐进式Web应用
|
||||
- [x] Complete ID3 for ncm 补全ncm的ID3信息
|
||||
- [x] Multi-threads 多线程
|
||||
- [x] [.mgg](https://github.com/ix64/unlock-music/issues/3)
|
||||
- [x] 网易云音乐格式 (.ncm)
|
||||
- [x] 补全ncm的ID3信息
|
||||
- [x] 虾米音乐格式 (.xm) (测试阶段)
|
||||
- [x] 酷我音乐格式 (.kwm) (测试阶段)
|
||||
- [ ] 酷狗音乐格式 (.kgm) ([Alpha测试](https://github.com/ix64/unlock-music/wiki/%E5%85%B6%E4%BB%96%E9%9F%B3%E4%B9%90%E6%A0%BC%E5%BC%8F%E5%B7%A5%E5%85%B7#%E9%85%B7%E7%8B%97%E9%9F%B3%E4%B9%90-kgmvpr%E8%A7%A3%E9%94%81%E5%B7%A5%E5%85%B7))
|
||||
|
||||
## 其他特性
|
||||
- [x] 在浏览器中解锁
|
||||
- [x] 拖放文件
|
||||
- [x] 在线播放
|
||||
- [x] 批量解锁
|
||||
- [x] 渐进式Web应用
|
||||
- [x] 多线程
|
||||
|
||||
|
||||
# 使用方法
|
||||
## 下载已构建版本
|
||||
- 已构建的版本发布在 [GitHub Release](https://github.com/ix64/unlock-music/releases/latest), 下载解压缩后即可部署或本地使用
|
||||
## 使用已构建版本
|
||||
- 从[GitHub Release](https://github.com/ix64/unlock-music/releases/latest)下载已构建的版本
|
||||
- 解压缩后即可部署或本地使用(**请勿直接运行源代码**)
|
||||
|
||||
## 自行构建
|
||||
- 环境要求
|
||||
|
1155
package-lock.json
generated
1155
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "unlock-music",
|
||||
"version": "1.4.1",
|
||||
"updateInfo": "支持.qmc2;qq音乐显示封面图片;界面优化;修复GBK编码ID3信息",
|
||||
"version": "1.5.1",
|
||||
"updateInfo": "改善.mgg解锁算法",
|
||||
"license": "MIT",
|
||||
"description": "Unlock encrypted music file in browser.",
|
||||
"repository": {
|
||||
@@ -15,6 +15,7 @@
|
||||
"fix-compatibility": "node ./src/fix-compatibility.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"base64-js": "^1.3.1",
|
||||
"browser-id3-writer": "^4.4.0",
|
||||
"core-js": "^3.6.4",
|
||||
"crypto-js": "^4.0.0",
|
||||
|
@@ -10,7 +10,7 @@
|
||||
<!--@formatter:on-->
|
||||
<script async src="https://stats.ixarea.com/ixarea-stats.js"></script>
|
||||
<title>音乐解锁 - By IXarea</title>
|
||||
<meta content="音乐,解锁,ncm,qmc,qmc0,qmc3,qmcflac,qmcogg,mflac,qq音乐,网易云音乐,加密" name="keywords"/>
|
||||
<meta content="音乐,解锁,ncm,qmc,mgg,mflac,qq音乐,网易云音乐,加密" name="keywords"/>
|
||||
<meta content="音乐解锁 - 在任何设备上解锁已购的加密音乐!" name="description"/>
|
||||
<!--@formatter:off-->
|
||||
<style>#loader{position:absolute;left:50%;top:50%;z-index:1010;margin:-75px 0 0 -75px;border:16px solid #f3f3f3;border-radius:50%;border-top:16px solid #3498db;width:120px;height:120px;animation:spin 2s linear infinite}@keyframes spin{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}#loader-mask{position:absolute;width:100%;height:100%;bottom:0;left:0;right:0;top:0;z-index:1009;background-color:rgba(242,246,252,0.88)}</style>
|
||||
@@ -22,7 +22,7 @@
|
||||
<div id="loader"></div>
|
||||
<noscript>
|
||||
<img alt=""
|
||||
src="https://stats.ixarea.com/ixarea-stats/report?idsite=2&rec=1&action_name=音乐解锁+-+By+IXarea"
|
||||
src="https://stats.ixarea.com/ixarea-stats/report?rec=1&action_name=音乐解锁-NoJS&idsite=2"
|
||||
style="border:0"/>
|
||||
</noscript>
|
||||
<div hidden id="loader-tips-outdated">
|
||||
@@ -53,12 +53,12 @@
|
||||
var m;
|
||||
if (!ua) return true;
|
||||
if (/MSIE |Trident\//.exec(ua)) return true; // no IE
|
||||
m = /Edge\/([\d.]+)/.exec(ua); // Edge >= 16
|
||||
if (m && Number(m[1]) < 16) return true;
|
||||
m = /Chrome\/([\d.]+)/.exec(ua); // Chrome >= 50
|
||||
if (m && Number(m[1]) < 50) return true;
|
||||
m = /Firefox\/([\d.]+)/.exec(ua); // Firefox >= 38
|
||||
return m && Number(m[1]) < 38;
|
||||
m = /Edge\/([\d.]+)/.exec(ua); // Edge >= 17
|
||||
if (m && Number(m[1]) < 17) return true;
|
||||
m = /Chrome\/([\d.]+)/.exec(ua); // Chrome >= 58
|
||||
if (m && Number(m[1]) < 58) return true;
|
||||
m = /Firefox\/([\d.]+)/.exec(ua); // Firefox >= 45
|
||||
return m && Number(m[1]) < 45;
|
||||
})();
|
||||
if (detected) {
|
||||
document.getElementById('loader-tips-outdated').hidden = false;
|
||||
|
@@ -41,8 +41,8 @@
|
||||
<a href="https://github.com/ix64/unlock-music/wiki/使用提示" target="_blank">使用提示</a>
|
||||
</el-row>
|
||||
<el-row>
|
||||
目前支持网易云音乐(ncm)、QQ音乐(qmc, mflac, mgg, tkm)以及
|
||||
<a href="https://github.com/ix64/unlock-music/blob/master/README.md" target="_blank">其他格式</a>。
|
||||
目前支持网易云音乐(ncm), QQ音乐(qmc, mflac, mgg), 虾米音乐(xm), 酷我音乐(.kwm)
|
||||
<a href="https://github.com/ix64/unlock-music/blob/master/README.md" target="_blank">更多</a>。
|
||||
</el-row>
|
||||
<el-row>
|
||||
<span>Copyright © 2019-</span><span v-text="(new Date()).getFullYear()"></span> MengYX
|
||||
@@ -92,12 +92,13 @@
|
||||
try {
|
||||
const resp = await fetch("https://stats.ixarea.com/collect/music/app-version", {
|
||||
method: "POST", headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify({Version: this.version})
|
||||
body: JSON.stringify({"Version": this.version})
|
||||
});
|
||||
updateInfo = await resp.json();
|
||||
} catch (e) {
|
||||
}
|
||||
if (!!updateInfo && !!updateInfo.Found) {
|
||||
if ((!!updateInfo && process.env.NODE_ENV === 'production') && (!!updateInfo.HttpsFound ||
|
||||
(!!updateInfo.Found && window.location.protocol !== "https:"))) {
|
||||
this.$notify.warning({
|
||||
title: '发现更新',
|
||||
message: '发现新版本 v' + updateInfo.Version +
|
||||
|
@@ -1,4 +1,6 @@
|
||||
const NcmDecrypt = require("./ncm");
|
||||
const KwmDecrypt = require("./kwm");
|
||||
const XmDecrypt = require("./xm");
|
||||
const QmcDecrypt = require("./qmc");
|
||||
const RawDecrypt = require("./raw");
|
||||
const TmDecrypt = require("./tm");
|
||||
@@ -11,9 +13,16 @@ export async function CommonDecrypt(file) {
|
||||
case "ncm":// Netease Mp3/Flac
|
||||
rt_data = await NcmDecrypt.Decrypt(file.raw, raw_filename, raw_ext);
|
||||
break;
|
||||
case "mp3":// Raw Mp3
|
||||
case "flac"://Raw Flac
|
||||
case "m4a":// Raw M4a
|
||||
case "kwm":// Kuwo Mp3/Flac
|
||||
rt_data = await KwmDecrypt.Decrypt(file.raw, raw_filename, raw_ext);
|
||||
break
|
||||
case "xm": // Xiami Wav/M4a/Mp3/Flac
|
||||
case "wav":// Xiami/Raw Wav
|
||||
case "mp3":// Xiami/Raw Mp3
|
||||
case "flac":// Xiami/Raw Flac
|
||||
case "m4a":// Xiami/Raw M4a
|
||||
rt_data = await XmDecrypt.Decrypt(file.raw, raw_filename, raw_ext);
|
||||
break;
|
||||
case "ogg":// Raw Ogg
|
||||
rt_data = await RawDecrypt.Decrypt(file.raw, raw_filename, raw_ext);
|
||||
break;
|
||||
|
84
src/decrypt/kwm.js
Normal file
84
src/decrypt/kwm.js
Normal file
@@ -0,0 +1,84 @@
|
||||
import {
|
||||
AudioMimeType,
|
||||
DetectAudioExt,
|
||||
GetArrayBuffer,
|
||||
GetFileInfo,
|
||||
GetMetaCoverURL,
|
||||
IsBytesEqual
|
||||
} from "./util";
|
||||
|
||||
const musicMetadata = require("music-metadata-browser");
|
||||
const MagicHeader = [
|
||||
0x79, 0x65, 0x65, 0x6C, 0x69, 0x6F, 0x6E, 0x2D,
|
||||
0x6B, 0x75, 0x77, 0x6F, 0x2D, 0x74, 0x6D, 0x65,
|
||||
]
|
||||
const PreDefinedKey = "MoOtOiTvINGwd2E6n0E1i7L5t2IoOoNk"
|
||||
|
||||
export async function Decrypt(file, raw_filename, raw_ext) {
|
||||
const oriData = new Uint8Array(await GetArrayBuffer(file));
|
||||
if (!IsBytesEqual(MagicHeader, oriData.slice(0, 0x10)))
|
||||
return {status: false, message: "Not a valid kwm file!"}
|
||||
|
||||
let fileKey = oriData.slice(0x18, 0x20)
|
||||
let mask = createMaskFromKey(fileKey)
|
||||
|
||||
function Uint8ArrayToString(fileData) {
|
||||
var dataString = "";
|
||||
for (var i = 0; i < fileData.length; i++) {
|
||||
dataString += String.fromCharCode(fileData[i]);
|
||||
}
|
||||
|
||||
return dataString
|
||||
}
|
||||
|
||||
|
||||
let audioData = oriData.slice(0x400);
|
||||
let lenAudioData = audioData.length;
|
||||
for (let cur = 0; cur < lenAudioData; ++cur)
|
||||
audioData[cur] ^= mask[cur % 0x20];
|
||||
|
||||
|
||||
const ext = DetectAudioExt(audioData, "mp3");
|
||||
const mime = AudioMimeType[ext];
|
||||
let musicBlob = new Blob([audioData], {type: mime});
|
||||
|
||||
const musicMeta = await musicMetadata.parseBlob(musicBlob);
|
||||
const info = GetFileInfo(musicMeta.common.artist, musicMeta.common.title, raw_filename);
|
||||
|
||||
const imgUrl = GetMetaCoverURL(musicMeta);
|
||||
|
||||
return {
|
||||
status: true,
|
||||
title: info.title,
|
||||
artist: info.artist,
|
||||
ext: ext,
|
||||
album: musicMeta.common.album,
|
||||
picture: imgUrl,
|
||||
file: URL.createObjectURL(musicBlob),
|
||||
mime: mime
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function createMaskFromKey(keyBytes) {
|
||||
let keyView = new DataView(keyBytes.buffer)
|
||||
let keyStr = keyView.getBigUint64(0, true).toString()
|
||||
let keyStrTrim = trimKey(keyStr)
|
||||
let key = new Uint8Array(32)
|
||||
for (let i = 0; i < 32; i++) {
|
||||
key[i] = PreDefinedKey[i].charCodeAt() ^ keyStrTrim[i].charCodeAt()
|
||||
}
|
||||
return key
|
||||
}
|
||||
|
||||
|
||||
function trimKey(keyRaw) {
|
||||
let lenRaw = keyRaw.length;
|
||||
let out = keyRaw;
|
||||
if (lenRaw > 32) {
|
||||
out = keyRaw.slice(0, 32)
|
||||
} else if (lenRaw < 32) {
|
||||
out = keyRaw.padEnd(32, keyRaw)
|
||||
}
|
||||
return out
|
||||
}
|
@@ -19,7 +19,8 @@ export async function Decrypt(file, raw_filename, raw_ext) {
|
||||
let audioOffset = musicMetaObj.offset + dataView.getUint32(musicMetaObj.offset + 5, true) + 13;
|
||||
let audioData = new Uint8Array(fileBuffer, audioOffset);
|
||||
|
||||
for (let cur = 0; cur < audioData.length; ++cur) audioData[cur] ^= keyBox[cur & 0xff];
|
||||
let lenAudioData = audioData.length;
|
||||
for (let cur = 0; cur < lenAudioData; ++cur) audioData[cur] ^= keyBox[cur & 0xff];
|
||||
|
||||
|
||||
if (musicMeta.album === undefined) musicMeta.album = "";
|
||||
|
@@ -1,7 +1,8 @@
|
||||
import {AudioMimeType, DetectAudioExt, GetArrayBuffer, GetFileInfo, GetMetaCoverURL, RequestJsonp} from "./util";
|
||||
import {QmcMaskCreate58, QmcMaskDetectMflac, QmcMaskDetectMgg, QmcMaskGetDefault} from "./qmcMask";
|
||||
|
||||
import {decode} from "iconv-lite"
|
||||
|
||||
import {fromByteArray as Base64Encode, toByteArray as Base64Decode} from 'base64-js'
|
||||
|
||||
const musicMetadata = require("music-metadata-browser");
|
||||
|
||||
@@ -25,11 +26,13 @@ export async function Decrypt(file, raw_filename, raw_ext) {
|
||||
const fileData = new Uint8Array(await GetArrayBuffer(file));
|
||||
let audioData, seed, keyData;
|
||||
if (handler.detect) {
|
||||
audioData = fileData.slice(0, -0x170);
|
||||
const keyLen = new DataView(fileData.slice(fileData.length - 4).buffer).getUint32(0, true)
|
||||
const keyPos = fileData.length - 4 - keyLen;
|
||||
audioData = fileData.slice(0, keyPos);
|
||||
seed = handler.handler(audioData);
|
||||
keyData = fileData.slice(-0x170);
|
||||
keyData = fileData.slice(keyPos, keyPos + keyLen);
|
||||
if (seed === undefined) seed = await queryKeyInfo(keyData, raw_filename, raw_ext);
|
||||
if (seed === undefined) return {status: false, message: raw_ext + "格式仅提供实验性支持!"};
|
||||
if (seed === undefined) return {status: false, message: raw_ext + "格式仅提供实验性支持"};
|
||||
} else {
|
||||
audioData = fileData;
|
||||
seed = handler.handler(audioData);
|
||||
@@ -50,7 +53,6 @@ export async function Decrypt(file, raw_filename, raw_ext) {
|
||||
}
|
||||
}
|
||||
|
||||
//todo: Use artists list to replace artist
|
||||
const info = GetFileInfo(musicMeta.common.artist, musicMeta.common.title, raw_filename);
|
||||
if (handler.detect) reportKeyUsage(keyData, seed.Matrix128,
|
||||
info.artist, info.title, musicMeta.common.album, raw_filename, raw_ext);
|
||||
@@ -77,7 +79,7 @@ function reportKeyUsage(keyData, maskData, artist, title, album, filename, forma
|
||||
method: "POST",
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify({
|
||||
Mask: Array.from(maskData), Key: Array.from(keyData),
|
||||
Mask: Base64Encode(new Uint8Array(maskData)), Key: Base64Encode(keyData),
|
||||
Artist: artist, Title: title, Album: album, Filename: filename, Format: format
|
||||
}),
|
||||
}).then().catch()
|
||||
@@ -88,11 +90,12 @@ async function queryKeyInfo(keyData, filename, format) {
|
||||
const resp = await fetch("https://stats.ixarea.com/collect/qmcmask/query", {
|
||||
method: "POST",
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify({Format: format, Key: Array.from(keyData), Filename: filename}),
|
||||
body: JSON.stringify({Format: format, Key: Base64Encode(keyData), Filename: filename, Type: 44}),
|
||||
});
|
||||
let data = await resp.json();
|
||||
return QmcMaskCreate58(data.Matrix58, data.Super58A, data.Super58B);
|
||||
return QmcMaskCreate58(Base64Decode(data.Matrix44));
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,18 +108,15 @@ async function queryAlbumCoverImage(artist, title, album) {
|
||||
jsonpData = await RequestJsonp(song_query_url, "callback");
|
||||
queriedSong = jsonpData["data"]["song"]["list"][0];
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
console.log(queriedSong);
|
||||
let imgUrl = "";
|
||||
if (undefined !== queriedSong && undefined !== queriedSong["album"]) {
|
||||
if (!!queriedSong && !!queriedSong["album"]) {
|
||||
if (queriedSong["album"]["pmid"] !== undefined) {
|
||||
imgUrl = "https://y.gtimg.cn/music/photo_new/T002M000" + queriedSong["album"]["pmid"] + ".jpg"
|
||||
} else if (queriedSong["album"]["id"] !== undefined) {
|
||||
imgUrl = "https://imgcache.qq.com/music/photo/album/" +
|
||||
queriedSong["album"]["id"] % 100 +
|
||||
"/albumpic_" + queriedSong["album"]["id"] + "_0.jpg"
|
||||
queriedSong["album"]["id"] % 100 + "/albumpic_" + queriedSong["album"]["id"] + "_0.jpg"
|
||||
}
|
||||
}
|
||||
return imgUrl;
|
||||
}
|
||||
}
|
||||
|
@@ -1,50 +1,57 @@
|
||||
import {FLAC_HEADER, IsBytesEqual, OGG_HEADER} from "./util"
|
||||
|
||||
const QMOggConstHeader = [
|
||||
0x4F, 0x67, 0x67, 0x53, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x1E, 0x01, 0x76, 0x6F, 0x72,
|
||||
0x62, 0x69, 0x73, 0x00, 0x00, 0x00, 0x00, 0x02, 0x44, 0xAC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0xEE, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB8, 0x01, 0x4F, 0x67, 0x67, 0x53, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x03, 0x76, 0x6F, 0x72, 0x62, 0x69, 0x73, 0x2C, 0x00, 0x00, 0x00,
|
||||
0x58, 0x69, 0x70, 0x68, 0x2E, 0x4F, 0x72, 0x67, 0x20, 0x6C, 0x69, 0x62, 0x56, 0x6F, 0x72, 0x62,
|
||||
0x69, 0x73, 0x20, 0x49, 0x20, 0x32, 0x30, 0x31, 0x35, 0x30, 0x31, 0x30, 0x35, 0x20, 0x28, 0xE2,
|
||||
0x9B, 0x84, 0xE2, 0x9B, 0x84, 0xE2, 0x9B, 0x84, 0xE2, 0x9B, 0x84, 0x29, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x54, 0x49, 0x54, 0x4C, 0x45, 0x3D];
|
||||
const QMOggConstHeaderConfidence = [
|
||||
const QMOggPublicHeader1 = [
|
||||
0x4f, 0x67, 0x67, 0x53, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
|
||||
0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x1e, 0x01, 0x76, 0x6f, 0x72,
|
||||
0x62, 0x69, 0x73, 0x00, 0x00, 0x00, 0x00, 0x02, 0x44, 0xac, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0xee, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, 0x01, 0x4f, 0x67, 0x67, 0x53, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00,
|
||||
0xff, 0xff, 0xff, 0xff];
|
||||
const QMOggPublicHeader2 = [
|
||||
0x03, 0x76, 0x6f, 0x72, 0x62, 0x69, 0x73, 0x2c, 0x00, 0x00, 0x00, 0x58, 0x69, 0x70, 0x68, 0x2e,
|
||||
0x4f, 0x72, 0x67, 0x20, 0x6c, 0x69, 0x62, 0x56, 0x6f, 0x72, 0x62, 0x69, 0x73, 0x20, 0x49, 0x20,
|
||||
0x32, 0x30, 0x31, 0x35, 0x30, 0x31, 0x30, 0x35, 0x20, 0x28, 0xe2, 0x9b, 0x84, 0xe2, 0x9b, 0x84,
|
||||
0xe2, 0x9b, 0x84, 0xe2, 0x9b, 0x84, 0x29, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x54,
|
||||
0x49, 0x54, 0x4c, 0x45, 0x3d];
|
||||
const QMOggPublicConf1 = [
|
||||
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 0, 0,
|
||||
0, 0, 9, 9, 9, 9, 0, 0, 0, 0, 9, 9, 9, 9, 9, 9,
|
||||
9, 9, 9, 9, 9, 9, 9, 6, 3, 3, 3, 3, 6, 6, 6, 6,
|
||||
3, 3, 3, 3, 6, 6, 6, 6, 6, 9, 9, 9, 9, 9, 9, 9,
|
||||
9, 9, 9, 9, 9, 9, 9, 9, 0, 0, 0, 0, 9, 9, 9, 9,
|
||||
0, 0, 0, 0, 6, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
||||
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
||||
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
||||
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 0, 1, 9, 9,
|
||||
0, 1, 9, 9, 9, 9, 9, 9, 9, 9];
|
||||
0, 0, 0, 0];
|
||||
const QMOggPublicConf2 = [
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 0, 1, 3, 3, 0, 1, 3, 3, 3,
|
||||
3, 3, 3, 3, 3];
|
||||
const QMCDefaultMaskMatrix = [
|
||||
0x4A, 0xD6, 0xCA, 0x90, 0x67, 0xF7, 0x52, 0x5E,
|
||||
0x95, 0x23, 0x9F, 0x13, 0x11, 0x7E, 0x47, 0x74,
|
||||
0x3D, 0x90, 0xAA, 0x3F, 0x51, 0xC6, 0x09, 0xD5,
|
||||
0x9F, 0xFA, 0x66, 0xF9, 0xF3, 0xD6, 0xA1, 0x90,
|
||||
0xA0, 0xF7, 0xF0, 0x1D, 0x95, 0xDE, 0x9F, 0x84,
|
||||
0x11, 0xF4, 0x0E, 0x74, 0xBB, 0x90, 0xBC, 0x3F,
|
||||
0x92, 0x00, 0x09, 0x5B, 0x9F, 0x62, 0x66, 0xA1];
|
||||
const QMCDefaultMaskSuperA = 0xC3;
|
||||
const QMCDefaultMaskSuperB = 0xD8;
|
||||
0xde, 0x51, 0xfa, 0xc3, 0x4a, 0xd6, 0xca, 0x90,
|
||||
0x7e, 0x67, 0x5e, 0xf7, 0xd5, 0x52, 0x84, 0xd8,
|
||||
0x47, 0x95, 0xbb, 0xa1, 0xaa, 0xc6, 0x66, 0x23,
|
||||
0x92, 0x62, 0xf3, 0x74, 0xa1, 0x9f, 0xf4, 0xa0,
|
||||
0x1d, 0x3f, 0x5b, 0xf0, 0x13, 0x0e, 0x09, 0x3d,
|
||||
0xf9, 0xbc, 0x00, 0x11];
|
||||
|
||||
|
||||
class QmcMask {
|
||||
constructor(matrix, superA, superB) {
|
||||
if (superA === undefined || superB === undefined) {
|
||||
this.Matrix128 = matrix;
|
||||
if (matrix.length === 44) {
|
||||
this.Matrix44 = matrix
|
||||
this.generateMask128from44()
|
||||
} else {
|
||||
this.Matrix128 = matrix
|
||||
this.generateMask44from128()
|
||||
}
|
||||
this.generateMask58from128()
|
||||
} else {
|
||||
this.Matrix58 = matrix;
|
||||
this.Super58A = superA;
|
||||
this.Super58B = superB;
|
||||
this.generateMask128from58();
|
||||
this.generateMask44from128()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,6 +95,35 @@ class QmcMask {
|
||||
this.Super58B = superB;
|
||||
}
|
||||
|
||||
generateMask44from128() {
|
||||
if (this.Matrix128.length !== 128) throw "incorrect mask128 matrix length";
|
||||
let mapping = GetConvertMapping()
|
||||
this.Matrix44 = []
|
||||
let idxI44 = 0
|
||||
mapping.forEach(it256 => {
|
||||
let it256Len = it256.length
|
||||
for (let i = 1; i < it256Len; i++) {
|
||||
if (this.Matrix128[it256[0]] !== this.Matrix128[it256[i]]) {
|
||||
throw "decode mask-128 to mask-44 failed"
|
||||
}
|
||||
}
|
||||
this.Matrix44[idxI44] = this.Matrix128[it256[0]]
|
||||
idxI44++
|
||||
})
|
||||
}
|
||||
|
||||
generateMask128from44() {
|
||||
if (this.Matrix44.length !== 44) throw "incorrect mask length"
|
||||
this.Matrix128 = []
|
||||
let idx44 = 0
|
||||
GetConvertMapping().forEach(it256 => {
|
||||
it256.forEach(m => {
|
||||
this.Matrix128[m] = this.Matrix44[idx44]
|
||||
})
|
||||
idx44++
|
||||
})
|
||||
}
|
||||
|
||||
Decrypt(data) {
|
||||
let dst = data.slice(0);
|
||||
let index = -1;
|
||||
@@ -107,7 +143,7 @@ class QmcMask {
|
||||
}
|
||||
|
||||
export function QmcMaskGetDefault() {
|
||||
return new QmcMask(QMCDefaultMaskMatrix, QMCDefaultMaskSuperA, QMCDefaultMaskSuperB)
|
||||
return new QmcMask(QMCDefaultMaskMatrix)
|
||||
}
|
||||
|
||||
export function QmcMaskDetectMflac(data) {
|
||||
@@ -123,31 +159,38 @@ export function QmcMaskDetectMflac(data) {
|
||||
}
|
||||
|
||||
export function QmcMaskDetectMgg(data) {
|
||||
if (data.length < QMOggConstHeader.length) return;
|
||||
if (data.length < 0x100) return
|
||||
let matrixConfidence = {};
|
||||
for (let i = 0; i < 58; i++) matrixConfidence[i] = {};
|
||||
for (let i = 0; i < 44; i++) matrixConfidence[i] = {};
|
||||
|
||||
for (let idx128 = 0; idx128 < QMOggConstHeader.length; idx128++) {
|
||||
if (QMOggConstHeaderConfidence[idx128] === 0) continue;
|
||||
let idx58 = GetMask58Index(idx128);
|
||||
let mask = data[idx128] ^ QMOggConstHeader[idx128];
|
||||
let confidence = QMOggConstHeaderConfidence[idx128];
|
||||
if (mask in matrixConfidence[idx58]) {
|
||||
matrixConfidence[idx58][mask] += confidence
|
||||
const page2 = data[0x54] ^ data[0xC] ^ QMOggPublicHeader1[0xC];
|
||||
const spHeader = QmcGenerateOggHeader(page2)
|
||||
const spConf = QmcGenerateOggConf(page2)
|
||||
|
||||
for (let idx128 = 0; idx128 < spHeader.length; idx128++) {
|
||||
if (spConf[idx128] === 0) continue;
|
||||
let idx44 = GetMask44Index(idx128);
|
||||
let _m = data[idx128] ^ spHeader[idx128]
|
||||
let confidence = spConf[idx128];
|
||||
if (_m in matrixConfidence[idx44]) {
|
||||
matrixConfidence[idx44][_m] += confidence
|
||||
} else {
|
||||
matrixConfidence[idx58][mask] = confidence
|
||||
matrixConfidence[idx44][_m] = confidence
|
||||
}
|
||||
}
|
||||
let matrix = [], superA, superB;
|
||||
let matrix = [];
|
||||
try {
|
||||
for (let i = 0; i < 56; i++) matrix[i] = getMaskConfidenceResult(matrixConfidence[i]);
|
||||
superA = getMaskConfidenceResult(matrixConfidence[56]);
|
||||
superB = getMaskConfidenceResult(matrixConfidence[57]);
|
||||
for (let i = 0; i < 44; i++)
|
||||
matrix[i] = getMaskConfidenceResult(matrixConfidence[i]);
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
const mask = new QmcMask(matrix, superA, superB);
|
||||
if (!IsBytesEqual(OGG_HEADER, mask.Decrypt(data.slice(0, OGG_HEADER.length)))) return;
|
||||
const mask = new QmcMask(matrix);
|
||||
let dx = mask.Decrypt(data.slice(0, OGG_HEADER.length));
|
||||
if (!IsBytesEqual(OGG_HEADER, dx)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return mask;
|
||||
}
|
||||
|
||||
@@ -159,12 +202,17 @@ export function QmcMaskCreate58(matrix, superA, superB) {
|
||||
return new QmcMask(matrix, superA, superB)
|
||||
}
|
||||
|
||||
export function QmcMaskCreate44(mask44) {
|
||||
return new QmcMask(mask44)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param confidence {{}}
|
||||
* @returns {number}
|
||||
*/
|
||||
function getMaskConfidenceResult(confidence) {
|
||||
if (confidence.length === 0) throw "can not match at least one key";
|
||||
if (confidence.length > 1) console.warn("There are 2 potential value for the mask!")
|
||||
let result, conf = 0;
|
||||
for (let idx in confidence) {
|
||||
if (confidence[idx] > conf) {
|
||||
@@ -178,27 +226,48 @@ function getMaskConfidenceResult(confidence) {
|
||||
/**
|
||||
* @return {number}
|
||||
*/
|
||||
function GetMask58Index(idx128) {
|
||||
if (idx128 > 127) idx128 = idx128 % 128;
|
||||
let col = idx128 % 16;
|
||||
let row = (idx128 - col) / 16;
|
||||
switch (col) {
|
||||
case 0://Super 1
|
||||
row = 8;
|
||||
col = 0;
|
||||
break;
|
||||
case 8://Super 2
|
||||
row = 8;
|
||||
col = 1;
|
||||
break;
|
||||
default:
|
||||
if (col > 7) {
|
||||
row = 7 - row;
|
||||
col = 15 - col;
|
||||
} else {
|
||||
col -= 1;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
const allMapping = [];
|
||||
const mask128to44 = [];
|
||||
|
||||
(function () {
|
||||
for (let i = 0; i < 128; i++) {
|
||||
let realIdx = (i * i + 27) % 256
|
||||
if (realIdx in allMapping) {
|
||||
allMapping[realIdx].push(i)
|
||||
} else {
|
||||
allMapping[realIdx] = [i]
|
||||
}
|
||||
}
|
||||
return row * 7 + col
|
||||
|
||||
let idx44 = 0
|
||||
allMapping.forEach(all128 => {
|
||||
all128.forEach(_i128 => {
|
||||
mask128to44[_i128] = idx44
|
||||
})
|
||||
idx44++
|
||||
})
|
||||
})();
|
||||
|
||||
function GetConvertMapping() {
|
||||
return allMapping;
|
||||
}
|
||||
|
||||
function GetMask44Index(idx128) {
|
||||
return mask128to44[idx128 % 128]
|
||||
}
|
||||
|
||||
function QmcGenerateOggHeader(page2) {
|
||||
let spec = [page2, 0xFF]
|
||||
for (let i = 2; i < page2; i++) spec.push(0xFF)
|
||||
spec.push(0xFF)
|
||||
return QMOggPublicHeader1.concat(spec, QMOggPublicHeader2)
|
||||
}
|
||||
|
||||
function QmcGenerateOggConf(page2) {
|
||||
let specConf = [6, 0]
|
||||
for (let i = 2; i < page2; i++) specConf.push(4)
|
||||
specConf.push(0)
|
||||
return QMOggPublicConf1.concat(specConf, QMOggPublicConf2)
|
||||
}
|
@@ -3,11 +3,18 @@ export const FLAC_HEADER = [0x66, 0x4C, 0x61, 0x43];
|
||||
export const MP3_HEADER = [0x49, 0x44, 0x33];
|
||||
export const OGG_HEADER = [0x4F, 0x67, 0x67, 0x53];
|
||||
export const M4A_HEADER = [0x66, 0x74, 0x79, 0x70];
|
||||
export const WMA_HEADER = [
|
||||
0x30, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11,
|
||||
0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C,
|
||||
]
|
||||
export const WAV_HEADER = [0x52, 0x49, 0x46, 0x46]
|
||||
export const AudioMimeType = {
|
||||
mp3: "audio/mpeg",
|
||||
flac: "audio/flac",
|
||||
m4a: "audio/mp4",
|
||||
ogg: "audio/ogg"
|
||||
ogg: "audio/ogg",
|
||||
wma: "audio/x-ms-wma",
|
||||
wav: "audio/x-wav"
|
||||
};
|
||||
|
||||
// Also a new draft API: blob.arrayBuffer()
|
||||
@@ -21,9 +28,9 @@ export async function GetArrayBuffer(blobObject) {
|
||||
});
|
||||
}
|
||||
|
||||
export function GetFileInfo(artist, title, filenameNoExt) {
|
||||
export function GetFileInfo(artist, title, filenameNoExt, separator = "-") {
|
||||
let newArtist = "", newTitle = "";
|
||||
let filenameArray = filenameNoExt.split("-");
|
||||
let filenameArray = filenameNoExt.split(separator);
|
||||
if (filenameArray.length > 1) {
|
||||
newArtist = filenameArray[0].trim();
|
||||
newTitle = filenameArray[1].trim();
|
||||
@@ -63,6 +70,8 @@ export function DetectAudioExt(data, fallbackExt) {
|
||||
if (IsBytesEqual(FLAC_HEADER, data.slice(0, FLAC_HEADER.length))) return "flac";
|
||||
if (IsBytesEqual(OGG_HEADER, data.slice(0, OGG_HEADER.length))) return "ogg";
|
||||
if (IsBytesEqual(M4A_HEADER, data.slice(4, 4 + M4A_HEADER.length))) return "m4a";
|
||||
if (IsBytesEqual(WMA_HEADER, data.slice(0, WMA_HEADER.length))) return "wma";
|
||||
if (IsBytesEqual(WAV_HEADER, data.slice(0, WAV_HEADER.length))) return "wav";
|
||||
return fallbackExt;
|
||||
}
|
||||
|
||||
|
72
src/decrypt/xm.js
Normal file
72
src/decrypt/xm.js
Normal file
@@ -0,0 +1,72 @@
|
||||
import {
|
||||
AudioMimeType,
|
||||
DetectAudioExt,
|
||||
GetArrayBuffer,
|
||||
GetFileInfo,
|
||||
GetMetaCoverURL,
|
||||
IsBytesEqual
|
||||
} from "./util";
|
||||
|
||||
import {Decrypt as RawDecrypt} from "./raw";
|
||||
|
||||
const musicMetadata = require("music-metadata-browser");
|
||||
const MagicHeader = [0x69, 0x66, 0x6D, 0x74]
|
||||
const MagicHeader2 = [0xfe, 0xfe, 0xfe, 0xfe]
|
||||
const FileTypeMap = {
|
||||
" WAV": ".wav",
|
||||
"FLAC": ".flac",
|
||||
" MP3": ".mp3",
|
||||
" A4M": ".m4a",
|
||||
}
|
||||
|
||||
export async function Decrypt(file, raw_filename, raw_ext) {
|
||||
const oriData = new Uint8Array(await GetArrayBuffer(file));
|
||||
if (!IsBytesEqual(MagicHeader, oriData.slice(0, 4)) ||
|
||||
!IsBytesEqual(MagicHeader2, oriData.slice(8, 12))) {
|
||||
if (raw_ext === "xm") {
|
||||
return {status: false, message: "Not a valid xm file!"}
|
||||
} else {
|
||||
return await RawDecrypt(file, raw_filename, raw_ext, true)
|
||||
}
|
||||
}
|
||||
|
||||
let typeText = (new TextDecoder()).decode(oriData.slice(4, 8))
|
||||
if (!FileTypeMap.hasOwnProperty(typeText)) {
|
||||
return {status: false, message: "New Xiami file category!"}
|
||||
}
|
||||
|
||||
let key = oriData[0xf]
|
||||
let dataOffset = oriData[0xc] | oriData[0xd] << 8
|
||||
let audioData = oriData.slice(0x10);
|
||||
let lenAudioData = audioData.length;
|
||||
for (let cur = dataOffset; cur < lenAudioData; ++cur)
|
||||
audioData[cur] = (audioData[cur] - key) ^ 0xff;
|
||||
|
||||
const ext = DetectAudioExt(audioData, "mp3");
|
||||
const mime = AudioMimeType[ext];
|
||||
let musicBlob = new Blob([audioData], {type: mime});
|
||||
|
||||
const musicMeta = await musicMetadata.parseBlob(musicBlob);
|
||||
if (ext === "wav") {
|
||||
//todo:未知的编码方式
|
||||
musicMeta.common.album = "";
|
||||
musicMeta.common.artist = "";
|
||||
musicMeta.common.title = "";
|
||||
}
|
||||
|
||||
const info = GetFileInfo(musicMeta.common.artist, musicMeta.common.title, raw_filename, "_");
|
||||
|
||||
const imgUrl = GetMetaCoverURL(musicMeta);
|
||||
|
||||
return {
|
||||
status: true,
|
||||
title: info.title,
|
||||
artist: info.artist,
|
||||
ext: ext,
|
||||
album: musicMeta.common.album,
|
||||
picture: imgUrl,
|
||||
file: URL.createObjectURL(musicBlob),
|
||||
mime: mime
|
||||
}
|
||||
}
|
||||
|
@@ -5,10 +5,7 @@ import {register} from 'register-service-worker'
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
register(`${process.env.BASE_URL}service-worker.js`, {
|
||||
ready() {
|
||||
console.log(
|
||||
'App is being served from cache by a service worker.\n' +
|
||||
'For more details, visit https://goo.gl/AFskqB'
|
||||
)
|
||||
console.log('App is being served from cache by a service worker.')
|
||||
},
|
||||
registered() {
|
||||
console.log('Service worker has been registered.')
|
||||
|
Reference in New Issue
Block a user