mirror of
https://git.um-react.app/um/um-react.git
synced 2025-11-28 11:33:02 +00:00
feat(kgm): kgm v5 (aka. kgg) support
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
import { DecipherInstance, DecipherOK, DecipherResult, Status } from '~/decrypt-worker/Deciphers';
|
||||
import { KuGou } from '@unlock-music/crypto';
|
||||
import { KuGou, KuGouHeader } from '@unlock-music/crypto';
|
||||
import type { DecryptCommandOptions } from '~/decrypt-worker/types.ts';
|
||||
import { chunkBuffer } from '~/decrypt-worker/util/buffer.ts';
|
||||
|
||||
export class KugouMusicDecipher implements DecipherInstance {
|
||||
cipherName = 'Kugou';
|
||||
|
||||
async decrypt(buffer: Uint8Array, _options: DecryptCommandOptions): Promise<DecipherResult | DecipherOK> {
|
||||
async decrypt(buffer: Uint8Array, options: DecryptCommandOptions): Promise<DecipherResult | DecipherOK> {
|
||||
let kgm: KuGou | undefined;
|
||||
let kgmHdr: KuGouHeader | undefined;
|
||||
|
||||
try {
|
||||
kgm = KuGou.from_header(buffer.subarray(0, 0x400));
|
||||
kgmHdr = new KuGouHeader(buffer.subarray(0, 0x400));
|
||||
kgm = KuGou.fromHeaderV5(kgmHdr, options.kugouKey);
|
||||
|
||||
const audioBuffer = new Uint8Array(buffer.subarray(0x400));
|
||||
for (const [block, offset] of chunkBuffer(audioBuffer)) {
|
||||
@@ -23,6 +25,7 @@ export class KugouMusicDecipher implements DecipherInstance {
|
||||
data: audioBuffer,
|
||||
};
|
||||
} finally {
|
||||
kgmHdr?.free();
|
||||
kgm?.free();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user