This commit is contained in:
sanex3339
2016-05-16 20:38:01 +03:00
parent df783473ee
commit 19fe8255ef
4 changed files with 24 additions and 15 deletions
+8 -6
View File
@@ -3,23 +3,25 @@ const esprima = require('esprima');
const escodegen = require('escodegen');
const Obfuscator_1 = require('./src/Obfuscator');
class JavaScriptObfuscator {
static obfuscate(sourceCode, options = {}) {
let astTree = esprima.parse(sourceCode), obfuscator = new Obfuscator_1.Obfuscator(options);
static obfuscate(sourceCode, customOptions) {
let astTree = esprima.parse(sourceCode), options = Object.assign(JavaScriptObfuscator.defaultOptions, customOptions), obfuscator = new Obfuscator_1.Obfuscator(options);
obfuscator.obfuscateNode(astTree);
return JavaScriptObfuscator.generateCode(astTree, options);
}
static generateCode(astTree, options = {}) {
static generateCode(astTree, options) {
let escodegenParams = Object.assign({}, JavaScriptObfuscator.escodegenParams);
if (options.hasOwnProperty('compact')) {
escodegenParams.format = {};
escodegenParams.format.compact = options.compact;
}
return escodegen.generate(astTree, escodegenParams);
}
}
JavaScriptObfuscator.defaultOptions = {
compact: true,
rotateUnicodeArray: true
};
JavaScriptObfuscator.escodegenParams = {
format: {
compact: true
},
verbatim: 'x-verbatim-property'
};
exports.JavaScriptObfuscator = JavaScriptObfuscator;
+10 -6
View File
@@ -8,22 +8,25 @@ import { IProgramNode } from './src/interfaces/nodes/IProgramNode';
import { Obfuscator } from './src/Obfuscator';
export class JavaScriptObfuscator {
private static defaultOptions: any = {
compact: true,
rotateUnicodeArray: true
};
/**
* @type any
*/
private static escodegenParams: any = {
format: {
compact: true
},
verbatim: 'x-verbatim-property'
};
/**
* @param sourceCode
* @param options
* @param customOptions
*/
public static obfuscate (sourceCode: string, options: any = {}): string {
public static obfuscate (sourceCode: string, customOptions: any): string {
let astTree: IProgramNode = esprima.parse(sourceCode),
options: any = Object.assign(JavaScriptObfuscator.defaultOptions, customOptions),
obfuscator: Obfuscator = new Obfuscator(options);
obfuscator.obfuscateNode(astTree);
@@ -35,10 +38,11 @@ export class JavaScriptObfuscator {
* @param astTree
* @param options
*/
private static generateCode (astTree: IProgramNode, options: any = {}): string {
private static generateCode (astTree: IProgramNode, options: any): string {
let escodegenParams: any = Object.assign({}, JavaScriptObfuscator.escodegenParams);
if (options.hasOwnProperty('compact')) {
escodegenParams.format = {};
escodegenParams.format.compact = options.compact;
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "javascript-obfuscator",
"version": "0.2.1",
"version": "0.3.0",
"description": "JavaScript obfuscator",
"main": "index.js",
"dependencies": {
+5 -2
View File
@@ -5,8 +5,6 @@ Compatible with ES6.
Tested on Angular2 bundle.
https://gist.github.com/sanex3339/ffc2876123b52e6d11ce45369fd53acf
##Important: right now obfuscation of code which was minimized with UglifyJS may not work (tested on Angular 2 bundle). I will try to fix that soon or later.
###Installation
Install the package with NPM and add it to your devDependencies:
@@ -62,6 +60,11 @@ Options for JavaScript obfuscator:
```
###Available options
####compact
Type: `boolean` Default: `true`
Compact code output in one line.
####rotateUnicodeArray
Type: `boolean` Default: `true`