mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
additional test for FunctionControlFlowTransformer
This commit is contained in:
+1
@@ -0,0 +1 @@
|
||||
var test = 1 + 2;
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
(function () {
|
||||
function foo () {
|
||||
function bar () {
|
||||
function baz () {
|
||||
function bash () {
|
||||
var variable = 1 + 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
||||
+56
-1
@@ -46,7 +46,7 @@ describe('FunctionControlFlowTransformer', () => {
|
||||
});
|
||||
|
||||
describe('variant #2 - two `control flow storage` nodes: root and inner', () => {
|
||||
const samplesCount: number = 150;
|
||||
const samplesCount: number = 200;
|
||||
const delta: number = 0.1;
|
||||
const expectedValue: number = 0.5;
|
||||
const regExp1: RegExp = new RegExp(
|
||||
@@ -114,5 +114,60 @@ describe('FunctionControlFlowTransformer', () => {
|
||||
assert.match(obfuscatedCode, regexp);
|
||||
});
|
||||
});
|
||||
|
||||
describe('variant #4 - no `control flow storage` node to the root block scope', () => {
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
readFileAsString(
|
||||
'./test/fixtures/node-transformers/node-control-flow-transformers/function-control-flow-transformer-root-block-scope-1.js'
|
||||
),
|
||||
{
|
||||
...NO_CUSTOM_NODES_PRESET,
|
||||
controlFlowFlattening: true,
|
||||
controlFlowFlatteningThreshold: 1
|
||||
}
|
||||
);
|
||||
const obfuscatedCode: string = obfuscationResult.getObfuscatedCode();
|
||||
|
||||
it('should\'t add control flow storage node when transformed node in the root block scope', () => {
|
||||
assert.match(obfuscatedCode, /^var *test *= *0x1 *\+ *0x2;$/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('variant #5 - no `control flow storage` node in the root block scope', () => {
|
||||
const samplesCount: number = 20;
|
||||
const expectedValue: number = 0;
|
||||
const regExp: RegExp = new RegExp(
|
||||
`var *[a-zA-Z]{6} *= *\\{` +
|
||||
`'(\\\\x[a-f0-9]*){3}' *: *function *_0x[0-9] *\\(${variableMatch}, *${variableMatch}\\) *\\{` +
|
||||
`return *${variableMatch} *\\+ *${variableMatch};` +
|
||||
`\\}` +
|
||||
`\\};`
|
||||
);
|
||||
|
||||
|
||||
it('should\'t add control flow storage node to the root block scope when transformed nodes not in the root block scope', () => {
|
||||
let totalValue: number = 0;
|
||||
|
||||
for (let i = 0; i < samplesCount; i++) {
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
readFileAsString(
|
||||
'./test/fixtures/node-transformers/node-control-flow-transformers/function-control-flow-transformer-root-block-scope-2.js'
|
||||
),
|
||||
{
|
||||
...NO_CUSTOM_NODES_PRESET,
|
||||
controlFlowFlattening: true,
|
||||
controlFlowFlatteningThreshold: 1
|
||||
}
|
||||
);
|
||||
const obfuscatedCode: string = obfuscationResult.getObfuscatedCode();
|
||||
|
||||
if (regExp.test(obfuscatedCode)) {
|
||||
totalValue++;
|
||||
}
|
||||
}
|
||||
|
||||
assert.equal(totalValue, expectedValue);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user