Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion dist/index.browser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.cli.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "javascript-obfuscator",
"version": "2.10.2",
"version": "2.10.3",
"description": "JavaScript obfuscator",
"keywords": [
"obfuscator",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)

/**
Expand Down
25 changes: 10 additions & 15 deletions test/dev/dev.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function foo() {
if (true) {
if (false) {
const bar = baz();
}
} else {
var bark = hawk();
}
}