1
0
forked from um/web

Merge remote-tracking branch 'upstream/master'

This commit is contained in:
xhacker-zzz 2022-11-24 04:40:04 +08:00
commit c2556d7cc5
3 changed files with 23 additions and 5 deletions

View 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);
});
});

Binary file not shown.

View File

@ -35,11 +35,9 @@ export async function Decrypt(file: Blob, raw_filename: string, raw_ext: string)
musicDecoded = new Uint8Array(buffer); musicDecoded = new Uint8Array(buffer);
let length = musicDecoded.length; let length = musicDecoded.length;
for (let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
musicDecoded[i] ^= 0xf4; let byte = musicDecoded[i] ^ 0xf4; // xor 0xf4
if (musicDecoded[i] <= 0x3f) musicDecoded[i] = musicDecoded[i] * 4; byte = ((byte & 0b0011_1111) << 2) | (byte >> 6); // rol 2
else if (musicDecoded[i] <= 0x7f) musicDecoded[i] = (musicDecoded[i] - 0x40) * 4 + 1; musicDecoded[i] = byte;
else if (musicDecoded[i] <= 0xbf) musicDecoded[i] = (musicDecoded[i] - 0x80) * 4 + 2;
else musicDecoded[i] = (musicDecoded[i] - 0xc0) * 4 + 3;
} }
} }
let ext = SniffAudioExt(musicDecoded, ''); let ext = SniffAudioExt(musicDecoded, '');