Compare commits

..

No commits in common. "49e0526ae933dfbf747e6f3030fa30ff9235b543" and "27bccbbd55912b8b6f1d0aa392fb3b9c239a6591" have entirely different histories.

3 changed files with 50 additions and 72 deletions

View File

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

View File

@ -1,52 +1,50 @@
import { import {
AudioMimeType, AudioMimeType,
GetArrayBuffer, GetArrayBuffer,
GetCoverFromFile, GetCoverFromFile,
GetMetaFromFile, GetMetaFromFile,
SniffAudioExt, SniffAudioExt,
SplitFilename, SplitFilename,
} from '@/decrypt/utils'; } from '@/decrypt/utils';
import { Decrypt as QmcDecrypt, HandlerMap } from '@/decrypt/qmc'; import { Decrypt as QmcDecrypt, HandlerMap } from '@/decrypt/qmc';
import { DecryptResult } from '@/decrypt/entity'; import { DecryptResult } from '@/decrypt/entity';
import { parseBlob as metaParseBlob } from 'music-metadata-browser'; import { parseBlob as metaParseBlob } from 'music-metadata-browser';
export function DecryptBuffer(buffer: Uint8Array | Buffer) { export async function Decrypt(file: Blob, raw_filename: string, _: string): Promise<DecryptResult> {
let length = buffer.byteLength; const buffer = new Uint8Array(await GetArrayBuffer(file));
for (let i = 0; i < length; i++) { let length = buffer.length;
let byte = buffer[i] ^ 0xf4; // xor 0xf4 for (let i = 0; i < length; i++) {
byte = ((byte & 0b0011_1111) << 2) | (byte >> 6); // rol 2 buffer[i] ^= 0xf4;
buffer[i] = byte; 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;
export async function Decrypt(file: Blob, raw_filename: string, _: string): Promise<DecryptResult> { }
const buffer = new Uint8Array(await GetArrayBuffer(file)); let ext = SniffAudioExt(buffer, '');
DecryptBuffer(buffer); const newName = SplitFilename(raw_filename);
let ext = SniffAudioExt(buffer, ''); let audioBlob: Blob;
const newName = SplitFilename(raw_filename); if (ext !== '' || newName.ext === 'mp3') {
let audioBlob: Blob; audioBlob = new Blob([buffer], { type: AudioMimeType[ext] });
if (ext !== '' || newName.ext === 'mp3') { } else if (newName.ext in HandlerMap) {
audioBlob = new Blob([buffer], { type: AudioMimeType[ext] }); audioBlob = new Blob([buffer], { type: 'application/octet-stream' });
} else if (newName.ext in HandlerMap) { return QmcDecrypt(audioBlob, newName.name, newName.ext);
audioBlob = new Blob([buffer], { type: 'application/octet-stream' }); } else {
return QmcDecrypt(audioBlob, newName.name, newName.ext); throw '不支持的QQ音乐缓存格式';
} else { }
throw '不支持的QQ音乐缓存格式'; const tag = await metaParseBlob(audioBlob);
} const { title, artist } = GetMetaFromFile(raw_filename, tag.common.title, tag.common.artist);
const tag = await metaParseBlob(audioBlob);
const { title, artist } = GetMetaFromFile(raw_filename, tag.common.title, tag.common.artist); return {
title,
return { artist,
title, ext,
artist, album: tag.common.album,
ext, picture: GetCoverFromFile(tag),
album: tag.common.album, file: URL.createObjectURL(audioBlob),
picture: GetCoverFromFile(tag), blob: audioBlob,
file: URL.createObjectURL(audioBlob), mime: AudioMimeType[ext],
blob: audioBlob, };
mime: AudioMimeType[ext], }
};
}