mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
added option for disabling console output
This commit is contained in:
@@ -21,6 +21,7 @@ JavaScriptObfuscator.defaultOptions = {
|
||||
compact: true,
|
||||
debugProtection: false,
|
||||
debugProtectionInterval: false,
|
||||
disableConsoleOutput: true,
|
||||
rotateUnicodeArray: true
|
||||
};
|
||||
JavaScriptObfuscator.escodegenParams = {
|
||||
|
||||
@@ -15,6 +15,7 @@ export class JavaScriptObfuscator {
|
||||
compact: true,
|
||||
debugProtection: false,
|
||||
debugProtectionInterval: false,
|
||||
disableConsoleOutput: true,
|
||||
rotateUnicodeArray: true
|
||||
};
|
||||
|
||||
|
||||
@@ -86,6 +86,11 @@ Works if `debugProtection` is enabled.
|
||||
|
||||
Force enable debug mode in some browsers (mainly based on WebKit) when Developers Tools panel was enbaled, even after page was loaded.
|
||||
|
||||
####disableConsoleOutput
|
||||
Type: `boolean` Default: `true`
|
||||
|
||||
Disable `console.log`, `console.info`, `console.error` and `console.warn` messages output into browser console.
|
||||
|
||||
####rotateUnicodeArray
|
||||
Type: `boolean` Default: `true`
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ const estraverse = require('estraverse');
|
||||
const AppendState_1 = require('./enums/AppendState');
|
||||
const NodeType_1 = require("./enums/NodeType");
|
||||
const CatchClauseObfuscator_1 = require("./node-obfuscators/CatchClauseObfuscator");
|
||||
const ConsoleOutputDisableExpressionNode_1 = require("./nodes/ConsoleOutputDisableExpressionNode");
|
||||
const DebugProtectionNodesGroup_1 = require("./node-groups/DebugProtectionNodesGroup");
|
||||
const FunctionDeclarationObfuscator_1 = require('./node-obfuscators/FunctionDeclarationObfuscator');
|
||||
const FunctionObfuscator_1 = require('./node-obfuscators/FunctionObfuscator');
|
||||
@@ -76,6 +77,9 @@ class Obfuscator {
|
||||
else {
|
||||
this.setNode('unicodeArrayNode', new UnicodeArrayNode_1.UnicodeArrayNode(astTree, Utils_1.Utils.getRandomVariableName(UnicodeArrayNode_1.UnicodeArrayNode.UNICODE_ARRAY_RANDOM_LENGTH)));
|
||||
}
|
||||
if (this.options['disableConsoleOutput']) {
|
||||
this.setNode('consoleOutputDisableExpressionNode', new ConsoleOutputDisableExpressionNode_1.ConsoleOutputDisableExpressionNode(astTree));
|
||||
}
|
||||
if (this.options['debugProtection']) {
|
||||
this.setNodesGroup(new DebugProtectionNodesGroup_1.DebugProtectionNodesGroup(astTree, this.options));
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { AppendState } from './enums/AppendState';
|
||||
import { NodeType } from "./enums/NodeType";
|
||||
|
||||
import { CatchClauseObfuscator } from "./node-obfuscators/CatchClauseObfuscator";
|
||||
import { ConsoleOutputDisableExpressionNode } from "./nodes/ConsoleOutputDisableExpressionNode";
|
||||
import { DebugProtectionNodesGroup } from "./node-groups/DebugProtectionNodesGroup";
|
||||
import { FunctionDeclarationObfuscator } from './node-obfuscators/FunctionDeclarationObfuscator';
|
||||
import { FunctionObfuscator } from './node-obfuscators/FunctionObfuscator';
|
||||
@@ -127,6 +128,13 @@ export class Obfuscator {
|
||||
);
|
||||
}
|
||||
|
||||
if (this.options['disableConsoleOutput']) {
|
||||
this.setNode(
|
||||
'consoleOutputDisableExpressionNode',
|
||||
new ConsoleOutputDisableExpressionNode(astTree)
|
||||
);
|
||||
}
|
||||
|
||||
if (this.options['debugProtection']) {
|
||||
this.setNodesGroup(new DebugProtectionNodesGroup(astTree, this.options));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
"use strict";
|
||||
const estraverse = require('estraverse');
|
||||
const NodeType_1 = require("../enums/NodeType");
|
||||
const Node_1 = require('./Node');
|
||||
class ConsoleOutputDisableExpressionNode extends Node_1.Node {
|
||||
constructor(astTree) {
|
||||
super();
|
||||
this.astTree = astTree;
|
||||
this.node = this.getNodeStructure();
|
||||
}
|
||||
appendNode() {
|
||||
estraverse.replace(this.astTree, {
|
||||
leave: (node, parent) => {
|
||||
switch (node.type) {
|
||||
case NodeType_1.NodeType.Program:
|
||||
node.body.unshift(this.getNode());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
getNodeStructure() {
|
||||
return {
|
||||
"type": NodeType_1.NodeType.ExpressionStatement,
|
||||
"expression": {
|
||||
"type": NodeType_1.NodeType.CallExpression,
|
||||
"callee": {
|
||||
"type": NodeType_1.NodeType.CallExpression,
|
||||
"callee": {
|
||||
"type": NodeType_1.NodeType.MemberExpression,
|
||||
"computed": true,
|
||||
"object": {
|
||||
"type": NodeType_1.NodeType.MemberExpression,
|
||||
"computed": true,
|
||||
"object": {
|
||||
"type": NodeType_1.NodeType.ArrayExpression,
|
||||
"elements": []
|
||||
},
|
||||
"property": {
|
||||
"type": NodeType_1.NodeType.Literal,
|
||||
"value": "filter",
|
||||
"raw": "\"filter\""
|
||||
}
|
||||
},
|
||||
"property": {
|
||||
"type": NodeType_1.NodeType.Literal,
|
||||
"value": "constructor",
|
||||
"raw": "\"constructor\""
|
||||
}
|
||||
},
|
||||
"arguments": [
|
||||
{
|
||||
"type": NodeType_1.NodeType.BinaryExpression,
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": NodeType_1.NodeType.BinaryExpression,
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": NodeType_1.NodeType.BinaryExpression,
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": NodeType_1.NodeType.BinaryExpression,
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": NodeType_1.NodeType.BinaryExpression,
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": NodeType_1.NodeType.BinaryExpression,
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": NodeType_1.NodeType.BinaryExpression,
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": NodeType_1.NodeType.Literal,
|
||||
"value": "_='(\u0002var \u0004\u0005[][\"filter\"]",
|
||||
"raw": "\"_='(\\u0002var \\u0004\\u0005[][\\\"filter\\\"]\""
|
||||
},
|
||||
"right": {
|
||||
"type": NodeType_1.NodeType.Literal,
|
||||
"value": "[\"\u0006tructor\"](\"return t",
|
||||
"raw": "\"[\\\"\\u0006tructor\\\"](\\\"return t\""
|
||||
}
|
||||
},
|
||||
"right": {
|
||||
"type": NodeType_1.NodeType.Literal,
|
||||
"value": "his\")()\u0003log\u0001error\u0001info\u0001warn\u0005\u0002};})()\u0001\u0005\u0002}\u0003\u0002function () {\u0003;\u0004.\u0006ole.\u0004_window\u0005 = \u0006cons';for(Y in $='\u0006\u0005\u0004\u0003\u0002\u0001')with",
|
||||
"raw": "\"his\\\")()\\u0003log\\u0001error\\u0001info\\u0001warn\\u0005\\u0002};})()\\u0001\\u0005\\u0002}\\u0003\\u0002function () {\\u0003;\\u0004.\\u0006ole.\\u0004_window\\u0005 = \\u0006cons';for(Y in $='\\u0006\\u0005\\u0004\\u0003\\u0002\\u0001')with\""
|
||||
}
|
||||
},
|
||||
"right": {
|
||||
"type": NodeType_1.NodeType.Literal,
|
||||
"value": "(_.",
|
||||
"raw": "\"(_.\""
|
||||
}
|
||||
},
|
||||
"right": {
|
||||
"type": NodeType_1.NodeType.Literal,
|
||||
"value": "split($[Y]))_=jo",
|
||||
"raw": "\"split($[Y]))_=jo\""
|
||||
}
|
||||
},
|
||||
"right": {
|
||||
"type": NodeType_1.NodeType.Literal,
|
||||
"value": "in(pop",
|
||||
"raw": "\"in(pop\""
|
||||
}
|
||||
},
|
||||
"right": {
|
||||
"type": NodeType_1.NodeType.Literal,
|
||||
"value": "());ev",
|
||||
"raw": "\"());ev\""
|
||||
}
|
||||
},
|
||||
"right": {
|
||||
"type": NodeType_1.NodeType.Literal,
|
||||
"value": "al(_)",
|
||||
"raw": "\"al(_)\""
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"arguments": []
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.ConsoleOutputDisableExpressionNode = ConsoleOutputDisableExpressionNode;
|
||||
@@ -0,0 +1,156 @@
|
||||
/* tslint:disable:max-line-length */
|
||||
|
||||
import * as estraverse from 'estraverse';
|
||||
|
||||
import { IProgramNode } from '../interfaces/nodes/IProgramNode';
|
||||
import { ITreeNode } from '../interfaces/nodes/ITreeNode';
|
||||
|
||||
import { NodeType } from "../enums/NodeType";
|
||||
|
||||
import { Node } from './Node';
|
||||
|
||||
export class ConsoleOutputDisableExpressionNode extends Node {
|
||||
/**
|
||||
* @type {ITreeNode}
|
||||
*/
|
||||
protected node: ITreeNode;
|
||||
|
||||
/**
|
||||
* @type {ITreeNode}
|
||||
*/
|
||||
private astTree: ITreeNode;
|
||||
|
||||
/**
|
||||
* @param astTree
|
||||
*/
|
||||
constructor (astTree: ITreeNode) {
|
||||
super();
|
||||
|
||||
this.astTree = astTree;
|
||||
this.node = this.getNodeStructure();
|
||||
}
|
||||
|
||||
public appendNode (): void {
|
||||
estraverse.replace(this.astTree, {
|
||||
leave: (node: ITreeNode, parent: ITreeNode): any => {
|
||||
switch (node.type) {
|
||||
case NodeType.Program:
|
||||
(<IProgramNode>node).body.unshift(this.getNode());
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns any
|
||||
*/
|
||||
protected getNodeStructure (): any {
|
||||
return {
|
||||
"type": NodeType.ExpressionStatement,
|
||||
"expression": {
|
||||
"type": NodeType.CallExpression,
|
||||
"callee": {
|
||||
"type": NodeType.CallExpression,
|
||||
"callee": {
|
||||
"type": NodeType.MemberExpression,
|
||||
"computed": true,
|
||||
"object": {
|
||||
"type": NodeType.MemberExpression,
|
||||
"computed": true,
|
||||
"object": {
|
||||
"type": NodeType.ArrayExpression,
|
||||
"elements": []
|
||||
},
|
||||
"property": {
|
||||
"type": NodeType.Literal,
|
||||
"value": "filter",
|
||||
"raw": "\"filter\""
|
||||
}
|
||||
},
|
||||
"property": {
|
||||
"type": NodeType.Literal,
|
||||
"value": "constructor",
|
||||
"raw": "\"constructor\""
|
||||
}
|
||||
},
|
||||
"arguments": [
|
||||
{
|
||||
"type": NodeType.BinaryExpression,
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": NodeType.BinaryExpression,
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": NodeType.BinaryExpression,
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": NodeType.BinaryExpression,
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": NodeType.BinaryExpression,
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": NodeType.BinaryExpression,
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": NodeType.BinaryExpression,
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": NodeType.Literal,
|
||||
"value": "_='(\u0002var \u0004\u0005[][\"filter\"]",
|
||||
"raw": "\"_='(\\u0002var \\u0004\\u0005[][\\\"filter\\\"]\""
|
||||
},
|
||||
"right": {
|
||||
"type": NodeType.Literal,
|
||||
"value": "[\"\u0006tructor\"](\"return t",
|
||||
"raw": "\"[\\\"\\u0006tructor\\\"](\\\"return t\""
|
||||
}
|
||||
},
|
||||
"right": {
|
||||
"type": NodeType.Literal,
|
||||
"value": "his\")()\u0003log\u0001error\u0001info\u0001warn\u0005\u0002};})()\u0001\u0005\u0002}\u0003\u0002function () {\u0003;\u0004.\u0006ole.\u0004_window\u0005 = \u0006cons';for(Y in $='\u0006\u0005\u0004\u0003\u0002\u0001')with",
|
||||
"raw": "\"his\\\")()\\u0003log\\u0001error\\u0001info\\u0001warn\\u0005\\u0002};})()\\u0001\\u0005\\u0002}\\u0003\\u0002function () {\\u0003;\\u0004.\\u0006ole.\\u0004_window\\u0005 = \\u0006cons';for(Y in $='\\u0006\\u0005\\u0004\\u0003\\u0002\\u0001')with\""
|
||||
}
|
||||
},
|
||||
"right": {
|
||||
"type": NodeType.Literal,
|
||||
"value": "(_.",
|
||||
"raw": "\"(_.\""
|
||||
}
|
||||
},
|
||||
"right": {
|
||||
"type": NodeType.Literal,
|
||||
"value": "split($[Y]))_=jo",
|
||||
"raw": "\"split($[Y]))_=jo\""
|
||||
}
|
||||
},
|
||||
"right": {
|
||||
"type": NodeType.Literal,
|
||||
"value": "in(pop",
|
||||
"raw": "\"in(pop\""
|
||||
}
|
||||
},
|
||||
"right": {
|
||||
"type": NodeType.Literal,
|
||||
"value": "());ev",
|
||||
"raw": "\"());ev\""
|
||||
}
|
||||
},
|
||||
"right": {
|
||||
"type": NodeType.Literal,
|
||||
"value": "al(_)",
|
||||
"raw": "\"al(_)\""
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"arguments": []
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,7 @@ let obfuscatedCode = index_1.JavaScriptObfuscator.obfuscate(`
|
||||
console.log(true, false);
|
||||
})();
|
||||
`, {
|
||||
disableConsoleOutput: false,
|
||||
rotateUnicodeArray: false
|
||||
});
|
||||
console.log(obfuscatedCode);
|
||||
|
||||
@@ -49,6 +49,7 @@ let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
|
||||
})();
|
||||
`,
|
||||
{
|
||||
disableConsoleOutput: false,
|
||||
rotateUnicodeArray: false
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user