Skip to content

Commit ae507ad

Browse files
authored
Merge pull request javascript-obfuscator#140 from javascript-obfuscator/0.12.5
0.12.5 release
2 parents 7ece658 + 7c325d4 commit ae507ad

File tree

10 files changed

+125
-35
lines changed

10 files changed

+125
-35
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Change Log
22
===
3+
v0.12.5
4+
---
5+
* https://github.com/javascript-obfuscator/javascript*-obfuscator/issues/139
6+
37
v0.12.4
48
---
59
* https://github.com/javascript-obfuscator/javascript-obfuscator/issues/136

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "javascript-obfuscator",
3-
"version": "0.12.4",
3+
"version": "0.12.5",
44
"description": "JavaScript obfuscator",
55
"keywords": [
66
"obfuscator",
@@ -51,7 +51,7 @@
5151
"@types/sinon": "4.0.0",
5252
"@types/string-template": "1.0.2",
5353
"@types/webpack-env": "1.13.2",
54-
"awesome-typescript-loader": "3.4.0",
54+
"awesome-typescript-loader": "3.4.1",
5555
"babel-cli": "6.26.0",
5656
"babel-loader": "7.1.2",
5757
"babel-plugin-array-includes": "2.0.3",
@@ -62,7 +62,7 @@
6262
"mocha": "4.0.1",
6363
"pre-commit": "1.2.2",
6464
"sinon": "4.1.2",
65-
"threads": "^0.9.0",
65+
"threads": "^0.10.0",
6666
"ts-node": "3.3.0",
6767
"tslint": "5.8.0",
6868
"tslint-eslint-rules": "4.1.1",

src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@ import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
1010

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

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

1515
import { AbstractCustomNode } from '../AbstractCustomNode';
1616
import { NodeUtils } from '../../node/NodeUtils';
1717

1818
@injectable()
1919
export class DebugProtectionFunctionCallNode extends AbstractCustomNode {
20+
/**
21+
* @type {string}
22+
*/
23+
@initializable()
24+
private callsControllerFunctionName: string;
25+
2026
/**
2127
* @type {string}
2228
*/
@@ -36,9 +42,11 @@ export class DebugProtectionFunctionCallNode extends AbstractCustomNode {
3642

3743
/**
3844
* @param {string} debugProtectionFunctionName
45+
* @param {string} callsControllerFunctionName
3946
*/
40-
public initialize (debugProtectionFunctionName: string): void {
47+
public initialize (debugProtectionFunctionName: string, callsControllerFunctionName: string): void {
4148
this.debugProtectionFunctionName = debugProtectionFunctionName;
49+
this.callsControllerFunctionName = callsControllerFunctionName;
4250
}
4351

4452
/**
@@ -53,7 +61,8 @@ export class DebugProtectionFunctionCallNode extends AbstractCustomNode {
5361
*/
5462
protected getTemplate (): string {
5563
return format(DebugProtectionFunctionCallTemplate(), {
56-
debugProtectionFunctionName: this.debugProtectionFunctionName
64+
debugProtectionFunctionName: this.debugProtectionFunctionName,
65+
singleNodeCallControllerFunctionName: this.callsControllerFunctionName
5766
});
5867
}
5968
}

src/custom-nodes/debug-protection-nodes/group/DebugProtectionCustomNodeGroup.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ export class DebugProtectionCustomNodeGroup extends AbstractCustomNodeGroup {
7979

8080
NodeAppender.insertNodeAtIndex(blockScopeNode, customNode.getNode(), randomIndex);
8181
});
82+
83+
// nodeCallsControllerFunctionNode append
84+
this.appendCustomNodeIfExist(CustomNode.NodeCallsControllerFunctionNode, (customNode: ICustomNode) => {
85+
let targetBlockScope: TNodeWithBlockStatement;
86+
87+
if (stackTraceData.length) {
88+
targetBlockScope = NodeAppender.getOptimalBlockScope(stackTraceData, randomStackTraceIndex, 1);
89+
} else {
90+
targetBlockScope = blockScopeNode;
91+
}
92+
93+
NodeAppender.prependNode(targetBlockScope, customNode.getNode());
94+
});
8295
}
8396

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

91104
const debugProtectionFunctionName: string = this.randomGenerator.getRandomVariableName(6);
105+
const callsControllerFunctionName: string = this.randomGenerator.getRandomVariableName(6);
92106

93107
const debugProtectionFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.DebugProtectionFunctionNode);
94108
const debugProtectionFunctionCallNode: ICustomNode = this.customNodeFactory(CustomNode.DebugProtectionFunctionCallNode);
95109
const debugProtectionFunctionIntervalNode: ICustomNode = this.customNodeFactory(CustomNode.DebugProtectionFunctionIntervalNode);
110+
const nodeCallsControllerFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.NodeCallsControllerFunctionNode);
96111

97112
debugProtectionFunctionNode.initialize(debugProtectionFunctionName);
98-
debugProtectionFunctionCallNode.initialize(debugProtectionFunctionName);
113+
debugProtectionFunctionCallNode.initialize(debugProtectionFunctionName, callsControllerFunctionName);
99114
debugProtectionFunctionIntervalNode.initialize(debugProtectionFunctionName);
115+
nodeCallsControllerFunctionNode.initialize(this.appendEvent, callsControllerFunctionName);
100116

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

104120
if (this.options.debugProtectionInterval) {
105121
this.customNodes.set(CustomNode.DebugProtectionFunctionIntervalNode, debugProtectionFunctionIntervalNode);
106122
}
123+
124+
this.customNodes.set(CustomNode.NodeCallsControllerFunctionNode, nodeCallsControllerFunctionNode);
107125
}
108126
}

src/templates/debug-protection-nodes/debug-protection-function-call-node/DebufProtectionFunctionCallTemplate.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @returns {string}
3+
*/
4+
export function DebugProtectionFunctionCallTemplate (): string {
5+
return `
6+
(function () {
7+
{singleNodeCallControllerFunctionName}(this, function () {
8+
var regExp1 = new RegExp('function *\\\\( *\\\\)');
9+
var regExp2 = new RegExp('\\\\+\\\\+ *\\(?:_0x(?:[a-f0-9]){4,6}|\\\\b[a-zA-Z]{1,2}\\\\b\\)');
10+
11+
var result = {debugProtectionFunctionName}('init');
12+
13+
if (!regExp1.test(result + 'chain') || !regExp2.test(result + 'input')) {
14+
result('0');
15+
} else {
16+
{debugProtectionFunctionName}();
17+
}
18+
})();
19+
})();
20+
`;
21+
}

test/functional-tests/templates/custom-nodes/debug-protection-nodes/DebufProtectionFunctionCallTemplate.spec.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ describe('DebugProtectionFunctionCallTemplate (): string', () => {
100100
});
101101
});
102102

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

106106
let obfuscatedCode: string,
@@ -135,4 +135,39 @@ describe('DebugProtectionFunctionCallTemplate (): string', () => {
135135
assert.equal(evaluationResult, expectedEvaluationResult);
136136
});
137137
});
138+
139+
describe('variant #4: single call of debug protection code', () => {
140+
const expectedEvaluationResult: number = 1;
141+
142+
let obfuscatedCode: string,
143+
evaluationResult: number = 0;
144+
145+
beforeEach((done) => {
146+
const code: string = readFileAsString(__dirname + '/fixtures/single-call.js');
147+
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
148+
code,
149+
{
150+
...NO_CUSTOM_NODES_PRESET,
151+
debugProtection: true
152+
}
153+
);
154+
155+
obfuscatedCode = obfuscationResult.getObfuscatedCode();
156+
157+
spawnThread(
158+
() => obfuscatedCode,
159+
(response: number) => {
160+
evaluationResult = response;
161+
done();
162+
},
163+
() => {
164+
done();
165+
}
166+
);
167+
});
168+
169+
it('should correctly evaluate code with enabled debug protection', () => {
170+
assert.equal(evaluationResult, expectedEvaluationResult);
171+
});
172+
});
138173
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
(function () {
2+
function foo () {
3+
function bar () {
4+
function baz () {
5+
return 1;
6+
}
7+
8+
return baz();
9+
}
10+
11+
return bar();
12+
}
13+
14+
for (var i = 0; i <= 10000; i++) {
15+
if (i < 10000) {
16+
foo();
17+
} else {
18+
return foo();
19+
}
20+
}
21+
})();

yarn.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,9 @@ atob@^2.0.0:
252252
version "2.0.3"
253253
resolved "https://registry.yarnpkg.com/atob/-/atob-2.0.3.tgz#19c7a760473774468f20b2d2d03372ad7d4cbf5d"
254254

255-
256-
version "3.4.0"
257-
resolved "https://registry.yarnpkg.com/awesome-typescript-loader/-/awesome-typescript-loader-3.4.0.tgz#aed2c83af614d617d11e3ec368ac3befb55d002f"
255+
256+
version "3.4.1"
257+
resolved "https://registry.yarnpkg.com/awesome-typescript-loader/-/awesome-typescript-loader-3.4.1.tgz#22fa49800f0619ec18ab15383aef93b95378dea9"
258258
dependencies:
259259
colors "^1.1.2"
260260
enhanced-resolve "3.3.0"
@@ -1054,11 +1054,11 @@ combined-stream@^1.0.5, combined-stream@~1.0.5:
10541054
dependencies:
10551055
delayed-stream "~1.0.0"
10561056

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

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

@@ -3655,9 +3655,9 @@ text-encoding@^0.6.4:
36553655
version "0.6.4"
36563656
resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.6.4.tgz#e399a982257a276dae428bb92845cb71bdc26d19"
36573657

3658-
threads@^0.9.0:
3659-
version "0.9.0"
3660-
resolved "https://registry.yarnpkg.com/threads/-/threads-0.9.0.tgz#cf1132ee7b6b205253e8dedc13904cc7646dbcc4"
3658+
threads@^0.10.0:
3659+
version "0.10.0"
3660+
resolved "https://registry.yarnpkg.com/threads/-/threads-0.10.0.tgz#a6b0bc5d916fa75434b166c612769684b65fead5"
36613661
dependencies:
36623662
eventemitter3 "^2.0.2"
36633663
native-promise-only "^0.8.1"

0 commit comments

Comments
 (0)