mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Updated logic for random string array function position
This commit is contained in:
+31
-11
@@ -8,26 +8,46 @@ import { readFileAsString } from '../../../helpers/readFileAsString';
|
||||
import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscatorFacade';
|
||||
|
||||
describe('StringArrayCodeHelper', () => {
|
||||
const regExp: RegExp = getStringArrayRegExp(['test']);
|
||||
const stringArrayRegExp: RegExp = getStringArrayRegExp(['test']);
|
||||
|
||||
describe('`stringArray` option is set', () => {
|
||||
const samplesCount: number = 100;
|
||||
const stringArrayAtFirstPositionRegExp: RegExp = new RegExp(`^${stringArrayRegExp.source}`);
|
||||
const variableDeclarationAtFirstPositionRegExp: RegExp = /^var test *= *_0x([a-f0-9]){4}\(0x0\);/;
|
||||
|
||||
let obfuscatedCode: string;
|
||||
let stringArrayAtFirstPositionMatchesCount: number = 0;
|
||||
let variableDeclarationAtFirstPositionMatchesCount: number = 0;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
stringArray: true,
|
||||
stringArrayThreshold: 1
|
||||
for (let i = 0; i < samplesCount; i++) {
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
stringArray: true,
|
||||
stringArrayThreshold: 1
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
|
||||
if (obfuscatedCode.match(stringArrayAtFirstPositionRegExp)) {
|
||||
stringArrayAtFirstPositionMatchesCount++;
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
|
||||
if (obfuscatedCode.match(variableDeclarationAtFirstPositionRegExp)) {
|
||||
variableDeclarationAtFirstPositionMatchesCount++;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('should correctly append code helper into the obfuscated code', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
it('Match #1: should correctly append code helper into the obfuscated code at random index', () => {
|
||||
assert.isAbove(stringArrayAtFirstPositionMatchesCount, 1);
|
||||
});
|
||||
|
||||
it('Match #2: should correctly append code helper into the obfuscated code at random index', () => {
|
||||
assert.isAbove(variableDeclarationAtFirstPositionMatchesCount, 1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -47,7 +67,7 @@ describe('StringArrayCodeHelper', () => {
|
||||
});
|
||||
|
||||
it('shouldn\'t append code helper into the obfuscated code', () => {
|
||||
assert.notMatch(obfuscatedCode, regExp);
|
||||
assert.notMatch(obfuscatedCode, stringArrayRegExp);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user