From 73bad51e8e2afb025b97b1543f8b11a8dc387469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Wed, 18 Sep 2024 22:05:05 +0100 Subject: [PATCH] refactor: simplify kgm decipher --- src/decrypt-worker/decipher/KugouMusic.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/decrypt-worker/decipher/KugouMusic.ts b/src/decrypt-worker/decipher/KugouMusic.ts index 1f1fc3f..567975f 100644 --- a/src/decrypt-worker/decipher/KugouMusic.ts +++ b/src/decrypt-worker/decipher/KugouMusic.ts @@ -1,5 +1,5 @@ import { DecipherInstance, DecipherOK, DecipherResult, Status } from '~/decrypt-worker/Deciphers'; -import { KuGouDecipher, KuGouHeader } from '@unlock-music/crypto'; +import { KuGou } from '@unlock-music/crypto'; import type { DecryptCommandOptions } from '~/decrypt-worker/types.ts'; import { chunkBuffer } from '~/decrypt-worker/util/buffer.ts'; @@ -7,12 +7,10 @@ export class KugouMusicDecipher implements DecipherInstance { cipherName = 'Kugou'; async decrypt(buffer: Uint8Array, _options: DecryptCommandOptions): Promise { - let kgm: KuGouDecipher | undefined; - let header: KuGouHeader | undefined; + let kgm: KuGou | undefined; try { - header = KuGouHeader.parse(buffer.subarray(0, 0x400)); - kgm = new KuGouDecipher(header); + kgm = KuGou.from_header(buffer.subarray(0, 0x400)); const audioBuffer = new Uint8Array(buffer.subarray(0x400)); for (const [block, offset] of chunkBuffer(audioBuffer)) { @@ -26,7 +24,6 @@ export class KugouMusicDecipher implements DecipherInstance { }; } finally { kgm?.free(); - header?.free(); } }