mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
0.12.4 release: fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/136
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
Change Log
|
||||
===
|
||||
v0.12.4
|
||||
---
|
||||
* https://github.com/javascript-obfuscator/javascript-obfuscator/issues/136
|
||||
|
||||
v0.12.3
|
||||
---
|
||||
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/129
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+7
-7
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "javascript-obfuscator",
|
||||
"version": "0.12.3",
|
||||
"version": "0.12.4",
|
||||
"description": "JavaScript obfuscator",
|
||||
"keywords": [
|
||||
"obfuscator",
|
||||
@@ -22,8 +22,8 @@
|
||||
"chalk": "2.3.0",
|
||||
"chance": "1.0.12",
|
||||
"class-validator": "0.7.3",
|
||||
"commander": "2.11.0",
|
||||
"escodegen-wallaby": "1.6.14",
|
||||
"commander": "2.12.2",
|
||||
"escodegen-wallaby": "1.6.15",
|
||||
"esmangle": "1.0.1",
|
||||
"esprima": "4.0.0",
|
||||
"estraverse": "4.2.0",
|
||||
@@ -37,7 +37,7 @@
|
||||
"tslib": "1.8.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chai": "4.0.5",
|
||||
"@types/chai": "4.0.6",
|
||||
"@types/chance": "0.7.35",
|
||||
"@types/commander": "2.11.0",
|
||||
"@types/escodegen": "0.0.6",
|
||||
@@ -62,14 +62,14 @@
|
||||
"mocha": "4.0.1",
|
||||
"pre-commit": "1.2.2",
|
||||
"sinon": "4.1.2",
|
||||
"threads": "^0.8.1",
|
||||
"threads": "^0.9.0",
|
||||
"ts-node": "3.3.0",
|
||||
"tslint": "5.8.0",
|
||||
"tslint-eslint-rules": "4.1.1",
|
||||
"tslint-language-service": "0.9.6",
|
||||
"tslint-webpack-plugin": "1.0.0",
|
||||
"typescript": "2.6.1",
|
||||
"webpack": "3.8.1",
|
||||
"typescript": "2.6.2",
|
||||
"webpack": "3.9.1",
|
||||
"webpack-node-externals": "1.6.0"
|
||||
},
|
||||
"repository": {
|
||||
|
||||
@@ -26,6 +26,7 @@ export enum NodeType {
|
||||
Program = 'Program',
|
||||
Property = 'Property',
|
||||
ReturnStatement = 'ReturnStatement',
|
||||
Super = 'Super',
|
||||
SwitchCase = 'SwitchCase',
|
||||
SwitchStatement = 'SwitchStatement',
|
||||
TemplateLiteral = 'TemplateLiteral',
|
||||
|
||||
+12
-3
@@ -73,6 +73,17 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer {
|
||||
this.transformersRunner = transformersRunner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node
|
||||
* @returns {boolean}
|
||||
*/
|
||||
private static isValidBlockStatementNode (node: ESTree.Node): boolean {
|
||||
return !NodeGuards.isBreakStatementNode(node) &&
|
||||
!NodeGuards.isContinueStatementNode(node) &&
|
||||
!NodeGuards.isAwaitExpressionNode(node) &&
|
||||
!NodeGuards.isSuperNode(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {IVisitor}
|
||||
*/
|
||||
@@ -173,9 +184,7 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer {
|
||||
*/
|
||||
if (
|
||||
nestedBlockStatementsCount > DeadCodeInjectionTransformer.maxNestedBlockStatementsCount ||
|
||||
NodeGuards.isBreakStatementNode(node) ||
|
||||
NodeGuards.isContinueStatementNode(node) ||
|
||||
NodeGuards.isAwaitExpressionNode(node)
|
||||
!DeadCodeInjectionTransformer.isValidBlockStatementNode(node)
|
||||
) {
|
||||
isValidBlockStatementNode = false;
|
||||
|
||||
|
||||
@@ -242,6 +242,14 @@ export class NodeGuards {
|
||||
return node.type === NodeType.ReturnStatement;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node
|
||||
* @returns {boolean}
|
||||
*/
|
||||
public static isSuperNode (node: ESTree.Node): node is ESTree.Super {
|
||||
return node.type === NodeType.Super;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node
|
||||
* @returns {boolean}
|
||||
|
||||
+54
-3
@@ -229,7 +229,58 @@ describe('DeadCodeInjectionTransformer', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('variant #6 - chance of `IfStatement` variant', () => {
|
||||
describe('variant #6 - super expression in block statement', () => {
|
||||
const functionRegExp: RegExp = new RegExp(
|
||||
`var *${variableMatch} *= *function *\\(\\) *\\{` +
|
||||
`console\\[${variableMatch}\\('${hexMatch}'\\)\\]\\(${variableMatch}\\('${hexMatch}'\\)\\);` +
|
||||
`\\};`,
|
||||
'g'
|
||||
);
|
||||
const superExpressionRegExp: RegExp = new RegExp(
|
||||
`super *\\(\\);`,
|
||||
'g'
|
||||
);
|
||||
const expectedFunctionMatchesLength: number = 4;
|
||||
const expectedSuperExpressionMatchesLength: number = 1;
|
||||
|
||||
let functionMatchesLength: number = 0,
|
||||
superExpressionMatchesLength: number = 0;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/super-expression.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_CUSTOM_NODES_PRESET,
|
||||
deadCodeInjection: true,
|
||||
deadCodeInjectionThreshold: 1,
|
||||
stringArray: true,
|
||||
stringArrayThreshold: 1
|
||||
}
|
||||
);
|
||||
const obfuscatedCode: string = obfuscationResult.getObfuscatedCode();
|
||||
const functionMatches: RegExpMatchArray = <RegExpMatchArray>obfuscatedCode.match(functionRegExp);
|
||||
const superExpressionMatches: RegExpMatchArray = <RegExpMatchArray>obfuscatedCode.match(superExpressionRegExp);
|
||||
|
||||
if (functionMatches) {
|
||||
functionMatchesLength = functionMatches.length;
|
||||
}
|
||||
|
||||
if (superExpressionMatches) {
|
||||
superExpressionMatchesLength = superExpressionMatches.length;
|
||||
}
|
||||
});
|
||||
|
||||
it('match #1: shouldn\'t add dead code', () => {
|
||||
assert.equal(functionMatchesLength, expectedFunctionMatchesLength);
|
||||
});
|
||||
|
||||
it('match #2: shouldn\'t add dead code', () => {
|
||||
assert.equal(superExpressionMatchesLength, expectedSuperExpressionMatchesLength);
|
||||
});
|
||||
});
|
||||
|
||||
describe('variant #7- chance of `IfStatement` variant', () => {
|
||||
const samplesCount: number = 1000;
|
||||
const delta: number = 0.1;
|
||||
const expectedDistribution: number = 0.25;
|
||||
@@ -331,7 +382,7 @@ describe('DeadCodeInjectionTransformer', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('variant #7 - block scope of block statement is `ProgramNode`', () => {
|
||||
describe('variant #8 - block scope of block statement is `ProgramNode`', () => {
|
||||
const regExp: RegExp = new RegExp(
|
||||
`if *\\(!!\\[\\]\\) *{` +
|
||||
`console\\[${variableMatch}\\('${hexMatch}'\\)\\]\\(${variableMatch}\\('${hexMatch}'\\)\\);` +
|
||||
@@ -361,7 +412,7 @@ describe('DeadCodeInjectionTransformer', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('variant #8 - correct obfuscation of dead-code block statements', () => {
|
||||
describe('variant #9 - correct obfuscation of dead-code block statements', () => {
|
||||
const variableName: string = 'importantVariableName';
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
(function(){
|
||||
if (true) {
|
||||
var foo = function () {
|
||||
console.log('abc');
|
||||
};
|
||||
var bar = function () {
|
||||
console.log('def');
|
||||
};
|
||||
var baz = function () {
|
||||
console.log('ghi');
|
||||
};
|
||||
var bark = function () {
|
||||
console.log('jkl');
|
||||
};
|
||||
|
||||
foo();
|
||||
bar();
|
||||
baz();
|
||||
bark();
|
||||
|
||||
class Abstract {}
|
||||
|
||||
class Concrete extends Abstract {
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
||||
@@ -2,9 +2,9 @@
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@types/chai@4.0.5":
|
||||
version "4.0.5"
|
||||
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.0.5.tgz#b6e250e281b47e0192e236619e9b1afe62fd345c"
|
||||
"@types/chai@4.0.6":
|
||||
version "4.0.6"
|
||||
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.0.6.tgz#9cb5a7fb7dd83be0cfcaafdbd95a2b5dd351762f"
|
||||
|
||||
"@types/chance@0.7.35":
|
||||
version "0.7.35"
|
||||
@@ -1058,6 +1058,10 @@ commander@2.11.0, commander@^2.11.0, commander@^2.9.0:
|
||||
version "2.11.0"
|
||||
resolved "https://registry.yarnpkg.com/commander/-/commander-2.11.0.tgz#157152fd1e7a6c8d98a5b715cf376df928004563"
|
||||
|
||||
commander@2.12.2:
|
||||
version "2.12.2"
|
||||
resolved "https://registry.yarnpkg.com/commander/-/commander-2.12.2.tgz#0f5946c427ed9ec0d91a46bb9def53e54650e555"
|
||||
|
||||
commondir@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
|
||||
@@ -1409,9 +1413,9 @@ escape-string-regexp@1.0.5, escape-string-regexp@^1.0.2, escape-string-regexp@^1
|
||||
version "1.0.5"
|
||||
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
|
||||
|
||||
escodegen-wallaby@1.6.14:
|
||||
version "1.6.14"
|
||||
resolved "https://registry.yarnpkg.com/escodegen-wallaby/-/escodegen-wallaby-1.6.14.tgz#41a0a7a2a2bd776207d25b4d2f373f12853de23f"
|
||||
escodegen-wallaby@1.6.15:
|
||||
version "1.6.15"
|
||||
resolved "https://registry.yarnpkg.com/escodegen-wallaby/-/escodegen-wallaby-1.6.15.tgz#9d5ef67dd4d8c7c8a58aff1e4edd63512566ba9f"
|
||||
dependencies:
|
||||
esprima "^2.7.1"
|
||||
estraverse "^1.9.1"
|
||||
@@ -1462,7 +1466,7 @@ esprima@4.0.0, esprima@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.0.tgz#4499eddcd1110e0b218bacf2fa7f7f59f55ca804"
|
||||
|
||||
esprima@^2.6.0, esprima@^2.7.1:
|
||||
esprima@^2.7.1:
|
||||
version "2.7.3"
|
||||
resolved "https://registry.yarnpkg.com/esprima/-/esprima-2.7.3.tgz#96e3b70d5779f6ad49cd032673d1c312767ba581"
|
||||
|
||||
@@ -2268,14 +2272,7 @@ js-tokens@^3.0.0, js-tokens@^3.0.2:
|
||||
version "3.0.2"
|
||||
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"
|
||||
|
||||
js-yaml@3.x:
|
||||
version "3.6.1"
|
||||
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.6.1.tgz#6e5fe67d8b205ce4d22fad05b7781e8dadcc4b30"
|
||||
dependencies:
|
||||
argparse "^1.0.7"
|
||||
esprima "^2.6.0"
|
||||
|
||||
js-yaml@^3.6.1, js-yaml@^3.7.0:
|
||||
js-yaml@3.x, js-yaml@^3.6.1, js-yaml@^3.7.0:
|
||||
version "3.10.0"
|
||||
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.10.0.tgz#2e78441646bd4682e963f22b6e92823c309c62dc"
|
||||
dependencies:
|
||||
@@ -3658,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.8.1:
|
||||
version "0.8.1"
|
||||
resolved "https://registry.yarnpkg.com/threads/-/threads-0.8.1.tgz#e340115b5947316d2f7ee3123c4c2c5bf9c76d72"
|
||||
threads@^0.9.0:
|
||||
version "0.9.0"
|
||||
resolved "https://registry.yarnpkg.com/threads/-/threads-0.9.0.tgz#cf1132ee7b6b205253e8dedc13904cc7646dbcc4"
|
||||
dependencies:
|
||||
eventemitter3 "^2.0.2"
|
||||
native-promise-only "^0.8.1"
|
||||
@@ -3818,9 +3815,9 @@ typedarray@^0.0.6:
|
||||
version "0.0.6"
|
||||
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
|
||||
|
||||
typescript@2.6.1:
|
||||
version "2.6.1"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.6.1.tgz#ef39cdea27abac0b500242d6726ab90e0c846631"
|
||||
typescript@2.6.2:
|
||||
version "2.6.2"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.6.2.tgz#3c5b6fd7f6de0914269027f03c0946758f7673a4"
|
||||
|
||||
uglify-js@^2.6, uglify-js@^2.8.29:
|
||||
version "2.8.29"
|
||||
@@ -3956,9 +3953,9 @@ webpack-sources@^1.0.1:
|
||||
source-list-map "^2.0.0"
|
||||
source-map "~0.5.3"
|
||||
|
||||
webpack@3.8.1:
|
||||
version "3.8.1"
|
||||
resolved "https://registry.yarnpkg.com/webpack/-/webpack-3.8.1.tgz#b16968a81100abe61608b0153c9159ef8bb2bd83"
|
||||
webpack@3.9.1:
|
||||
version "3.9.1"
|
||||
resolved "https://registry.yarnpkg.com/webpack/-/webpack-3.9.1.tgz#9a60aa544ed5d4d454c069e3f521aa007e02643c"
|
||||
dependencies:
|
||||
acorn "^5.0.0"
|
||||
acorn-dynamic-import "^2.0.0"
|
||||
|
||||
Reference in New Issue
Block a user