forked from um/web
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
c2556d7cc5
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.
@ -35,11 +35,9 @@ export async function Decrypt(file: Blob, raw_filename: string, raw_ext: string)
|
||||
musicDecoded = new Uint8Array(buffer);
|
||||
let length = musicDecoded.length;
|
||||
for (let i = 0; i < length; i++) {
|
||||
musicDecoded[i] ^= 0xf4;
|
||||
if (musicDecoded[i] <= 0x3f) musicDecoded[i] = musicDecoded[i] * 4;
|
||||
else if (musicDecoded[i] <= 0x7f) musicDecoded[i] = (musicDecoded[i] - 0x40) * 4 + 1;
|
||||
else if (musicDecoded[i] <= 0xbf) musicDecoded[i] = (musicDecoded[i] - 0x80) * 4 + 2;
|
||||
else musicDecoded[i] = (musicDecoded[i] - 0xc0) * 4 + 3;
|
||||
let byte = musicDecoded[i] ^ 0xf4; // xor 0xf4
|
||||
byte = ((byte & 0b0011_1111) << 2) | (byte >> 6); // rol 2
|
||||
musicDecoded[i] = byte;
|
||||
}
|
||||
}
|
||||
let ext = SniffAudioExt(musicDecoded, '');
|
||||
|
Loading…
Reference in New Issue
Block a user