version 0.5.0

This commit is contained in:
sanex3339
2016-05-28 14:31:25 +03:00
parent 839181e9c3
commit 171234250f
19 changed files with 77 additions and 46 deletions
+2 -1
View File
@@ -22,7 +22,8 @@ JavaScriptObfuscator.defaultOptions = {
debugProtection: false,
debugProtectionInterval: false,
disableConsoleOutput: true,
rotateUnicodeArray: true
rotateUnicodeArray: true,
wrapUnicodeArrayCalls: false
};
JavaScriptObfuscator.escodegenParams = {
verbatim: 'x-verbatim-property'
+1 -1
View File
@@ -70,7 +70,7 @@ class Obfuscator {
return;
}
this.nodeObfuscators.get(node.type).forEach((obfuscator) => {
new obfuscator(this.nodes).obfuscateNode(node, parentNode);
new obfuscator(this.nodes, this.options).obfuscateNode(node, parentNode);
});
}
obfuscate(node) {
@@ -4,11 +4,11 @@ const AppendState_1 = require("../../enums/AppendState");
const Node_1 = require('../Node');
const NodeUtils_1 = require("../../NodeUtils");
const Utils_1 = require("../../Utils");
class UnicodeArrayTranslator extends Node_1.Node {
constructor(unicodeArrayTranslatorName, unicodeArrayName, unicodeArray) {
class UnicodeArrayCallsWrapper extends Node_1.Node {
constructor(unicodeArrayCallsWrapperName, unicodeArrayName, unicodeArray) {
super();
this.appendState = AppendState_1.AppendState.AfterObfuscation;
this.unicodeArrayTranslatorName = unicodeArrayTranslatorName;
this.unicodeArrayCallsWrapperName = unicodeArrayCallsWrapperName;
this.unicodeArrayName = unicodeArrayName;
this.unicodeArray = unicodeArray;
this.node = this.getNodeStructure();
@@ -17,7 +17,7 @@ class UnicodeArrayTranslator extends Node_1.Node {
NodeUtils_1.NodeUtils.insertNodeAtIndex(blockScopeNode.body, this.getNode(), 1);
}
getNodeIdentifier() {
return this.unicodeArrayTranslatorName;
return this.unicodeArrayCallsWrapperName;
}
;
getNode() {
@@ -28,7 +28,7 @@ class UnicodeArrayTranslator extends Node_1.Node {
}
getNodeStructure() {
let keyName = Utils_1.Utils.getRandomVariableName(), node = esprima.parse(`
var ${this.unicodeArrayTranslatorName} = function (${keyName}) {
var ${this.unicodeArrayCallsWrapperName} = function (${keyName}) {
return ${this.unicodeArrayName}[[][${Utils_1.Utils.stringToUnicode('filter')}][${Utils_1.Utils.stringToUnicode('constructor')}](${Utils_1.Utils.stringToUnicode('return this')})()[${Utils_1.Utils.stringToUnicode('parseInt')}](${keyName})]
};
`);
@@ -36,4 +36,4 @@ class UnicodeArrayTranslator extends Node_1.Node {
return NodeUtils_1.NodeUtils.getBlockScopeNodeByIndex(node);
}
}
exports.UnicodeArrayTranslator = UnicodeArrayTranslator;
exports.UnicodeArrayCallsWrapper = UnicodeArrayCallsWrapper;
+4 -5
View File
@@ -1,9 +1,9 @@
"use strict";
const NodesGroup_1 = require('./NodesGroup');
const UnicodeArrayCallsWrapper_1 = require("../custom-nodes/unicode-array-nodes/UnicodeArrayCallsWrapper");
const UnicodeArrayNode_1 = require('../custom-nodes/unicode-array-nodes/UnicodeArrayNode');
const UnicodeArrayRotateFunctionNode_1 = require('../custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode');
const Utils_1 = require('../Utils');
const UnicodeArrayTranslator_1 = require("../custom-nodes/unicode-array-nodes/UnicodeArrayTranslator");
class UnicodeArrayNodesGroup extends NodesGroup_1.NodesGroup {
constructor(options) {
super();
@@ -16,12 +16,11 @@ class UnicodeArrayNodesGroup extends NodesGroup_1.NodesGroup {
[
'unicodeArrayNode',
unicodeArrayNode
],
[
'unicodeArrayTranslator',
new UnicodeArrayTranslator_1.UnicodeArrayTranslator(this.unicodeArrayTranslatorName, this.unicodeArrayName, unicodeArray)
]
]);
if (this.options['wrapUnicodeArrayCalls']) {
this.nodes.set('unicodeArrayCallsWrapper', new UnicodeArrayCallsWrapper_1.UnicodeArrayCallsWrapper(this.unicodeArrayTranslatorName, this.unicodeArrayName, unicodeArray));
}
if (this.options['rotateUnicodeArray']) {
this.nodes.set('unicodeArrayRotateFunctionNode', new UnicodeArrayRotateFunctionNode_1.UnicodeArrayRotateFunctionNode(this.unicodeArrayName, unicodeArray, this.unicodeArrayRotateValue));
}
+1 -1
View File
@@ -19,7 +19,7 @@ class LiteralObfuscator extends NodeObfuscator_1.NodeObfuscator {
content = this.replaceLiteralNumberByHexadecimalValue(literalNode.value);
break;
case 'string':
content = this.replaceLiteralStringByUnicodeArrayTranslatorCall(literalNode.value);
content = this.replaceLiteralStringByUnicodeArrayCall(literalNode.value);
break;
default:
return;
+2 -2
View File
@@ -26,7 +26,7 @@ class MemberExpressionObfuscator extends NodeObfuscator_1.NodeObfuscator {
let nodeValue = node.name, literalNode = {
raw: `'${nodeValue}'`,
'x-verbatim-property': {
content: this.replaceLiteralStringByUnicodeArrayTranslatorCall(nodeValue),
content: this.replaceLiteralStringByUnicodeArrayCall(nodeValue),
precedence: escodegen.Precedence.Primary
},
type: NodeType_1.NodeType.Literal,
@@ -42,7 +42,7 @@ class MemberExpressionObfuscator extends NodeObfuscator_1.NodeObfuscator {
break;
}
node['x-verbatim-property'] = {
content: this.replaceLiteralStringByUnicodeArrayTranslatorCall(node.value),
content: this.replaceLiteralStringByUnicodeArrayCall(node.value),
precedence: escodegen.Precedence.Primary
};
break;
+1 -1
View File
@@ -18,7 +18,7 @@ class MethodDefinitionObfuscator extends NodeObfuscator_1.NodeObfuscator {
!Utils_1.Utils.arrayContains(this.ignoredNames, node.name) &&
methodDefinitionNode.computed === false) {
methodDefinitionNode.computed = true;
node.name = this.replaceLiteralStringByUnicodeArrayTranslatorCall(node.name);
node.name = this.replaceLiteralStringByUnicodeArrayCall(node.name);
return;
}
return estraverse.VisitorOption.Skip;
+7 -3
View File
@@ -3,8 +3,9 @@ const JSFuck_1 = require("../enums/JSFuck");
const NodeUtils_1 = require("../NodeUtils");
const Utils_1 = require('../Utils');
class NodeObfuscator {
constructor(nodes) {
constructor(nodes, options = {}) {
this.nodes = nodes;
this.options = options;
}
replaceNodeIdentifierByNewValue(node, parentNode, namesMap) {
if (NodeUtils_1.NodeUtils.isIdentifierNode(node) && namesMap.has(node.name)) {
@@ -25,7 +26,7 @@ class NodeObfuscator {
}
return `${prefix}${Utils_1.Utils.decToHex(nodeValue)}`;
}
replaceLiteralStringByUnicodeArrayTranslatorCall(nodeValue) {
replaceLiteralStringByUnicodeArrayCall(nodeValue) {
let value = Utils_1.Utils.stringToUnicode(nodeValue), unicodeArray = this.nodes.get('unicodeArrayNode').getNodeData(), sameIndex = unicodeArray.indexOf(value), index, hexadecimalIndex;
if (sameIndex < 0) {
index = unicodeArray.length;
@@ -35,7 +36,10 @@ class NodeObfuscator {
index = sameIndex;
}
hexadecimalIndex = this.replaceLiteralNumberByHexadecimalValue(index);
return `${this.nodes.get('unicodeArrayTranslator').getNodeIdentifier()}('${hexadecimalIndex}')`;
if (this.options['wrapUnicodeArrayCalls']) {
return `${this.nodes.get('unicodeArrayCallsWrapper').getNodeIdentifier()}('${hexadecimalIndex}')`;
}
return `${this.nodes.get('unicodeArrayNode').getNodeIdentifier()}[${hexadecimalIndex}]`;
}
}
exports.NodeObfuscator = NodeObfuscator;
+2 -1
View File
@@ -16,7 +16,8 @@ class JavaScriptObfuscator {
debugProtection: false,
debugProtectionInterval: false,
disableConsoleOutput: true,
rotateUnicodeArray: true
rotateUnicodeArray: true,
wrapUnicodeArrayCalls: false
};
/**
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "javascript-obfuscator",
"version": "0.4.3",
"version": "0.5.0",
"description": "JavaScript obfuscator",
"keywords": [
"obfuscator",
+12
View File
@@ -101,3 +101,15 @@ which will rotate array values back to their original indexes.
This option affected only on visual code organisation, because we can easily get original array during debug process.
Not recommended for small source code, because helper function will attract attention.
####wrapUnicodeArrayCalls
Type: `boolean` Default: `false`
#####This option have huge affect on performance! Use this option only on small pieces of code (< 5000 LOC)
Instead using direct calls to `unicodeArray` items `var t = _0x43a123[0x0]`,
when index `0x0` can be easy reverted to `0` with few js beautifiers, this option wrap all calls to special function instead.
```javascript
`var t = _0x12a634('0x0')`
```
+1 -1
View File
@@ -125,7 +125,7 @@ export class Obfuscator {
}
this.nodeObfuscators.get(node.type).forEach((obfuscator: Function) => {
new (<INodeObfuscator> obfuscator(this.nodes)).obfuscateNode(node, parentNode);
new (<INodeObfuscator> obfuscator(this.nodes, this.options)).obfuscateNode(node, parentNode);
});
}
@@ -10,7 +10,7 @@ import { Node } from '../Node';
import { NodeUtils } from "../../NodeUtils";
import { Utils } from "../../Utils";
export class UnicodeArrayTranslator extends Node {
export class UnicodeArrayCallsWrapper extends Node {
/**
* @type {AppendState}
*/
@@ -29,21 +29,21 @@ export class UnicodeArrayTranslator extends Node {
/**
* @type {string}
*/
private unicodeArrayTranslatorName: string;
private unicodeArrayCallsWrapperName: string;
/**
* @param unicodeArrayTranslatorName
* @param unicodeArrayCallsWrapperName
* @param unicodeArrayName
* @param unicodeArray
*/
constructor (
unicodeArrayTranslatorName: string,
unicodeArrayCallsWrapperName: string,
unicodeArrayName: string,
unicodeArray: string[]
) {
super();
this.unicodeArrayTranslatorName = unicodeArrayTranslatorName;
this.unicodeArrayCallsWrapperName = unicodeArrayCallsWrapperName;
this.unicodeArrayName = unicodeArrayName;
this.unicodeArray = unicodeArray;
@@ -61,7 +61,7 @@ export class UnicodeArrayTranslator extends Node {
* @returns {string}
*/
public getNodeIdentifier (): string {
return this.unicodeArrayTranslatorName;
return this.unicodeArrayCallsWrapperName;
};
/**
@@ -81,7 +81,7 @@ export class UnicodeArrayTranslator extends Node {
protected getNodeStructure (): any {
let keyName: string = Utils.getRandomVariableName(),
node: INode = esprima.parse(`
var ${this.unicodeArrayTranslatorName} = function (${keyName}) {
var ${this.unicodeArrayCallsWrapperName} = function (${keyName}) {
return ${this.unicodeArrayName}[[][${Utils.stringToUnicode('filter')}][${Utils.stringToUnicode('constructor')}](${Utils.stringToUnicode('return this')})()[${Utils.stringToUnicode('parseInt')}](${keyName})]
};
`);
+10 -7
View File
@@ -1,10 +1,10 @@
import { ICustomNode } from '../interfaces/ICustomNode';
import { NodesGroup } from './NodesGroup';
import { UnicodeArrayCallsWrapper } from "../custom-nodes/unicode-array-nodes/UnicodeArrayCallsWrapper";
import { UnicodeArrayNode } from '../custom-nodes/unicode-array-nodes/UnicodeArrayNode';
import { UnicodeArrayRotateFunctionNode } from '../custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode';
import { Utils } from '../Utils';
import {UnicodeArrayTranslator} from "../custom-nodes/unicode-array-nodes/UnicodeArrayTranslator";
export class UnicodeArrayNodesGroup extends NodesGroup {
/**
@@ -45,16 +45,19 @@ export class UnicodeArrayNodesGroup extends NodesGroup {
[
'unicodeArrayNode',
unicodeArrayNode
],
[
'unicodeArrayTranslator',
new UnicodeArrayTranslator(
]
]);
if (this.options['wrapUnicodeArrayCalls']) {
this.nodes.set(
'unicodeArrayCallsWrapper',
new UnicodeArrayCallsWrapper(
this.unicodeArrayTranslatorName,
this.unicodeArrayName,
unicodeArray
)
]
]);
);
}
if (this.options['rotateUnicodeArray']) {
this.nodes.set(
+1 -1
View File
@@ -35,7 +35,7 @@ export class LiteralObfuscator extends NodeObfuscator {
case 'string':
content = this.replaceLiteralStringByUnicodeArrayTranslatorCall(<string>literalNode.value);
content = this.replaceLiteralStringByUnicodeArrayCall(<string>literalNode.value);
break;
@@ -53,7 +53,7 @@ export class MemberExpressionObfuscator extends NodeObfuscator {
literalNode: ILiteralNode = {
raw: `'${nodeValue}'`,
'x-verbatim-property': {
content : this.replaceLiteralStringByUnicodeArrayTranslatorCall(nodeValue),
content : this.replaceLiteralStringByUnicodeArrayCall(nodeValue),
precedence: escodegen.Precedence.Primary
},
type: NodeType.Literal,
@@ -82,7 +82,7 @@ export class MemberExpressionObfuscator extends NodeObfuscator {
}
node['x-verbatim-property'] = {
content : this.replaceLiteralStringByUnicodeArrayTranslatorCall(<string>node.value),
content : this.replaceLiteralStringByUnicodeArrayCall(<string>node.value),
precedence: escodegen.Precedence.Primary
};
@@ -42,7 +42,7 @@ export class MethodDefinitionObfuscator extends NodeObfuscator {
methodDefinitionNode.computed === false
) {
methodDefinitionNode.computed = true;
node.name = this.replaceLiteralStringByUnicodeArrayTranslatorCall(node.name);
node.name = this.replaceLiteralStringByUnicodeArrayCall(node.name);
return;
}
+15 -4
View File
@@ -14,10 +14,17 @@ export abstract class NodeObfuscator implements INodeObfuscator {
protected nodes: Map <string, ICustomNode>;
/**
* @param nodes
* @type any
*/
constructor(nodes: Map <string, ICustomNode>) {
protected options: any;
/**
* @param nodes
* @param options
*/
constructor(nodes: Map <string, ICustomNode>, options: any = {}) {
this.nodes = nodes;
this.options = options;
}
/**
@@ -70,7 +77,7 @@ export abstract class NodeObfuscator implements INodeObfuscator {
* @param nodeValue
* @returns {string}
*/
protected replaceLiteralStringByUnicodeArrayTranslatorCall (nodeValue: string): string {
protected replaceLiteralStringByUnicodeArrayCall (nodeValue: string): string {
let value: string = Utils.stringToUnicode(nodeValue),
unicodeArray: string[] = this.nodes.get('unicodeArrayNode').getNodeData(),
sameIndex: number = unicodeArray.indexOf(value),
@@ -86,6 +93,10 @@ export abstract class NodeObfuscator implements INodeObfuscator {
hexadecimalIndex = this.replaceLiteralNumberByHexadecimalValue(index);
return `${this.nodes.get('unicodeArrayTranslator').getNodeIdentifier()}('${hexadecimalIndex}')`;
if (this.options['wrapUnicodeArrayCalls']) {
return `${this.nodes.get('unicodeArrayCallsWrapper').getNodeIdentifier()}('${hexadecimalIndex}')`;
}
return `${this.nodes.get('unicodeArrayNode').getNodeIdentifier()}[${hexadecimalIndex}]`;
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
import * as JavaScriptObfuscator from "../index";
let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
let obfuscatedCode: string = (<any>JavaScriptObfuscator).obfuscate(
`
(function(){
var result = 1,