|
@@ -63,28 +63,7 @@ describe('StringArrayTransformer', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('Variant #3: string contains non-latin and non-digit characters and `unicodeEscapeSequence` is disabled', () => {
|
|
|
- let testFunc: () => void;
|
|
|
-
|
|
|
- before(() => {
|
|
|
- const code: string = readFileAsString(__dirname + '/fixtures/error-when-non-latin.js');
|
|
|
-
|
|
|
- testFunc = () => JavaScriptObfuscator.obfuscate(
|
|
|
- code,
|
|
|
- {
|
|
|
- ...NO_ADDITIONAL_NODES_PRESET,
|
|
|
- stringArray: true,
|
|
|
- stringArrayThreshold: 1
|
|
|
- }
|
|
|
- );
|
|
|
- });
|
|
|
-
|
|
|
- it('should\'t throw an error', () => {
|
|
|
- assert.doesNotThrow(testFunc);
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- describe('Variant #4: same literal node values', () => {
|
|
|
+ describe('Variant #3: same literal node values', () => {
|
|
|
const stringArrayRegExp: RegExp = /^var _0x([a-f0-9]){4} *= *\['test'\];/;
|
|
|
const stringArrayCallRegExp: RegExp = /var test *= *_0x([a-f0-9]){4}\('0x0'\);/;
|
|
|
|
|
@@ -112,59 +91,7 @@ describe('StringArrayTransformer', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('Variant #5: `unicodeEscapeSequence` option is enabled', () => {
|
|
|
- const regExp: RegExp = /^var test *= *'\\x74\\x65\\x73\\x74';$/;
|
|
|
-
|
|
|
- let obfuscatedCode: string;
|
|
|
-
|
|
|
- before(() => {
|
|
|
- const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js');
|
|
|
-
|
|
|
- obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
|
|
- code,
|
|
|
- {
|
|
|
- ...NO_ADDITIONAL_NODES_PRESET,
|
|
|
- unicodeEscapeSequence: true
|
|
|
-
|
|
|
- }
|
|
|
- ).getObfuscatedCode();
|
|
|
- });
|
|
|
-
|
|
|
- it('should replace literal node value with unicode escape sequence', () => {
|
|
|
- assert.match(obfuscatedCode, regExp);
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- describe('Variant #6: `unicodeEscapeSequence` and `stringArray` options are enabled', () => {
|
|
|
- const stringArrayRegExp: RegExp = /^var _0x([a-f0-9]){4} *= *\['\\x74\\x65\\x73\\x74'\];/;
|
|
|
- const stringArrayCallRegExp: RegExp = /var test *= *_0x([a-f0-9]){4}\('\\x30\\x78\\x30'\);/;
|
|
|
-
|
|
|
- let obfuscatedCode: string;
|
|
|
-
|
|
|
- before(() => {
|
|
|
- const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js');
|
|
|
-
|
|
|
- obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
|
|
- code,
|
|
|
- {
|
|
|
- ...NO_ADDITIONAL_NODES_PRESET,
|
|
|
- stringArray: true,
|
|
|
- stringArrayThreshold: 1,
|
|
|
- unicodeEscapeSequence: true
|
|
|
- }
|
|
|
- ).getObfuscatedCode();
|
|
|
- });
|
|
|
-
|
|
|
- it('match #1: should replace literal node value with unicode escape sequence from string array', () => {
|
|
|
- assert.match(obfuscatedCode, stringArrayRegExp);
|
|
|
- });
|
|
|
-
|
|
|
- it('match #2: should replace literal node value with unicode escape sequence from string array', () => {
|
|
|
- assert.match(obfuscatedCode, stringArrayCallRegExp);
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- describe('Variant #7: short literal node value', () => {
|
|
|
+ describe('Variant #4: short literal node value', () => {
|
|
|
const regExp: RegExp = /var test *= *'te';/;
|
|
|
|
|
|
let obfuscatedCode: string;
|
|
@@ -187,7 +114,7 @@ describe('StringArrayTransformer', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('Variant #8: base64 encoding', () => {
|
|
|
+ describe('Variant #5: base64 encoding', () => {
|
|
|
const stringArrayRegExp: RegExp = new RegExp(`^var _0x([a-f0-9]){4} *= *\\['${swapLettersCase('dGVzdA==')}'];`);
|
|
|
const stringArrayCallRegExp: RegExp = /var test *= *_0x([a-f0-9]){4}\('0x0'\);/;
|
|
|
|
|
@@ -216,7 +143,7 @@ describe('StringArrayTransformer', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('Variant #9: rc4 encoding', () => {
|
|
|
+ describe('Variant #6: rc4 encoding', () => {
|
|
|
describe('Variant #1: single string literal', () => {
|
|
|
const regExp: RegExp = /var test *= *_0x([a-f0-9]){4}\('0x0', *'.{4}'\);/;
|
|
|
|
|
@@ -282,7 +209,7 @@ describe('StringArrayTransformer', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('Variant #10: none and base64 encoding', () => {
|
|
|
+ describe('Variant #7: none and base64 encoding', () => {
|
|
|
describe('Variant #1: string array values', () => {
|
|
|
const samplesCount: number = 300;
|
|
|
const expectedMatchesChance: number = 0.5;
|
|
@@ -338,7 +265,7 @@ describe('StringArrayTransformer', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('Variant #11: none and rc4 encoding', () => {
|
|
|
+ describe('Variant #8: none and rc4 encoding', () => {
|
|
|
describe('Variant #1: string array calls wrapper call', () => {
|
|
|
const samplesCount: number = 300;
|
|
|
const expectedMatchesChance: number = 0.5;
|
|
@@ -394,7 +321,7 @@ describe('StringArrayTransformer', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('Variant #12: base64 and rc4 encoding', () => {
|
|
|
+ describe('Variant #9: base64 and rc4 encoding', () => {
|
|
|
describe('Variant #1: single string literal', () => {
|
|
|
const samplesCount: number = 300;
|
|
|
const expectedMatchesChance: number = 0.5;
|
|
@@ -450,7 +377,7 @@ describe('StringArrayTransformer', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('Variant #13: `stringArrayThreshold` option value', () => {
|
|
|
+ describe('Variant #10: `stringArrayThreshold` option value', () => {
|
|
|
const samples: number = 1000;
|
|
|
const stringArrayThreshold: number = 0.5;
|
|
|
const delta: number = 0.1;
|
|
@@ -493,7 +420,7 @@ describe('StringArrayTransformer', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('Variant #14: string array calls wrapper name', () => {
|
|
|
+ describe('Variant #11: string array calls wrapper name', () => {
|
|
|
const regExp: RegExp = /console\[b\('0x0'\)]\('a'\);/;
|
|
|
|
|
|
let obfuscatedCode: string;
|
|
@@ -517,7 +444,7 @@ describe('StringArrayTransformer', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('Variant #15: `reservedStrings` option is enabled', () => {
|
|
|
+ describe('Variant #12: `reservedStrings` option is enabled', () => {
|
|
|
describe('Variant #1: base `reservedStrings` values', () => {
|
|
|
describe('Variant #1: single reserved string value', () => {
|
|
|
const stringLiteralRegExp1: RegExp = /const foo *= *'foo';/;
|
|
@@ -526,7 +453,7 @@ describe('StringArrayTransformer', function () {
|
|
|
let obfuscatedCode: string;
|
|
|
|
|
|
before(() => {
|
|
|
- const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option-1.js');
|
|
|
+ const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option.js');
|
|
|
|
|
|
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
|
|
code,
|
|
@@ -555,7 +482,7 @@ describe('StringArrayTransformer', function () {
|
|
|
let obfuscatedCode: string;
|
|
|
|
|
|
before(() => {
|
|
|
- const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option-1.js');
|
|
|
+ const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option.js');
|
|
|
|
|
|
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
|
|
code,
|
|
@@ -586,7 +513,7 @@ describe('StringArrayTransformer', function () {
|
|
|
let obfuscatedCode: string;
|
|
|
|
|
|
before(() => {
|
|
|
- const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option-1.js');
|
|
|
+ const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option.js');
|
|
|
|
|
|
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
|
|
code,
|
|
@@ -615,7 +542,7 @@ describe('StringArrayTransformer', function () {
|
|
|
let obfuscatedCode: string;
|
|
|
|
|
|
before(() => {
|
|
|
- const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option-1.js');
|
|
|
+ const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option.js');
|
|
|
|
|
|
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
|
|
code,
|
|
@@ -637,59 +564,9 @@ describe('StringArrayTransformer', function () {
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
-
|
|
|
- describe('Variant #3: `unicodeEscapeSequence` option is enabled', () => {
|
|
|
- const stringLiteralRegExp1: RegExp = /const foo *= *'foo';/;
|
|
|
- const stringLiteralRegExp2: RegExp = /const bar *= *'\\x62\\x61\\x72';/;
|
|
|
-
|
|
|
- let obfuscatedCode: string;
|
|
|
-
|
|
|
- before(() => {
|
|
|
- const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option-1.js');
|
|
|
-
|
|
|
- obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
|
|
- code,
|
|
|
- {
|
|
|
- ...NO_ADDITIONAL_NODES_PRESET,
|
|
|
- reservedStrings: ['foo'],
|
|
|
- unicodeEscapeSequence: true
|
|
|
- }
|
|
|
- ).getObfuscatedCode();
|
|
|
- });
|
|
|
-
|
|
|
- it('match #1: should ignore reserved strings', () => {
|
|
|
- assert.match(obfuscatedCode, stringLiteralRegExp1);
|
|
|
- });
|
|
|
-
|
|
|
- it('match #2: should transform non-reserved strings', () => {
|
|
|
- assert.match(obfuscatedCode, stringLiteralRegExp2);
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- describe('Variant #4: correct escape of special characters', () => {
|
|
|
- const stringLiteralRegExp: RegExp = /var baz *= *'Cannot find module \\'' *\+ *foo *\+ *'\\x27';/;
|
|
|
-
|
|
|
- let obfuscatedCode: string;
|
|
|
-
|
|
|
- before(() => {
|
|
|
- const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option-2.js');
|
|
|
-
|
|
|
- obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
|
|
- code,
|
|
|
- {
|
|
|
- ...NO_ADDITIONAL_NODES_PRESET,
|
|
|
- reservedStrings: ['a']
|
|
|
- }
|
|
|
- ).getObfuscatedCode();
|
|
|
- });
|
|
|
-
|
|
|
- it('match #1: should ignore reserved strings', () => {
|
|
|
- assert.match(obfuscatedCode, stringLiteralRegExp);
|
|
|
- });
|
|
|
- });
|
|
|
});
|
|
|
|
|
|
- describe('Variant #16: `forceTransformedStrings` option is enabled', () => {
|
|
|
+ describe('Variant #13: `forceTransformedStrings` option is enabled', () => {
|
|
|
describe('Variant #1: base `forceTransformedStrings` values', () => {
|
|
|
describe('Variant #1: single force transformed string value', () => {
|
|
|
const stringLiteralRegExp1: RegExp = /const foo *= *'foo';/;
|
|
@@ -698,7 +575,7 @@ describe('StringArrayTransformer', function () {
|
|
|
let obfuscatedCode: string;
|
|
|
|
|
|
before(() => {
|
|
|
- const code: string = readFileAsString(__dirname + '/fixtures/force-transformed-strings-option-1.js');
|
|
|
+ const code: string = readFileAsString(__dirname + '/fixtures/force-transformed-strings-option.js');
|
|
|
|
|
|
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
|
|
code,
|
|
@@ -727,7 +604,7 @@ describe('StringArrayTransformer', function () {
|
|
|
let obfuscatedCode: string;
|
|
|
|
|
|
before(() => {
|
|
|
- const code: string = readFileAsString(__dirname + '/fixtures/force-transformed-strings-option-1.js');
|
|
|
+ const code: string = readFileAsString(__dirname + '/fixtures/force-transformed-strings-option.js');
|
|
|
|
|
|
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
|
|
code,
|
|
@@ -758,7 +635,7 @@ describe('StringArrayTransformer', function () {
|
|
|
let obfuscatedCode: string;
|
|
|
|
|
|
before(() => {
|
|
|
- const code: string = readFileAsString(__dirname + '/fixtures/force-transformed-strings-option-1.js');
|
|
|
+ const code: string = readFileAsString(__dirname + '/fixtures/force-transformed-strings-option.js');
|
|
|
|
|
|
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
|
|
code,
|
|
@@ -787,7 +664,7 @@ describe('StringArrayTransformer', function () {
|
|
|
let obfuscatedCode: string;
|
|
|
|
|
|
before(() => {
|
|
|
- const code: string = readFileAsString(__dirname + '/fixtures/force-transformed-strings-option-1.js');
|
|
|
+ const code: string = readFileAsString(__dirname + '/fixtures/force-transformed-strings-option.js');
|
|
|
|
|
|
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
|
|
code,
|
|
@@ -810,35 +687,7 @@ describe('StringArrayTransformer', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('Variant #3: `unicodeEscapeSequence` option is disabled', () => {
|
|
|
- const stringLiteralRegExp1: RegExp = /const foo *= *'foo';/;
|
|
|
- const stringLiteralRegExp2: RegExp = /const bar *= *'bar';/;
|
|
|
-
|
|
|
- let obfuscatedCode: string;
|
|
|
-
|
|
|
- before(() => {
|
|
|
- const code: string = readFileAsString(__dirname + '/fixtures/force-transformed-strings-option-1.js');
|
|
|
-
|
|
|
- obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
|
|
- code,
|
|
|
- {
|
|
|
- ...NO_ADDITIONAL_NODES_PRESET,
|
|
|
- forceTransformedStrings: ['bar'],
|
|
|
- unicodeEscapeSequence: false
|
|
|
- }
|
|
|
- ).getObfuscatedCode();
|
|
|
- });
|
|
|
-
|
|
|
- it('match #1: should not encode force transformed string with unicode escape sequence', () => {
|
|
|
- assert.match(obfuscatedCode, stringLiteralRegExp1);
|
|
|
- });
|
|
|
-
|
|
|
- it('match #2: should not encode force transformed string with unicode escape sequence', () => {
|
|
|
- assert.match(obfuscatedCode, stringLiteralRegExp2);
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- describe('Variant #4: `stringArray` option is disabled', () => {
|
|
|
+ describe('Variant #3: `stringArray` option is disabled', () => {
|
|
|
describe('Variant #1: base case', () => {
|
|
|
const stringLiteralRegExp1: RegExp = /const foo *= *'foo';/;
|
|
|
const stringLiteralRegExp2: RegExp = /const bar *= *'bar';/;
|
|
@@ -846,7 +695,7 @@ describe('StringArrayTransformer', function () {
|
|
|
let obfuscatedCode: string;
|
|
|
|
|
|
before(() => {
|
|
|
- const code: string = readFileAsString(__dirname + '/fixtures/force-transformed-strings-option-1.js');
|
|
|
+ const code: string = readFileAsString(__dirname + '/fixtures/force-transformed-strings-option.js');
|
|
|
|
|
|
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
|
|
code,
|
|
@@ -870,7 +719,7 @@ describe('StringArrayTransformer', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('Variant #17: object expression key literal', () => {
|
|
|
+ describe('Variant #14: object expression key literal', () => {
|
|
|
describe('Variant #1: base key literal', () => {
|
|
|
const stringArrayRegExp: RegExp = /^var _0x([a-f0-9]){4} *= *\['bar'];/;
|
|
|
const objectExpressionRegExp: RegExp = /var test *= *{'foo' *: *_0x([a-f0-9]){4}\('0x0'\)};/;
|
|
@@ -928,7 +777,7 @@ describe('StringArrayTransformer', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('Variant #18: import declaration source literal', () => {
|
|
|
+ describe('Variant #15: import declaration source literal', () => {
|
|
|
const importDeclarationRegExp: RegExp = /import *{ *bar *} *from *'foo';/;
|
|
|
|
|
|
let obfuscatedCode: string;
|
|
@@ -951,7 +800,7 @@ describe('StringArrayTransformer', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('Variant #19: export all declaration source literal', () => {
|
|
|
+ describe('Variant #16: export all declaration source literal', () => {
|
|
|
const exportAllDeclarationRegExp: RegExp = /export *\* *from *'foo';/;
|
|
|
|
|
|
let obfuscatedCode: string;
|
|
@@ -974,7 +823,7 @@ describe('StringArrayTransformer', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('Variant #20: export named declaration source literal', () => {
|
|
|
+ describe('Variant #17: export named declaration source literal', () => {
|
|
|
const exportNamedDeclarationRegExp: RegExp = /export *{ *bar *} *from *'foo';/;
|
|
|
|
|
|
let obfuscatedCode: string;
|