mirror of
https://git.um-react.app/um/um-react.git
synced 2025-11-28 03:23:02 +00:00
feat: added support for ncm (#15)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { CryptoFactory } from './CryptoBase';
|
||||
import { NCMCrypto } from './ncm/ncm_pc';
|
||||
|
||||
import { QMC1Crypto } from './qmc/qmc_v1';
|
||||
import { QMC2Crypto } from './qmc/qmc_v2';
|
||||
@@ -12,6 +13,9 @@ export const allCryptoFactories: CryptoFactory[] = [
|
||||
// QMCv2 (*.mflac)
|
||||
QMC2Crypto.make,
|
||||
|
||||
// NCM (*.ncm)
|
||||
NCMCrypto.make,
|
||||
|
||||
// Crypto that does not implement "checkBySignature" or need to decrypt the entire file and then check audio type,
|
||||
// should be moved to the bottom of the list for performance reasons.
|
||||
|
||||
|
||||
2
src/decrypt-worker/crypto/ncm/ncm_pc.key.ts
Normal file
2
src/decrypt-worker/crypto/ncm/ncm_pc.key.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export const NCM_KEY = 'hzHRAmso5kInbaxW';
|
||||
export const NCM_MAGIC_HEADER = new Uint8Array([0x43, 0x54, 0x45, 0x4e, 0x46, 0x44, 0x41, 0x4d]);
|
||||
21
src/decrypt-worker/crypto/ncm/ncm_pc.ts
Normal file
21
src/decrypt-worker/crypto/ncm/ncm_pc.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { transformBlob } from '~/decrypt-worker/util/transformBlob';
|
||||
import type { CryptoBase } from '../CryptoBase';
|
||||
import { NCM_KEY, NCM_MAGIC_HEADER } from './ncm_pc.key';
|
||||
|
||||
export class NCMCrypto implements CryptoBase {
|
||||
cryptoName = 'NCM/PC';
|
||||
checkByDecryptHeader = false;
|
||||
|
||||
async checkBySignature(buffer: ArrayBuffer) {
|
||||
const view = new DataView(buffer, 0, NCM_MAGIC_HEADER.byteLength);
|
||||
return NCM_MAGIC_HEADER.every((value, i) => value === view.getUint8(i));
|
||||
}
|
||||
|
||||
async decrypt(buffer: ArrayBuffer): Promise<Blob> {
|
||||
return transformBlob(buffer, (p) => p.make.NeteaseNCM(NCM_KEY));
|
||||
}
|
||||
|
||||
public static make() {
|
||||
return new NCMCrypto();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user