fix(QMCv2): overflow error in js decoder

(cherry picked from commit 191ac6a932efb290f49e2824839db20ac6ff47ca)
master
MengYX 9 months ago
parent 4f7d16e2b0
commit 976077e3e1
No known key found for this signature in database
GPG Key ID: E63F9C7303E8F604
  1. 2
      src/decrypt/qmc.test.ts
  2. 8
      src/decrypt/qmc_cipher.test.ts
  3. 7
      src/decrypt/qmc_cipher.ts
  4. 2
      src/decrypt/qmc_key.test.ts
  5. 1
      testdata/mflac_rc4_key.bin
  6. 1
      testdata/mflac_rc4_key_raw.bin
  7. BIN
      testdata/mflac_rc4_raw.bin
  8. BIN
      testdata/mflac_rc4_suffix.bin
  9. BIN
      testdata/mflac_rc4_target.bin

@ -18,7 +18,7 @@ function loadTestDataDecoder(name: string): {
}
test('qmc: real file', async () => {
const cases = ['mflac0_rc4', 'mflac_map', 'mgg_map', 'qmc0_static'];
const cases = ['mflac0_rc4', 'mflac_rc4', 'mflac_map', 'mgg_map', 'qmc0_static'];
for (const name of cases) {
const { clearText, cipherText } = loadTestDataDecoder(name);
const c = new QmcDecoder(cipherText);

@ -69,7 +69,7 @@ test('map cipher: real file', async () => {
});
test('rc4 cipher: real file', async () => {
const cases = ['mflac0_rc4'];
const cases = ['mflac0_rc4', 'mflac_rc4'];
for (const name of cases) {
const { key, clearText, cipherText } = loadTestDataCipher(name);
const c = new QmcRC4Cipher(key);
@ -81,7 +81,7 @@ test('rc4 cipher: real file', async () => {
});
test('rc4 cipher: first segment', async () => {
const cases = ['mflac0_rc4'];
const cases = ['mflac0_rc4', 'mflac_rc4'];
for (const name of cases) {
const { key, clearText, cipherText } = loadTestDataCipher(name);
const c = new QmcRC4Cipher(key);
@ -93,7 +93,7 @@ test('rc4 cipher: first segment', async () => {
});
test('rc4 cipher: align block (128~5120)', async () => {
const cases = ['mflac0_rc4'];
const cases = ['mflac0_rc4', 'mflac_rc4'];
for (const name of cases) {
const { key, clearText, cipherText } = loadTestDataCipher(name);
const c = new QmcRC4Cipher(key);
@ -105,7 +105,7 @@ test('rc4 cipher: align block (128~5120)', async () => {
});
test('rc4 cipher: simple block (5120~10240)', async () => {
const cases = ['mflac0_rc4'];
const cases = ['mflac0_rc4', 'mflac_rc4'];
for (const name of cases) {
const { key, clearText, cipherText } = loadTestDataCipher(name);
const c = new QmcRC4Cipher(key);

@ -119,7 +119,7 @@ export class QmcRC4Cipher implements QmcStreamCipher {
// ignore if key char is '\x00'
if (!value) continue;
const next_hash = (this.hash * value) & 0xffffffff;
const next_hash = (this.hash * value) >>> 0;
if (next_hash == 0 || next_hash <= this.hash) break;
this.hash = next_hash;
@ -174,7 +174,8 @@ export class QmcRC4Cipher implements QmcStreamCipher {
// Calculate the number of bytes to skip.
// The initial "key" derived from segment id, plus the current offset.
const skipLen = (offset % QmcRC4Cipher.SEGMENT_SIZE) + this.getSegmentKey(offset / QmcRC4Cipher.SEGMENT_SIZE);
const skipLen =
(offset % QmcRC4Cipher.SEGMENT_SIZE) + this.getSegmentKey(Math.floor(offset / QmcRC4Cipher.SEGMENT_SIZE));
// decrypt the block
let j = 0;
@ -192,7 +193,7 @@ export class QmcRC4Cipher implements QmcStreamCipher {
private getSegmentKey(id: number): number {
const seed = this.key[id % this.N];
const idx = ((this.hash / ((id + 1) * seed)) * 100.0) | 0;
const idx = Math.floor((this.hash / ((id + 1) * seed)) * 100.0);
return idx % this.N;
}
}

@ -16,7 +16,7 @@ function loadTestDataKeyDecrypt(name: string): {
}
test('key dec: real file', async () => {
const cases = ['mflac_map', 'mgg_map', 'mflac0_rc4'];
const cases = ['mflac_map', 'mgg_map', 'mflac0_rc4', 'mflac_rc4'];
for (const name of cases) {
const { clearText, cipherText } = loadTestDataKeyDecrypt(name);
const buf = QmcDeriveKey(cipherText);

@ -0,0 +1 @@
pUtyvqr0TgAvR95mNmY7DmNl386TsJNAEIz95CEcgIgJCcs28686O7llxD5E74ldn70xMtd5cG58TA5ILw09I8BOTf5EdHKd6wwPn689DUK13y3Req6H0P33my2miJ5bQ2AA22B8vp4V0NJ3hBqNt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Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save