web/src/decrypt/qmc.test.ts

30 lines
960 B
TypeScript
Raw Normal View History

2021-12-18 13:55:31 +00:00
import fs from 'fs';
import { QmcDecoder } from '@/decrypt/qmc';
import { BytesEqual } from '@/decrypt/utils';
2021-12-16 22:07:43 +00:00
function loadTestDataDecoder(name: string): {
2021-12-18 13:55:31 +00:00
cipherText: Uint8Array;
clearText: Uint8Array;
2021-12-16 22:07:43 +00:00
} {
const cipherBody = fs.readFileSync(`./testdata/${name}_raw.bin`);
const cipherSuffix = fs.readFileSync(`./testdata/${name}_suffix.bin`);
const cipherText = new Uint8Array(cipherBody.length + cipherSuffix.length);
cipherText.set(cipherBody);
cipherText.set(cipherSuffix, cipherBody.length);
return {
cipherText,
2021-12-18 13:55:31 +00:00
clearText: fs.readFileSync(`testdata/${name}_target.bin`),
};
2021-12-16 22:07:43 +00:00
}
2021-12-18 13:55:31 +00:00
test('qmc: real file', async () => {
const cases = ['mflac0_rc4', 'mflac_rc4', 'mflac_map', 'mgg_map', 'qmc0_static'];
2021-12-16 22:07:43 +00:00
for (const name of cases) {
2021-12-18 13:55:31 +00:00
const { clearText, cipherText } = loadTestDataDecoder(name);
const c = new QmcDecoder(cipherText);
const buf = c.decrypt();
2021-12-16 22:07:43 +00:00
2021-12-18 13:55:31 +00:00
expect(BytesEqual(buf, clearText)).toBeTruthy();
2021-12-16 22:07:43 +00:00
}
2021-12-18 13:55:31 +00:00
});