Initial commit

This commit is contained in:
sanex3339
2016-05-09 11:17:04 +03:00
commit c3b9da3821
70 changed files with 3754 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
.idea
node_modules
+20
View File
@@ -0,0 +1,20 @@
"use strict";
const Obfuscator_1 = require('./src/Obfuscator');
let escodegen = require('escodegen'), esprima = require('esprima'), RawSource = require('webpack-core/lib/RawSource');
class JavaScriptObfuscator {
static obfuscate(sourceCode, options) {
let astTree = esprima.parse(sourceCode), obfuscator = new Obfuscator_1.Obfuscator(options);
obfuscator.obfuscateNode(astTree);
return JavaScriptObfuscator.generateCode(astTree);
}
static generateCode(astTree) {
return new RawSource(escodegen.generate(astTree, JavaScriptObfuscator.escodegenParams));
}
}
JavaScriptObfuscator.escodegenParams = {
format: {},
verbatim: 'x-verbatim-property'
};
exports.JavaScriptObfuscator = JavaScriptObfuscator;
module.exports = JavaScriptObfuscator;
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAIb,6BAA2B,kBAAkB,CAAC,CAAA;AAI9C,IAAI,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,EAChC,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,EAC5B,SAAS,GAAQ,OAAO,CAAC,4BAA4B,CAAC,CAAC;AAE3D;IAeI,OAAc,SAAS,CAAE,UAAkB,EAAE,OAAY;QACrD,IAAI,OAAO,GAAQ,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,EACxC,UAAU,GAAe,IAAI,uBAAU,CAAC,OAAO,CAAC,CAAC;QAErD,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAElC,MAAM,CAAC,oBAAoB,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IACtD,CAAC;IAKD,OAAe,YAAY,CAAE,OAAY;QACrC,MAAM,CAAC,IAAI,SAAS,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAC,eAAe,CAAC,CAAC,CAAC;IAC5F,CAAC;AACL,CAAC;AA1BkB,oCAAe,GAAQ;IAClC,MAAM,EAAE,EAEP;IACD,QAAQ,EAAE,qBAAqB;CAClC,CAAC;AATO,4BAAoB,uBA8BhC,CAAA;AAED,MAAM,CAAC,OAAO,GAAG,oBAAoB,CAAC"}
+45
View File
@@ -0,0 +1,45 @@
"use strict";
declare let module: any;
import { Obfuscator } from './src/Obfuscator';
import { UnicodeArrayNodesGroup } from './src/node-groups/UnicodeArrayNodesGroup';
import { Utils } from './src/Utils';
let escodegen = require('escodegen'),
esprima = require('esprima'),
RawSource: any = require('webpack-core/lib/RawSource');
export class JavaScriptObfuscator {
/**
* @type any
*/
private static escodegenParams: any = {
format: {
//compact: true
},
verbatim: 'x-verbatim-property'
};
/**
* @param sourceCode
* @param options
*/
public static obfuscate (sourceCode: string, options: any): string {
let astTree: any = esprima.parse(sourceCode),
obfuscator: Obfuscator = new Obfuscator(options);
obfuscator.obfuscateNode(astTree);
return JavaScriptObfuscator.generateCode(astTree);
}
/**
* @param astTree
*/
private static generateCode (astTree: any): string {
return new RawSource(escodegen.generate(astTree, JavaScriptObfuscator.escodegenParams));
}
}
module.exports = JavaScriptObfuscator;
+27
View File
@@ -0,0 +1,27 @@
{
"name": "javascript-obfuscator",
"version": "0.0.9",
"description": "JavaScript obfuscator",
"main": "index.js",
"dependencies": {
},
"devDependencies": {
"lite-server": "^1.3.1",
"tsd": "^0.6.5",
"typescript": "*"
},
"repository": {
"type": "git",
"url": "git+https://github.com/sanex3339/javascript-obfuscator.git"
},
"scripts": {
"tsc": "tsc",
"tsc:w": "tsc -w",
"lite": "lite-server",
"start": "concurrent \"npm run tsc:w\" \"npm run lite\" "
},
"author": {
"name": "sanex3339"
},
"license": "ISC"
}
+50
View File
@@ -0,0 +1,50 @@
#JavaScript obfuscator for Node.js
JavaScript obfuscator for Node.js and free alternative of [js-obfuscator](https://github.com/caiguanhao/js-obfuscator) without any limits.
###Installation
Install the package with NPM and add it to your devDependencies:
`npm install --save-dev javascript-obfuscator`
###Usage:
```javascript
var JavaScriptObfuscator = require('javascript-obfuscator');
var obfuscatedCode = JavaScriptObfuscator.obfuscate(
`var variable = 'abc'; console.log(variable);`,
{
rotateUnicodeArray: false
}
);
```
## obfuscate(sourceCode, options)
###sourceCode
Type: `string` Default: `null`
Any valid SourceCode
###options
Type: `Object` Default: `null`
Options for JavaScript obfuscator:
```javascript
{
rotateUnicodeArray: false
}
```
####Available options
#####rotateUnicodeArray
Default: `true`
For more hard understanding of code, during each obfuscation all literal values are stored in array as Unicode codes sequence.
This options will rotate all values inside array at random value during obfuscation of code, and insert inside source code helper function
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.
+89
View File
@@ -0,0 +1,89 @@
"use strict";
const AppendState_1 = require('./enums/AppendState');
const FunctionDeclarationObfuscator_1 = require('./node-obfuscators/FunctionDeclarationObfuscator');
const FunctionObfuscator_1 = require('./node-obfuscators/FunctionObfuscator');
const LiteralObfuscator_1 = require('./node-obfuscators/LiteralObfuscator');
const MemberExpressionObfuscator_1 = require('./node-obfuscators/MemberExpressionObfuscator');
const MethodDefinitionObfuscator_1 = require('./node-obfuscators/MethodDefinitionObfuscator');
const ObjectExpressionObfuscator_1 = require('./node-obfuscators/ObjectExpressionObfuscator');
const UnicodeArrayNode_1 = require('./nodes/UnicodeArrayNode');
const UnicodeArrayNodesGroup_1 = require('./node-groups/UnicodeArrayNodesGroup');
const Utils_1 = require('./Utils');
const VariableDeclarationObfuscator_1 = require('./node-obfuscators/VariableDeclarationObfuscator');
let estraverse = require('estraverse');
class Obfuscator {
constructor(options) {
this.nodes = new Map();
this.nodeObfuscators = new Map([
['ClassDeclaration', [FunctionDeclarationObfuscator_1.FunctionDeclarationObfuscator]],
['FunctionDeclaration', [
FunctionDeclarationObfuscator_1.FunctionDeclarationObfuscator,
FunctionObfuscator_1.FunctionObfuscator
]],
['ArrowFunctionExpression', [FunctionObfuscator_1.FunctionObfuscator]],
['FunctionExpression', [FunctionObfuscator_1.FunctionObfuscator]],
['MethodDefinition', [MethodDefinitionObfuscator_1.MethodDefinitionObfuscator]],
['VariableDeclaration', [VariableDeclarationObfuscator_1.VariableDeclarationObfuscator]],
['ObjectExpression', [ObjectExpressionObfuscator_1.ObjectExpressionObfuscator]],
['MemberExpression', [MemberExpressionObfuscator_1.MemberExpressionObfuscator]],
['Literal', [LiteralObfuscator_1.LiteralObfuscator]]
]);
this.options = {
rotateUnicodeArray: true
};
Object.assign(this.options, options);
}
obfuscateNode(node) {
if (this.options['rotateUnicodeArray']) {
this.setNodesGroup('unicodeArrayNodesGroup', new UnicodeArrayNodesGroup_1.UnicodeArrayNodesGroup(node));
}
else {
this.setNode('unicodeArrayNode', new UnicodeArrayNode_1.UnicodeArrayNode(node, Utils_1.Utils.getRandomVariableName(UnicodeArrayNode_1.UnicodeArrayNode.UNICODE_ARRAY_RANDOM_LENGTH)));
}
this.beforeObfuscation(node);
estraverse.replace(node, {
leave: (node, parent) => this.nodeController(node, parent)
});
this.afterObfuscation(node);
}
setNode(nodeName, node) {
this.nodes.set(nodeName, node);
}
setNodesGroup(groupName, nodesGroup) {
let nodes = nodesGroup.getNodes();
nodes.forEach((node, key) => {
this.nodes.set(key, node);
});
}
afterObfuscation(node) {
this.nodes.forEach((node) => {
if (node.getAppendState() === AppendState_1.AppendState.AfterObfuscation) {
node.appendNode();
}
});
}
beforeObfuscation(node) {
this.nodes.forEach((node) => {
if (node.getAppendState() === AppendState_1.AppendState.BeforeObfuscation) {
node.appendNode();
}
});
}
;
nodeController(node, parent) {
switch (node.type) {
default:
this.initializeNodeObfuscators(node, parent);
}
}
initializeNodeObfuscators(node, parent) {
if (!this.nodeObfuscators.has(node.type)) {
return;
}
this.nodeObfuscators.get(node.type).forEach((obfuscator) => {
new obfuscator(this.nodes).obfuscateNode(node, parent);
});
}
}
exports.Obfuscator = Obfu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3B,EAAE,CAAC,CAAC,IAAI,CAAC,cAAc,EAAE,KAAK,yBAAW,CAAC,gBAAgB,CAAC,CAAC,CAAC;gBACzD,IAAI,CAAC,UAAU,EAAE,CAAC;YACtB,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IAKO,iBAAiB,CAAE,IAAS;QAChC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAW;YAC3B,EAAE,CAAC,CAAC,IAAI,CAAC,cAAc,EAAE,KAAK,yBAAW,CAAC,iBAAiB,CAAC,CAAC,CAAC;gBAC1D,IAAI,CAAC,UAAU,EAAE,CAAC;YACtB,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;;IAMO,cAAc,CAAE,IAAI,EAAE,MAAM;QAChC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YAChB;gBACI,IAAI,CAAC,yBAAyB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACrD,CAAC;IACL,CAAC;IAMO,yBAAyB,CAAE,IAAS,EAAE,MAAW;QACrD,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACvC,MAAM,CAAC;QACX,CAAC;QAED,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,UAAoB;YAC7D,IAAuB,UAAU,CAAC,IAAI,CAAC,KAAK,CAAE,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC/E,CAAC,CAAC,CAAC;IACP,CAAC;AACL,CAAC;AA9HY,kBAAU,aA8HtB,CAAA"}
+148
View File
@@ -0,0 +1,148 @@
import { INode } from './interfaces/INode';
import { INodeObfuscator } from './interfaces/INodeObfuscator';
import { INodesGroup } from './interfaces/INodesGroup';
import { AppendState } from './enums/AppendState';
import { FunctionDeclarationObfuscator } from './node-obfuscators/FunctionDeclarationObfuscator';
import { FunctionObfuscator } from './node-obfuscators/FunctionObfuscator';
import { LiteralObfuscator } from './node-obfuscators/LiteralObfuscator';
import { NodesGroup } from './node-groups/NodesGroup';
import { MemberExpressionObfuscator } from './node-obfuscators/MemberExpressionObfuscator';
import { MethodDefinitionObfuscator } from './node-obfuscators/MethodDefinitionObfuscator';
import { ObjectExpressionObfuscator } from './node-obfuscators/ObjectExpressionObfuscator';
import { UnicodeArrayNode } from './nodes/UnicodeArrayNode';
import { UnicodeArrayNodesGroup } from './node-groups/UnicodeArrayNodesGroup';
import { UnicodeArrayRotateFunctionNode } from './nodes/UnicodeArrayRotateFunctionNode';
import { Utils } from './Utils';
import { VariableDeclarationObfuscator } from './node-obfuscators/VariableDeclarationObfuscator';
let estraverse = require('estraverse');
export class Obfuscator {
/**
* @type {Map<string, Node>}
*/
private nodes: Map <string, INode> = new Map <string, INode> ();
/**
* @type {Map<string, Function[]>}
*/
private nodeObfuscators: Map <string, Function[]> = new Map <string, Function[]> ([
['ClassDeclaration', [FunctionDeclarationObfuscator]],
['FunctionDeclaration', [
FunctionDeclarationObfuscator,
FunctionObfuscator
]],
['ArrowFunctionExpression', [FunctionObfuscator]],
['FunctionExpression', [FunctionObfuscator]],
['MethodDefinition', [MethodDefinitionObfuscator]],
['VariableDeclaration', [VariableDeclarationObfuscator]],
['ObjectExpression', [ObjectExpressionObfuscator]],
['MemberExpression', [MemberExpressionObfuscator]],
['Literal', [LiteralObfuscator]]
]);
/**
* @type any
*/
private options: any = {
rotateUnicodeArray: true
};
/**
* @param options
*/
constructor (options: any) {
Object.assign(this.options, options);
}
/**
* @param node
*/
public obfuscateNode (node: any): void {
if (this.options['rotateUnicodeArray']) {
this.setNodesGroup('unicodeArrayNodesGroup', new UnicodeArrayNodesGroup(node));
} else {
this.setNode(
'unicodeArrayNode',
new UnicodeArrayNode(node, Utils.getRandomVariableName(UnicodeArrayNode.UNICODE_ARRAY_RANDOM_LENGTH))
);
}
this.beforeObfuscation(node);
estraverse.replace(node, {
leave: (node, parent) => this.nodeController(node, parent)
});
this.afterObfuscation(node);
}
/**
* @param nodeName
* @param node
*/
public setNode (nodeName: string, node: INode): void {
this.nodes.set(nodeName, node);
}
/**
* @param groupName
* @param nodesGroup
*/
public setNodesGroup (groupName: string, nodesGroup: NodesGroup): void {
let nodes: Map <string, INode> = nodesGroup.getNodes();
nodes.forEach((node: INode, key: string) => {
this.nodes.set(key, node);
});
}
/**
* @param node
*/
private afterObfuscation (node: any): void {
this.nodes.forEach((node: INode) => {
if (node.getAppendState() === AppendState.AfterObfuscation) {
node.appendNode();
}
});
}
/**
* @param node
*/
private beforeObfuscation (node: any): void {
this.nodes.forEach((node: INode) => {
if (node.getAppendState() === AppendState.BeforeObfuscation) {
node.appendNode();
}
});
};
/**
* @param node
* @param parent
*/
private nodeController (node, parent): void {
switch (node.type) {
default:
this.initializeNodeObfuscators(node, parent);
}
}
/**
* @param node
* @param parent
*/
private initializeNodeObfuscators (node: any, parent: any): void {
if (!this.nodeObfuscators.has(node.type)) {
return;
}
this.nodeObfuscators.get(node.type).forEach((obfuscator: Function) => {
new (<INodeObfuscator> obfuscator(this.nodes)).obfuscateNode(node, parent);
});
}
}
+37
View File
@@ -0,0 +1,37 @@
"use strict";
class Utils {
static arrayRotate(array, times, reverse = false) {
if (times < 0) {
return;
}
let newArray = array, temp;
while (times--) {
if (!reverse) {
temp = newArray.pop();
newArray.unshift(temp);
}
else {
temp = newArray.shift();
newArray.push(temp);
}
}
return newArray;
}
static decToHex(dec) {
return (dec + Math.pow(16, 6)).toString(16).substr(-6);
}
static getRandomInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
static getRandomVariableName(length = 6) {
const prefix = '_0x';
return `${prefix}${(Utils.decToHex(Utils.getRandomInteger(10000, 9999999))).substr(0, length)}`;
}
static stringToUnicode(string) {
return `'${string.replace(/[\s\S]/g, (escape) => {
return `\\u${('0000' + escape.charCodeAt(0).toString(16)).slice(-4)}`;
})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AAC,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC;IACpG,CAAC;IAMD,OAAc,eAAe,CAAE,MAAc;QACzC,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,MAAM;YACxC,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1E,CAAC,CAAC,GAAG,CAAC;IACV,CAAC;AACL,CAAC;AAhEY,aAAK,QAgEjB,CAAA"}
+65
View File
@@ -0,0 +1,65 @@
export class Utils {
/**
* @param array
* @param times
* @param reverse
* @returns {any[]}
*/
public static arrayRotate (array: any[], times: number, reverse: boolean = false) {
if (times < 0) {
return;
}
let newArray: any[] = array,
temp: any;
while (times--) {
if (!reverse) {
temp = newArray.pop();
newArray.unshift(temp);
} else {
temp = newArray.shift();
newArray.push(temp);
}
}
return newArray;
}
/**
* @param dec
* @returns {string}
*/
public static decToHex(dec: number): string {
return (dec + Math.pow(16, 6)).toString(16).substr(-6);
}
/**
* @param min
* @param max
* @returns {number}
*/
public static getRandomInteger(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
/**
* @param length
* @returns {any}
*/
public static getRandomVariableName (length: number = 6): string {
const prefix = '_0x';
return `${prefix}${(Utils.decToHex(Utils.getRandomInteger(10000, 9999999))).substr(0, length)}`;
}
/**
* @param string
* @returns {string}
*/
public static stringToUnicode (string: string): string {
return `'${string.replace(/[\s\S]/g, (escape) => {
return `\\u${('0000' + escape.charCodeAt(0).toString(16)).slice(-4)}`;
})}'`;
}
}
+7
View File
@@ -0,0 +1,7 @@
"use strict";
(function (AppendState) {
AppendState[AppendState["BeforeObfuscation"] = 0] = "BeforeObfuscation";
AppendState[AppendState["AfterObfuscation"] = 1] = "AfterObfuscation";
})(exports.AppendState || (exports.AppendState = {}));
var AppendState = exports.AppendState;
//# sourceMappingURL=AppendState.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"AppendState.js","sourceRoot":"","sources":["AppendState.ts"],"names":[],"mappings":";AAAA,WAAY,WAAW;IAAE,uEAAiB,CAAA;IAAE,qEAAgB,CAAA;AAAA,CAAC,EAAjD,mBAAW,KAAX,mBAAW,QAAsC;AAA7D,IAAY,WAAW,GAAX,mBAAiD,CAAA"}
+1
View File
@@ -0,0 +1 @@
export enum AppendState {BeforeObfuscation, AfterObfuscation}
+2
View File
@@ -0,0 +1,2 @@
"use strict";
//# sourceMappingURL=INode.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"INode.js","sourceRoot":"","sources":["INode.ts"],"names":[],"mappings":""}
+32
View File
@@ -0,0 +1,32 @@
import { AppendState } from '../enums/AppendState';
export interface INode {
appendNode (): void;
/**
* @returns {AppendState}
*/
getAppendState (): AppendState;
/**
* @returns any
*/
getNode (): any;
/**
* @returns {string}
*/
getNodeIdentifier ? (): string;
/**
* @returns any
*/
getNodeData ? (): any;
/**
* @param node
*/
setNode (node: any): void;
updateNode (): void;
}
+2
View File
@@ -0,0 +1,2 @@
"use strict";
//# sourceMappingURL=INodeObfuscator.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"INodeObfuscator.js","sourceRoot":"","sources":["INodeObfuscator.ts"],"names":[],"mappings":""}
+7
View File
@@ -0,0 +1,7 @@
export interface INodeObfuscator {
/**
* @param node
* @param parentNode
*/
obfuscateNode (node: any, parentNode?: any): void;
}
+2
View File
@@ -0,0 +1,2 @@
"use strict";
//# sourceMappingURL=INodesGroup.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"INodesGroup.js","sourceRoot":"","sources":["INodesGroup.ts"],"names":[],"mappings":""}
+8
View File
@@ -0,0 +1,8 @@
import { INode } from './INode';
export interface INodesGroup {
/**
* @returns {Map <string, INode>}
*/
getNodes (): Map <string, INode>;
}
+8
View File
@@ -0,0 +1,8 @@
"use strict";
class NodesGroup {
getNodes() {
return this.nodes;
}
}
exports.NodesGroup = NodesGroup;
//# sourceMappingURL=NodesGroup.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"NodesGroup.js","sourceRoot":"","sources":["NodesGroup.ts"],"names":[],"mappings":";AAIA;IASW,QAAQ;QACX,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;AACL,CAAC;AAZqB,kBAAU,aAY/B,CAAA"}
+17
View File
@@ -0,0 +1,17 @@
import { INode } from '../interfaces/INode';
import { INodesGroup } from '../interfaces/INodesGroup';
export abstract class NodesGroup implements INodesGroup {
/**
* @type {Map<string, Node>}
*/
protected nodes: Map <string, INode>;
/**
* @returns {Map<string, INode>}
*/
public getNodes (): Map <string, INode> {
return this.nodes;
}
}
+29
View File
@@ -0,0 +1,29 @@
"use strict";
const NodesGroup_1 = require('./NodesGroup');
const UnicodeArrayNode_1 = require('../nodes/UnicodeArrayNode');
const UnicodeArrayRotateFunctionCallNode_1 = require('../nodes/UnicodeArrayRotateFunctionCallNode');
const UnicodeArrayRotateFunctionNode_1 = require('../nodes/UnicodeArrayRotateFunctionNode');
const Utils_1 = require('../Utils');
class UnicodeArrayNodesGroup extends NodesGroup_1.NodesGroup {
constructor(astTree) {
super();
this.unicodeArrayRotateFunctionIdentifier = Utils_1.Utils.getRandomVariableName();
let unicodeArrayName = Utils_1.Utils.getRandomVariableName(UnicodeArrayNode_1.UnicodeArrayNode.UNICODE_ARRAY_RANDOM_LENGTH), unicodeArrayRotateValue = Utils_1.Utils.getRandomInteger(100, 500);
this.nodes = new Map([
[
'unicodeArrayNode',
new UnicodeArrayNode_1.UnicodeArrayNode(astTree, unicodeArrayName, unicodeArrayRotateValue)
],
[
'unicodeArrayRotateFunctionNode',
new UnicodeArrayRotateFunctionNode_1.UnicodeArrayRotateFunctionNode(astTree, this.unicodeArrayRotateFunctionIdentifier, unicodeArrayName)
],
[
'unicodeArrayRotateFunctionCallNode',
new UnicodeArrayRotateFunctionCallNode_1.UnicodeArrayRotateFunctionCallNode(astTree, this.unicodeArrayRotateFunctionIdentifier, unicodeArrayName, unicodeArrayRotateValue)
]
]);
}
}
exports.UnicodeArrayNodesGroup = UnicodeArrayNodesGroup;
//# sourceMappingURL=UnicodeArrayNodesGroup.js.map
@@ -0,0 +1 @@
{"version":3,"file":"UnicodeArrayNodesGroup.js","sourceRoot":"","sources":["UnicodeArrayNodesGroup.ts"],"names":[],"mappings":";AAEA,6BAA2B,cAAc,CAAC,CAAA;AAC1C,mCAAiC,2BAA2B,CAAC,CAAA;AAC7D,qDAAmD,6CAA6C,CAAC,CAAA;AACjG,iDAA+C,yCAAyC,CAAC,CAAA;AACzF,wBAAsB,UAAU,CAAC,CAAA;AAEjC,qCAA4C,uBAAU;IASlD,YAAa,OAAY;QACrB,OAAO,CAAC;QANJ,yCAAoC,GAAW,aAAK,CAAC,qBAAqB,EAAE,CAAC;QAQjF,IAAI,gBAAgB,GAAW,aAAK,CAAC,qBAAqB,CAAC,mCAAgB,CAAC,2BAA2B,CAAC,EACpG,uBAAuB,GAAW,aAAK,CAAC,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAEvE,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,CAAkB;YAClC;gBACI,kBAAkB;gBAClB,IAAI,mCAAgB,CAChB,OAAO,EACP,gBAAgB,EAChB,uBAAuB,CAC1B;aACJ;YACD;gBACI,gCAAgC;gBAChC,IAAI,+DAA8B,CAC9B,OAAO,EACP,IAAI,CAAC,oCAAoC,EACzC,gBAAgB,CACnB;aACJ;YACD;gBACI,oCAAoC;gBACpC,IAAI,uEAAkC,CAClC,OAAO,EACP,IAAI,CAAC,oCAAoC,EACzC,gBAAgB,EAChB,uBAAuB,CAC1B;aACJ;SACJ,CAAC,CAAA;IACN,CAAC;AACL,CAAC;AA3CY,8BAAsB,yBA2ClC,CAAA"}
+52
View File
@@ -0,0 +1,52 @@
import { INode } from '../interfaces/INode';
import { NodesGroup } from './NodesGroup';
import { UnicodeArrayNode } from '../nodes/UnicodeArrayNode';
import { UnicodeArrayRotateFunctionCallNode } from '../nodes/UnicodeArrayRotateFunctionCallNode';
import { UnicodeArrayRotateFunctionNode } from '../nodes/UnicodeArrayRotateFunctionNode';
import { Utils } from '../Utils';
export class UnicodeArrayNodesGroup extends NodesGroup {
/**
* @type {string}
*/
private unicodeArrayRotateFunctionIdentifier: string = Utils.getRandomVariableName();
/**
* @param astTree
*/
constructor (astTree: any) {
super();
let unicodeArrayName: string = Utils.getRandomVariableName(UnicodeArrayNode.UNICODE_ARRAY_RANDOM_LENGTH),
unicodeArrayRotateValue: number = Utils.getRandomInteger(100, 500);
this.nodes = new Map <string, INode> ([
[
'unicodeArrayNode',
new UnicodeArrayNode(
astTree,
unicodeArrayName,
unicodeArrayRotateValue
)
],
[
'unicodeArrayRotateFunctionNode',
new UnicodeArrayRotateFunctionNode(
astTree,
this.unicodeArrayRotateFunctionIdentifier,
unicodeArrayName
)
],
[
'unicodeArrayRotateFunctionCallNode',
new UnicodeArrayRotateFunctionCallNode(
astTree,
this.unicodeArrayRotateFunctionIdentifier,
unicodeArrayName,
unicodeArrayRotateValue
)
]
])
}
}
@@ -0,0 +1,37 @@
"use strict";
const NodeObfuscator_1 = require('./NodeObfuscator');
const Utils_1 = require('../Utils');
let estraverse = require('estraverse');
class FunctionDeclarationObfuscator extends NodeObfuscator_1.NodeObfuscator {
constructor(...args) {
super(...args);
this.functionName = new Map();
}
obfuscateNode(functionDeclarationNode, parentNode) {
if (parentNode.type === 'Program') {
return;
}
this.replaceFunctionName(functionDeclarationNode);
this.replaceFunctionCalls(parentNode);
}
replaceFunctionName(functionDeclarationNode) {
estraverse.replace(functionDeclarationNode.id, {
leave: (node) => {
if (node.type !== 'Identifier') {
return;
}
this.functionName.set(node.name, Utils_1.Utils.getRandomVariableName());
node.name = this.functionName.get(node.name);
}
});
}
replaceFunctionCalls(functionParentNode) {
estraverse.replace(functionParentNode, {
leave: (node, parentNode) => {
this.replaceNodeIdentifierByNewValue(node, parentNode, this.functionName);
}
});
}
}
exports.FunctionDeclarationObfuscator = FunctionDeclarationObfuscator;
//# sourceMappingURL=FunctionDeclarationObfuscator.js.map
@@ -0,0 +1 @@
{"version":3,"file":"FunctionDeclarationObfuscator.js","sourceRoot":"","sources":["FunctionDeclarationObfuscator.ts"],"names":[],"mappings":";AAAA,iCAA+B,kBAAkB,CAAC,CAAA;AAClD,wBAAsB,UAAU,CAAC,CAAA;AAEjC,IAAI,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAWvC,4CAAmD,+BAAc;IAAjE;QAAmD,eAAc;QAIrD,iBAAY,GAAyB,IAAI,GAAG,EAAoB,CAAC;IAyC7E,CAAC;IAnCU,aAAa,CAAE,uBAA4B,EAAE,UAAe;QAC/D,EAAE,CAAC,CAAC,UAAU,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC;YAChC,MAAM,CAAC;QACX,CAAC;QAED,IAAI,CAAC,mBAAmB,CAAC,uBAAuB,CAAC,CAAC;QAClD,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;IAC1C,CAAC;IAKO,mBAAmB,CAAE,uBAA4B;QACrD,UAAU,CAAC,OAAO,CAAC,uBAAuB,CAAC,EAAE,EAAE;YAC3C,KAAK,EAAE,CAAC,IAAI;gBACR,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC;oBAC7B,MAAM,CAAC;gBACX,CAAC;gBAED,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,aAAK,CAAC,qBAAqB,EAAE,CAAC,CAAC;gBAChE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjD,CAAC;SACJ,CAAC,CAAC;IACP,CAAC;IAKO,oBAAoB,CAAE,kBAAuB;QACjD,UAAU,CAAC,OAAO,CAAC,kBAAkB,EAAE;YACnC,KAAK,EAAE,CAAC,IAAI,EAAE,UAAU;gBACpB,IAAI,CAAC,+BAA+B,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;YAC9E,CAAC;SACJ,CAAC,CAAC;IACP,CAAC;AACL,CAAC;AA7CY,qCAA6B,gCA6CzC,CAAA"}
@@ -0,0 +1,60 @@
import { NodeObfuscator } from './NodeObfuscator';
import { Utils } from '../Utils';
let estraverse = require('estraverse');
/**
* replaces:
* function foo () { //... };
* foo();
*
* by:
* function _0x12d45f () { //... };
* _0x12d45f();
*/
export class FunctionDeclarationObfuscator extends NodeObfuscator {
/**
* @type {Map<string, string>}
*/
private functionName: Map <string, string> = new Map <string, string> ();
/**
* @param functionDeclarationNode
* @param parentNode
*/
public obfuscateNode (functionDeclarationNode: any, parentNode: any): void {
if (parentNode.type === 'Program') {
return;
}
this.replaceFunctionName(functionDeclarationNode);
this.replaceFunctionCalls(parentNode);
}
/**
* @param functionDeclarationNode
*/
private replaceFunctionName (functionDeclarationNode: any): void {
estraverse.replace(functionDeclarationNode.id, {
leave: (node) => {
if (node.type !== 'Identifier') {
return;
}
this.functionName.set(node.name, Utils.getRandomVariableName());
node.name = this.functionName.get(node.name);
}
});
}
/**
* @param functionParentNode
*/
private replaceFunctionCalls (functionParentNode: any): void {
estraverse.replace(functionParentNode, {
leave: (node, parentNode) => {
this.replaceNodeIdentifierByNewValue(node, parentNode, this.functionName);
}
});
}
}
@@ -0,0 +1,36 @@
"use strict";
const NodeObfuscator_1 = require('./NodeObfuscator');
const Utils_1 = require('../Utils');
let estraverse = require('estraverse');
class FunctionObfuscator extends NodeObfuscator_1.NodeObfuscator {
constructor(...args) {
super(...args);
this.functionParams = new Map();
}
obfuscateNode(functionNode) {
this.replaceFunctionParams(functionNode);
this.replaceFunctionParamsInBody(functionNode);
}
replaceFunctionParams(functionNode) {
functionNode.params.forEach((paramsNode) => {
estraverse.replace(paramsNode, {
leave: (node, parentNode) => {
if (node.type !== 'Identifier') {
return;
}
this.functionParams.set(node.name, Utils_1.Utils.getRandomVariableName());
node.name = this.functionParams.get(node.name);
}
});
});
}
replaceFunctionParamsInBody(functionNode) {
estraverse.replace(functionNode.body, {
leave: (node, parentNode) => {
this.replaceNodeIdentifierByNewValue(node, parentNode, this.functionParams);
}
});
}
}
exports.FunctionObfuscator = FunctionObfuscator;
//# sourceMappingURL=FunctionObfuscator.js.map
@@ -0,0 +1 @@
{"version":3,"file":"FunctionObfuscator.js","sourceRoot":"","sources":["FunctionObfuscator.ts"],"names":[],"mappings":";AAAA,iCAA+B,kBAAkB,CAAC,CAAA;AAClD,wBAAsB,UAAU,CAAC,CAAA;AAEjC,IAAI,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAUvC,iCAAwC,+BAAc;IAAtD;QAAwC,eAAc;QAI1C,mBAAc,GAAyB,IAAI,GAAG,EAAoB,CAAC;IAsC/E,CAAC;IAjCU,aAAa,CAAE,YAAiB;QACnC,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;QACzC,IAAI,CAAC,2BAA2B,CAAC,YAAY,CAAC,CAAC;IACnD,CAAC;IAKO,qBAAqB,CAAE,YAAiB;QAC5C,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,UAAU;YACnC,UAAU,CAAC,OAAO,CAAC,UAAU,EAAE;gBAC3B,KAAK,EAAE,CAAC,IAAI,EAAE,UAAU;oBACpB,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC;wBAC9B,MAAM,CAAC;oBACV,CAAC;oBAED,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,aAAK,CAAC,qBAAqB,EAAE,CAAC,CAAC;oBAClE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACnD,CAAC;aACJ,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IAKO,2BAA2B,CAAE,YAAiB;QAClD,UAAU,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE;YAClC,KAAK,EAAE,CAAC,IAAI,EAAE,UAAU;gBACpB,IAAI,CAAC,+BAA+B,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;YAChF,CAAC;SACJ,CAAC,CAAC;IACP,CAAC;AACL,CAAC;AA1CY,0BAAkB,qBA0C9B,CAAA"}
@@ -0,0 +1,56 @@
import { NodeObfuscator } from './NodeObfuscator';
import { Utils } from '../Utils';
let estraverse = require('estraverse');
/**
* replaces:
* function foo (argument1) { return argument1; };
*
* by:
* function foo (_0x12d45f) { return _0x12d45f; };
*
*/
export class FunctionObfuscator extends NodeObfuscator {
/**
* @type {Map<string, string>}
*/
private functionParams: Map <string, string> = new Map <string, string> ();
/**
* @param functionNode
*/
public obfuscateNode (functionNode: any): void {
this.replaceFunctionParams(functionNode);
this.replaceFunctionParamsInBody(functionNode);
}
/**
* @param functionNode
*/
private replaceFunctionParams (functionNode: any): void {
functionNode.params.forEach((paramsNode) => {
estraverse.replace(paramsNode, {
leave: (node, parentNode) => {
if (node.type !== 'Identifier') {
return;
}
this.functionParams.set(node.name, Utils.getRandomVariableName());
node.name = this.functionParams.get(node.name);
}
});
});
}
/**
* @param functionNode
*/
private replaceFunctionParamsInBody (functionNode: any): void {
estraverse.replace(functionNode.body, {
leave: (node, parentNode) => {
this.replaceNodeIdentifierByNewValue(node, parentNode, this.functionParams);
}
});
}
}
+23
View File
@@ -0,0 +1,23 @@
"use strict";
const NodeObfuscator_1 = require('./NodeObfuscator');
let escodegen = require('escodegen'), estraverse = require('estraverse');
class LiteralObfuscator extends NodeObfuscator_1.NodeObfuscator {
obfuscateNode(literalNode, parentNode) {
if (parentNode.type === 'Property' && parentNode.key === literalNode) {
return;
}
switch (typeof literalNode.value) {
case 'string':
if (literalNode['x-verbatim-property']) {
break;
}
literalNode['x-verbatim-property'] = {
content: this.replaceLiteralStringByArrayElement(literalNode.value),
precedence: escodegen.Precedence.Primary
};
break;
}
}
}
exports.LiteralObfuscator = LiteralObfuscator;
//# sourceMappingURL=LiteralObfuscator.js.map
@@ -0,0 +1 @@
{"version":3,"file":"LiteralObfuscator.js","sourceRoot":"","sources":["LiteralObfuscator.ts"],"names":[],"mappings":";AAAA,iCAA+B,kBAE/B,CAAC,CAFgD;AAEjD,IAAI,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,EAChC,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAEvC,gCAAuC,+BAAc;IAK1C,aAAa,CAAE,WAAgB,EAAE,UAAe;QACnD,EAAE,CAAC,CAAC,UAAU,CAAC,IAAI,KAAK,UAAU,IAAI,UAAU,CAAC,GAAG,KAAK,WAAW,CAAC,CAAC,CAAC;YACnE,MAAM,CAAC;QACX,CAAC;QAED,MAAM,CAAC,CAAC,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;YAC/B,KAAK,QAAQ;gBACT,EAAE,CAAC,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;oBACrC,KAAK,CAAC;gBACV,CAAC;gBAED,WAAW,CAAC,qBAAqB,CAAC,GAAG;oBACjC,OAAO,EAAG,IAAI,CAAC,kCAAkC,CAAC,WAAW,CAAC,KAAK,CAAC;oBACpE,UAAU,EAAE,SAAS,CAAC,UAAU,CAAC,OAAO;iBAC3C,CAAC;gBAEF,KAAK,CAAC;QACd,CAAC;IACL,CAAC;AACL,CAAC;AAxBY,yBAAiB,oBAwB7B,CAAA"}
+30
View File
@@ -0,0 +1,30 @@
import { NodeObfuscator } from './NodeObfuscator'
let escodegen = require('escodegen'),
estraverse = require('estraverse');
export class LiteralObfuscator extends NodeObfuscator {
/**
* @param literalNode
* @param parentNode
*/
public obfuscateNode (literalNode: any, parentNode: any): void {
if (parentNode.type === 'Property' && parentNode.key === literalNode) {
return;
}
switch (typeof literalNode.value) {
case 'string':
if (literalNode['x-verbatim-property']) {
break;
}
literalNode['x-verbatim-property'] = {
content : this.replaceLiteralStringByArrayElement(literalNode.value),
precedence: escodegen.Precedence.Primary
};
break;
}
}
}
@@ -0,0 +1,49 @@
"use strict";
const NodeObfuscator_1 = require('./NodeObfuscator');
let escodegen = require('escodegen'), estraverse = require('estraverse');
class MemberExpressionObfuscator extends NodeObfuscator_1.NodeObfuscator {
obfuscateNode(memberExpressionNode) {
estraverse.replace(memberExpressionNode.property, {
leave: (node, parentNode) => {
switch (node.type) {
case 'Literal':
this.literalNodeController(node);
break;
case 'Identifier':
if (memberExpressionNode.computed) {
break;
}
memberExpressionNode.computed = true;
this.identifierNodeController(node);
break;
}
}
});
}
identifierNodeController(node) {
let nodeValue = node['name'];
node['type'] = 'Literal';
node['value'] = nodeValue;
node['raw'] = `'${nodeValue}'`;
node['x-verbatim-property'] = {
content: this.replaceLiteralStringByArrayElement(nodeValue),
precedence: escodegen['Precedence']['Primary']
};
delete node['name'];
}
literalNodeController(node) {
switch (typeof node.value) {
case 'string':
if (node['x-verbatim-property']) {
break;
}
node['x-verbatim-property'] = {
content: this.replaceLiteralStringByArrayElement(node.value),
precedence: escodegen['Precedence']['Primary']
};
break;
}
}
}
exports.MemberExpressionObfuscator = MemberExpressionObfuscator;
//# sourceMappingURL=MemberExpressionObfuscator.js.map
@@ -0,0 +1 @@
{"version":3,"file":"MemberExpressionObfuscator.js","sourceRoot":"","sources":["MemberExpressionObfuscator.ts"],"names":[],"mappings":";AAAA,iCAA+B,kBAE/B,CAAC,CAFgD;AAEjD,IAAI,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,EAChC,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC,C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AC;oBAC9B,KAAK,CAAC;gBACV,CAAC;gBAED,IAAI,CAAC,qBAAqB,CAAC,GAAG;oBAC1B,OAAO,EAAG,IAAI,CAAC,kCAAkC,CAAC,IAAI,CAAC,KAAK,CAAC;oBAC7D,UAAU,EAAE,SAAS,CAAC,YAAY,CAAC,CAAC,SAAS,CAAC;iBACjD,CAAC;gBAEF,KAAK,CAAC;QACd,CAAC;IACL,CAAC;AACL,CAAC;AA7EY,kCAA0B,6BA6EtC,CAAA"}
@@ -0,0 +1,83 @@
import { NodeObfuscator } from './NodeObfuscator'
let escodegen = require('escodegen'),
estraverse = require('estraverse');
export class MemberExpressionObfuscator extends NodeObfuscator {
/**
* @param memberExpressionNode
*/
public obfuscateNode (memberExpressionNode: any): void {
estraverse.replace(memberExpressionNode.property, {
leave: (node, parentNode) => {
switch (node.type) {
case 'Literal':
this.literalNodeController(node);
break;
case 'Identifier':
if (memberExpressionNode.computed) {
break;
}
memberExpressionNode.computed = true;
this.identifierNodeController(node);
break;
}
}
});
}
/**
* replaces:
* object.identifier = 1;
*
* by:
* object[_0x23d45[25]] = 1;
*
* and skip:
* object[identifier] = 1;
*
* @param node
*/
private identifierNodeController (node: any): void {
let nodeValue: string = node['name'];
node['type'] = 'Literal';
node['value'] = nodeValue;
node['raw'] = `'${nodeValue}'`;
node['x-verbatim-property'] = {
content : this.replaceLiteralStringByArrayElement(nodeValue),
precedence: escodegen['Precedence']['Primary']
};
delete node['name'];
}
/**
* replaces:
* object['literal'] = 1;
*
* by:
* object[_0x23d45[25]] = 1;
*
* @param node
*/
private literalNodeController (node: any): void {
switch (typeof node.value) {
case 'string':
if (node['x-verbatim-property']) {
break;
}
node['x-verbatim-property'] = {
content : this.replaceLiteralStringByArrayElement(node.value),
precedence: escodegen['Precedence']['Primary']
};
break;
}
}
}
@@ -0,0 +1,28 @@
"use strict";
const NodeObfuscator_1 = require('./NodeObfuscator');
let estraverse = require('estraverse');
class MethodDefinitionObfuscator extends NodeObfuscator_1.NodeObfuscator {
constructor(...args) {
super(...args);
this.methodName = new Map();
this.ignoredNames = ['constructor'];
}
obfuscateNode(methodDefinitionNode, parentNode) {
this.replaceMethodName(methodDefinitionNode);
}
replaceMethodName(methodDefinitionNode) {
estraverse.replace(methodDefinitionNode.key, {
leave: (node) => {
if (node.type !== 'Identifier' ||
this.ignoredNames.indexOf(node.name) >= 0 ||
methodDefinitionNode.computed === true) {
return;
}
methodDefinitionNode.computed = true;
node.name = this.replaceLiteralStringByArrayElement(node.name);
}
});
}
}
exports.MethodDefinitionObfuscator = MethodDefinitionObfuscator;
//# sourceMappingURL=MethodDefinitionObfuscator.js.map
@@ -0,0 +1 @@
{"version":3,"file":"MethodDefinitionObfuscator.js","sourceRoot":"","sources":["MethodDefinitionObfuscator.ts"],"names":[],"mappings":";AAAA,iCAA+B,kBAAkB,CAAC,CAAA;AAGlD,IAAI,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAWvC,yCAAgD,+BAAc;IAA9D;QAAgD,eAAc;QAIlD,eAAU,GAAyB,IAAI,GAAG,EAAoB,CAAC;QAK/D,iBAAY,GAAa,CAAC,aAAa,CAAC,CAAC;IA6BrD,CAAC;IAvBU,aAAa,CAAE,oBAAyB,EAAE,UAAe;QAC5D,IAAI,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,CAAC;IACjD,CAAC;IAKO,iBAAiB,CAAE,oBAAyB;QAChD,UAAU,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,EAAE;YACzC,KAAK,EAAE,CAAC,IAAI;gBACR,EAAE,CAAC,CACC,IAAI,CAAC,IAAI,KAAK,YAAY;oBAC1B,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;oBACzC,oBAAoB,CAAC,QAAQ,KAAK,IACtC,CAAC,CAAC,CAAC;oBACC,MAAM,CAAC;gBACX,CAAC;gBAED,oBAAoB,CAAC,QAAQ,GAAG,IAAI,CAAC;gBACrC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,kCAAkC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACnE,CAAC;SACJ,CAAC,CAAC;IACP,CAAC;AACL,CAAC;AAtCY,kCAA0B,6BAsCtC,CAAA"}
@@ -0,0 +1,53 @@
import { NodeObfuscator } from './NodeObfuscator';
import { Utils } from '../Utils';
let estraverse = require('estraverse');
/**
* replaces:
* function foo () { //... };
* foo();
*
* by:
* function _0x12d45f () { //... };
* _0x12d45f();
*/
export class MethodDefinitionObfuscator extends NodeObfuscator {
/**
* @type {Map<string, string>}
*/
private methodName: Map <string, string> = new Map <string, string> ();
/**
* @type {string[]}
*/
private ignoredNames: string[] = ['constructor'];
/**
* @param methodDefinitionNode
* @param parentNode
*/
public obfuscateNode (methodDefinitionNode: any, parentNode: any): void {
this.replaceMethodName(methodDefinitionNode);
}
/**
* @param methodDefinitionNode
*/
private replaceMethodName (methodDefinitionNode: any): void {
estraverse.replace(methodDefinitionNode.key, {
leave: (node) => {
if (
node.type !== 'Identifier' ||
this.ignoredNames.indexOf(node.name) >= 0 ||
methodDefinitionNode.computed === true
) {
return;
}
methodDefinitionNode.computed = true;
node.name = this.replaceLiteralStringByArrayElement(node.name);
}
});
}
}
+29
View File
@@ -0,0 +1,29 @@
"use strict";
const Utils_1 = require('../Utils');
class NodeObfuscator {
constructor(nodes) {
this.nodes = nodes;
}
replaceNodeIdentifierByNewValue(node, parentNode, namesMap) {
if (node.type === 'Identifier' && namesMap.has(node.name)) {
if ((parentNode.type === 'Property' && parentNode.key === node) ||
(parentNode.type === 'MemberExpression' && parentNode.computed === false && parentNode.property === node)) {
return;
}
node.name = namesMap.get(node.name);
}
}
replaceLiteralStringByArrayElement(nodeValue) {
let value = Utils_1.Utils.stringToUnicode(nodeValue), unicodeArray = this.nodes.get('unicodeArrayNode').getNodeData(), sameIndex = unicodeArray.indexOf(value), index;
if (sameIndex < 0) {
index = unicodeArray.length;
unicodeArray.push(Utils_1.Utils.stringToUnicode(nodeValue));
}
else {
index = sameIndex;
}
return `${this.nodes.get('unicodeArrayNode').getNodeIdentifier()}[${index}]`;
}
}
exports.NodeObfuscator = NodeObfuscator;
//# sourceMappingURL=NodeObfuscator.js.map
@@ -0,0 +1 @@
{"version":3,"file":"NodeObfuscator.js","sourceRoot":"","sources":["NodeObfuscator.ts"],"names":[],"mappings":";AAIA,wBAAsB,UAAU,CAAC,CAAA;AAEjC;IASI,YAAY,KAA0B;QAClC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAaS,+BAA+B,CAAE,IAAS,EAAE,UAAe,EAAE,QAA8B;QACjG,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,YAAY,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACxD,EAAE,CAAC,CACC,CAAC,UAAU,CAAC,IAAI,KAAK,UAAU,IAAI,UAAU,CAAC,GAAG,KAAK,IAAI,CAAC;gBAC3D,CAAC,UAAU,CAAC,IAAI,KAAK,kBAAkB,IAAI,UAAU,CAAC,QAAQ,KAAK,KAAK,IAAI,UAAU,CAAC,QAAQ,KAAK,IAAI,CAC5G,CAAC,CAAC,CAAC;gBACC,MAAM,CAAC;YACX,CAAC;YAED,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxC,CAAC;IACL,CAAC;IAMS,kCAAkC,CAAE,SAAiB;QAC3D,IAAI,KAAK,GAAW,aAAK,CAAC,eAAe,CAAC,SAAS,CAAC,EAChD,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,WAAW,EAAE,EAC/D,SAAS,GAAW,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,EAC/C,KAAa,CAAC;QAElB,EAAE,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC;YAChB,KAAK,GAAG,YAAY,CAAC,MAAM,CAAC;YAC5B,YAAY,CAAC,IAAI,CAAC,aAAK,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC;QACxD,CAAC;QAAC,IAAI,CAAC,CAAC;YACJ,KAAK,GAAG,SAAS,CAAC;QACtB,CAAC;QAED,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,iBAAiB,EAAE,IAAI,KAAK,GAAG,CAAC;IACjF,CAAC;AACL,CAAC;AAxDqB,sBAAc,iBAwDnC,CAAA"}
+63
View File
@@ -0,0 +1,63 @@
import { INode } from '../interfaces/INode';
import { INodeObfuscator } from '../interfaces/INodeObfuscator';
import { UnicodeArrayNode } from '../nodes/UnicodeArrayNode';
import { Utils } from '../Utils';
export abstract class NodeObfuscator implements INodeObfuscator {
/**
* @param Map <string, Node>
*/
protected nodes: Map <string, INode>;
/**
* @param nodes
*/
constructor(nodes: Map <string, INode>) {
this.nodes = nodes;
}
/**
* @param node
* @param parentNode
*/
public abstract obfuscateNode (node: any, parentNode?: any): void;
/**
* @param node
* @param parentNode
* @param namesMap
*/
protected replaceNodeIdentifierByNewValue (node: any, parentNode: any, namesMap: Map <string, string>) {
if (node.type === 'Identifier' && namesMap.has(node.name)) {
if (
(parentNode.type === 'Property' && parentNode.key === node) ||
(parentNode.type === 'MemberExpression' && parentNode.computed === false && parentNode.property === node)
) {
return;
}
node.name = namesMap.get(node.name);
}
}
/**
* @param nodeValue
* @returns {string}
*/
protected replaceLiteralStringByArrayElement (nodeValue: string): string {
let value: string = Utils.stringToUnicode(nodeValue),
unicodeArray = this.nodes.get('unicodeArrayNode').getNodeData(),
sameIndex: number = unicodeArray.indexOf(value),
index: number;
if (sameIndex < 0) {
index = unicodeArray.length;
unicodeArray.push(Utils.stringToUnicode(nodeValue));
} else {
index = sameIndex;
}
return `${this.nodes.get('unicodeArrayNode').getNodeIdentifier()}[${index}]`;
}
}
@@ -0,0 +1,48 @@
"use strict";
const NodeObfuscator_1 = require('./NodeObfuscator');
const Utils_1 = require('../Utils');
let escodegen = require('escodegen'), estraverse = require('estraverse');
class ObjectExpressionObfuscator extends NodeObfuscator_1.NodeObfuscator {
obfuscateNode(objectExpressionNode) {
objectExpressionNode.properties.forEach((property) => {
estraverse.replace(property.key, {
leave: (node, parentNode) => {
switch (node.type) {
case 'Literal':
this.literalNodeController(node);
break;
case 'Identifier':
this.identifierNodeController(node);
break;
}
}
});
});
}
literalNodeController(node) {
switch (typeof node.value) {
case 'string':
if (node['x-verbatim-property']) {
break;
}
node['x-verbatim-property'] = {
content: Utils_1.Utils.stringToUnicode(node.value),
precedence: escodegen['Precedence']['Primary']
};
break;
}
}
identifierNodeController(node) {
let nodeValue = node['name'];
node['type'] = 'Literal';
node['value'] = nodeValue;
node['raw'] = `'${nodeValue}'`;
node['x-verbatim-property'] = {
content: Utils_1.Utils.stringToUnicode(nodeValue),
precedence: escodegen['Precedence']['Primary']
};
delete node['name'];
}
}
exports.ObjectExpressionObfuscator = ObjectExpressionObfuscator;
//# sourceMappingURL=ObjectExpressionObfuscator.js.map
@@ -0,0 +1 @@
{"version":3,"file":"ObjectExpressionObfuscator.js","sourceRoot":"","sources":["ObjectExpressionObfuscator.ts"],"names":[],"mappings":";AAAA,iCAA+B,kBAC/B,CAAC,CADgD;AACjD,wBAAsB,UAAU,CAAC,CAAA;AAEjC,IAAI,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,EAChC,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAYvC,yCAAgD,+BAAc;IAInD,aAAa,CAAE,oBAAyB;QAC3C,oBAAoB,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,QAAQ;YAC7C,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE;gBAC7B,KAAK,EAAE,CAAC,IAAI,EAAE,UAAU;oBACpB,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;wBAChB,KAAK,SAAS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ils } from '../Utils';
let escodegen = require('escodegen'),
estraverse = require('estraverse');
/**
* replaces:
* var object = { 'PSEUDO': 1 };
*
* or:
* var object = { PSEUDO: 1 };
*
* by:
* var object = { '\u0050\u0053\u0045\u0055\u0044\u004f': 1 };
*/
export class ObjectExpressionObfuscator extends NodeObfuscator {
/**
* @param objectExpressionNode
*/
public obfuscateNode (objectExpressionNode: any): void {
objectExpressionNode.properties.forEach((property) => {
estraverse.replace(property.key, {
leave: (node, parentNode) => {
switch (node.type) {
case 'Literal':
this.literalNodeController(node);
break;
case 'Identifier':
this.identifierNodeController(node);
break;
}
}
});
});
}
/**
* @param node
*/
private literalNodeController (node: any): void {
switch (typeof node.value) {
case 'string':
if (node['x-verbatim-property']) {
break;
}
node['x-verbatim-property'] = {
content : Utils.stringToUnicode(node.value),
precedence: escodegen['Precedence']['Primary']
};
break;
}
}
/**
* @param node
*/
private identifierNodeController (node: any): void {
let nodeValue: string = node['name'];
node['type'] = 'Literal';
node['value'] = nodeValue;
node['raw'] = `'${nodeValue}'`;
node['x-verbatim-property'] = {
content : Utils.stringToUnicode(nodeValue),
precedence: escodegen['Precedence']['Primary']
};
delete node['name'];
}
}
@@ -0,0 +1,43 @@
"use strict";
const NodeObfuscator_1 = require('./NodeObfuscator');
const Utils_1 = require('../Utils');
let estraverse = require('estraverse');
class VariableDeclarationObfuscator extends NodeObfuscator_1.NodeObfuscator {
constructor(...args) {
super(...args);
this.variableName = new Map();
}
obfuscateNode(variableDeclarationNode, parentNode) {
if (parentNode.type === 'Program') {
return;
}
this.replaceVariableName(variableDeclarationNode);
this.replaceVariableCalls(parentNode);
}
replaceVariableName(variableDeclarationNode) {
variableDeclarationNode.declarations.forEach((declarationNode) => {
estraverse.replace(declarationNode, {
leave: (node) => {
if (node.type !== 'VariableDeclarator') {
return;
}
estraverse.replace(node.id, {
leave: (node) => {
this.variableName.set(node.name, Utils_1.Utils.getRandomVariableName());
node.name = this.variableName.get(node.name);
}
});
}
});
});
}
replaceVariableCalls(variableParentNode) {
estraverse.replace(variableParentNode, {
leave: (node, parentNode) => {
this.replaceNodeIdentifierByNewValue(node, parentNode, this.variableName);
}
});
}
}
exports.VariableDeclarationObfuscator = VariableDeclarationObfuscator;
//# sourceMappingURL=VariableDeclarationObfuscator.js.map
@@ -0,0 +1 @@
{"version":3,"file":"VariableDeclarationObfuscator.js","sourceRoot":"","sources":["VariableDeclarationObfuscator.ts"],"names":[],"mappings":";AAAA,iCAA+B,kBAAkB,CAAC,CAAA;AAClD,wBAAsB,UAAU,CAAC,CAAA;AAEjC,IAAI,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAYvC,4CAAmD,+BAAc;IAAjE;QAAmD,eAAc;QAIrD,iBAAY,GAAyB,IAAI,GAAG,EAAoB,CAAC;IA+C7E,CAAC;IAzCU,aAAa,CAAE,uBAA4B,EAAE,UAAe;QAC/D,EAAE,CAAC,CAAC,UAAU,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC;YAChC,MAAM,CAAC;QACX,CAAC;QAED,IAAI,CAAC,mBAAmB,CAAC,uBAAuB,CAAC,CAAC;QAClD,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;IAC1C,CAAC;IAKO,mBAAmB,CAAE,uBAA4B;QACrD,uBAAuB,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,eAAe;YACzD,UAAU,CAAC,OAAO,CAAC,eAAe,EAAE;gBAChC,KAAK,EAAE,CAAC,IAAI;oBACR,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,oBAAoB,CAAC,CAAC,CAAC;wBACrC,MAAM,CAAC;oBACX,CAAC;oBAED,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE;wBACxB,KAAK,EAAE,CAAC,IAAI;4BACR,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,aAAK,CAAC,qBAAqB,EAAE,CAAC,CAAC;4BAChE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;wBACjD,CAAC;qBACJ,CAAC,CAAC;gBACP,CAAC;aACJ,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IAKO,oBAAoB,CAAE,kBAAuB;QACjD,UAAU,CAAC,OAAO,CAAC,kBAAkB,EAAE;YACnC,KAAK,EAAE,CAAC,IAAI,EAAE,UAAU;gBACpB,IAAI,CAAC,+BAA+B,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;YAC9E,CAAC;SACJ,CAAC,CAAC;IACP,CAAC;AACL,CAAC;AAnDY,qCAA6B,gCAmDzC,CAAA"}
@@ -0,0 +1,67 @@
import { NodeObfuscator } from './NodeObfuscator';
import { Utils } from '../Utils';
let estraverse = require('estraverse');
/**
* replaces:
* var variable = 1;
* variable++;
*
* by:
* var _0x12d45f = 1;
* _0x12d45f++;
*
*/
export class VariableDeclarationObfuscator extends NodeObfuscator {
/**
* @type {Map<string, string>}
*/
private variableName: Map <string, string> = new Map <string, string> ();
/**
* @param variableDeclarationNode
* @param parentNode
*/
public obfuscateNode (variableDeclarationNode: any, parentNode: any): void {
if (parentNode.type === 'Program') {
return;
}
this.replaceVariableName(variableDeclarationNode);
this.replaceVariableCalls(parentNode);
}
/**
* @param variableDeclarationNode
*/
private replaceVariableName (variableDeclarationNode: any): void {
variableDeclarationNode.declarations.forEach((declarationNode) => {
estraverse.replace(declarationNode, {
leave: (node) => {
if (node.type !== 'VariableDeclarator') {
return;
}
estraverse.replace(node.id, {
leave: (node) => {
this.variableName.set(node.name, Utils.getRandomVariableName());
node.name = this.variableName.get(node.name);
}
});
}
});
});
}
/**
* @param variableParentNode
*/
private replaceVariableCalls (variableParentNode: any): void {
estraverse.replace(variableParentNode, {
leave: (node, parentNode) => {
this.replaceNodeIdentifierByNewValue(node, parentNode, this.variableName);
}
});
}
}
+21
View File
@@ -0,0 +1,21 @@
"use strict";
const AppendState_1 = require('../enums/AppendState');
class Node {
constructor() {
this.appendState = AppendState_1.AppendState.BeforeObfuscation;
}
getAppendState() {
return this.appendState;
}
getNode() {
return this.node;
}
setNode(node) {
this.node = node;
}
updateNode() {
this.node = this.getNodeStructure();
}
}
exports.Node = Node;
//# sourceMappingURL=Node.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"Node.js","sourceRoot":"","sources":["Node.ts"],"names":[],"mappings":";AAEA,8BAA4B,sBAAsB,CAAC,CAAA;AAEnD;IAWI;QAPU,gBAAW,GAAgB,yBAAW,CAAC,iBAAiB,CAAC;IAOnD,CAAC;IAOV,cAAc;QACjB,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IAKM,OAAO;QACV,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAKM,OAAO,CAAE,IAAS;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;IAEM,UAAU;QACb,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;IACxC,CAAC;AAML,CAAC;AA5CqB,YAAI,OA4CzB,CAAA"}
+49
View File
@@ -0,0 +1,49 @@
import { INode } from '../interfaces/INode';
import { AppendState } from '../enums/AppendState';
export abstract class Node implements INode {
/**
* @type {AppendState}
*/
protected appendState: AppendState = AppendState.BeforeObfuscation;
/**
* @type any
*/
protected node: any;
constructor () {}
public abstract appendNode (): void;
/**
* @returns {AppendState}
*/
public getAppendState (): AppendState {
return this.appendState;
}
/**
* @returns any
*/
public getNode (): any {
return this.node;
}
/**
* @param node
*/
public setNode (node: any): void {
this.node = node;
}
public updateNode (): void {
this.node = this.getNodeStructure();
}
/**
* @returns any
*/
protected abstract getNodeStructure (): any;
}
+70
View File
@@ -0,0 +1,70 @@
"use strict";
const Node_1 = require('./Node');
const Utils_1 = require('../Utils');
const AppendState_1 = require('../enums/AppendState');
let escodegen = require('escodegen'), estraverse = require('estraverse');
class UnicodeArrayNode extends Node_1.Node {
constructor(astTree, unicodeArrayName, unicodeArrayRotateValue = 0) {
super();
this.appendState = AppendState_1.AppendState.AfterObfuscation;
this.unicodeArray = [];
this.astTree = astTree;
this.unicodeArrayName = unicodeArrayName;
this.unicodeArrayRotateValue = unicodeArrayRotateValue;
this.node = this.getNodeStructure();
}
appendNode() {
estraverse.replace(this.astTree, {
leave: (node, parent) => {
switch (node.type) {
case 'Program':
node.body.unshift(this.getNode());
break;
}
}
});
}
getNodeIdentifier() {
return this.unicodeArrayName;
}
getNodeData() {
return this.unicodeArray;
}
getNode() {
Utils_1.Utils.arrayRotate(this.unicodeArray, this.unicodeArrayRotateValue);
this.updateNode();
return this.node;
}
getNodeStructure() {
return {
'type': 'VariableDeclaration',
'declarations': [
{
'type': 'VariableDeclarator',
'id': {
'type': 'Identifier',
'name': this.unicodeArrayName
},
'init': {
'type': 'ArrayExpression',
'elements': this.unicodeArray.map((value) => {
return {
'type': 'Literal',
'value': value,
'raw': `'${value}'`,
'x-verbatim-property': {
'content': value,
precedence: escodegen.Precedence.Primary
}
};
})
}
}
],
'kind': 'var'
};
}
}
UnicodeArrayNode.UNICODE_ARRAY_RANDOM_LENGTH = 4;
exports.UnicodeArrayNode = UnicodeArrayNode;
//# sourceMappingURL=UnicodeArrayNode.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"UnicodeArrayNode.js","sourceRoot":"","sources":["UnicodeArrayNode.ts"],"names":[],"mappings":";AAAA,uBAAqB,QAAQ,CAAC,CAAA;AAC9B,wBAAsB,UAAU,CAAC,CAAA;AAEjC,8BAA4B,sBAAsB,CAAC,CAAA;AAEnD,IAAI,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,EAChC,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAEvC,+BAAsC,WAAI;IAyCtC,YAAa,OAAY,EAAE,gBAAwB,EAAE,uBAAuB,GAAW,CAAC;QACpF,OAAO,CAAC;QAj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C,YAAY,CAAC,GAAG,CAAC,CAAC,KAAK;4BACpC,MAAM,CAAC;gCACH,MAAM,EAAE,SAAS;gCACjB,OAAO,EAAE,KAAK;gCACd,KAAK,EAAE,IAAI,KAAK,GAAG;gCACnB,qBAAqB,EAAE;oCACnB,SAAS,EAAG,KAAK;oCACjB,UAAU,EAAE,SAAS,CAAC,UAAU,CAAC,OAAO;iCAC3C;6BACJ,CAAC;wBACN,CAAC,CAAC;qBACL;iBACJ;aACJ;YACD,MAAM,EAAE,KAAK;SAChB,CAAC;IACN,CAAC;AACL,CAAC;AApHiB,4CAA2B,GAAW,CAAC,CAAC;AAJ7C,wBAAgB,mBAwH5B,CAAA"}
+129
View File
@@ -0,0 +1,129 @@
import { Node } from './Node';
import { Utils } from '../Utils';
import { AppendState } from '../enums/AppendState';
let escodegen = require('escodegen'),
estraverse = require('estraverse');
export class UnicodeArrayNode extends Node {
/**
* @type {number}
*/
public static UNICODE_ARRAY_RANDOM_LENGTH: number = 4;
/**
* @type {AppendState}
*/
protected appendState: AppendState = AppendState.AfterObfuscation;
/**
* @type any
*/
private astTree: any;
/**
* @type {string[]}
*/
private unicodeArray: string[] = [];
/**
* @type {string}
*/
private unicodeArrayName: string;
/**
* @type {number}
*/
private unicodeArrayRotateValue: number;
/**
* @type any
*/
protected node: any;
/**
* @param astTree
* @param unicodeArrayName
* @param unicodeArrayRotateValue
*/
constructor (astTree: any, unicodeArrayName: string, unicodeArrayRotateValue: number = 0) {
super();
this.astTree = astTree;
this.unicodeArrayName = unicodeArrayName;
this.unicodeArrayRotateValue = unicodeArrayRotateValue;
this.node = this.getNodeStructure();
}
public appendNode (): void {
estraverse.replace(this.astTree, {
leave: (node, parent) => {
switch (node.type) {
case 'Program':
node.body.unshift(this.getNode());
break;
}
}
});
}
/**
* @returns {string}
*/
public getNodeIdentifier (): string {
return this.unicodeArrayName;
}
/**
* @returns {string[]}
*/
public getNodeData (): string[] {
return this.unicodeArray;
}
/**
* @returns any
*/
public getNode (): any {
Utils.arrayRotate(this.unicodeArray, this.unicodeArrayRotateValue);
this.updateNode();
return this.node;
}
/**
* @returns any
*/
protected getNodeStructure (): any {
return {
'type': 'VariableDeclaration',
'declarations': [
{
'type': 'VariableDeclarator',
'id': {
'type': 'Identifier',
'name': this.unicodeArrayName
},
'init': {
'type': 'ArrayExpression',
'elements': this.unicodeArray.map((value) => {
return {
'type': 'Literal',
'value': value,
'raw': `'${value}'`,
'x-verbatim-property': {
'content' : value,
precedence: escodegen.Precedence.Primary
}
};
})
}
}
],
'kind': 'var'
};
}
}
@@ -0,0 +1,54 @@
"use strict";
const Node_1 = require('./Node');
let estraverse = require('estraverse');
class UnicodeArrayRotateFunctionCallNode extends Node_1.Node {
constructor(astTree, unicodeArrayRotateFunctionName, unicodeArrayName, unicodeArrayRotateValue) {
super();
this.astTree = astTree;
this.unicodeArrayRotateFunctionName = unicodeArrayRotateFunctionName;
this.unicodeArrayName = unicodeArrayName;
this.unicodeArrayRotateValue = unicodeArrayRotateValue;
this.node = this.getNodeStructure();
}
appendNode() {
estraverse.replace(this.astTree, {
leave: (node, parent) => {
switch (node.type) {
case 'Program':
node.body.unshift(this.getNode());
break;
}
}
});
}
getNodeStructure() {
return {
'type': 'ExpressionStatement',
'expression': {
'type': 'CallExpression',
'callee': {
'type': 'Identifier',
'name': this.unicodeArrayRotateFunctionName
},
'arguments': [
{
'type': 'Identifier',
'name': this.unicodeArrayName
},
{
'type': 'Literal',
'value': this.unicodeArrayRotateValue,
'raw': `'${this.unicodeArrayRotateValue}'`
},
{
'type': 'Literal',
'value': true,
'raw': 'true'
}
]
}
};
}
}
exports.UnicodeArrayRotateFunctionCallNode = UnicodeArrayRotateFunctionCallNode;
//# sourceMappingURL=UnicodeArrayRotateFunctionCallNode.js.map
@@ -0,0 +1 @@
{"version":3,"file":"UnicodeArrayRotateFunctionCallNode.js","sourceRoot":"","sources":["UnicodeArrayRotateFunctionCallNode.ts"],"names":[],"mappings":";AAAA,uBAAqB,QAAQ,CAAC,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AI;wBACb,KAAK,EAAE,MAAM;qBAChB;iBACJ;aACJ;SACJ,CAAC;IACN,CAAC;AACL,CAAC;AA3FY,0CAAkC,qCA2F9C,CAAA"}
@@ -0,0 +1,96 @@
import { Node } from './Node';
let estraverse = require('estraverse');
export class UnicodeArrayRotateFunctionCallNode extends Node {
/**
* @type any
*/
private astTree: any;
/**
* @type {string}
*/
private unicodeArrayName: string;
/**
* @type {number}
*/
private unicodeArrayRotateValue: number;
/**
* @param {string}
*/
private unicodeArrayRotateFunctionName: string;
/**
* @type any
*/
protected node: any;
/**
* @param astTree
* @param unicodeArrayRotateFunctionName
* @param unicodeArrayName
* @param unicodeArrayRotateValue
*/
constructor (
astTree: any,
unicodeArrayRotateFunctionName: string,
unicodeArrayName: string,
unicodeArrayRotateValue: number
) {
super();
this.astTree = astTree;
this.unicodeArrayRotateFunctionName = unicodeArrayRotateFunctionName;
this.unicodeArrayName = unicodeArrayName;
this.unicodeArrayRotateValue = unicodeArrayRotateValue;
this.node = this.getNodeStructure();
}
public appendNode (): void {
estraverse.replace(this.astTree, {
leave: (node, parent) => {
switch (node.type) {
case 'Program':
node.body.unshift(this.getNode());
break;
}
}
});
}
/**
* @returns any
*/
protected getNodeStructure (): any {
return {
'type': 'ExpressionStatement',
'expression': {
'type': 'CallExpression',
'callee': {
'type': 'Identifier',
'name': this.unicodeArrayRotateFunctionName
},
'arguments': [
{
'type': 'Identifier',
'name': this.unicodeArrayName
},
{
'type': 'Literal',
'value': this.unicodeArrayRotateValue,
'raw': `'${this.unicodeArrayRotateValue}'`
},
{
'type': 'Literal',
'value': true,
'raw': 'true'
}
]
}
};
}
}
+269
View File
@@ -0,0 +1,269 @@
"use strict";
const Node_1 = require('./Node');
const Utils_1 = require('../Utils');
let estraverse = require('estraverse');
class UnicodeArrayRotateFunctionNode extends Node_1.Node {
constructor(astTree, unicodeArrayRotateFunctionName, unicodeArrayName) {
super();
this.astTree = astTree;
this.unicodeArrayRotateFunctionName = unicodeArrayRotateFunctionName;
this.unicodeArrayName = unicodeArrayName;
this.node = this.getNodeStructure();
}
appendNode() {
estraverse.replace(this.astTree, {
leave: (node, parent) => {
switch (node.type) {
case 'Program':
node.body.push(this.getNode());
break;
}
}
});
}
getNodeIdentifier() {
return this.unicodeArrayRotateFunctionName;
}
getNodeStructure() {
return {
'type': 'FunctionExpression',
'id': {
'type': 'Identifier',
'name': this.unicodeArrayRotateFunctionName
},
'params': [
{
'type': 'Identifier',
'name': 'array'
},
{
'type': 'Identifier',
'name': 'times'
},
{
'type': 'Identifier',
'name': 'reverse'
}
],
'defaults': [],
'body': {
'type': 'BlockStatement',
'body': [
{
'type': 'IfStatement',
'test': {
'type': 'BinaryExpression',
'operator': '<',
'left': {
'type': 'Identifier',
'name': 'times'
},
'right': {
'type': 'Literal',
'value': 0,
'raw': '0'
}
},
'consequent': {
'type': 'BlockStatement',
'body': [
{
'type': 'ReturnStatement',
'argument': null
}
]
},
'alternate': null
},
{
'type': 'ExpressionStatement',
'expression': {
'type': 'AssignmentExpression',
'operator': '=',
'left': {
'type': 'Identifier',
'name': 'reverse'
},
'right': {
'type': 'LogicalExpression',
'operator': '||',
'left': {
'type': 'Identifier',
'name': 'reverse'
},
'right': {
'type': 'Literal',
'value': false,
'raw': 'false'
}
}
}
},
{
'type': 'VariableDeclaration',
'declarations': [
{
'type': 'VariableDeclarator',
'id': {
'type': 'Identifier',
'name': 'temp'
},
'init': null
}
],
'kind': 'var'
},
{
'type': 'WhileStatement',
'test': {
'type': 'UpdateExpression',
'operator': '--',
'argument': {
'type': 'Identifier',
'name': 'times'
},
'prefix': false
},
'body': {
'type': 'BlockStatement',
'body': [
{
'type': 'IfStatement',
'test': {
'type': 'UnaryExpression',
'operator': '!',
'argument': {
'type': 'Identifier',
'name': 'reverse'
},
'prefix': true
},
'consequent': {
'type': 'BlockStatement',
'body': [
{
'type': 'ExpressionStatement',
'expression': {
'type': 'AssignmentExpression',
'operator': '=',
'left': {
'type': 'Identifier',
'name': 'temp'
},
'right': {
'type': 'CallExpression',
'callee': {
'type': 'MemberExpression',
'computed': true,
'object': {
'type': 'Identifier',
'name': 'array'
},
'property': {
'type': 'Literal',
'name': 'pop',
'x-verbatim-property': Utils_1.Utils.stringToUnicode('pop')
}
},
'arguments': []
}
}
},
{
'type': 'ExpressionStatement',
'expression': {
'type': 'CallExpression',
'callee': {
'type': 'MemberExpression',
'computed': true,
'object': {
'type': 'Identifier',
'name': 'array'
},
'property': {
'type': 'Literal',
'name': 'unshift',
'x-verbatim-property': Utils_1.Utils.stringToUnicode('unshift')
}
},
'arguments': [
{
'type': 'Identifier',
'name': 'temp'
}
]
}
}
]
},
'alternate': {
'type': 'BlockStatement',
'body': [
{
'type': 'ExpressionStatement',
'expression': {
'type': 'AssignmentExpression',
'operator': '=',
'left': {
'type': 'Identifier',
'name': 'temp'
},
'right': {
'type': 'CallExpression',
'callee': {
'type': 'MemberExpression',
'computed': true,
'object': {
'type': 'Identifier',
'name': 'array'
},
'property': {
'type': 'Literal',
'name': 'shift',
'x-verbatim-property': Utils_1.Utils.stringToUnicode('shift')
}
},
'arguments': []
}
}
},
{
'type': 'ExpressionStatement',
'expression': {
'type': 'CallExpression',
'callee': {
'type': 'MemberExpression',
'computed': true,
'object': {
'type': 'Identifier',
'name': 'array'
},
'property': {
'type': 'Literal',
'name': 'push',
'x-verbatim-property': Utils_1.Utils.stringToUnicode('push')
}
},
'arguments': [
{
'type': 'Identifier',
'name': 'temp'
}
]
}
}
]
}
}
]
}
}
]
},
'generator': false,
'expression': false
};
}
}
exports.UnicodeArrayRotateFunctionNode = UnicodeArrayRotateFunctionNode;
//# sourceMappingURL=UnicodeArrayRotateFunctionNode.js.map
@@ -0,0 +1 @@
{"version":3,"file":"UnicodeArrayRotateFunctionNode.js","sourceRoot":"","sources":["UnicodeArrayRotateFunctionNode.ts"],"names":[],"mappings":";AAAA,uBAAqB,QAAQ,CAAC,CAAA;AAC9B,wBAAsB,UAAU,CAAC,CAAA;AAEjC,IAAI,UAAU,GAA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DACD,WAAW,EAAE;wDACT;4DACI,MAAM,EAAE,YAAY;4DACpB,MAAM,EAAE,MAAM;yDACjB;qDACJ;iDACJ;6CACJ;yCACJ;qCACJ;iCACJ;6BACJ;yBACJ;qBACJ;iBACJ;aACJ;YACD,WAAW,EAAE,KAAK;YAClB,YAAY,EAAE,KAAK;SACtB,CAAC;IACN,CAAC;AACL,CAAC;AA7SY,sCAA8B,iCA6S1C,CAAA"}
+307
View File
@@ -0,0 +1,307 @@
import { Node } from './Node';
import { Utils } from '../Utils';
let estraverse = require('estraverse');
export class UnicodeArrayRotateFunctionNode extends Node {
/**
* @type any
*/
private astTree: any;
/**
* @type {string}
*/
private unicodeArrayName: string;
/**
* @param {string}
*/
private unicodeArrayRotateFunctionName: string;
/**
* @type any
*/
protected node: any;
/**
* @param astTree
* @param unicodeArrayRotateFunctionName
* @param unicodeArrayName
*/
constructor (
astTree: any,
unicodeArrayRotateFunctionName: string,
unicodeArrayName: string
) {
super();
this.astTree = astTree;
this.unicodeArrayRotateFunctionName = unicodeArrayRotateFunctionName;
this.unicodeArrayName = unicodeArrayName;
this.node = this.getNodeStructure();
}
public appendNode (): void {
estraverse.replace(this.astTree, {
leave: (node, parent) => {
switch (node.type) {
case 'Program':
node.body.push(this.getNode());
break;
}
}
});
}
/**
* @returns {string}
*/
public getNodeIdentifier (): string {
return this.unicodeArrayRotateFunctionName;
}
/**
* @returns any
*/
protected getNodeStructure (): any {
return {
'type': 'FunctionExpression',
'id': {
'type': 'Identifier',
'name': this.unicodeArrayRotateFunctionName
},
'params': [
{
'type': 'Identifier',
'name': 'array'
},
{
'type': 'Identifier',
'name': 'times'
},
{
'type': 'Identifier',
'name': 'reverse'
}
],
'defaults': [],
'body': {
'type': 'BlockStatement',
'body': [
{
'type': 'IfStatement',
'test': {
'type': 'BinaryExpression',
'operator': '<',
'left': {
'type': 'Identifier',
'name': 'times'
},
'right': {
'type': 'Literal',
'value': 0,
'raw': '0'
}
},
'consequent': {
'type': 'BlockStatement',
'body': [
{
'type': 'ReturnStatement',
'argument': null
}
]
},
'alternate': null
},
{
'type': 'ExpressionStatement',
'expression': {
'type': 'AssignmentExpression',
'operator': '=',
'left': {
'type': 'Identifier',
'name': 'reverse'
},
'right': {
'type': 'LogicalExpression',
'operator': '||',
'left': {
'type': 'Identifier',
'name': 'reverse'
},
'right': {
'type': 'Literal',
'value': false,
'raw': 'false'
}
}
}
},
{
'type': 'VariableDeclaration',
'declarations': [
{
'type': 'VariableDeclarator',
'id': {
'type': 'Identifier',
'name': 'temp'
},
'init': null
}
],
'kind': 'var'
},
{
'type': 'WhileStatement',
'test': {
'type': 'UpdateExpression',
'operator': '--',
'argument': {
'type': 'Identifier',
'name': 'times'
},
'prefix': false
},
'body': {
'type': 'BlockStatement',
'body': [
{
'type': 'IfStatement',
'test': {
'type': 'UnaryExpression',
'operator': '!',
'argument': {
'type': 'Identifier',
'name': 'reverse'
},
'prefix': true
},
'consequent': {
'type': 'BlockStatement',
'body': [
{
'type': 'ExpressionStatement',
'expression': {
'type': 'AssignmentExpression',
'operator': '=',
'left': {
'type': 'Identifier',
'name': 'temp'
},
'right': {
'type': 'CallExpression',
'callee': {
'type': 'MemberExpression',
'computed': true,
'object': {
'type': 'Identifier',
'name': 'array'
},
'property': {
'type': 'Literal',
'name': 'pop',
'x-verbatim-property': Utils.stringToUnicode('pop')
}
},
'arguments': []
}
}
},
{
'type': 'ExpressionStatement',
'expression': {
'type': 'CallExpression',
'callee': {
'type': 'MemberExpression',
'computed': true,
'object': {
'type': 'Identifier',
'name': 'array'
},
'property': {
'type': 'Literal',
'name': 'unshift',
'x-verbatim-property': Utils.stringToUnicode('unshift')
}
},
'arguments': [
{
'type': 'Identifier',
'name': 'temp'
}
]
}
}
]
},
'alternate': {
'type': 'BlockStatement',
'body': [
{
'type': 'ExpressionStatement',
'expression': {
'type': 'AssignmentExpression',
'operator': '=',
'left': {
'type': 'Identifier',
'name': 'temp'
},
'right': {
'type': 'CallExpression',
'callee': {
'type': 'MemberExpression',
'computed': true,
'object': {
'type': 'Identifier',
'name': 'array'
},
'property': {
'type': 'Literal',
'name': 'shift',
'x-verbatim-property': Utils.stringToUnicode('shift')
}
},
'arguments': []
}
}
},
{
'type': 'ExpressionStatement',
'expression': {
'type': 'CallExpression',
'callee': {
'type': 'MemberExpression',
'computed': true,
'object': {
'type': 'Identifier',
'name': 'array'
},
'property': {
'type': 'Literal',
'name': 'push',
'x-verbatim-property': Utils.stringToUnicode('push')
}
},
'arguments': [
{
'type': 'Identifier',
'name': 'temp'
}
]
}
}
]
}
}
]
}
}
]
},
'generator': false,
'expression': false
};
}
}
+1283
View File
File diff suppressed because it is too large Load Diff
+11
View File
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": true,
"noImplicitAny": false
}
}
+12
View File
@@ -0,0 +1,12 @@
{
"version": "v4",
"repo": "borisyankov/DefinitelyTyped",
"ref": "master",
"path": "src/typings",
"bundle": "typings/tsd.d.ts",
"installed": {
"node/node.d.ts": {
"commit": "6834f97fb33561a3ad40695084da2b660efaee29"
}
}
}
+1
View File
@@ -0,0 +1 @@
/// <reference path="../src/typings/node/node.d.ts" />