test: added test cases for qmc cache.
This commit is contained in:
parent
97cd7afc44
commit
c3b75c8fea
20
src/decrypt/__test__/QmcCache.test.ts
Normal file
20
src/decrypt/__test__/QmcCache.test.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { DecryptBuffer as DecryptQmcCacheBuffer } from '../qmccache';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
|
const expectedBuffer = fs.readFileSync(__dirname + '/fixture/qmc_cache_expected.bin');
|
||||||
|
|
||||||
|
const createInputBuffer = () => {
|
||||||
|
const buffer = Buffer.alloc(256);
|
||||||
|
for (let i = buffer.byteLength; i >= 0; i--) {
|
||||||
|
buffer[i] = i;
|
||||||
|
}
|
||||||
|
return buffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('decrypt/qmccache', () => {
|
||||||
|
it('should decrypt specified buffer correctly', () => {
|
||||||
|
const input = createInputBuffer();
|
||||||
|
DecryptQmcCacheBuffer(input);
|
||||||
|
expect(input).toEqual(expectedBuffer);
|
||||||
|
});
|
||||||
|
});
|
BIN
src/decrypt/__test__/fixture/qmc_cache_expected.bin
Normal file
BIN
src/decrypt/__test__/fixture/qmc_cache_expected.bin
Normal file
Binary file not shown.
@ -13,9 +13,8 @@ import { DecryptResult } from '@/decrypt/entity';
|
|||||||
|
|
||||||
import { parseBlob as metaParseBlob } from 'music-metadata-browser';
|
import { parseBlob as metaParseBlob } from 'music-metadata-browser';
|
||||||
|
|
||||||
export async function Decrypt(file: Blob, raw_filename: string, _: string): Promise<DecryptResult> {
|
export function DecryptBuffer(buffer: Uint8Array | Buffer) {
|
||||||
const buffer = new Uint8Array(await GetArrayBuffer(file));
|
let length = buffer.byteLength;
|
||||||
let length = buffer.length;
|
|
||||||
for (let i = 0; i < length; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
buffer[i] ^= 0xf4;
|
buffer[i] ^= 0xf4;
|
||||||
if (buffer[i] <= 0x3f) buffer[i] = buffer[i] * 4;
|
if (buffer[i] <= 0x3f) buffer[i] = buffer[i] * 4;
|
||||||
@ -23,6 +22,11 @@ export async function Decrypt(file: Blob, raw_filename: string, _: string): Prom
|
|||||||
else if (buffer[i] <= 0xbf) buffer[i] = (buffer[i] - 0x80) * 4 + 2;
|
else if (buffer[i] <= 0xbf) buffer[i] = (buffer[i] - 0x80) * 4 + 2;
|
||||||
else buffer[i] = (buffer[i] - 0xc0) * 4 + 3;
|
else buffer[i] = (buffer[i] - 0xc0) * 4 + 3;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function Decrypt(file: Blob, raw_filename: string, _: string): Promise<DecryptResult> {
|
||||||
|
const buffer = new Uint8Array(await GetArrayBuffer(file));
|
||||||
|
DecryptBuffer(buffer);
|
||||||
let ext = SniffAudioExt(buffer, '');
|
let ext = SniffAudioExt(buffer, '');
|
||||||
const newName = SplitFilename(raw_filename);
|
const newName = SplitFilename(raw_filename);
|
||||||
let audioBlob: Blob;
|
let audioBlob: Blob;
|
||||||
|
Loading…
Reference in New Issue
Block a user