feat(decrypt/kwm): support raw .acc
This commit is contained in:
parent
9ae860cb11
commit
4637a3650a
@ -1,5 +1,5 @@
|
||||
import {AudioMimeType, GetFileInfo, GetMetaCoverURL} from "./util";
|
||||
import {BytesHasPrefix, GetArrayBuffer, SniffAudioExt} from "@/decrypt/utils.ts";
|
||||
import {GetFileInfo, GetMetaCoverURL} from "./util";
|
||||
import {AudioMimeType, BytesHasPrefix, GetArrayBuffer, SniffAudioExt} from "@/decrypt/utils.ts";
|
||||
|
||||
const musicMetadata = require("music-metadata-browser");
|
||||
const VprHeader = [
|
||||
|
@ -1,17 +1,23 @@
|
||||
import {AudioMimeType, GetFileInfo, GetMetaCoverURL} from "./util";
|
||||
import {BytesHasPrefix, GetArrayBuffer, SniffAudioExt} from "@/decrypt/utils.ts";
|
||||
import {GetFileInfo, GetMetaCoverURL} from "./util";
|
||||
import {AudioMimeType, BytesHasPrefix, GetArrayBuffer, SniffAudioExt} from "@/decrypt/utils.ts";
|
||||
import {Decrypt as RawDecrypt} from "@/decrypt/raw.ts";
|
||||
|
||||
import {parseBlob as metaParseBlob} from "music-metadata-browser";
|
||||
|
||||
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, _) {
|
||||
export async function Decrypt(file: File, raw_filename: string, _: string) {
|
||||
const oriData = new Uint8Array(await GetArrayBuffer(file));
|
||||
if (!BytesHasPrefix(oriData, MagicHeader))
|
||||
if (!BytesHasPrefix(oriData, MagicHeader)) {
|
||||
if (SniffAudioExt(oriData) === "aac") {
|
||||
return await RawDecrypt(file, raw_filename, "aac", true)
|
||||
}
|
||||
return {status: false, message: "Not a valid kwm file!"}
|
||||
}
|
||||
|
||||
let fileKey = oriData.slice(0x18, 0x20)
|
||||
let mask = createMaskFromKey(fileKey)
|
||||
@ -25,7 +31,7 @@ export async function Decrypt(file, raw_filename, _) {
|
||||
const mime = AudioMimeType[ext];
|
||||
let musicBlob = new Blob([audioData], {type: mime});
|
||||
|
||||
const musicMeta = await musicMetadata.parseBlob(musicBlob);
|
||||
const musicMeta = await metaParseBlob(musicBlob);
|
||||
const info = GetFileInfo(musicMeta.common.artist, musicMeta.common.title, raw_filename);
|
||||
|
||||
const imgUrl = GetMetaCoverURL(musicMeta);
|
||||
@ -43,19 +49,19 @@ export async function Decrypt(file, raw_filename, _) {
|
||||
}
|
||||
|
||||
|
||||
function createMaskFromKey(keyBytes) {
|
||||
function createMaskFromKey(keyBytes: Uint8Array): Uint8Array {
|
||||
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()
|
||||
key[i] = PreDefinedKey.charCodeAt(i) ^ keyStrTrim.charCodeAt(i)
|
||||
}
|
||||
return key
|
||||
}
|
||||
|
||||
|
||||
function trimKey(keyRaw) {
|
||||
function trimKey(keyRaw: string): string {
|
||||
let lenRaw = keyRaw.length;
|
||||
let out = keyRaw;
|
||||
if (lenRaw > 32) {
|
@ -1,4 +1,4 @@
|
||||
import {BytesHasPrefix, GetArrayBuffer, SniffAudioExt} from "@/decrypt/utils.ts";
|
||||
import {AudioMimeType, BytesHasPrefix, GetArrayBuffer, SniffAudioExt} from "@/decrypt/utils.ts";
|
||||
|
||||
const CryptoJS = require("crypto-js");
|
||||
const MetaFlac = require('metaflac-js');
|
||||
@ -9,7 +9,6 @@ const musicMetadata = require("music-metadata-browser");
|
||||
import jimp from 'jimp';
|
||||
|
||||
import {
|
||||
AudioMimeType,
|
||||
GetFileInfo,
|
||||
GetWebImage,
|
||||
WriteMp3Meta
|
||||
|
@ -1,5 +1,4 @@
|
||||
import {
|
||||
AudioMimeType,
|
||||
GetFileInfo,
|
||||
GetMetaCoverURL,
|
||||
GetWebImage,
|
||||
@ -8,11 +7,10 @@ import {
|
||||
} from "./util";
|
||||
import {QmcMaskCreate58, QmcMaskDetectMflac, QmcMaskDetectMgg, QmcMaskGetDefault} from "./qmcMask";
|
||||
import {fromByteArray as Base64Encode, toByteArray as Base64Decode} from 'base64-js'
|
||||
import {GetArrayBuffer, SniffAudioExt} from "@/decrypt/utils.ts";
|
||||
import {AudioMimeType, GetArrayBuffer, SniffAudioExt} from "@/decrypt/utils.ts";
|
||||
|
||||
const MetaFlac = require('metaflac-js');
|
||||
|
||||
const ID3Writer = require("browser-id3-writer");
|
||||
|
||||
const iconv = require('iconv-lite');
|
||||
const decode = iconv.decode
|
||||
|
@ -1,16 +1,17 @@
|
||||
import {GetArrayBuffer, SniffAudioExt} from "@/decrypt/utils.ts";
|
||||
import {AudioMimeType, GetArrayBuffer, SniffAudioExt} from "@/decrypt/utils.ts";
|
||||
|
||||
const musicMetadata = require("music-metadata-browser");
|
||||
import {AudioMimeType, GetMetaCoverURL, GetFileInfo} from "./util";
|
||||
|
||||
export async function Decrypt(file, raw_filename, raw_ext, detect = true) {
|
||||
import {parseBlob as metaParseBlob} from "music-metadata-browser";
|
||||
import {GetMetaCoverURL, GetFileInfo} from "./util";
|
||||
|
||||
export async function Decrypt(file: Blob, raw_filename: string, raw_ext: string, detect: boolean = true) {
|
||||
let ext = raw_ext;
|
||||
if (detect) {
|
||||
const buffer = new Uint8Array(await GetArrayBuffer(file));
|
||||
ext = SniffAudioExt(buffer, raw_ext);
|
||||
if (ext !== raw_ext) file = new Blob([buffer], {type: AudioMimeType[ext]})
|
||||
}
|
||||
const tag = await musicMetadata.parseBlob(file);
|
||||
const tag = await metaParseBlob(file);
|
||||
const info = GetFileInfo(tag.common.artist, tag.common.title, raw_filename);
|
||||
return {
|
||||
status: true,
|
@ -1,13 +1,6 @@
|
||||
const ID3Writer = require("browser-id3-writer");
|
||||
|
||||
export const AudioMimeType = {
|
||||
mp3: "audio/mpeg",
|
||||
flac: "audio/flac",
|
||||
m4a: "audio/mp4",
|
||||
ogg: "audio/ogg",
|
||||
wma: "audio/x-ms-wma",
|
||||
wav: "audio/x-wav"
|
||||
};
|
||||
|
||||
export const IXAREA_API_ENDPOINT = "https://stats.ixarea.com/apis"
|
||||
|
||||
|
||||
|
@ -8,6 +8,14 @@ export const WMA_HEADER = [
|
||||
]
|
||||
export const WAV_HEADER = [0x52, 0x49, 0x46, 0x46]
|
||||
export const AAC_HEADER = [0xFF, 0xF1]
|
||||
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"
|
||||
};
|
||||
|
||||
export function BytesHasPrefix(data: Uint8Array, prefix: number[]): boolean {
|
||||
if (prefix.length > data.length) return false
|
||||
@ -24,14 +32,14 @@ export function BytesEquals(data: Uint8Array, another: Uint8Array): boolean {
|
||||
}
|
||||
|
||||
export function SniffAudioExt(data: Uint8Array, fallback_ext: string = "mp3"): string {
|
||||
if (BytesHasPrefix(data, MP3_HEADER)) return ".mp3"
|
||||
if (BytesHasPrefix(data, FLAC_HEADER)) return ".flac"
|
||||
if (BytesHasPrefix(data, OGG_HEADER)) return ".ogg"
|
||||
if (BytesHasPrefix(data, MP3_HEADER)) return "mp3"
|
||||
if (BytesHasPrefix(data, FLAC_HEADER)) return "flac"
|
||||
if (BytesHasPrefix(data, OGG_HEADER)) return "ogg"
|
||||
if (data.length >= 4 + M4A_HEADER.length &&
|
||||
BytesHasPrefix(data.slice(4), M4A_HEADER)) return ".m4a"
|
||||
if (BytesHasPrefix(data, WAV_HEADER)) return ".wav"
|
||||
if (BytesHasPrefix(data, WMA_HEADER)) return ".wma"
|
||||
if (BytesHasPrefix(data, AAC_HEADER)) return ".aac"
|
||||
BytesHasPrefix(data.slice(4), M4A_HEADER)) return "m4a"
|
||||
if (BytesHasPrefix(data, WAV_HEADER)) return "wav"
|
||||
if (BytesHasPrefix(data, WMA_HEADER)) return "wma"
|
||||
if (BytesHasPrefix(data, AAC_HEADER)) return "aac"
|
||||
return fallback_ext;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import {AudioMimeType, GetFileInfo, GetMetaCoverURL} from "./util";
|
||||
import {GetFileInfo, GetMetaCoverURL} from "./util";
|
||||
|
||||
import {Decrypt as RawDecrypt} from "./raw";
|
||||
import {BytesHasPrefix, GetArrayBuffer} from "@/decrypt/utils.ts";
|
||||
import {AudioMimeType, BytesHasPrefix, GetArrayBuffer} from "@/decrypt/utils.ts";
|
||||
|
||||
const musicMetadata = require("music-metadata-browser");
|
||||
const MagicHeader = [0x69, 0x66, 0x6D, 0x74]
|
||||
|
Loading…
Reference in New Issue
Block a user