Merge branch 'master' into rotate-string-array-improvements

# Conflicts:
#	dist/index.browser.js
#	dist/index.cli.js
#	dist/index.js
This commit is contained in:
sanex
2020-12-30 10:46:57 +03:00
13 changed files with 158 additions and 48 deletions
@@ -9,7 +9,7 @@ import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFac
describe('DirectivePlacementTransformer', function () {
this.timeout(120000);
describe('Program lexical scope', () => {
describe('Variant #1: program scope', () => {
describe('Variant #1: directive at the top of program scope', () => {
const directiveRegExp: RegExp = /^'use strict'; *var _0x([a-f0-9]){4} *= *\['test'];/;
@@ -62,8 +62,8 @@ describe('DirectivePlacementTransformer', function () {
});
});
describe('Function lexical scope', () => {
describe('Variant #1: directive at the top of function scope', () => {
describe('Variant #2: function declaration scope', () => {
describe('Variant #1: directive at the top of function declaration scope', () => {
const directiveRegExp: RegExp = new RegExp(
'function test\\(\\) *{ *' +
'\'use strict\'; *' +
@@ -74,7 +74,7 @@ describe('DirectivePlacementTransformer', function () {
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/top-of-function-scope.js');
const code: string = readFileAsString(__dirname + '/fixtures/top-of-function-declaration-scope.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
@@ -87,12 +87,12 @@ describe('DirectivePlacementTransformer', function () {
).getObfuscatedCode();
});
it('should keep directive at the top of function scope', () => {
it('should keep directive at the top of function declaration scope', () => {
assert.match(obfuscatedCode, directiveRegExp);
});
});
describe('Variant #2: directive-like string literal at the middle of function scope', () => {
describe('Variant #2: directive-like string literal at the middle of function-declaration scope', () => {
const directiveRegExp: RegExp = new RegExp(
'function test\\(\\) *{ *' +
'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4}; *' +
@@ -103,7 +103,7 @@ describe('DirectivePlacementTransformer', function () {
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/middle-of-function-scope.js');
const code: string = readFileAsString(__dirname + '/fixtures/middle-of-function-declaration-scope.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
@@ -116,7 +116,127 @@ describe('DirectivePlacementTransformer', function () {
).getObfuscatedCode();
});
it('should keep directive-like string literal at the middle of function scope', () => {
it('should keep directive-like string literal at the middle of function declaration scope', () => {
assert.match(obfuscatedCode, directiveRegExp);
});
})
});
describe('Variant #3: function expression scope', () => {
describe('Variant #1: directive at the top of function expression scope', () => {
const directiveRegExp: RegExp = new RegExp(
'var test *= *function *\\(\\) *{ *' +
'\'use strict\'; *' +
'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4}; *' +
'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(0x0\\);'
);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/top-of-function-expression-scope.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1,
stringArrayWrappersCount: 1
}
).getObfuscatedCode();
});
it('should keep directive at the top of function expression scope', () => {
assert.match(obfuscatedCode, directiveRegExp);
});
});
describe('Variant #2: directive-like string literal at the middle of function-expression scope', () => {
const directiveRegExp: RegExp = new RegExp(
'var test *= *function *\\(\\) *{ *' +
'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4}; *' +
'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(0x0\\);' +
'_0x([a-f0-9]){4,6}\\(0x1\\);'
);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/middle-of-function-expression-scope.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1,
stringArrayWrappersCount: 1
}
).getObfuscatedCode();
});
it('should keep directive-like string literal at the middle of function expression scope', () => {
assert.match(obfuscatedCode, directiveRegExp);
});
})
});
describe('Variant #4: arrow function expression scope', () => {
describe('Variant #1: directive at the top of arrow function expression scope', () => {
const directiveRegExp: RegExp = new RegExp(
'var test *= *\\(\\) *=> *{ *' +
'\'use strict\'; *' +
'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4}; *' +
'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(0x0\\);'
);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/top-of-arrow-function-expression-scope.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1,
stringArrayWrappersCount: 1
}
).getObfuscatedCode();
});
it('should keep directive at the top of arrow function expression scope', () => {
assert.match(obfuscatedCode, directiveRegExp);
});
});
describe('Variant #2: directive-like string literal at the middle of arrow function-expression scope', () => {
const directiveRegExp: RegExp = new RegExp(
'var test *= *\\(\\) *=> *{ *' +
'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4}; *' +
'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(0x0\\);' +
'_0x([a-f0-9]){4,6}\\(0x1\\);'
);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/middle-of-arrow-function-expression-scope.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1,
stringArrayWrappersCount: 1
}
).getObfuscatedCode();
});
it('should keep directive-like string literal at the middle of arrow function expression scope', () => {
assert.match(obfuscatedCode, directiveRegExp);
});
})
@@ -0,0 +1,4 @@
var test = function () {
var test = 'test';
'use strict';
};
@@ -0,0 +1,4 @@
var test = () => {
'use strict';
var test = 'test';
};
@@ -0,0 +1,4 @@
var test = function () {
'use strict';
var test = 'test';
};