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
===
v0.12.5
---
* https://github.com/javascript-obfuscator/javascript*-obfuscator/issues/139

v0.12.4
---
* https://github.com/javascript-obfuscator/javascript-obfuscator/issues/136
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "javascript-obfuscator",
"version": "0.12.4",
"version": "0.12.5",
"description": "JavaScript obfuscator",
"keywords": [
"obfuscator",
Expand Down Expand Up @@ -51,7 +51,7 @@
"@types/sinon": "4.0.0",
"@types/string-template": "1.0.2",
"@types/webpack-env": "1.13.2",
"awesome-typescript-loader": "3.4.0",
"awesome-typescript-loader": "3.4.1",
"babel-cli": "6.26.0",
"babel-loader": "7.1.2",
"babel-plugin-array-includes": "2.0.3",
Expand All @@ -62,7 +62,7 @@
"mocha": "4.0.1",
"pre-commit": "1.2.2",
"sinon": "4.1.2",
"threads": "^0.9.0",
"threads": "^0.10.0",
"ts-node": "3.3.0",
"tslint": "5.8.0",
"tslint-eslint-rules": "4.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';

import { initializable } from '../../decorators/Initializable';

import { DebugProtectionFunctionCallTemplate } from '../../templates/debug-protection-nodes/debug-protection-function-call-node/DebufProtectionFunctionCallTemplate';
import { DebugProtectionFunctionCallTemplate } from '../../templates/debug-protection-nodes/debug-protection-function-call-node/DebugProtectionFunctionCallTemplate';

import { AbstractCustomNode } from '../AbstractCustomNode';
import { NodeUtils } from '../../node/NodeUtils';

@injectable()
export class DebugProtectionFunctionCallNode extends AbstractCustomNode {
/**
* @type {string}
*/
@initializable()
private callsControllerFunctionName: string;

/**
* @type {string}
*/
Expand All @@ -36,9 +42,11 @@ export class DebugProtectionFunctionCallNode extends AbstractCustomNode {

/**
* @param {string} debugProtectionFunctionName
* @param {string} callsControllerFunctionName
*/
public initialize (debugProtectionFunctionName: string): void {
public initialize (debugProtectionFunctionName: string, callsControllerFunctionName: string): void {
this.debugProtectionFunctionName = debugProtectionFunctionName;
this.callsControllerFunctionName = callsControllerFunctionName;
}

/**
Expand All @@ -53,7 +61,8 @@ export class DebugProtectionFunctionCallNode extends AbstractCustomNode {
*/
protected getTemplate (): string {
return format(DebugProtectionFunctionCallTemplate(), {
debugProtectionFunctionName: this.debugProtectionFunctionName
debugProtectionFunctionName: this.debugProtectionFunctionName,
singleNodeCallControllerFunctionName: this.callsControllerFunctionName
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ export class DebugProtectionCustomNodeGroup extends AbstractCustomNodeGroup {

NodeAppender.insertNodeAtIndex(blockScopeNode, customNode.getNode(), randomIndex);
});

// nodeCallsControllerFunctionNode append
this.appendCustomNodeIfExist(CustomNode.NodeCallsControllerFunctionNode, (customNode: ICustomNode) => {
let targetBlockScope: TNodeWithBlockStatement;

if (stackTraceData.length) {
targetBlockScope = NodeAppender.getOptimalBlockScope(stackTraceData, randomStackTraceIndex, 1);
} else {
targetBlockScope = blockScopeNode;
}

NodeAppender.prependNode(targetBlockScope, customNode.getNode());
});
}

public initialize (): void {
Expand All @@ -89,20 +102,25 @@ export class DebugProtectionCustomNodeGroup extends AbstractCustomNodeGroup {
}

const debugProtectionFunctionName: string = this.randomGenerator.getRandomVariableName(6);
const callsControllerFunctionName: string = this.randomGenerator.getRandomVariableName(6);

const debugProtectionFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.DebugProtectionFunctionNode);
const debugProtectionFunctionCallNode: ICustomNode = this.customNodeFactory(CustomNode.DebugProtectionFunctionCallNode);
const debugProtectionFunctionIntervalNode: ICustomNode = this.customNodeFactory(CustomNode.DebugProtectionFunctionIntervalNode);
const nodeCallsControllerFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.NodeCallsControllerFunctionNode);

debugProtectionFunctionNode.initialize(debugProtectionFunctionName);
debugProtectionFunctionCallNode.initialize(debugProtectionFunctionName);
debugProtectionFunctionCallNode.initialize(debugProtectionFunctionName, callsControllerFunctionName);
debugProtectionFunctionIntervalNode.initialize(debugProtectionFunctionName);
nodeCallsControllerFunctionNode.initialize(this.appendEvent, callsControllerFunctionName);

this.customNodes.set(CustomNode.DebugProtectionFunctionNode, debugProtectionFunctionNode);
this.customNodes.set(CustomNode.DebugProtectionFunctionCallNode, debugProtectionFunctionCallNode);

if (this.options.debugProtectionInterval) {
this.customNodes.set(CustomNode.DebugProtectionFunctionIntervalNode, debugProtectionFunctionIntervalNode);
}

this.customNodes.set(CustomNode.NodeCallsControllerFunctionNode, nodeCallsControllerFunctionNode);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @returns {string}
*/
export function DebugProtectionFunctionCallTemplate (): string {
return `
(function () {
{singleNodeCallControllerFunctionName}(this, function () {
var regExp1 = new RegExp('function *\\\\( *\\\\)');
var regExp2 = new RegExp('\\\\+\\\\+ *\\(?:_0x(?:[a-f0-9]){4,6}|\\\\b[a-zA-Z]{1,2}\\\\b\\)');

var result = {debugProtectionFunctionName}('init');

if (!regExp1.test(result + 'chain') || !regExp2.test(result + 'input')) {
result('0');
} else {
{debugProtectionFunctionName}();
}
})();
})();
`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('DebugProtectionFunctionCallTemplate (): string', () => {
});
});

describe('variant #3: obfuscated code with removed debug protection function call', () => {
describe('variant #3: obfuscated code with removed debug protection code', () => {
const expectedEvaluationResult: number = 0;

let obfuscatedCode: string,
Expand Down Expand Up @@ -135,4 +135,39 @@ describe('DebugProtectionFunctionCallTemplate (): string', () => {
assert.equal(evaluationResult, expectedEvaluationResult);
});
});

describe('variant #4: single call of debug protection code', () => {
const expectedEvaluationResult: number = 1;

let obfuscatedCode: string,
evaluationResult: number = 0;

beforeEach((done) => {
const code: string = readFileAsString(__dirname + '/fixtures/single-call.js');
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
debugProtection: true
}
);

obfuscatedCode = obfuscationResult.getObfuscatedCode();

spawnThread(
() => obfuscatedCode,
(response: number) => {
evaluationResult = response;
done();
},
() => {
done();
}
);
});

it('should correctly evaluate code with enabled debug protection', () => {
assert.equal(evaluationResult, expectedEvaluationResult);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(function () {
function foo () {
function bar () {
function baz () {
return 1;
}

return baz();
}

return bar();
}

for (var i = 0; i <= 10000; i++) {
if (i < 10000) {
foo();
} else {
return foo();
}
}
})();
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ atob@^2.0.0:
version "2.0.3"
resolved "https://registry.yarnpkg.com/atob/-/atob-2.0.3.tgz#19c7a760473774468f20b2d2d03372ad7d4cbf5d"

[email protected].0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/awesome-typescript-loader/-/awesome-typescript-loader-3.4.0.tgz#aed2c83af614d617d11e3ec368ac3befb55d002f"
[email protected].1:
version "3.4.1"
resolved "https://registry.yarnpkg.com/awesome-typescript-loader/-/awesome-typescript-loader-3.4.1.tgz#22fa49800f0619ec18ab15383aef93b95378dea9"
dependencies:
colors "^1.1.2"
enhanced-resolve "3.3.0"
Expand Down Expand Up @@ -1054,11 +1054,11 @@ combined-stream@^1.0.5, combined-stream@~1.0.5:
dependencies:
delayed-stream "~1.0.0"

[email protected], commander@^2.11.0, commander@^2.9.0:
[email protected]:
version "2.11.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.11.0.tgz#157152fd1e7a6c8d98a5b715cf376df928004563"

[email protected]:
[email protected], commander@^2.11.0, commander@^2.9.0:
version "2.12.2"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.12.2.tgz#0f5946c427ed9ec0d91a46bb9def53e54650e555"

Expand Down Expand Up @@ -3655,9 +3655,9 @@ text-encoding@^0.6.4:
version "0.6.4"
resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.6.4.tgz#e399a982257a276dae428bb92845cb71bdc26d19"

threads@^0.9.0:
version "0.9.0"
resolved "https://registry.yarnpkg.com/threads/-/threads-0.9.0.tgz#cf1132ee7b6b205253e8dedc13904cc7646dbcc4"
threads@^0.10.0:
version "0.10.0"
resolved "https://registry.yarnpkg.com/threads/-/threads-0.10.0.tgz#a6b0bc5d916fa75434b166c612769684b65fead5"
dependencies:
eventemitter3 "^2.0.2"
native-promise-only "^0.8.1"
Expand Down