Browse Source

refactor: implement a more efficient buffer decryption algorithm for qmc cache.

20230320
Jixun Wu 2 years ago
parent
commit
8b2834b06a
  1. 8
      src/decrypt/qmccache.ts

8
src/decrypt/qmccache.ts

@ -16,11 +16,9 @@ import { parseBlob as metaParseBlob } from 'music-metadata-browser';
export function DecryptBuffer(buffer: Uint8Array | Buffer) { export function DecryptBuffer(buffer: Uint8Array | Buffer) {
let length = buffer.byteLength; let length = buffer.byteLength;
for (let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
buffer[i] ^= 0xf4; let byte = buffer[i] ^ 0xf4; // xor 0xf4
if (buffer[i] <= 0x3f) buffer[i] = buffer[i] * 4; byte = ((byte & 0b0011_1111) << 2) | (byte >> 6); // rol 2
else if (buffer[i] <= 0x7f) buffer[i] = (buffer[i] - 0x40) * 4 + 1; buffer[i] = byte;
else if (buffer[i] <= 0xbf) buffer[i] = (buffer[i] - 0x80) * 4 + 2;
else buffer[i] = (buffer[i] - 0xc0) * 4 + 3;
} }
} }

Loading…
Cancel
Save