mirror of
https://git.unlock-music.dev/um/web.git
synced 2024-12-30 01:15:03 +08:00
feat(QMCv2): use js decoder
(cherry picked from commit c24e5d29733cfa771dd41ae40032029c6bbb9186)
This commit is contained in:
parent
1ab05bb509
commit
979168b68f
@ -10,7 +10,7 @@ import {
|
||||
WriteMetaToMp3
|
||||
} from "@/decrypt/utils";
|
||||
import {parseBlob as metaParseBlob} from "music-metadata-browser";
|
||||
import {DecryptQMCv2} from "./qmcv2";
|
||||
import {DecryptQMCWasm} from "./qmc_wasm";
|
||||
|
||||
|
||||
import iconv from "iconv-lite";
|
||||
@ -55,22 +55,19 @@ export async function Decrypt(file: Blob, raw_filename: string, raw_ext: string)
|
||||
const fileBuffer = await GetArrayBuffer(file);
|
||||
let musicDecoded: Uint8Array | undefined;
|
||||
|
||||
if (version === 2) {
|
||||
const v2Decrypted = await DecryptQMCv2(fileBuffer);
|
||||
if (version === 2 && globalThis.WebAssembly) {
|
||||
console.log("qmc: using wasm decoder")
|
||||
const v2Decrypted = await DecryptQMCWasm(fileBuffer);
|
||||
// 如果 v2 检测失败,降级到 v1 再尝试一次
|
||||
if (v2Decrypted) {
|
||||
musicDecoded = v2Decrypted;
|
||||
} else {
|
||||
version = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (version === 1) {
|
||||
const seed = new QmcStaticCipher();
|
||||
musicDecoded = new Uint8Array(fileBuffer)
|
||||
seed.decrypt(musicDecoded, 0);
|
||||
} else if (!musicDecoded) {
|
||||
throw new Error(`解密失败: ${raw_ext}`);
|
||||
if (!musicDecoded) {
|
||||
// may throw error
|
||||
console.log("qmc: using js decoder")
|
||||
const d = new QmcDecoder(new Uint8Array(fileBuffer))
|
||||
musicDecoded = d.decrypt()
|
||||
}
|
||||
|
||||
const ext = SniffAudioExt(musicDecoded, handler.ext);
|
||||
|
@ -29,7 +29,7 @@ function MergeUint8Array(array: Uint8Array[]): Uint8Array {
|
||||
* @param {ArrayBuffer} mggBlob 读入的文件 Blob
|
||||
* @return {Promise<Uint8Array|false>}
|
||||
*/
|
||||
export async function DecryptQMCv2(mggBlob: ArrayBuffer) {
|
||||
export async function DecryptQMCWasm(mggBlob: ArrayBuffer) {
|
||||
// 初始化模组
|
||||
const QMCCrypto = await QMCCryptoModule();
|
||||
|
Loading…
Reference in New Issue
Block a user