Browse Source

Merge remote-tracking branch 'upstream/master'

20230320
xhacker-zzz 2 years ago
parent
commit
b63683781c
  1. 20
      src/decrypt/__test__/QmcCache.test.ts
  2. BIN
      src/decrypt/__test__/fixture/qmc_cache_expected.bin
  3. 8
      src/decrypt/qmccache.ts

20
src/decrypt/__test__/QmcCache.test.ts

@ -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

Binary file not shown.

8
src/decrypt/qmccache.ts

@ -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…
Cancel
Save