Compare commits
255 Commits
v1.10.0-be
...
v1.9.0-bet
Author | SHA1 | Date | |
---|---|---|---|
![]() |
73bb9438b1 | ||
![]() |
21d5ae305c | ||
![]() |
759c1bd87e | ||
![]() |
c7e5dfb4c4 | ||
![]() |
ca4ed149b2 | ||
![]() |
b3c6fe2f24 | ||
![]() |
aca1c11332 | ||
![]() |
15dba7b92f | ||
![]() |
37a641e69e | ||
![]() |
342241b379 | ||
![]() |
a1eddb230f | ||
![]() |
3c0a9e92f9 | ||
![]() |
4637a3650a | ||
![]() |
9ae860cb11 | ||
![]() |
ec711990a1 | ||
![]() |
f3f6f9ef40 | ||
![]() |
213ac35157 | ||
![]() |
e36df21f01 | ||
![]() |
fc52423976 | ||
![]() |
5ca9b1fab4 | ||
![]() |
3dfed44021 | ||
![]() |
9e04bc8690 | ||
![]() |
7716c356ed | ||
![]() |
701f750476 | ||
![]() |
d73493a624 | ||
![]() |
85fdbff00d | ||
![]() |
3a5afeb8a6 | ||
![]() |
8dc1a66d69 | ||
![]() |
7733fa6ad1 | ||
![]() |
6a2dd672f3 | ||
![]() |
ca82842b04 | ||
![]() |
137df9c4c2 | ||
![]() |
b17bb37c38 | ||
![]() |
9607580e8b | ||
![]() |
5956412d7e | ||
![]() |
22312959f3 | ||
![]() |
549983a928 | ||
![]() |
ce2642ad1f | ||
![]() |
c6ea98333e | ||
![]() |
042b1ca0dd | ||
![]() |
e089fe1268 | ||
![]() |
67966d4b54 | ||
![]() |
ca462f94fa | ||
![]() |
297c7c9252 | ||
![]() |
8acc1ade81 | ||
![]() |
e543024641 | ||
![]() |
cf48554424 | ||
![]() |
2e0cd04255 | ||
![]() |
adbcdfd083 | ||
![]() |
e1505148c8 | ||
![]() |
b65e47514f | ||
![]() |
31215772e3 | ||
![]() |
070c642dbf | ||
![]() |
8e135f7004 | ||
![]() |
0fb30ddc17 | ||
![]() |
e9a25f3140 | ||
![]() |
5e2f3d36c2 | ||
![]() |
a040c88a07 | ||
![]() |
b370f4ceb6 | ||
![]() |
bf0df4e68d | ||
![]() |
f24ea6a07b | ||
![]() |
c11f3fd130 | ||
![]() |
2ffcbf79b5 | ||
![]() |
6a2b98798b | ||
![]() |
60e2039e56 | ||
![]() |
fbdad625c5 | ||
![]() |
10814ea109 | ||
![]() |
52657046d6 | ||
![]() |
175112180d | ||
![]() |
7b26630428 | ||
![]() |
55b2f17ed7 | ||
![]() |
be09790810 | ||
![]() |
df2d409351 | ||
![]() |
a558dac34b | ||
![]() |
44642b1c39 | ||
![]() |
6e66d2da4f | ||
![]() |
e1cf15cf8c | ||
![]() |
1d415cae52 | ||
![]() |
66e2b96bad | ||
![]() |
79c0c85ab3 | ||
![]() |
ad47a713ad | ||
![]() |
6ef0850c40 | ||
![]() |
9af2ba5e62 | ||
![]() |
0f52c53d6c | ||
![]() |
24764875f3 | ||
![]() |
65a41b21c3 | ||
![]() |
b93b93110b | ||
![]() |
7a5cefd950 | ||
![]() |
3b885f82ca | ||
![]() |
b6757e81a2 | ||
![]() |
8d79035675 | ||
![]() |
6592f304b6 | ||
![]() |
e5bff35f89 | ||
![]() |
9b28676c43 | ||
![]() |
4a2d31238b | ||
![]() |
fd2866f53d | ||
![]() |
5e8af22f08 | ||
![]() |
4aa2ff7f91 | ||
![]() |
c9a4a901be | ||
![]() |
a824bf1f63 | ||
![]() |
bb811178d4 | ||
![]() |
c25055f875 | ||
![]() |
62e36ef228 | ||
![]() |
438383979d | ||
![]() |
59d47c755e | ||
![]() |
e2d4283003 | ||
![]() |
6b1c08663a | ||
![]() |
c338b6ef04 | ||
![]() |
c95cfcb984 | ||
![]() |
26b6b03ef3 | ||
![]() |
f548412d8d | ||
![]() |
f8a1ec137c | ||
![]() |
8622aef21f | ||
![]() |
ecff3d34b0 | ||
![]() |
a140b45e5f | ||
![]() |
d42e6e3259 | ||
![]() |
bceabe4fcf | ||
![]() |
7b9070f99d | ||
![]() |
6410576adb | ||
![]() |
24bfc9e603 | ||
![]() |
b6886b7001 | ||
![]() |
dd965688a9 | ||
![]() |
f9543965b6 | ||
![]() |
e7b86a4779 | ||
![]() |
c3756bb3b3 | ||
![]() |
4d5d70f4b6 | ||
![]() |
e31eb9c1f1 | ||
![]() |
f64fa71b1e | ||
![]() |
181a3c402f | ||
![]() |
4c4e4061f5 | ||
![]() |
2526adcab0 | ||
![]() |
f2ea85bae9 | ||
![]() |
c07d55565d | ||
![]() |
71a8d9fab7 | ||
![]() |
7233fdc707 | ||
![]() |
0d119094df | ||
![]() |
1f804e1037 | ||
![]() |
77d9ca4ba8 | ||
![]() |
8f3c74c100 | ||
![]() |
29c27bbfd9 | ||
![]() |
c87e6e04ed | ||
![]() |
0b52a0acb2 | ||
![]() |
a087da67b2 | ||
![]() |
3ca3142d11 | ||
![]() |
23b01d5f87 | ||
![]() |
12025e3709 | ||
![]() |
2415db67be | ||
![]() |
9569e2f145 | ||
![]() |
87356a0514 | ||
![]() |
ff63c420eb | ||
![]() |
1d3725f9a4 | ||
![]() |
a70aaf03af | ||
![]() |
31fdaf11f7 | ||
![]() |
0c23249d76 | ||
![]() |
6502d2d067 | ||
![]() |
24e1d33642 | ||
![]() |
a72804544f | ||
![]() |
2aeb60d0a9 | ||
![]() |
97ca09dbae | ||
![]() |
e78118b4d0 | ||
![]() |
37c60caa06 | ||
![]() |
fba020969b | ||
![]() |
790715726a | ||
![]() |
4ca45e1233 | ||
![]() |
cfacb77d15 | ||
![]() |
5f7461e8aa | ||
![]() |
aa98ec422c | ||
![]() |
d2ec667c19 | ||
![]() |
94ee8eb3bd | ||
![]() |
c13f7fcced | ||
![]() |
1d83898f08 | ||
![]() |
98ca5bc8ff | ||
![]() |
984b549448 | ||
![]() |
9fd7177ebb | ||
![]() |
f7d19e62fd | ||
![]() |
86d59f4e6f | ||
![]() |
3906572723 | ||
![]() |
179f72687a | ||
![]() |
ce251e3c9e | ||
![]() |
cc8e818142 | ||
![]() |
f99e885d9f | ||
![]() |
58d9039960 | ||
![]() |
c314a251c2 | ||
![]() |
10f09958c4 | ||
![]() |
41a45176be | ||
![]() |
47cea6eae9 | ||
![]() |
2fc9368a92 | ||
![]() |
4e1bfb0b55 | ||
![]() |
27b74ea5dd | ||
![]() |
9aab7a7713 | ||
![]() |
dcde0d3fbb | ||
![]() |
0c0299d63a | ||
![]() |
3ee9f5d2d1 | ||
![]() |
e3ca175258 | ||
![]() |
05cdd7b896 | ||
![]() |
91ba19d878 | ||
![]() |
a7c7b6cbfa | ||
![]() |
50fbb69394 | ||
![]() |
402fb184f7 | ||
![]() |
0766e2fcb0 | ||
![]() |
92bd0f6be3 | ||
![]() |
9c6af8ff9c | ||
![]() |
8094f3ad58 | ||
![]() |
e6a81f8546 | ||
![]() |
211b4e0206 | ||
![]() |
4cd5b45986 | ||
![]() |
60445b7ed9 | ||
![]() |
4e499b2deb | ||
![]() |
0cddb98612 | ||
![]() |
ca3f4c1aa4 | ||
![]() |
eec5bd0fb8 | ||
![]() |
bddde78fcd | ||
![]() |
bc138c4078 | ||
![]() |
51a5a8a44f | ||
![]() |
2fb5aecdb2 | ||
![]() |
8014c33538 | ||
![]() |
e6bce501bb | ||
![]() |
de37519f8c | ||
![]() |
a483594c4b | ||
![]() |
014fe5ae26 | ||
![]() |
73f3959094 | ||
![]() |
48658701a2 | ||
![]() |
c4e9fb0dcc | ||
![]() |
d51d7ec773 | ||
![]() |
683f58964c | ||
![]() |
0ca830e896 | ||
![]() |
2266ca2cf1 | ||
![]() |
c71cb8ee85 | ||
![]() |
b68efea15b | ||
![]() |
591c1a5312 | ||
![]() |
95de3e8cc5 | ||
![]() |
d91f48aa70 | ||
![]() |
497a63486d | ||
![]() |
538705187a | ||
![]() |
04be04204a | ||
![]() |
d99cd23e0c | ||
![]() |
c9770bdd59 | ||
![]() |
757d4d4847 | ||
![]() |
0913337612 | ||
![]() |
23ff9cdec1 | ||
![]() |
0b0b19163b | ||
![]() |
382a637a2c | ||
![]() |
82e4ec6312 | ||
![]() |
0e59843944 | ||
![]() |
c7ed517ede | ||
![]() |
bd377db39b | ||
![]() |
32128ed425 | ||
![]() |
9416ded167 | ||
![]() |
1ba40d1fc2 | ||
![]() |
76c0577185 | ||
![]() |
3ceb56900d | ||
![]() |
e0ffd3f477 | ||
![]() |
94136ec2e6 | ||
![]() |
428a4505ad | ||
![]() |
6ed0291e54 |
44
.github/workflows/build.yml
vendored
44
.github/workflows/build.yml
vendored
@@ -3,7 +3,6 @@ on:
|
||||
push:
|
||||
paths:
|
||||
- "**/*.js"
|
||||
- "**/*.ts"
|
||||
- "**/*.vue"
|
||||
- "public/**/*"
|
||||
- "package-lock.json"
|
||||
@@ -13,21 +12,14 @@ on:
|
||||
types: [ opened, synchronize, reopened ]
|
||||
paths:
|
||||
- "**/*.js"
|
||||
- "**/*.ts"
|
||||
- "**/*.vue"
|
||||
- "public/**/*"
|
||||
- "package-lock.json"
|
||||
- "package.json"
|
||||
|
||||
|
||||
|
||||
jobs:
|
||||
test-coverage:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Test Coverage
|
||||
uses: ArtiomTr/jest-coverage-report-action@v2.0-rc.6
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
@@ -43,30 +35,40 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Use Node.js 16.x
|
||||
- name: Use Node.js 14.x
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: "16"
|
||||
node-version: "14"
|
||||
|
||||
- name: Install Dependencies
|
||||
run: npm ci
|
||||
run: |
|
||||
npm ci
|
||||
npm run fix-compatibility
|
||||
|
||||
- name: Build
|
||||
run: npm run build ${{ matrix.BUILD_ARGS }}
|
||||
env:
|
||||
GZIP: "--best"
|
||||
run: |
|
||||
npm run build ${{ matrix.BUILD_ARGS }}
|
||||
tar -czvf dist.tar.gz -C ./dist .
|
||||
|
||||
- name: Build Extension
|
||||
if: ${{ matrix.BUILD_EXTENSION }}
|
||||
run: |
|
||||
npm run make-extension
|
||||
cd dist
|
||||
zip -rJ9 ../extension.zip *
|
||||
cd ..
|
||||
|
||||
- name: Publish artifact
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: ${{ matrix.build }}
|
||||
path: ./dist
|
||||
|
||||
- name: Build Extension
|
||||
if: ${{ matrix.BUILD_EXTENSION }}
|
||||
run: npm run make-extension
|
||||
name: unlock-music-${{ matrix.build }}.tar.gz
|
||||
path: ./dist.tar.gz
|
||||
|
||||
- name: Publish artifact - Extension
|
||||
if: ${{ matrix.BUILD_EXTENSION }}
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: extension
|
||||
path: ./dist
|
||||
name: extension.zip
|
||||
path: ./extension.zip
|
||||
|
8
.github/workflows/release-build.yml
vendored
8
.github/workflows/release-build.yml
vendored
@@ -11,13 +11,15 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Use Node.js 16.x
|
||||
- name: Use Node.js 14.x
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: "16"
|
||||
node-version: "14"
|
||||
|
||||
- name: Install Dependencies
|
||||
run: npm ci
|
||||
run: |
|
||||
npm ci
|
||||
npm run fix-compatibility
|
||||
|
||||
- name: Build Legacy
|
||||
env:
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,7 +1,6 @@
|
||||
.DS_Store
|
||||
node_modules
|
||||
/dist
|
||||
/coverage
|
||||
|
||||
# local env files
|
||||
.env.local
|
||||
|
4
LICENSE
4
LICENSE
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019-2021 MengYX
|
||||
Copyright (c) 2019-2020 MengYX
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -18,4 +18,4 @@ 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.
|
||||
SOFTWARE.
|
@@ -22,6 +22,8 @@
|
||||
- [x] QQ音乐新格式 (实验性支持)
|
||||
- [x] .mflac
|
||||
- [x] [.mgg](https://github.com/ix64/unlock-music/issues/3)
|
||||
- [x] 网易云音乐格式 (.ncm)
|
||||
- [x] 补全ncm的ID3/FlacMeta信息
|
||||
- [x] 虾米音乐格式 (.xm) (测试阶段)
|
||||
- [x] 酷我音乐格式 (.kwm) (测试阶段)
|
||||
- [x] 酷狗音乐格式 (
|
||||
|
@@ -1,7 +1,6 @@
|
||||
module.exports = {
|
||||
presets: [
|
||||
'@vue/app',
|
||||
'@babel/preset-typescript'
|
||||
'@vue/app'
|
||||
],
|
||||
plugins: [
|
||||
["component", {
|
||||
|
@@ -1,5 +0,0 @@
|
||||
module.exports = {
|
||||
moduleNameMapper: {
|
||||
'@/(.*)': '<rootDir>/src/$1'
|
||||
}
|
||||
};
|
@@ -15,9 +15,6 @@ const manifest = JSON.parse(manifestRaw)
|
||||
const pkgRaw = fs.readFileSync("./package.json", "utf-8")
|
||||
const pkg = JSON.parse(pkgRaw)
|
||||
|
||||
ver_str = pkg["version"]
|
||||
if (ver_str.startsWith("v")) ver_str = ver_str.slice(1)
|
||||
manifest["version"] = ver_str
|
||||
|
||||
manifest["version"] = pkg["version"]
|
||||
fs.writeFileSync("./dist/manifest.json", JSON.stringify(manifest), "utf-8")
|
||||
console.log("Write: manifest.json")
|
||||
|
31055
package-lock.json
generated
31055
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
31
package.json
31
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "unlock-music",
|
||||
"version": "v1.10.0-beta.1",
|
||||
"version": "v1.9.0-beta",
|
||||
"updateInfo": "新增写入本地文件系统; 优化.kwm解锁; 支持.acc嗅探; 使用Typescript重构",
|
||||
"license": "MIT",
|
||||
"description": "Unlock encrypted music file in browser.",
|
||||
@@ -10,45 +10,38 @@
|
||||
},
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"postinstall": "patch-package",
|
||||
"serve": "vue-cli-service serve",
|
||||
"build": "vue-cli-service build",
|
||||
"test": "jest",
|
||||
"fix-compatibility": "node ./src/fix-compatibility.js",
|
||||
"make-extension": "node ./make-extension.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/preset-typescript": "^7.16.5",
|
||||
"@jixun/qmc2-crypto": "^0.0.5-R4",
|
||||
"base64-js": "^1.5.1",
|
||||
"browser-id3-writer": "^4.4.0",
|
||||
"core-js": "^3.16.0",
|
||||
"crypto-js": "^4.1.1",
|
||||
"element-ui": "^2.15.5",
|
||||
"core-js": "^3.12.1",
|
||||
"crypto-js": "^4.0.0",
|
||||
"element-ui": "^2.15.1",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"jimp": "^0.16.1",
|
||||
"metaflac-js": "^1.0.5",
|
||||
"music-metadata": "7.9.0",
|
||||
"music-metadata-browser": "2.2.7",
|
||||
"music-metadata-browser": "^2.2.6",
|
||||
"register-service-worker": "^1.7.2",
|
||||
"threads": "^1.6.5",
|
||||
"vue": "^2.6.14"
|
||||
"threads": "^1.6.4",
|
||||
"vue": "^2.6.12"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/crypto-js": "^4.0.2",
|
||||
"@types/jest": "^27.0.3",
|
||||
"@types/crypto-js": "^4.0.1",
|
||||
"@vue/cli-plugin-babel": "^4.5.13",
|
||||
"@vue/cli-plugin-pwa": "^4.5.13",
|
||||
"@vue/cli-plugin-typescript": "^4.5.13",
|
||||
"@vue/cli-service": "^4.5.13",
|
||||
"babel-plugin-component": "^1.1.1",
|
||||
"jest": "^27.4.5",
|
||||
"patch-package": "^6.4.7",
|
||||
"sass": "^1.38.1",
|
||||
"node-sass": "^5.0.0",
|
||||
"sass-loader": "^10.2.0",
|
||||
"semver": "^7.3.5",
|
||||
"threads-plugin": "^1.4.0",
|
||||
"typescript": "^4.5.4",
|
||||
"typescript": "~4.1.5",
|
||||
"vue-cli-plugin-element": "^1.0.1",
|
||||
"vue-template-compiler": "^2.6.14"
|
||||
"vue-template-compiler": "^2.6.12"
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +0,0 @@
|
||||
diff --git a/node_modules/threads/worker.mjs b/node_modules/threads/worker.mjs
|
||||
index c53ac7d..619007b 100644
|
||||
--- a/node_modules/threads/worker.mjs
|
||||
+++ b/node_modules/threads/worker.mjs
|
||||
@@ -1,4 +1,5 @@
|
||||
-import WorkerContext from "./dist/worker/index.js"
|
||||
+// Workaround: use of import seems to break minifier.
|
||||
+const WorkerContext = require("./dist/worker/index.js")
|
||||
|
||||
export const expose = WorkerContext.expose
|
||||
export const registerSerializer = WorkerContext.registerSerializer
|
@@ -6,7 +6,7 @@
|
||||
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
|
||||
<meta content="width=device-width,initial-scale=1.0" name="viewport">
|
||||
<title>音乐解锁</title>
|
||||
<meta content="音乐,解锁,qmc,mgg,mflac,qq音乐,加密" name="keywords"/>
|
||||
<meta content="音乐,解锁,ncm,qmc,mgg,mflac,qq音乐,网易云音乐,加密" name="keywords"/>
|
||||
<meta content="音乐解锁 - 在任何设备上解锁已购的加密音乐!" name="description"/>
|
||||
<script src="./ixarea-stats.js"></script>
|
||||
<!--@formatter:off-->
|
||||
|
@@ -10,7 +10,7 @@
|
||||
<a href="https://github.com/ix64/unlock-music/wiki/使用提示" target="_blank">使用提示</a>
|
||||
</el-row>
|
||||
<el-row>
|
||||
目前支持 QQ音乐(qmc, mflac, mgg), 酷狗音乐(kgm), 虾米音乐(xm), 酷我音乐(.kwm)
|
||||
目前支持网易云音乐(ncm), QQ音乐(qmc, mflac, mgg), 酷狗音乐(kgm), 虾米音乐(xm), 酷我音乐(.kwm)
|
||||
<a href="https://github.com/ix64/unlock-music/blob/master/README.md" target="_blank">更多</a>。
|
||||
</el-row>
|
||||
<el-row>
|
||||
|
@@ -63,7 +63,7 @@ export default {
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
if (window.Worker && window.location.protocol !== "file:" && process.env.NODE_ENV === 'production') {
|
||||
if (window.Worker && process.env.NODE_ENV === 'production') {
|
||||
console.log("Using Worker Pool")
|
||||
this.queue = Pool(
|
||||
() => spawn(new Worker('@/utils/worker.ts')),
|
||||
|
@@ -1,34 +1,37 @@
|
||||
import {Decrypt as NcmDecrypt} from "@/decrypt/ncm";
|
||||
import {Decrypt as XmDecrypt} from "@/decrypt/xm";
|
||||
import {Decrypt as QmcDecrypt} from "@/decrypt/qmc";
|
||||
import {Decrypt as QmcCacheDecrypt} from "@/decrypt/qmccache";
|
||||
import {Decrypt as KgmDecrypt} from "@/decrypt/kgm";
|
||||
import {Decrypt as KwmDecrypt} from "@/decrypt/kwm";
|
||||
import {Decrypt as RawDecrypt} from "@/decrypt/raw";
|
||||
import {Decrypt as TmDecrypt} from "@/decrypt/tm";
|
||||
import {DecryptResult, FileInfo} from "@/decrypt/entity";
|
||||
import {SplitFilename} from "@/decrypt/utils";
|
||||
|
||||
|
||||
export async function CommonDecrypt(file: FileInfo): Promise<DecryptResult> {
|
||||
const raw = SplitFilename(file.name)
|
||||
let raw_ext = file.name.substring(file.name.lastIndexOf(".") + 1, file.name.length).toLowerCase();
|
||||
let raw_filename = file.name.substring(0, file.name.lastIndexOf("."));
|
||||
let rt_data: DecryptResult;
|
||||
switch (raw.ext) {
|
||||
switch (raw_ext) {
|
||||
case "ncm":// Netease Mp3/Flac
|
||||
rt_data = await NcmDecrypt(file.raw, raw_filename, raw_ext);
|
||||
break;
|
||||
case "kwm":// Kuwo Mp3/Flac
|
||||
rt_data = await KwmDecrypt(file.raw, raw.name, raw.ext);
|
||||
rt_data = await KwmDecrypt(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(file.raw, raw.name, raw.ext);
|
||||
rt_data = await XmDecrypt(file.raw, raw_filename, raw_ext);
|
||||
break;
|
||||
case "ogg":// Raw Ogg
|
||||
rt_data = await RawDecrypt(file.raw, raw.name, raw.ext);
|
||||
rt_data = await RawDecrypt(file.raw, raw_filename, raw_ext);
|
||||
break;
|
||||
case "tm0":// QQ Music IOS Mp3
|
||||
case "tm3":// QQ Music IOS Mp3
|
||||
rt_data = await RawDecrypt(file.raw, raw.name, "mp3");
|
||||
rt_data = await RawDecrypt(file.raw, raw_filename, "mp3");
|
||||
break;
|
||||
case "qmc3"://QQ Music Android Mp3
|
||||
case "qmc2"://QQ Music Android Ogg
|
||||
@@ -38,35 +41,30 @@ export async function CommonDecrypt(file: FileInfo): Promise<DecryptResult> {
|
||||
case "tkm"://QQ Music Accompaniment M4a
|
||||
case "bkcmp3"://Moo Music Mp3
|
||||
case "bkcflac"://Moo Music Flac
|
||||
case "mflac"://QQ Music New Flac
|
||||
case "mflac0"://QQ Music New Flac
|
||||
case "mgg": //QQ Music New Ogg
|
||||
case "mgg1": //QQ Music New Ogg
|
||||
case "mflac"://QQ Music Desktop Flac
|
||||
case "mgg": //QQ Music Desktop Ogg
|
||||
case "666c6163"://QQ Music Weiyun Flac
|
||||
case "6d7033"://QQ Music Weiyun Mp3
|
||||
case "6f6767"://QQ Music Weiyun Ogg
|
||||
case "6d3461"://QQ Music Weiyun M4a
|
||||
case "776176"://QQ Music Weiyun Wav
|
||||
rt_data = await QmcDecrypt(file.raw, raw.name, raw.ext);
|
||||
rt_data = await QmcDecrypt(file.raw, raw_filename, raw_ext);
|
||||
break;
|
||||
case "tm2":// QQ Music IOS M4a
|
||||
case "tm6":// QQ Music IOS M4a
|
||||
rt_data = await TmDecrypt(file.raw, raw.name);
|
||||
break;
|
||||
case "cache"://QQ Music Cache
|
||||
rt_data = await QmcCacheDecrypt(file.raw, raw.name, raw.ext);
|
||||
rt_data = await TmDecrypt(file.raw, raw_filename);
|
||||
break;
|
||||
case "vpr":
|
||||
case "kgm":
|
||||
case "kgma":
|
||||
rt_data = await KgmDecrypt(file.raw, raw.name, raw.ext);
|
||||
rt_data = await KgmDecrypt(file.raw, raw_filename, raw_ext);
|
||||
break
|
||||
default:
|
||||
throw "不支持此文件格式"
|
||||
}
|
||||
|
||||
if (!rt_data.rawExt) rt_data.rawExt = raw.ext;
|
||||
if (!rt_data.rawFilename) rt_data.rawFilename = raw.name;
|
||||
if (!rt_data.rawExt) rt_data.rawExt = raw_ext;
|
||||
if (!rt_data.rawFilename) rt_data.rawFilename = raw_filename;
|
||||
console.log(rt_data);
|
||||
return rt_data;
|
||||
}
|
||||
|
@@ -5,10 +5,9 @@ import {
|
||||
GetCoverFromFile,
|
||||
GetMetaFromFile,
|
||||
SniffAudioExt
|
||||
} from "@/decrypt/utils";
|
||||
} from "@/decrypt/utils.ts";
|
||||
import {parseBlob as metaParseBlob} from "music-metadata-browser";
|
||||
import {DecryptResult} from "@/decrypt/entity";
|
||||
import config from "@/../package.json"
|
||||
|
||||
const VprHeader = [
|
||||
0x05, 0x28, 0xBC, 0x96, 0xE9, 0xE4, 0x5A, 0x43,
|
||||
@@ -23,6 +22,9 @@ const VprMaskDiff = [
|
||||
|
||||
|
||||
export async function Decrypt(file: File, raw_filename: string, raw_ext: string): Promise<DecryptResult> {
|
||||
if (window?.location?.protocol === "file:") {
|
||||
throw Error("请使用 <a target='_blank' href='https://github.com/unlock-music/cli'>CLI版本</a> 进行解锁")
|
||||
}
|
||||
|
||||
const oriData = new Uint8Array(await GetArrayBuffer(file));
|
||||
if (raw_ext === "vpr") {
|
||||
@@ -82,16 +84,8 @@ function GetMask(pos: number) {
|
||||
let MaskV2: Uint8Array = new Uint8Array(0);
|
||||
|
||||
async function LoadMaskV2(): Promise<boolean> {
|
||||
let mask_url = `https://cdn.jsdelivr.net/gh/unlock-music/unlock-music@${config.version}/public/static/kgm.mask`
|
||||
if (["http:", "https:"].some(v => v == self.location.protocol)) {
|
||||
if (!!self.document) {// using Web Worker
|
||||
mask_url = "./static/kgm.mask"
|
||||
} else {// using Main thread
|
||||
mask_url = "../static/kgm.mask"
|
||||
}
|
||||
}
|
||||
try {
|
||||
const resp = await fetch(mask_url, {method: "GET"})
|
||||
const resp = await fetch("./static/kgm.mask", {method: "GET"})
|
||||
MaskV2 = new Uint8Array(await resp.arrayBuffer());
|
||||
return true
|
||||
} catch (e) {
|
||||
|
@@ -5,8 +5,8 @@ import {
|
||||
GetCoverFromFile,
|
||||
GetMetaFromFile,
|
||||
SniffAudioExt
|
||||
} from "@/decrypt/utils";
|
||||
import {Decrypt as RawDecrypt} from "@/decrypt/raw";
|
||||
} from "@/decrypt/utils.ts";
|
||||
import {Decrypt as RawDecrypt} from "@/decrypt/raw.ts";
|
||||
|
||||
import {parseBlob as metaParseBlob} from "music-metadata-browser";
|
||||
import {DecryptResult} from "@/decrypt/entity";
|
||||
|
235
src/decrypt/ncm.ts
Normal file
235
src/decrypt/ncm.ts
Normal file
@@ -0,0 +1,235 @@
|
||||
import {
|
||||
AudioMimeType,
|
||||
BytesHasPrefix,
|
||||
GetArrayBuffer,
|
||||
GetImageFromURL,
|
||||
GetMetaFromFile, IMusicMeta,
|
||||
SniffAudioExt,
|
||||
WriteMetaToFlac,
|
||||
WriteMetaToMp3
|
||||
} from "@/decrypt/utils.ts";
|
||||
import {parseBlob as metaParseBlob} from "music-metadata-browser";
|
||||
import jimp from 'jimp';
|
||||
|
||||
import CryptoJS from "crypto-js";
|
||||
import {DecryptResult} from "@/decrypt/entity";
|
||||
|
||||
const CORE_KEY = CryptoJS.enc.Hex.parse("687a4852416d736f356b496e62617857");
|
||||
const META_KEY = CryptoJS.enc.Hex.parse("2331346C6A6B5F215C5D2630553C2728");
|
||||
const MagicHeader = [0x43, 0x54, 0x45, 0x4E, 0x46, 0x44, 0x41, 0x4D];
|
||||
|
||||
|
||||
export async function Decrypt(file: File, raw_filename: string, _: string): Promise<DecryptResult> {
|
||||
return (new NcmDecrypt(await GetArrayBuffer(file), raw_filename)).decrypt()
|
||||
}
|
||||
|
||||
|
||||
interface NcmMusicMeta {
|
||||
//musicId: number
|
||||
musicName?: string
|
||||
artist?: Array<string | number>[]
|
||||
format?: string
|
||||
album?: string
|
||||
albumPic?: string
|
||||
}
|
||||
|
||||
interface NcmDjMeta {
|
||||
mainMusic: NcmMusicMeta
|
||||
}
|
||||
|
||||
|
||||
class NcmDecrypt {
|
||||
raw: ArrayBuffer
|
||||
view: DataView
|
||||
offset: number = 0
|
||||
filename: string
|
||||
format: string = ""
|
||||
mime: string = ""
|
||||
audio?: Uint8Array
|
||||
blob?: Blob
|
||||
oriMeta?: NcmMusicMeta
|
||||
newMeta?: IMusicMeta
|
||||
image?: { mime: string, buffer: ArrayBuffer, url: string }
|
||||
|
||||
constructor(buf: ArrayBuffer, filename: string) {
|
||||
const prefix = new Uint8Array(buf, 0, 8)
|
||||
if (!BytesHasPrefix(prefix, MagicHeader)) throw Error("此ncm文件已损坏")
|
||||
this.offset = 10
|
||||
this.raw = buf
|
||||
this.view = new DataView(buf)
|
||||
this.filename = filename
|
||||
}
|
||||
|
||||
_getKeyData(): Uint8Array {
|
||||
const keyLen = this.view.getUint32(this.offset, true);
|
||||
this.offset += 4;
|
||||
const cipherText = new Uint8Array(this.raw, this.offset, keyLen)
|
||||
.map(uint8 => uint8 ^ 0x64);
|
||||
this.offset += keyLen;
|
||||
|
||||
const plainText = CryptoJS.AES.decrypt(
|
||||
// @ts-ignore
|
||||
{ciphertext: CryptoJS.lib.WordArray.create(cipherText)},
|
||||
CORE_KEY,
|
||||
{mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7}
|
||||
);
|
||||
|
||||
const result = new Uint8Array(plainText.sigBytes);
|
||||
|
||||
const words = plainText.words;
|
||||
const sigBytes = plainText.sigBytes;
|
||||
for (let i = 0; i < sigBytes; i++) {
|
||||
result[i] = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
|
||||
}
|
||||
|
||||
return result.slice(17)
|
||||
}
|
||||
|
||||
_getKeyBox(): Uint8Array {
|
||||
const keyData = this._getKeyData()
|
||||
const box = new Uint8Array(Array(256).keys());
|
||||
|
||||
const keyDataLen = keyData.length;
|
||||
|
||||
let j = 0;
|
||||
|
||||
for (let i = 0; i < 256; i++) {
|
||||
j = (box[i] + j + keyData[i % keyDataLen]) & 0xff;
|
||||
[box[i], box[j]] = [box[j], box[i]];
|
||||
}
|
||||
|
||||
return box.map((_, i, arr) => {
|
||||
i = (i + 1) & 0xff;
|
||||
const si = arr[i];
|
||||
const sj = arr[(i + si) & 0xff];
|
||||
return arr[(si + sj) & 0xff];
|
||||
});
|
||||
}
|
||||
|
||||
_getMetaData(): NcmMusicMeta {
|
||||
const metaDataLen = this.view.getUint32(this.offset, true);
|
||||
this.offset += 4;
|
||||
if (metaDataLen === 0) return {};
|
||||
|
||||
const cipherText = new Uint8Array(this.raw, this.offset, metaDataLen)
|
||||
.map(data => data ^ 0x63);
|
||||
this.offset += metaDataLen;
|
||||
|
||||
const plainText = CryptoJS.AES.decrypt(
|
||||
//@ts-ignore
|
||||
{
|
||||
ciphertext: CryptoJS.enc.Base64.parse(
|
||||
//@ts-ignore
|
||||
CryptoJS.lib.WordArray.create(cipherText.slice(22)).toString(CryptoJS.enc.Utf8)
|
||||
)
|
||||
},
|
||||
META_KEY,
|
||||
{mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7}
|
||||
).toString(CryptoJS.enc.Utf8);
|
||||
|
||||
const labelIndex = plainText.indexOf(":");
|
||||
let result: NcmMusicMeta;
|
||||
if (plainText.slice(0, labelIndex) === "dj") {
|
||||
const tmp: NcmDjMeta = JSON.parse(plainText.slice(labelIndex + 1));
|
||||
result = tmp.mainMusic;
|
||||
} else {
|
||||
result = JSON.parse(plainText.slice(labelIndex + 1));
|
||||
}
|
||||
if (!!result.albumPic) {
|
||||
result.albumPic = result.albumPic.replace("http://", "https://") + "?param=500y500"
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
_getAudio(keyBox: Uint8Array): Uint8Array {
|
||||
this.offset += this.view.getUint32(this.offset + 5, true) + 13
|
||||
const audioData = new Uint8Array(this.raw, this.offset)
|
||||
let lenAudioData = audioData.length
|
||||
for (let cur = 0; cur < lenAudioData; ++cur) audioData[cur] ^= keyBox[cur & 0xff]
|
||||
return audioData
|
||||
}
|
||||
|
||||
async _buildMeta() {
|
||||
if (!this.oriMeta) throw Error("invalid sequence")
|
||||
|
||||
const info = GetMetaFromFile(this.filename, this.oriMeta.musicName)
|
||||
|
||||
// build artists
|
||||
let artists: string[] = [];
|
||||
if (!!this.oriMeta.artist) {
|
||||
this.oriMeta.artist.forEach(arr => artists.push(<string>arr[0]));
|
||||
}
|
||||
|
||||
if (artists.length === 0 && !!info.artist) {
|
||||
artists = info.artist.split(',')
|
||||
.map(val => val.trim()).filter(val => val != "");
|
||||
}
|
||||
|
||||
if (this.oriMeta.albumPic) try {
|
||||
this.image = await GetImageFromURL(this.oriMeta.albumPic)
|
||||
while (this.image && this.image.buffer.byteLength >= 1 << 24) {
|
||||
let img = await jimp.read(Buffer.from(this.image.buffer))
|
||||
await img.resize(Math.round(img.getHeight() / 2), jimp.AUTO)
|
||||
this.image.buffer = await img.getBufferAsync("image/jpeg")
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("get cover image failed", e)
|
||||
}
|
||||
|
||||
|
||||
this.newMeta = {title: info.title, artists, album: this.oriMeta.album, picture: this.image?.buffer}
|
||||
}
|
||||
|
||||
async _writeMeta() {
|
||||
if (!this.audio || !this.newMeta) throw Error("invalid sequence")
|
||||
|
||||
if (!this.blob) this.blob = new Blob([this.audio], {type: this.mime})
|
||||
const ori = await metaParseBlob(this.blob);
|
||||
|
||||
let shouldWrite = !ori.common.album && !ori.common.artists && !ori.common.title
|
||||
if (shouldWrite || this.newMeta.picture) {
|
||||
if (this.format === "mp3") {
|
||||
this.audio = WriteMetaToMp3(Buffer.from(this.audio), this.newMeta, ori)
|
||||
} else if (this.format === "flac") {
|
||||
this.audio = WriteMetaToFlac(Buffer.from(this.audio), this.newMeta, ori)
|
||||
} else {
|
||||
console.info(`writing meta for ${this.format} is not being supported for now`)
|
||||
return
|
||||
}
|
||||
this.blob = new Blob([this.audio], {type: this.mime})
|
||||
}
|
||||
}
|
||||
|
||||
gatherResult(): DecryptResult {
|
||||
if (!this.newMeta) throw Error("bad sequence")
|
||||
return {
|
||||
title: this.newMeta.title,
|
||||
artist: this.newMeta.artists?.join("; "),
|
||||
ext: this.format,
|
||||
album: this.newMeta.album,
|
||||
picture: this.image?.url,
|
||||
file: URL.createObjectURL(this.blob),
|
||||
blob: this.blob as Blob,
|
||||
mime: this.mime
|
||||
}
|
||||
}
|
||||
|
||||
async decrypt() {
|
||||
const keyBox = this._getKeyBox()
|
||||
this.oriMeta = this._getMetaData()
|
||||
this.audio = this._getAudio(keyBox)
|
||||
this.format = this.oriMeta.format || SniffAudioExt(this.audio)
|
||||
this.mime = AudioMimeType[this.format]
|
||||
await this._buildMeta()
|
||||
try {
|
||||
await this._writeMeta()
|
||||
} catch (e) {
|
||||
console.warn("write meta data failed", e)
|
||||
}
|
||||
return this.gatherResult()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -1,139 +1,138 @@
|
||||
import {QmcStaticCipher} from "./qmc_cipher";
|
||||
import {QmcMask, QmcMaskDetectMflac, QmcMaskDetectMgg, QmcMaskGetDefault} from "./qmcMask";
|
||||
import {toByteArray as Base64Decode} from 'base64-js'
|
||||
import {
|
||||
AudioMimeType,
|
||||
GetArrayBuffer,
|
||||
GetCoverFromFile,
|
||||
GetImageFromURL,
|
||||
GetMetaFromFile,
|
||||
SniffAudioExt,
|
||||
WriteMetaToFlac,
|
||||
WriteMetaToMp3
|
||||
} from "@/decrypt/utils";
|
||||
AudioMimeType,
|
||||
GetArrayBuffer,
|
||||
GetCoverFromFile,
|
||||
GetImageFromURL,
|
||||
GetMetaFromFile,
|
||||
SniffAudioExt, WriteMetaToFlac, WriteMetaToMp3
|
||||
} from "@/decrypt/utils.ts";
|
||||
import {parseBlob as metaParseBlob} from "music-metadata-browser";
|
||||
import {DecryptQMCv2} from "./qmcv2";
|
||||
|
||||
|
||||
import iconv from "iconv-lite";
|
||||
import {DecryptResult} from "@/decrypt/entity";
|
||||
import {queryAlbumCover} from "@/utils/api";
|
||||
import {queryAlbumCover, queryKeyInfo, reportKeyUsage} from "@/utils/api";
|
||||
|
||||
interface Handler {
|
||||
ext: string
|
||||
version: number
|
||||
ext: string
|
||||
detect: boolean
|
||||
|
||||
handler(data?: Uint8Array): QmcMask | undefined
|
||||
}
|
||||
|
||||
export const HandlerMap: { [key: string]: Handler } = {
|
||||
"mgg": {ext: "ogg", version: 2},
|
||||
"mgg1": {ext: "ogg", version: 2},
|
||||
"mflac": {ext: "flac", version: 2},
|
||||
"mflac0": {ext: "flac", version: 2},
|
||||
|
||||
// qmcflac / qmcogg:
|
||||
// 有可能是 v2 加密但混用同一个后缀名。
|
||||
"qmcflac": {ext: "flac", version: 2},
|
||||
"qmcogg": {ext: "ogg", version: 2},
|
||||
|
||||
"qmc0": {ext: "mp3", version: 1},
|
||||
"qmc2": {ext: "ogg", version: 1},
|
||||
"qmc3": {ext: "mp3", version: 1},
|
||||
"bkcmp3": {ext: "mp3", version: 1},
|
||||
"bkcflac": {ext: "flac", version: 1},
|
||||
"tkm": {ext: "m4a", version: 1},
|
||||
"666c6163": {ext: "flac", version: 1},
|
||||
"6d7033": {ext: "mp3", version: 1},
|
||||
"6f6767": {ext: "ogg", version: 1},
|
||||
"6d3461": {ext: "m4a", version: 1},
|
||||
"776176": {ext: "wav", version: 1}
|
||||
const HandlerMap: { [key: string]: Handler } = {
|
||||
"mgg": {handler: QmcMaskDetectMgg, ext: "ogg", detect: true},
|
||||
"mflac": {handler: QmcMaskDetectMflac, ext: "flac", detect: true},
|
||||
"qmc0": {handler: QmcMaskGetDefault, ext: "mp3", detect: false},
|
||||
"qmc2": {handler: QmcMaskGetDefault, ext: "ogg", detect: false},
|
||||
"qmc3": {handler: QmcMaskGetDefault, ext: "mp3", detect: false},
|
||||
"qmcogg": {handler: QmcMaskGetDefault, ext: "ogg", detect: false},
|
||||
"qmcflac": {handler: QmcMaskGetDefault, ext: "flac", detect: false},
|
||||
"bkcmp3": {handler: QmcMaskGetDefault, ext: "mp3", detect: false},
|
||||
"bkcflac": {handler: QmcMaskGetDefault, ext: "flac", detect: false},
|
||||
"tkm": {handler: QmcMaskGetDefault, ext: "m4a", detect: false},
|
||||
"666c6163": {handler: QmcMaskGetDefault, ext: "flac", detect: false},
|
||||
"6d7033": {handler: QmcMaskGetDefault, ext: "mp3", detect: false},
|
||||
"6f6767": {handler: QmcMaskGetDefault, ext: "ogg", detect: false},
|
||||
"6d3461": {handler: QmcMaskGetDefault, ext: "m4a", detect: false},
|
||||
"776176": {handler: QmcMaskGetDefault, ext: "wav", detect: false}
|
||||
};
|
||||
|
||||
export async function Decrypt(file: Blob, raw_filename: string, raw_ext: string): Promise<DecryptResult> {
|
||||
if (!(raw_ext in HandlerMap)) throw `Qmc cannot handle type: ${raw_ext}`;
|
||||
const handler = HandlerMap[raw_ext];
|
||||
let {version} = handler;
|
||||
export async function Decrypt(file: File, raw_filename: string, raw_ext: string): Promise<DecryptResult> {
|
||||
if (!(raw_ext in HandlerMap)) throw "File type is incorrect!";
|
||||
const handler = HandlerMap[raw_ext];
|
||||
|
||||
const fileBuffer = await GetArrayBuffer(file);
|
||||
let musicDecoded: Uint8Array | undefined;
|
||||
|
||||
if (version === 2) {
|
||||
const v2Decrypted = await DecryptQMCv2(fileBuffer);
|
||||
// 如果 v2 检测失败,降级到 v1 再尝试一次
|
||||
if (v2Decrypted) {
|
||||
musicDecoded = v2Decrypted;
|
||||
const fileData = new Uint8Array(await GetArrayBuffer(file));
|
||||
let audioData, seed, keyData;
|
||||
if (handler.detect) {
|
||||
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(keyPos, keyPos + keyLen);
|
||||
if (!seed) seed = await queryKey(keyData, raw_filename, raw_ext);
|
||||
if (!seed) throw raw_ext + "格式仅提供实验性支持";
|
||||
} else {
|
||||
version = 1;
|
||||
audioData = fileData;
|
||||
seed = handler.handler(audioData) as QmcMask;
|
||||
}
|
||||
}
|
||||
let musicDecoded = seed.Decrypt(audioData);
|
||||
|
||||
if (version === 1) {
|
||||
const seed = new QmcStaticCipher();
|
||||
musicDecoded = new Uint8Array(fileBuffer)
|
||||
seed.decrypt(musicDecoded, 0);
|
||||
} else if (!musicDecoded) {
|
||||
throw new Error(`解密失败: ${raw_ext}`);
|
||||
}
|
||||
const ext = SniffAudioExt(musicDecoded, handler.ext);
|
||||
const mime = AudioMimeType[ext];
|
||||
|
||||
const ext = SniffAudioExt(musicDecoded, handler.ext);
|
||||
const mime = AudioMimeType[ext];
|
||||
let musicBlob = new Blob([musicDecoded], {type: mime});
|
||||
|
||||
let musicBlob = new Blob([musicDecoded], {type: mime});
|
||||
|
||||
const musicMeta = await metaParseBlob(musicBlob);
|
||||
for (let metaIdx in musicMeta.native) {
|
||||
if (!musicMeta.native.hasOwnProperty(metaIdx)) continue
|
||||
if (musicMeta.native[metaIdx].some(item => item.id === "TCON" && item.value === "(12)")) {
|
||||
console.warn("try using gbk encoding to decode meta")
|
||||
musicMeta.common.artist = iconv.decode(new Buffer(musicMeta.common.artist ?? ""), "gbk");
|
||||
musicMeta.common.title = iconv.decode(new Buffer(musicMeta.common.title ?? ""), "gbk");
|
||||
musicMeta.common.album = iconv.decode(new Buffer(musicMeta.common.album ?? ""), "gbk");
|
||||
}
|
||||
}
|
||||
|
||||
const info = GetMetaFromFile(raw_filename, musicMeta.common.title, musicMeta.common.artist)
|
||||
|
||||
let imgUrl = GetCoverFromFile(musicMeta);
|
||||
if (!imgUrl) {
|
||||
imgUrl = await getCoverImage(info.title, info.artist, musicMeta.common.album);
|
||||
if (imgUrl) {
|
||||
const imageInfo = await GetImageFromURL(imgUrl);
|
||||
if (imageInfo) {
|
||||
imgUrl = imageInfo.url
|
||||
try {
|
||||
const newMeta = {picture: imageInfo.buffer, title: info.title, artists: info.artist?.split(" _ ")}
|
||||
if (ext === "mp3") {
|
||||
musicDecoded = WriteMetaToMp3(Buffer.from(musicDecoded), newMeta, musicMeta)
|
||||
musicBlob = new Blob([musicDecoded], {type: mime});
|
||||
} else if (ext === 'flac') {
|
||||
musicDecoded = WriteMetaToFlac(Buffer.from(musicDecoded), newMeta, musicMeta)
|
||||
musicBlob = new Blob([musicDecoded], {type: mime});
|
||||
} else {
|
||||
console.info("writing metadata for " + ext + " is not being supported for now")
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("Error while appending cover image to file " + e)
|
||||
const musicMeta = await metaParseBlob(musicBlob);
|
||||
for (let metaIdx in musicMeta.native) {
|
||||
if (!musicMeta.native.hasOwnProperty(metaIdx)) continue
|
||||
if (musicMeta.native[metaIdx].some(item => item.id === "TCON" && item.value === "(12)")) {
|
||||
console.warn("try using gbk encoding to decode meta")
|
||||
musicMeta.common.artist = iconv.decode(new Buffer(musicMeta.common.artist ?? ""), "gbk");
|
||||
musicMeta.common.title = iconv.decode(new Buffer(musicMeta.common.title ?? ""), "gbk");
|
||||
musicMeta.common.album = iconv.decode(new Buffer(musicMeta.common.album ?? ""), "gbk");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
title: info.title,
|
||||
artist: info.artist,
|
||||
ext: ext,
|
||||
album: musicMeta.common.album,
|
||||
picture: imgUrl,
|
||||
file: URL.createObjectURL(musicBlob),
|
||||
blob: musicBlob,
|
||||
mime: mime
|
||||
}
|
||||
|
||||
const info = GetMetaFromFile(raw_filename, musicMeta.common.title, musicMeta.common.artist)
|
||||
if (keyData) reportKeyUsage(keyData, seed.getMatrix128(),
|
||||
raw_filename, raw_ext, info.title, info.artist, musicMeta.common.album).then().catch();
|
||||
|
||||
let imgUrl = GetCoverFromFile(musicMeta);
|
||||
if (!imgUrl) {
|
||||
imgUrl = await getCoverImage(info.title, info.artist, musicMeta.common.album);
|
||||
if (imgUrl) {
|
||||
const imageInfo = await GetImageFromURL(imgUrl);
|
||||
if (imageInfo) {
|
||||
imgUrl = imageInfo.url
|
||||
try {
|
||||
const newMeta = {picture: imageInfo.buffer, title: info.title, artists: info.artist?.split(" _ ")}
|
||||
if (ext === "mp3") {
|
||||
musicDecoded = WriteMetaToMp3(Buffer.from(musicDecoded), newMeta, musicMeta)
|
||||
musicBlob = new Blob([musicDecoded], {type: mime});
|
||||
} else if (ext === 'flac') {
|
||||
musicDecoded = WriteMetaToFlac(Buffer.from(musicDecoded), newMeta, musicMeta)
|
||||
musicBlob = new Blob([musicDecoded], {type: mime});
|
||||
} else {
|
||||
console.info("writing metadata for " + ext + " is not being supported for now")
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("Error while appending cover image to file " + e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
title: info.title,
|
||||
artist: info.artist,
|
||||
ext: ext,
|
||||
album: musicMeta.common.album,
|
||||
picture: imgUrl,
|
||||
file: URL.createObjectURL(musicBlob),
|
||||
blob: musicBlob,
|
||||
mime: mime
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function queryKey(keyData: Uint8Array, filename: string, format: string): Promise<QmcMask | undefined> {
|
||||
try {
|
||||
const data = await queryKeyInfo(keyData, filename, format)
|
||||
return new QmcMask(Base64Decode(data.Matrix44));
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
}
|
||||
}
|
||||
|
||||
async function getCoverImage(title: string, artist?: string, album?: string): Promise<string> {
|
||||
const song_query_url = "https://stats.ixarea.com/apis" + "/music/qq-cover"
|
||||
try {
|
||||
const data = await queryAlbumCover(title, artist, album)
|
||||
return `${song_query_url}/${data.Type}/${data.Id}`
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
}
|
||||
return ""
|
||||
const song_query_url = "https://stats.ixarea.com/apis" + "/music/qq-cover"
|
||||
try {
|
||||
const data = await queryAlbumCover(title, artist, album)
|
||||
return `${song_query_url}/${data.Type}/${data.Id}`
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
206
src/decrypt/qmcMask.ts
Normal file
206
src/decrypt/qmcMask.ts
Normal file
@@ -0,0 +1,206 @@
|
||||
import {BytesHasPrefix, FLAC_HEADER, OGG_HEADER} from "@/decrypt/utils.ts";
|
||||
|
||||
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];
|
||||
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 = [
|
||||
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];
|
||||
|
||||
|
||||
const AllMapping: number[][] = [];
|
||||
const Mask128to44: number[] = [];
|
||||
|
||||
(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]
|
||||
}
|
||||
}
|
||||
|
||||
let idx44 = 0
|
||||
AllMapping.forEach(all128 => {
|
||||
all128.forEach(_i128 => {
|
||||
Mask128to44[_i128] = idx44
|
||||
})
|
||||
idx44++
|
||||
})
|
||||
})();
|
||||
|
||||
|
||||
export class QmcMask {
|
||||
private readonly Matrix128: number[];
|
||||
|
||||
constructor(matrix: number[] | Uint8Array) {
|
||||
if (matrix instanceof Uint8Array) matrix = Array.from(matrix)
|
||||
if (matrix.length === 44) {
|
||||
this.Matrix128 = this._generate128(matrix)
|
||||
} else if (matrix.length === 128) {
|
||||
this.Matrix128 = matrix
|
||||
} else {
|
||||
throw Error("invalid mask length")
|
||||
}
|
||||
}
|
||||
|
||||
getMatrix128() {
|
||||
return this.Matrix128
|
||||
}
|
||||
|
||||
getMatrix44(): number[] {
|
||||
const matrix44: number[] = []
|
||||
let idxI44 = 0
|
||||
AllMapping.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"
|
||||
}
|
||||
}
|
||||
matrix44[idxI44] = this.Matrix128[it256[0]]
|
||||
idxI44++
|
||||
})
|
||||
return matrix44
|
||||
}
|
||||
|
||||
Decrypt(data: Uint8Array) {
|
||||
if (!this.Matrix128) throw Error("bad call sequence")
|
||||
let dst = data.slice(0);
|
||||
let index = -1;
|
||||
let maskIdx = -1;
|
||||
for (let cur = 0; cur < data.length; cur++) {
|
||||
index++;
|
||||
maskIdx++;
|
||||
if (index === 0x8000 || (index > 0x8000 && (index + 1) % 0x8000 === 0)) {
|
||||
index++;
|
||||
maskIdx++;
|
||||
}
|
||||
if (maskIdx >= 128) maskIdx -= 128;
|
||||
dst[cur] ^= this.Matrix128[maskIdx];
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
private _generate128(matrix44: number[]): number[] {
|
||||
const matrix128: number[] = []
|
||||
let idx44 = 0
|
||||
AllMapping.forEach(it256 => {
|
||||
it256.forEach(m => {
|
||||
matrix128[m] = matrix44[idx44]
|
||||
})
|
||||
idx44++
|
||||
})
|
||||
return matrix128
|
||||
}
|
||||
}
|
||||
|
||||
export function QmcMaskGetDefault() {
|
||||
return new QmcMask(QMCDefaultMaskMatrix)
|
||||
}
|
||||
|
||||
export function QmcMaskDetectMflac(data: Uint8Array) {
|
||||
let search_len = Math.min(0x8000, data.length), mask;
|
||||
for (let block_idx = 0; block_idx < search_len; block_idx += 128) {
|
||||
try {
|
||||
mask = new QmcMask(data.slice(block_idx, block_idx + 128));
|
||||
if (BytesHasPrefix(mask.Decrypt(data.slice(0, FLAC_HEADER.length)), FLAC_HEADER)) {
|
||||
break;
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
|
||||
export function QmcMaskDetectMgg(data: Uint8Array) {
|
||||
if (data.length < 0x100) return
|
||||
let matrixConfidence: { [key: number]: { [key: number]: number } } = {};
|
||||
for (let i = 0; i < 44; i++) matrixConfidence[i] = {};
|
||||
|
||||
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 = Mask128to44[idx128 % 128];
|
||||
let _m = data[idx128] ^ spHeader[idx128]
|
||||
let confidence = spConf[idx128];
|
||||
if (_m in matrixConfidence[idx44]) {
|
||||
matrixConfidence[idx44][_m] += confidence
|
||||
} else {
|
||||
matrixConfidence[idx44][_m] = confidence
|
||||
}
|
||||
}
|
||||
let matrix = [];
|
||||
try {
|
||||
for (let i = 0; i < 44; i++)
|
||||
matrix[i] = calcMaskFromConfidence(matrixConfidence[i]);
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
const mask = new QmcMask(matrix);
|
||||
if (!BytesHasPrefix(mask.Decrypt(data.slice(0, OGG_HEADER.length)), OGG_HEADER)) {
|
||||
return;
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
|
||||
|
||||
function calcMaskFromConfidence(confidence: { [key: number]: number }) {
|
||||
const count = Object.keys(confidence).length
|
||||
if (count === 0) throw "can not match at least one key";
|
||||
if (count > 1) console.warn("There are 2 potential value for the mask!")
|
||||
let result = ""
|
||||
let conf = 0
|
||||
for (let idx in confidence) {
|
||||
if (confidence[idx] > conf) {
|
||||
result = idx;
|
||||
conf = confidence[idx];
|
||||
}
|
||||
}
|
||||
return Number(result)
|
||||
}
|
||||
|
||||
function QmcGenerateOggHeader(page2: number) {
|
||||
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: number) {
|
||||
let specConf = [6, 0]
|
||||
for (let i = 2; i < page2; i++) specConf.push(4)
|
||||
specConf.push(0)
|
||||
return QMOggPublicConf1.concat(specConf, QMOggPublicConf2)
|
||||
}
|
@@ -1,27 +0,0 @@
|
||||
import {QmcStaticCipher} from "@/decrypt/qmc_cipher";
|
||||
|
||||
test("static cipher [0x7ff8,0x8000) ", () => {
|
||||
const expected = new Uint8Array([
|
||||
0xD8, 0x52, 0xF7, 0x67, 0x90, 0xCA, 0xD6, 0x4A,
|
||||
0x4A, 0xD6, 0xCA, 0x90, 0x67, 0xF7, 0x52, 0xD8,
|
||||
])
|
||||
|
||||
const c = new QmcStaticCipher()
|
||||
const buf = new Uint8Array(16)
|
||||
c.decrypt(buf, 0x7ff8)
|
||||
|
||||
expect(buf).toStrictEqual(expected)
|
||||
})
|
||||
|
||||
test("static cipher [0,0x10) ", () => {
|
||||
const expected = new Uint8Array([
|
||||
0xC3, 0x4A, 0xD6, 0xCA, 0x90, 0x67, 0xF7, 0x52,
|
||||
0xD8, 0xA1, 0x66, 0x62, 0x9F, 0x5B, 0x09, 0x00,
|
||||
])
|
||||
|
||||
const c = new QmcStaticCipher()
|
||||
const buf = new Uint8Array(16)
|
||||
c.decrypt(buf, 0)
|
||||
|
||||
expect(buf).toStrictEqual(expected)
|
||||
})
|
@@ -1,53 +0,0 @@
|
||||
const staticCipherBox = new Uint8Array([
|
||||
0x77, 0x48, 0x32, 0x73, 0xDE, 0xF2, 0xC0, 0xC8, //0x00
|
||||
0x95, 0xEC, 0x30, 0xB2, 0x51, 0xC3, 0xE1, 0xA0, //0x08
|
||||
0x9E, 0xE6, 0x9D, 0xCF, 0xFA, 0x7F, 0x14, 0xD1, //0x10
|
||||
0xCE, 0xB8, 0xDC, 0xC3, 0x4A, 0x67, 0x93, 0xD6, //0x18
|
||||
0x28, 0xC2, 0x91, 0x70, 0xCA, 0x8D, 0xA2, 0xA4, //0x20
|
||||
0xF0, 0x08, 0x61, 0x90, 0x7E, 0x6F, 0xA2, 0xE0, //0x28
|
||||
0xEB, 0xAE, 0x3E, 0xB6, 0x67, 0xC7, 0x92, 0xF4, //0x30
|
||||
0x91, 0xB5, 0xF6, 0x6C, 0x5E, 0x84, 0x40, 0xF7, //0x38
|
||||
0xF3, 0x1B, 0x02, 0x7F, 0xD5, 0xAB, 0x41, 0x89, //0x40
|
||||
0x28, 0xF4, 0x25, 0xCC, 0x52, 0x11, 0xAD, 0x43, //0x48
|
||||
0x68, 0xA6, 0x41, 0x8B, 0x84, 0xB5, 0xFF, 0x2C, //0x50
|
||||
0x92, 0x4A, 0x26, 0xD8, 0x47, 0x6A, 0x7C, 0x95, //0x58
|
||||
0x61, 0xCC, 0xE6, 0xCB, 0xBB, 0x3F, 0x47, 0x58, //0x60
|
||||
0x89, 0x75, 0xC3, 0x75, 0xA1, 0xD9, 0xAF, 0xCC, //0x68
|
||||
0x08, 0x73, 0x17, 0xDC, 0xAA, 0x9A, 0xA2, 0x16, //0x70
|
||||
0x41, 0xD8, 0xA2, 0x06, 0xC6, 0x8B, 0xFC, 0x66, //0x78
|
||||
0x34, 0x9F, 0xCF, 0x18, 0x23, 0xA0, 0x0A, 0x74, //0x80
|
||||
0xE7, 0x2B, 0x27, 0x70, 0x92, 0xE9, 0xAF, 0x37, //0x88
|
||||
0xE6, 0x8C, 0xA7, 0xBC, 0x62, 0x65, 0x9C, 0xC2, //0x90
|
||||
0x08, 0xC9, 0x88, 0xB3, 0xF3, 0x43, 0xAC, 0x74, //0x98
|
||||
0x2C, 0x0F, 0xD4, 0xAF, 0xA1, 0xC3, 0x01, 0x64, //0xA0
|
||||
0x95, 0x4E, 0x48, 0x9F, 0xF4, 0x35, 0x78, 0x95, //0xA8
|
||||
0x7A, 0x39, 0xD6, 0x6A, 0xA0, 0x6D, 0x40, 0xE8, //0xB0
|
||||
0x4F, 0xA8, 0xEF, 0x11, 0x1D, 0xF3, 0x1B, 0x3F, //0xB8
|
||||
0x3F, 0x07, 0xDD, 0x6F, 0x5B, 0x19, 0x30, 0x19, //0xC0
|
||||
0xFB, 0xEF, 0x0E, 0x37, 0xF0, 0x0E, 0xCD, 0x16, //0xC8
|
||||
0x49, 0xFE, 0x53, 0x47, 0x13, 0x1A, 0xBD, 0xA4, //0xD0
|
||||
0xF1, 0x40, 0x19, 0x60, 0x0E, 0xED, 0x68, 0x09, //0xD8
|
||||
0x06, 0x5F, 0x4D, 0xCF, 0x3D, 0x1A, 0xFE, 0x20, //0xE0
|
||||
0x77, 0xE4, 0xD9, 0xDA, 0xF9, 0xA4, 0x2B, 0x76, //0xE8
|
||||
0x1C, 0x71, 0xDB, 0x00, 0xBC, 0xFD, 0x0C, 0x6C, //0xF0
|
||||
0xA5, 0x47, 0xF7, 0xF6, 0x00, 0x79, 0x4A, 0x11, //0xF8
|
||||
])
|
||||
|
||||
interface streamCipher {
|
||||
decrypt(buf: Uint8Array, offset: number): void
|
||||
}
|
||||
|
||||
export class QmcStaticCipher implements streamCipher {
|
||||
|
||||
public getMask(offset: number) {
|
||||
if (offset > 0x7FFF) offset %= 0x7FFF
|
||||
return staticCipherBox[(offset * offset + 27) & 0xff]
|
||||
}
|
||||
|
||||
public decrypt(buf: Uint8Array, offset: number) {
|
||||
for (let i = 0; i < buf.length; i++) {
|
||||
buf[i] ^= this.getMask(offset + i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,51 +0,0 @@
|
||||
import {
|
||||
AudioMimeType,
|
||||
GetArrayBuffer,
|
||||
GetCoverFromFile,
|
||||
GetMetaFromFile,
|
||||
SniffAudioExt,
|
||||
SplitFilename
|
||||
} from "@/decrypt/utils";
|
||||
|
||||
import {Decrypt as QmcDecrypt, HandlerMap} from "@/decrypt/qmc";
|
||||
|
||||
import {DecryptResult} from "@/decrypt/entity";
|
||||
|
||||
import {parseBlob as metaParseBlob} from "music-metadata-browser";
|
||||
|
||||
export async function Decrypt(file: Blob, raw_filename: string, _: string)
|
||||
: Promise<DecryptResult> {
|
||||
const buffer = new Uint8Array(await GetArrayBuffer(file));
|
||||
let length = buffer.length
|
||||
for (let i = 0; i < length; i++) {
|
||||
buffer[i] ^= 0xf4
|
||||
if (buffer[i] <= 0x3f) buffer[i] = buffer[i] * 4;
|
||||
else if (buffer[i] <= 0x7f) buffer[i] = (buffer[i] - 0x40) * 4 + 1;
|
||||
else if (buffer[i] <= 0xbf) buffer[i] = (buffer[i] - 0x80) * 4 + 2;
|
||||
else buffer[i] = (buffer[i] - 0xc0) * 4 + 3;
|
||||
}
|
||||
let ext = SniffAudioExt(buffer, "");
|
||||
const newName = SplitFilename(raw_filename)
|
||||
let audioBlob: Blob
|
||||
if (ext !== "" || newName.ext === "mp3") {
|
||||
audioBlob = new Blob([buffer], {type: AudioMimeType[ext]})
|
||||
} else if (newName.ext in HandlerMap) {
|
||||
audioBlob = new Blob([buffer], {type: "application/octet-stream"})
|
||||
return QmcDecrypt(audioBlob, newName.name, newName.ext);
|
||||
} else {
|
||||
throw "不支持的QQ音乐缓存格式"
|
||||
}
|
||||
const tag = await metaParseBlob(audioBlob);
|
||||
const {title, artist} = GetMetaFromFile(raw_filename, tag.common.title, tag.common.artist)
|
||||
|
||||
return {
|
||||
title,
|
||||
artist,
|
||||
ext,
|
||||
album: tag.common.album,
|
||||
picture: GetCoverFromFile(tag),
|
||||
file: URL.createObjectURL(audioBlob),
|
||||
blob: audioBlob,
|
||||
mime: AudioMimeType[ext]
|
||||
}
|
||||
}
|
@@ -1,102 +0,0 @@
|
||||
import QMCCryptoModule from '@jixun/qmc2-crypto/QMC2-wasm-bundle';
|
||||
|
||||
// 检测文件末端使用的缓冲区大小
|
||||
const DETECTION_SIZE = 40;
|
||||
|
||||
// 每次处理 2M 的数据
|
||||
const DECRYPTION_BUF_SIZE = 2 * 1024 * 1024;
|
||||
|
||||
function MergeUint8Array(array: Uint8Array[]): Uint8Array {
|
||||
let length = 0;
|
||||
array.forEach(item => {
|
||||
length += item.length;
|
||||
});
|
||||
|
||||
let mergedArray = new Uint8Array(length);
|
||||
let offset = 0;
|
||||
array.forEach(item => {
|
||||
mergedArray.set(item, offset);
|
||||
offset += item.length;
|
||||
});
|
||||
|
||||
return mergedArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密一个 QMC2 加密的文件。
|
||||
*
|
||||
* 如果检测并解密成功,返回解密后的 Uint8Array 数据。
|
||||
* @param {ArrayBuffer} mggBlob 读入的文件 Blob
|
||||
* @return {Promise<Uint8Array|false>}
|
||||
*/
|
||||
export async function DecryptQMCv2(mggBlob: ArrayBuffer) {
|
||||
// 初始化模组
|
||||
const QMCCrypto = await QMCCryptoModule();
|
||||
|
||||
// 申请内存块,并文件末端数据到 WASM 的内存堆
|
||||
const detectionBuf = new Uint8Array(mggBlob.slice(-DETECTION_SIZE));
|
||||
const pDetectionBuf = QMCCrypto._malloc(detectionBuf.length);
|
||||
QMCCrypto.writeArrayToMemory(detectionBuf, pDetectionBuf);
|
||||
|
||||
// 检测结果内存块
|
||||
const pDetectionResult = QMCCrypto._malloc(QMCCrypto.sizeof_qmc_detection());
|
||||
|
||||
// 进行检测
|
||||
const detectOK = QMCCrypto.detectKeyEndPosition(
|
||||
pDetectionResult,
|
||||
pDetectionBuf,
|
||||
detectionBuf.length
|
||||
);
|
||||
|
||||
// 提取结构体内容:
|
||||
// (pos: i32; len: i32; error: char[??])
|
||||
const position = QMCCrypto.getValue(pDetectionResult, "i32");
|
||||
const len = QMCCrypto.getValue(pDetectionResult + 4, "i32");
|
||||
|
||||
// 释放内存
|
||||
QMCCrypto._free(pDetectionBuf);
|
||||
QMCCrypto._free(pDetectionResult);
|
||||
|
||||
if (!detectOK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 计算解密后文件的大小。
|
||||
// 之前得到的 position 为相对当前检测数据起点的偏移。
|
||||
const decryptedSize = mggBlob.byteLength - DETECTION_SIZE + position;
|
||||
|
||||
// 提取嵌入到文件的 EKey
|
||||
const ekey = new Uint8Array(
|
||||
mggBlob.slice(decryptedSize, decryptedSize + len)
|
||||
);
|
||||
|
||||
// 解码 UTF-8 数据到 string
|
||||
const decoder = new TextDecoder();
|
||||
const ekey_b64 = decoder.decode(ekey);
|
||||
|
||||
// 初始化加密与缓冲区
|
||||
const hCrypto = QMCCrypto.createInstWidthEKey(ekey_b64);
|
||||
const buf = QMCCrypto._malloc(DECRYPTION_BUF_SIZE);
|
||||
|
||||
const decryptedParts = [];
|
||||
let offset = 0;
|
||||
let bytesToDecrypt = decryptedSize;
|
||||
while (bytesToDecrypt > 0) {
|
||||
const blockSize = Math.min(bytesToDecrypt, DECRYPTION_BUF_SIZE);
|
||||
|
||||
// 解密一些片段
|
||||
const blockData = new Uint8Array(
|
||||
mggBlob.slice(offset, offset + blockSize)
|
||||
);
|
||||
QMCCrypto.writeArrayToMemory(blockData, buf);
|
||||
QMCCrypto.decryptStream(hCrypto, buf, offset, blockSize);
|
||||
decryptedParts.push(QMCCrypto.HEAPU8.slice(buf, buf + blockSize));
|
||||
|
||||
offset += blockSize;
|
||||
bytesToDecrypt -= blockSize;
|
||||
}
|
||||
QMCCrypto._free(buf);
|
||||
hCrypto.delete();
|
||||
|
||||
return MergeUint8Array(decryptedParts);
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
import {AudioMimeType, GetArrayBuffer, GetCoverFromFile, GetMetaFromFile, SniffAudioExt} from "@/decrypt/utils";
|
||||
import {AudioMimeType, GetArrayBuffer, GetCoverFromFile, GetMetaFromFile, SniffAudioExt} from "@/decrypt/utils.ts";
|
||||
|
||||
import {DecryptResult} from "@/decrypt/entity";
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import {Decrypt as RawDecrypt} from "./raw";
|
||||
import {GetArrayBuffer} from "@/decrypt/utils";
|
||||
import {GetArrayBuffer} from "@/decrypt/utils.ts";
|
||||
import {DecryptResult} from "@/decrypt/entity";
|
||||
|
||||
const TM_HEADER = [0x00, 0x00, 0x00, 0x20, 0x66, 0x74, 0x79, 0x70];
|
||||
|
@@ -12,16 +12,13 @@ export const WMA_HEADER = [
|
||||
]
|
||||
export const WAV_HEADER = [0x52, 0x49, 0x46, 0x46]
|
||||
export const AAC_HEADER = [0xFF, 0xF1]
|
||||
export const DFF_HEADER = [0x46, 0x52, 0x4D, 0x38]
|
||||
|
||||
export const AudioMimeType: { [key: string]: string } = {
|
||||
mp3: "audio/mpeg",
|
||||
flac: "audio/flac",
|
||||
m4a: "audio/mp4",
|
||||
ogg: "audio/ogg",
|
||||
wma: "audio/x-ms-wma",
|
||||
wav: "audio/x-wav",
|
||||
dff: "audio/x-dff"
|
||||
wav: "audio/x-wav"
|
||||
};
|
||||
|
||||
|
||||
@@ -42,7 +39,6 @@ export function SniffAudioExt(data: Uint8Array, fallback_ext: string = "mp3"): s
|
||||
if (BytesHasPrefix(data, WAV_HEADER)) return "wav"
|
||||
if (BytesHasPrefix(data, WMA_HEADER)) return "wma"
|
||||
if (BytesHasPrefix(data, AAC_HEADER)) return "aac"
|
||||
if (BytesHasPrefix(data, DFF_HEADER)) return "dff"
|
||||
return fallback_ext;
|
||||
}
|
||||
|
||||
@@ -160,11 +156,3 @@ export function WriteMetaToFlac(audioData: Buffer, info: IMusicMeta, original: I
|
||||
}
|
||||
return writer.save()
|
||||
}
|
||||
|
||||
export function SplitFilename(n: string): { name: string; ext: string } {
|
||||
const pos = n.lastIndexOf(".")
|
||||
return {
|
||||
ext: n.substring(pos + 1).toLowerCase(),
|
||||
name: n.substring(0, pos)
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import {Decrypt as RawDecrypt} from "@/decrypt/raw";
|
||||
import {DecryptResult} from "@/decrypt/entity";
|
||||
import {AudioMimeType, BytesHasPrefix, GetArrayBuffer, GetCoverFromFile, GetMetaFromFile} from "@/decrypt/utils";
|
||||
import {AudioMimeType, BytesHasPrefix, GetArrayBuffer, GetCoverFromFile, GetMetaFromFile} from "@/decrypt/utils.ts";
|
||||
|
||||
import {parseBlob as metaParseBlob} from "music-metadata-browser";
|
||||
|
||||
|
25
src/fix-compatibility.js
Normal file
25
src/fix-compatibility.js
Normal file
@@ -0,0 +1,25 @@
|
||||
//TODO: Use other method to fix this
|
||||
// !! Only Temporary Solution
|
||||
// it seems like that @babel/plugin-proposal-object-rest-spread not working
|
||||
// to fix up the compatibility for Edge 18 and some older Chromium
|
||||
// now manually edit the dependency files
|
||||
|
||||
const fs = require('fs');
|
||||
const filePath = "./node_modules/file-type/core.js";
|
||||
const regReplace = /{\s*([a-zA-Z0-9:,\s]*),\s*\.\.\.([a-zA-Z0-9]*)\s*};/m;
|
||||
if (fs.existsSync(filePath)) {
|
||||
console.log("File Found!");
|
||||
let data = fs.readFileSync(filePath).toString();
|
||||
const regResult = regReplace.exec(data);
|
||||
if (regResult != null) {
|
||||
data = data.replace(regResult[0],
|
||||
"Object.assign({ " + regResult[1] + " }, " + regResult[2] + ");"
|
||||
);
|
||||
fs.writeFileSync(filePath, data);
|
||||
console.log("Object rest spread in file-type fixed!");
|
||||
} else {
|
||||
console.log("No fix needed.");
|
||||
}
|
||||
} else {
|
||||
console.log("File Not Found!");
|
||||
}
|
9
src/shims-fs.d.ts
vendored
9
src/shims-fs.d.ts
vendored
@@ -6,10 +6,6 @@ interface FileSystemCreateWritableOptions {
|
||||
keepExistingData?: boolean
|
||||
}
|
||||
|
||||
interface FileSystemRemoveOptions {
|
||||
recursive?: boolean
|
||||
}
|
||||
|
||||
interface FileSystemFileHandle {
|
||||
getFile(): Promise<File>;
|
||||
|
||||
@@ -41,16 +37,13 @@ interface FileSystemWritableFileStream extends WritableStream {
|
||||
close(): Promise<undefined> // should be implemented in WritableStream
|
||||
}
|
||||
|
||||
|
||||
export declare interface FileSystemDirectoryHandle {
|
||||
getFileHandle(name: string, options?: FileSystemGetFileOptions): Promise<FileSystemFileHandle>
|
||||
|
||||
removeEntry(name: string, options?: FileSystemRemoveOptions): Promise<undefined>
|
||||
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
FileSystemDirectoryHandle
|
||||
|
||||
showDirectoryPicker?(): Promise<FileSystemDirectoryHandle>
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import {fromByteArray as Base64Encode} from "base64-js";
|
||||
|
||||
export const IXAREA_API_ENDPOINT = "https://um-api.ixarea.com"
|
||||
export const IXAREA_API_ENDPOINT = "https://stats.ixarea.com/apis"
|
||||
|
||||
export interface UpdateInfo {
|
||||
Found: boolean
|
||||
|
@@ -144,9 +144,9 @@ export default {
|
||||
}
|
||||
try {
|
||||
this.dir = await window.showDirectoryPicker()
|
||||
const test_filename = "__unlock_music_write_test.txt"
|
||||
await this.dir.getFileHandle(test_filename, {create: true})
|
||||
await this.dir.removeEntry(test_filename)
|
||||
window.dir = this.dir
|
||||
window.f = await this.dir.getFileHandle("write-test.txt", {create: true})
|
||||
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
|
@@ -14,8 +14,7 @@
|
||||
"sourceMap": true,
|
||||
"baseUrl": ".",
|
||||
"types": [
|
||||
"webpack-env",
|
||||
"jest"
|
||||
"webpack-env"
|
||||
],
|
||||
"paths": {
|
||||
"@/*": [
|
||||
@@ -27,8 +26,7 @@
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"scripthost"
|
||||
],
|
||||
"resolveJsonModule": true
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
|
Reference in New Issue
Block a user