Compare commits
No commits in common. "49e0526ae933dfbf747e6f3030fa30ff9235b543" and "27bccbbd55912b8b6f1d0aa392fb3b9c239a6591" have entirely different histories.
49e0526ae9
...
27bccbbd55
@ -1,20 +0,0 @@
|
||||
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.
@ -13,18 +13,16 @@ import { DecryptResult } from '@/decrypt/entity';
|
||||
|
||||
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++) {
|
||||
let byte = buffer[i] ^ 0xf4; // xor 0xf4
|
||||
byte = ((byte & 0b0011_1111) << 2) | (byte >> 6); // rol 2
|
||||
buffer[i] = byte;
|
||||
}
|
||||
}
|
||||
|
||||
export async function Decrypt(file: Blob, raw_filename: string, _: string): Promise<DecryptResult> {
|
||||
const buffer = new Uint8Array(await GetArrayBuffer(file));
|
||||
DecryptBuffer(buffer);
|
||||
let length = buffer.length;
|
||||
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 ext = SniffAudioExt(buffer, '');
|
||||
const newName = SplitFilename(raw_filename);
|
||||
let audioBlob: Blob;
|
||||
|
Loading…
Reference in New Issue
Block a user