String array improvement: fixed bugs

This commit is contained in:
sanex
2020-12-28 21:39:54 +03:00
parent cec4b3525a
commit 3b8af4b29a
20 changed files with 224 additions and 115 deletions
@@ -10,7 +10,7 @@ import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscatorFacade
describe('StringArrayRotateFunctionCodeHelper', () => {
describe('Base behaviour', () => {
const regExp: RegExp = /while *\(-- *_0x([a-f0-9]){4,6}\) *\{/;
const regExp: RegExp = /while *\(!!\[]\) *\{/;
describe('`stringArray` option is set', () => {
let obfuscatedCode: string;
@@ -58,8 +58,8 @@ describe('StringArrayRotateFunctionCodeHelper', () => {
});
describe('Preserve string array name', () => {
const rotateLogicRegExp: RegExp = /b\['push']\(b\['shift']\(\)\);/;
const incrementRegExp: RegExp = /f\(\+\+e\);/;
const arrayRotateRegExp: RegExp = /c\['push']\(c\['shift']\(\)\);/;
const comparisonRegExp: RegExp = /if *\(e *=== *d\) *{/;
let obfuscatedCode: string;
@@ -79,11 +79,11 @@ describe('StringArrayRotateFunctionCodeHelper', () => {
});
it('should preserve string array name', () => {
assert.match(obfuscatedCode, rotateLogicRegExp);
assert.match(obfuscatedCode, arrayRotateRegExp);
});
it('generate valid identifier names', () => {
assert.match(obfuscatedCode, incrementRegExp);
assert.match(obfuscatedCode, comparisonRegExp);
});
});
});
@@ -13,7 +13,7 @@ describe('StringArrayRotateFunctionTemplate', () => {
describe('Prevailing kind of variables', () => {
describe('`var` kind', () => {
let obfuscatedCode: string,
stringArrayRotateFunctionRegExp: RegExp = /function\(_0x([a-f0-9]){4,6}, *_0x([a-f0-9]){4,6}\){var _0x([a-f0-9]){4,6} *= *function/;
stringArrayRotateFunctionTryCatchRegExp: RegExp = /try *{var *_0x([a-f0-9]){4,6}/;
beforeEach(() => {
const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-var.js');
@@ -31,7 +31,7 @@ describe('StringArrayRotateFunctionTemplate', () => {
});
it('Should return correct kind of variables for string array rotate function', () => {
assert.match(obfuscatedCode, stringArrayRotateFunctionRegExp);
assert.match(obfuscatedCode, stringArrayRotateFunctionTryCatchRegExp);
});
it('Should does not break on obfuscating', () => {
@@ -41,7 +41,7 @@ describe('StringArrayRotateFunctionTemplate', () => {
describe('`const` kind', () => {
let obfuscatedCode: string,
stringArrayRotateFunctionRegExp: RegExp = /function\(_0x([a-f0-9]){4,6}, *_0x([a-f0-9]){4,6}\){const _0x([a-f0-9]){4,6} *= *function/;
stringArrayRotateFunctionTryCatchRegExp: RegExp = /try *{const *_0x([a-f0-9]){4,6}/;
beforeEach(() => {
const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-const.js');
@@ -59,7 +59,7 @@ describe('StringArrayRotateFunctionTemplate', () => {
});
it('Should return correct kind of variables for string array rotate function', () => {
assert.match(obfuscatedCode, stringArrayRotateFunctionRegExp);
assert.match(obfuscatedCode, stringArrayRotateFunctionTryCatchRegExp);
});
it('Should does not break on obfuscating', () => {
@@ -69,7 +69,7 @@ describe('StringArrayRotateFunctionTemplate', () => {
describe('`let` kind', () => {
let obfuscatedCode: string,
stringArrayRotateFunctionRegExp: RegExp = /function\(_0x([a-f0-9]){4,6}, *_0x([a-f0-9]){4,6}\){const _0x([a-f0-9]){4,6} *= *function/;
stringArrayRotateFunctionTryCatchRegExp: RegExp = /try *{const *_0x([a-f0-9]){4,6}/;
beforeEach(() => {
const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-let.js');
@@ -87,7 +87,7 @@ describe('StringArrayRotateFunctionTemplate', () => {
});
it('Should return correct kind of variables for string array rotate function', () => {
assert.match(obfuscatedCode, stringArrayRotateFunctionRegExp);
assert.match(obfuscatedCode, stringArrayRotateFunctionTryCatchRegExp);
});
it('Should does not break on obfuscating', () => {