mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Merge pull request #865 from javascript-obfuscator/if-statement-simplify-fix
Fixed `simplify` option regression after `2.10.2`
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
Change Log
|
||||
|
||||
v2.10.3
|
||||
---
|
||||
* Fixed `simplify` option regression after `2.10.2`. Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/864
|
||||
|
||||
v2.10.2
|
||||
---
|
||||
* Fixed behavior of `simplify` options when a node with a single-statement `body` is inside simplified `IfStatement` node. Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/860
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "javascript-obfuscator",
|
||||
"version": "2.10.2",
|
||||
"version": "2.10.3",
|
||||
"description": "JavaScript obfuscator",
|
||||
"keywords": [
|
||||
"obfuscator",
|
||||
|
||||
@@ -286,7 +286,8 @@ export class IfStatementSimplifyTransformer extends AbstractStatementSimplifyTra
|
||||
*/
|
||||
return NodeGuards.isFunctionDeclarationNode(statement)
|
||||
/**
|
||||
* Ignore any nodes with a single statement as a `body`
|
||||
* Have to ignore all `IfStatement` nodes
|
||||
* Also have to ignore any nodes with a single statement as a `body`
|
||||
* Without ignore it can break following code:
|
||||
* Input:
|
||||
* if (condition1) {
|
||||
@@ -306,6 +307,7 @@ export class IfStatementSimplifyTransformer extends AbstractStatementSimplifyTra
|
||||
*
|
||||
* See issue: https://github.com/javascript-obfuscator/javascript-obfuscator/issues/860
|
||||
*/
|
||||
|| NodeGuards.isIfStatementNode(statement)
|
||||
|| NodeGuards.isNodeWithSingleStatementBody(statement)
|
||||
|
||||
/**
|
||||
|
||||
+10
-15
@@ -1,31 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNodes';
|
||||
import { StringArrayEncoding } from '../../src/enums/node-transformers/string-array-transformers/StringArrayEncoding';
|
||||
|
||||
(function () {
|
||||
const JavaScriptObfuscator: any = require('../../index');
|
||||
|
||||
let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
|
||||
`
|
||||
console.log('1');
|
||||
console.log('22');
|
||||
console.log('333');
|
||||
console.log('4444');
|
||||
console.log('55555');
|
||||
console.log('666666');
|
||||
console.log('7777777');
|
||||
console.log('88888888');
|
||||
console.log('999999999');
|
||||
function foo () {
|
||||
if (bar) {
|
||||
if (baz) {
|
||||
const a = aa()
|
||||
}
|
||||
} else {
|
||||
bb()
|
||||
}
|
||||
}
|
||||
`,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
compact: false,
|
||||
stringArray: true,
|
||||
stringArrayThreshold: 1,
|
||||
stringArrayEncoding: [
|
||||
StringArrayEncoding.Rc4
|
||||
]
|
||||
simplify: true
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
|
||||
|
||||
+51
-19
@@ -753,31 +753,63 @@ describe('IfStatementSimplifyTransformer', () => {
|
||||
|
||||
describe('Prohibited single statement', () => {
|
||||
describe('Variant #1: `IfStatement` as prohibited single statement', () => {
|
||||
const regExp: RegExp = new RegExp(
|
||||
'if *\\(!!\\[]\\) *{ *' +
|
||||
'if *\\(!\\[]\\) *' +
|
||||
'var _0x([a-f0-9]){4,6} *= *baz\\(\\); *' +
|
||||
'} *else *' +
|
||||
'var _0x([a-f0-9]){4,6} *= *hawk\\(\\);'
|
||||
);
|
||||
describe('Variant #1: `IfStatement` with `var` variable inside`' , () => {
|
||||
const regExp: RegExp = new RegExp(
|
||||
'if *\\(!!\\[]\\) *{ *' +
|
||||
'if *\\(!\\[]\\) *' +
|
||||
'var _0x([a-f0-9]){4,6} *= *baz\\(\\); *' +
|
||||
'} *else *' +
|
||||
'var _0x([a-f0-9]){4,6} *= *hawk\\(\\);'
|
||||
);
|
||||
|
||||
|
||||
let obfuscatedCode: string;
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/if-statement-as-prohibited-single-statement.js');
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/if-statement-as-prohibited-single-statement-1.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
simplify: true
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
simplify: true
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('should not simplify if statement', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not simplify if statement', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
describe('Variant #2: `IfStatement` with `const` variable inside`' , () => {
|
||||
const regExp: RegExp = new RegExp(
|
||||
'if *\\(!!\\[]\\) *{ *' +
|
||||
'if *\\(!\\[]\\) *{ *' +
|
||||
'const _0x([a-f0-9]){4,6} *= *baz\\(\\); *' +
|
||||
'} *' +
|
||||
'} *else *' +
|
||||
'var _0x([a-f0-9]){4,6} *= *hawk\\(\\);'
|
||||
);
|
||||
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/if-statement-as-prohibited-single-statement-2.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
simplify: true
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('should not simplify if statement', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
function foo() {
|
||||
if (true) {
|
||||
if (false) {
|
||||
const bar = baz();
|
||||
}
|
||||
} else {
|
||||
var bark = hawk();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user