refactor: implement a more efficient buffer decryption algorithm for qmc cache.
This commit is contained in:
parent
2dff0c1f37
commit
8b2834b06a
@ -16,11 +16,9 @@ import { parseBlob as metaParseBlob } from 'music-metadata-browser';
|
||||
export function DecryptBuffer(buffer: Uint8Array | Buffer) {
|
||||
let length = buffer.byteLength;
|
||||
for (let i = 0; i < length; i++) {
|
||||
buffer[i] ^= 0xf4;
|
||||
if (buffer[i] <= 0x3f) buffer[i] = buffer[i] * 4;
|
||||
else if (buffer[i] <= 0x7f) buffer[i] = (buffer[i] - 0x40) * 4 + 1;
|
||||
else if (buffer[i] <= 0xbf) buffer[i] = (buffer[i] - 0x80) * 4 + 2;
|
||||
else buffer[i] = (buffer[i] - 0xc0) * 4 + 3;
|
||||
let byte = buffer[i] ^ 0xf4; // xor 0xf4
|
||||
byte = ((byte & 0b0011_1111) << 2) | (byte >> 6); // rol 2
|
||||
buffer[i] = byte;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user