mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
0.3.0
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "javascript-obfuscator",
|
||||
"version": "0.2.1",
|
||||
"version": "0.3.0",
|
||||
"description": "JavaScript obfuscator",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
|
||||
@@ -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`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user