mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
IOptions interface
This commit is contained in:
+2
-3
@@ -5,10 +5,9 @@ const DebugProtectionFunctionNode_1 = require("../custom-nodes/debug-protection-
|
||||
const NodesGroup_1 = require('./NodesGroup');
|
||||
const Utils_1 = require('../Utils');
|
||||
class DebugProtectionNodesGroup extends NodesGroup_1.NodesGroup {
|
||||
constructor(options) {
|
||||
super();
|
||||
constructor(options = {}) {
|
||||
super(options);
|
||||
this.debugProtectionFunctionIdentifier = Utils_1.Utils.getRandomVariableName();
|
||||
this.options = options;
|
||||
this.nodes = new Map([
|
||||
[
|
||||
'debugProtectionFunctionNode',
|
||||
|
||||
Vendored
+3
@@ -1,5 +1,8 @@
|
||||
"use strict";
|
||||
class NodesGroup {
|
||||
constructor(options = {}) {
|
||||
this.options = options;
|
||||
}
|
||||
getNodes() {
|
||||
return this.nodes;
|
||||
}
|
||||
|
||||
+2
-3
@@ -5,12 +5,11 @@ const UnicodeArrayNode_1 = require('../custom-nodes/unicode-array-nodes/UnicodeA
|
||||
const UnicodeArrayRotateFunctionNode_1 = require('../custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode');
|
||||
const Utils_1 = require('../Utils');
|
||||
class UnicodeArrayNodesGroup extends NodesGroup_1.NodesGroup {
|
||||
constructor(options) {
|
||||
super();
|
||||
constructor(options = {}) {
|
||||
super(options);
|
||||
this.unicodeArrayName = Utils_1.Utils.getRandomVariableName(UnicodeArrayNode_1.UnicodeArrayNode.UNICODE_ARRAY_RANDOM_LENGTH);
|
||||
this.unicodeArrayRotateValue = Utils_1.Utils.getRandomInteger(100, 500);
|
||||
this.unicodeArrayTranslatorName = Utils_1.Utils.getRandomVariableName(UnicodeArrayNode_1.UnicodeArrayNode.UNICODE_ARRAY_RANDOM_LENGTH);
|
||||
this.options = options;
|
||||
let unicodeArrayNode = new UnicodeArrayNode_1.UnicodeArrayNode(this.unicodeArrayName, this.unicodeArrayRotateValue), unicodeArray = unicodeArrayNode.getNodeData();
|
||||
this.nodes = new Map([
|
||||
[
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import * as esprima from 'esprima';
|
||||
import * as escodegen from 'escodegen';
|
||||
|
||||
import { IOptions } from "./src/interfaces/IOptions";
|
||||
import { IProgramNode } from './src/interfaces/nodes/IProgramNode';
|
||||
|
||||
import { Obfuscator } from './src/Obfuscator';
|
||||
@@ -11,7 +12,7 @@ class JavaScriptObfuscator {
|
||||
/**
|
||||
* @type any
|
||||
*/
|
||||
private static defaultOptions: any = {
|
||||
private static defaultOptions: IOptions = {
|
||||
compact: true,
|
||||
debugProtection: false,
|
||||
debugProtectionInterval: false,
|
||||
@@ -31,7 +32,7 @@ class JavaScriptObfuscator {
|
||||
* @param sourceCode
|
||||
* @param customOptions
|
||||
*/
|
||||
public static obfuscate (sourceCode: string, customOptions?: any): string {
|
||||
public static obfuscate (sourceCode: string, customOptions?: IOptions): string {
|
||||
let astTree: IProgramNode = esprima.parse(sourceCode),
|
||||
options: any = Object.assign(JavaScriptObfuscator.defaultOptions, customOptions),
|
||||
obfuscator: Obfuscator = new Obfuscator(options);
|
||||
@@ -45,7 +46,7 @@ class JavaScriptObfuscator {
|
||||
* @param astTree
|
||||
* @param options
|
||||
*/
|
||||
private static generateCode (astTree: IProgramNode, options: any): string {
|
||||
private static generateCode (astTree: IProgramNode, options: IOptions): string {
|
||||
let escodegenParams: any = Object.assign({}, JavaScriptObfuscator.escodegenParams);
|
||||
|
||||
if (options.hasOwnProperty('compact')) {
|
||||
|
||||
+3
-4
@@ -4,6 +4,7 @@ import { ICustomNode } from './interfaces/ICustomNode';
|
||||
import { INodeObfuscator } from './interfaces/INodeObfuscator';
|
||||
import { INodesGroup } from './interfaces/INodesGroup';
|
||||
import { INode } from './interfaces/nodes/INode';
|
||||
import { IOptions } from "./interfaces/IOptions";
|
||||
|
||||
import { AppendState } from './enums/AppendState';
|
||||
import { NodeType } from './enums/NodeType';
|
||||
@@ -18,9 +19,7 @@ import { MemberExpressionObfuscator } from './node-obfuscators/MemberExpressionO
|
||||
import { MethodDefinitionObfuscator } from './node-obfuscators/MethodDefinitionObfuscator';
|
||||
import { NodeUtils } from "./NodeUtils";
|
||||
import { ObjectExpressionObfuscator } from './node-obfuscators/ObjectExpressionObfuscator';
|
||||
import { UnicodeArrayNode } from './custom-nodes/unicode-array-nodes/UnicodeArrayNode';
|
||||
import { UnicodeArrayNodesGroup } from './node-groups/UnicodeArrayNodesGroup';
|
||||
import { Utils } from './Utils';
|
||||
import { VariableDeclarationObfuscator } from './node-obfuscators/VariableDeclarationObfuscator';
|
||||
|
||||
export class Obfuscator {
|
||||
@@ -51,12 +50,12 @@ export class Obfuscator {
|
||||
/**
|
||||
* @type any
|
||||
*/
|
||||
private options: any;
|
||||
private options: IOptions;
|
||||
|
||||
/**
|
||||
* @param options
|
||||
*/
|
||||
constructor (options: any = {}) {
|
||||
constructor (options: IOptions = {}) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
export interface IOptions {
|
||||
compact?: boolean;
|
||||
debugProtection?: boolean;
|
||||
debugProtectionInterval?: boolean;
|
||||
disableConsoleOutput?: boolean;
|
||||
rotateUnicodeArray?: boolean;
|
||||
wrapUnicodeArrayCalls?: boolean;
|
||||
[id: string]: any;
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ICustomNode } from '../interfaces/ICustomNode';
|
||||
import { IOptions } from "../interfaces/IOptions";
|
||||
|
||||
import { DebugProtectionFunctionCallNode } from "../custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode";
|
||||
import { DebugProtectionFunctionIntervalNode } from "../custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode";
|
||||
@@ -13,18 +14,11 @@ export class DebugProtectionNodesGroup extends NodesGroup {
|
||||
*/
|
||||
private debugProtectionFunctionIdentifier: string = Utils.getRandomVariableName();
|
||||
|
||||
/**
|
||||
* @type {any}
|
||||
*/
|
||||
private options: any;
|
||||
|
||||
/**
|
||||
* @param options
|
||||
*/
|
||||
constructor (options: any) {
|
||||
super();
|
||||
|
||||
this.options = options;
|
||||
constructor (options: IOptions = {}) {
|
||||
super(options);
|
||||
|
||||
this.nodes = new Map <string, ICustomNode> ([
|
||||
[
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ICustomNode } from '../interfaces/ICustomNode';
|
||||
|
||||
import { INodesGroup } from '../interfaces/INodesGroup';
|
||||
import { IOptions } from "../interfaces/IOptions";
|
||||
|
||||
export abstract class NodesGroup implements INodesGroup {
|
||||
/**
|
||||
@@ -8,6 +9,15 @@ export abstract class NodesGroup implements INodesGroup {
|
||||
*/
|
||||
protected nodes: Map <string, ICustomNode>;
|
||||
|
||||
/**
|
||||
* @type {IOptions}
|
||||
*/
|
||||
protected options: IOptions;
|
||||
|
||||
constructor (options: IOptions = {}) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Map<string, INode>}
|
||||
*/
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ICustomNode } from '../interfaces/ICustomNode';
|
||||
import { IOptions } from "../interfaces/IOptions";
|
||||
|
||||
import { NodesGroup } from './NodesGroup';
|
||||
import { UnicodeArrayCallsWrapper } from "../custom-nodes/unicode-array-nodes/UnicodeArrayCallsWrapper";
|
||||
@@ -7,11 +8,6 @@ import { UnicodeArrayRotateFunctionNode } from '../custom-nodes/unicode-array-no
|
||||
import { Utils } from '../Utils';
|
||||
|
||||
export class UnicodeArrayNodesGroup extends NodesGroup {
|
||||
/**
|
||||
* @type {any}
|
||||
*/
|
||||
private options: any;
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
@@ -30,10 +26,8 @@ export class UnicodeArrayNodesGroup extends NodesGroup {
|
||||
/**
|
||||
* @param options
|
||||
*/
|
||||
constructor (options: any) {
|
||||
super();
|
||||
|
||||
this.options = options;
|
||||
constructor (options: IOptions = {}) {
|
||||
super(options);
|
||||
|
||||
let unicodeArrayNode: UnicodeArrayNode = new UnicodeArrayNode(
|
||||
this.unicodeArrayName,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ICustomNode } from '../interfaces/ICustomNode';
|
||||
import { INodeObfuscator } from '../interfaces/INodeObfuscator';
|
||||
import { INode } from "../interfaces/nodes/INode";
|
||||
import { IOptions } from "../interfaces/IOptions";
|
||||
|
||||
import { JSFuck } from "../enums/JSFuck";
|
||||
|
||||
@@ -16,13 +17,13 @@ export abstract class NodeObfuscator implements INodeObfuscator {
|
||||
/**
|
||||
* @type any
|
||||
*/
|
||||
protected options: any;
|
||||
protected options: IOptions;
|
||||
|
||||
/**
|
||||
* @param nodes
|
||||
* @param options
|
||||
*/
|
||||
constructor(nodes: Map <string, ICustomNode>, options: any = {}) {
|
||||
constructor(nodes: Map <string, ICustomNode>, options: IOptions = {}) {
|
||||
this.nodes = nodes;
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user