mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Added partial if statement simplify with consequent only branch
This commit is contained in:
+12
-6
@@ -352,14 +352,16 @@ describe('IfStatementSimplifyTransformer', () => {
|
||||
describe('No `ReturnStatement`', () => {
|
||||
describe('Variant #1: single statement', () => {
|
||||
const regExp: RegExp = new RegExp(
|
||||
'!!\\[] *&& *bar\\(\\);'
|
||||
'if *\\(!!\\[]\\) *{ *' +
|
||||
'const _0x([a-f0-9]){4,6} *= *baz\\(\\); *' +
|
||||
'}'
|
||||
);
|
||||
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/full-consequent-only-no-return-single-statement.js');
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/partial-consequent-only-no-return-single-statement.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
@@ -370,21 +372,25 @@ describe('IfStatementSimplifyTransformer', () => {
|
||||
).getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('should simplify if statement', () => {
|
||||
it('should not simplify if statement', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #2: multiple statements', () => {
|
||||
const regExp: RegExp = new RegExp(
|
||||
'!!\\[] *&& *\\(bar\\(\\) *, *baz\\(\\) *, *bark\\(\\)\\);'
|
||||
'if *\\(!!\\[]\\) *{ *' +
|
||||
'const _0x([a-f0-9]){4,6} *= *baz\\(\\); *' +
|
||||
'bark\\(\\); *' +
|
||||
'return hawk\\(\\);' +
|
||||
'}'
|
||||
);
|
||||
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/full-consequent-only-no-return-multiple-statements.js');
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/partial-consequent-only-no-return-multiple-statements.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
@@ -395,7 +401,7 @@ describe('IfStatementSimplifyTransformer', () => {
|
||||
).getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('should simplify if statement', () => {
|
||||
it('should not simplify if statement', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
function foo () {
|
||||
if (true) {
|
||||
const bar = baz();
|
||||
|
||||
bark();
|
||||
|
||||
return hawk();
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
function foo () {
|
||||
if (true) {
|
||||
const bar = baz();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user