mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
Vendored
+7
-2
@@ -21,7 +21,11 @@ class Utils {
|
||||
return newArray;
|
||||
}
|
||||
static decToHex(dec) {
|
||||
return (dec + Math.pow(16, 6)).toString(16).substr(-6).replace(Utils.hexRepetitiveZerosRegExp, '');
|
||||
const decToHexSliceValue = -6, exponent = 6, radix = 16;
|
||||
return (dec + Math.pow(radix, exponent))
|
||||
.toString(radix)
|
||||
.substr(decToHexSliceValue)
|
||||
.replace(Utils.hexRepetitiveZerosRegExp, '');
|
||||
}
|
||||
static getRandomInteger(min, max) {
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
@@ -37,8 +41,9 @@ class Utils {
|
||||
return obj;
|
||||
}
|
||||
static stringToUnicode(string) {
|
||||
const radix = 16, unicodeSliceValue = -4;
|
||||
return `'${string.replace(/[\s\S]/g, (escape) => {
|
||||
return `\\u${('0000' + escape.charCodeAt(0).toString(16)).slice(-4)}`;
|
||||
return `\\u${('0000' + escape.charCodeAt(0).toString(radix)).slice(unicodeSliceValue)}`;
|
||||
})}'`;
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
-3
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
const JavaScriptObfuscator = require("../index");
|
||||
let obfuscatedCode = JavaScriptObfuscator.obfuscate(`
|
||||
let JavaScriptObfuscator = require('../index'), obfuscatedCode = JavaScriptObfuscator.obfuscate(`
|
||||
(function(){
|
||||
var result = 1,
|
||||
term1 = 0,
|
||||
|
||||
+5
-5
@@ -9,7 +9,7 @@ import { IPropertyNode } from "./interfaces/nodes/IPropertyNode";
|
||||
import { INode } from './interfaces/nodes/INode';
|
||||
import { IVariableDeclaratorNode } from "./interfaces/nodes/IVariableDeclaratorNode";
|
||||
|
||||
import { BlockScopeNode } from "./types/BlockScopeNode";
|
||||
import { TBlockScopeNode } from "./types/TBlockScopeNode";
|
||||
|
||||
import { NodeType } from "./enums/NodeType";
|
||||
|
||||
@@ -69,13 +69,13 @@ export class NodeUtils {
|
||||
* @param depth
|
||||
* @returns {INode}
|
||||
*/
|
||||
public static getBlockScopeOfNode (node: INode, depth: number = 0): BlockScopeNode {
|
||||
public static getBlockScopeOfNode (node: INode, depth: number = 0): TBlockScopeNode {
|
||||
if (!node.parentNode) {
|
||||
throw new ReferenceError('`parentNode` property of given node is `undefined`');
|
||||
}
|
||||
|
||||
if (node.parentNode.type === NodeType.Program) {
|
||||
return <BlockScopeNode> node.parentNode;
|
||||
return <TBlockScopeNode> node.parentNode;
|
||||
}
|
||||
|
||||
if (!Utils.arrayContains(NodeUtils.scopeNodes, node.parentNode.type)) {
|
||||
@@ -90,7 +90,7 @@ export class NodeUtils {
|
||||
return NodeUtils.getBlockScopeOfNode(node.parentNode);
|
||||
}
|
||||
|
||||
return <BlockScopeNode> node; // blocks statement of scopeNodes
|
||||
return <TBlockScopeNode> node; // blocks statement of scopeNodes
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,7 +142,7 @@ export class NodeUtils {
|
||||
* @param node
|
||||
* @returns {boolean}
|
||||
*/
|
||||
public static isNodeHasBlockScope (node: INode): node is BlockScopeNode {
|
||||
public static isNodeHasBlockScope (node: INode): node is TBlockScopeNode {
|
||||
return node.hasOwnProperty('body');
|
||||
}
|
||||
|
||||
|
||||
+6
-5
@@ -1,11 +1,12 @@
|
||||
import * as estraverse from 'estraverse';
|
||||
|
||||
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 { TNodeObfuscator } from "./types/TNodeObfuscator";
|
||||
|
||||
import { AppendState } from './enums/AppendState';
|
||||
import { NodeType } from './enums/NodeType';
|
||||
|
||||
@@ -29,9 +30,9 @@ export class Obfuscator {
|
||||
private nodes: Map <string, ICustomNode> = new Map <string, ICustomNode> ();
|
||||
|
||||
/**
|
||||
* @type {Map<string, Function[]>}
|
||||
* @type {Map<string, TNodeObfuscator[]>}
|
||||
*/
|
||||
private nodeObfuscators: Map <string, Function[]> = new Map <string, Function[]> ([
|
||||
private nodeObfuscators: Map <string, TNodeObfuscator[]> = new Map <string, TNodeObfuscator[]> ([
|
||||
[NodeType.ArrowFunctionExpression, [FunctionObfuscator]],
|
||||
[NodeType.ClassDeclaration, [FunctionDeclarationObfuscator]],
|
||||
[NodeType.CatchClause, [CatchClauseObfuscator]],
|
||||
@@ -123,8 +124,8 @@ export class Obfuscator {
|
||||
return;
|
||||
}
|
||||
|
||||
this.nodeObfuscators.get(node.type).forEach((obfuscator: Function) => {
|
||||
new (<INodeObfuscator> obfuscator(this.nodes, this.options)).obfuscateNode(node, parentNode);
|
||||
this.nodeObfuscators.get(node.type).forEach((obfuscator: TNodeObfuscator) => {
|
||||
new obfuscator(this.nodes, this.options).obfuscateNode(node, parentNode);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+16
-6
@@ -17,15 +17,15 @@ export class Utils {
|
||||
* @param array
|
||||
* @param times
|
||||
* @param reverse
|
||||
* @returns any[]
|
||||
* @returns {T[]}
|
||||
*/
|
||||
public static arrayRotate (array: any[], times: number, reverse: boolean = false): any[] {
|
||||
public static arrayRotate <T> (array: T[], times: number, reverse: boolean = false): T[] {
|
||||
if (times < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let newArray: any[] = array,
|
||||
temp: any;
|
||||
let newArray: T[] = array,
|
||||
temp: T;
|
||||
|
||||
while (times--) {
|
||||
if (!reverse) {
|
||||
@@ -45,7 +45,14 @@ export class Utils {
|
||||
* @returns {string}
|
||||
*/
|
||||
public static decToHex(dec: number): string {
|
||||
return (dec + Math.pow(16, 6)).toString(16).substr(-6).replace(Utils.hexRepetitiveZerosRegExp, '');
|
||||
const decToHexSliceValue: number = -6,
|
||||
exponent: number = 6,
|
||||
radix: number = 16;
|
||||
|
||||
return (dec + Math.pow(radix, exponent))
|
||||
.toString(radix)
|
||||
.substr(decToHexSliceValue)
|
||||
.replace(Utils.hexRepetitiveZerosRegExp, '');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,8 +97,11 @@ export class Utils {
|
||||
* @returns {string}
|
||||
*/
|
||||
public static stringToUnicode (string: string): string {
|
||||
const radix: number = 16,
|
||||
unicodeSliceValue: number = -4;
|
||||
|
||||
return `'${string.replace(/[\s\S]/g, (escape: string): string => {
|
||||
return `\\u${('0000' + escape.charCodeAt(0).toString(16)).slice(-4)}`;
|
||||
return `\\u${('0000' + escape.charCodeAt(0).toString(radix)).slice(unicodeSliceValue)}`;
|
||||
})}'`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import * as esprima from 'esprima';
|
||||
|
||||
import { BlockScopeNode } from "../../types/BlockScopeNode";
|
||||
import { INode } from "../../interfaces/nodes/INode";
|
||||
|
||||
import { TBlockScopeNode } from "../../types/TBlockScopeNode";
|
||||
|
||||
import { Node } from '../Node';
|
||||
import { NodeUtils } from "../../NodeUtils";
|
||||
@@ -15,7 +17,7 @@ export class ConsoleOutputDisableExpressionNode extends Node {
|
||||
/**
|
||||
* @param blockScopeNode
|
||||
*/
|
||||
public appendNode (blockScopeNode: BlockScopeNode): void {
|
||||
public appendNode (blockScopeNode: TBlockScopeNode): void {
|
||||
NodeUtils.prependNode(blockScopeNode.body, this.getNode());
|
||||
}
|
||||
|
||||
@@ -33,9 +35,9 @@ export class ConsoleOutputDisableExpressionNode extends Node {
|
||||
* _console
|
||||
* })();
|
||||
*
|
||||
* @returns any
|
||||
* @returns {INode}
|
||||
*/
|
||||
protected getNodeStructure (): any {
|
||||
protected getNodeStructure (): INode {
|
||||
return NodeUtils.getBlockScopeNodeByIndex(
|
||||
esprima.parse(`
|
||||
(function () {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { BlockScopeNode } from "../../types/BlockScopeNode";
|
||||
import { IExpressionStatementNode } from "../../interfaces/nodes/IExpressionStatementNode";
|
||||
|
||||
import { TBlockScopeNode } from "../../types/TBlockScopeNode";
|
||||
|
||||
import { NodeType } from "../../enums/NodeType";
|
||||
|
||||
@@ -25,14 +27,14 @@ export class DebugProtectionFunctionCallNode extends Node {
|
||||
/**
|
||||
* @param blockScopeNode
|
||||
*/
|
||||
public appendNode (blockScopeNode: BlockScopeNode): void {
|
||||
public appendNode (blockScopeNode: TBlockScopeNode): void {
|
||||
NodeUtils.appendNode(blockScopeNode.body, this.getNode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns any
|
||||
* @returns {IExpressionStatementNode}
|
||||
*/
|
||||
protected getNodeStructure (): any {
|
||||
protected getNodeStructure (): IExpressionStatementNode {
|
||||
return {
|
||||
'type': NodeType.ExpressionStatement,
|
||||
'expression': {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { BlockScopeNode } from "../../types/BlockScopeNode";
|
||||
import { IExpressionStatementNode } from "../../interfaces/nodes/IExpressionStatementNode";
|
||||
|
||||
import { TBlockScopeNode } from "../../types/TBlockScopeNode";
|
||||
|
||||
import { NodeType } from '../../enums/NodeType';
|
||||
|
||||
@@ -25,14 +27,14 @@ export class DebugProtectionFunctionIntervalNode extends Node {
|
||||
/**
|
||||
* @param blockScopeNode
|
||||
*/
|
||||
public appendNode (blockScopeNode: BlockScopeNode): void {
|
||||
public appendNode (blockScopeNode: TBlockScopeNode): void {
|
||||
NodeUtils.appendNode(blockScopeNode.body, this.getNode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns any
|
||||
* @returns {IExpressionStatementNode}
|
||||
*/
|
||||
protected getNodeStructure (): any {
|
||||
protected getNodeStructure (): IExpressionStatementNode {
|
||||
return {
|
||||
'type': NodeType.ExpressionStatement,
|
||||
'expression': {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import * as esprima from 'esprima';
|
||||
|
||||
import { BlockScopeNode } from "../../types/BlockScopeNode";
|
||||
import { INode } from "../../interfaces/nodes/INode";
|
||||
|
||||
import { TBlockScopeNode } from "../../types/TBlockScopeNode";
|
||||
|
||||
import { Node } from '../Node';
|
||||
import { NodeUtils } from '../../NodeUtils';
|
||||
@@ -28,7 +30,7 @@ export class DebugProtectionFunctionNode extends Node {
|
||||
/**
|
||||
* @param blockScopeNode
|
||||
*/
|
||||
public appendNode (blockScopeNode: BlockScopeNode): void {
|
||||
public appendNode (blockScopeNode: TBlockScopeNode): void {
|
||||
let programBodyLength: number = blockScopeNode.body.length,
|
||||
randomIndex: number = Utils.getRandomInteger(0, programBodyLength);
|
||||
|
||||
@@ -45,9 +47,9 @@ export class DebugProtectionFunctionNode extends Node {
|
||||
/**
|
||||
* Found this trick in JScrambler
|
||||
*
|
||||
* @returns any
|
||||
* @returns {INode}
|
||||
*/
|
||||
protected getNodeStructure (): any {
|
||||
protected getNodeStructure (): INode {
|
||||
return NodeUtils.getBlockScopeNodeByIndex(
|
||||
esprima.parse(`
|
||||
var ${this.debugProtectionFunctionName} = function () {
|
||||
|
||||
@@ -2,7 +2,7 @@ import * as esprima from 'esprima';
|
||||
|
||||
import { INode } from "../../interfaces/nodes/INode";
|
||||
|
||||
import { BlockScopeNode } from "../../types/BlockScopeNode";
|
||||
import { TBlockScopeNode } from "../../types/TBlockScopeNode";
|
||||
|
||||
import { AppendState } from "../../enums/AppendState";
|
||||
|
||||
@@ -53,7 +53,7 @@ export class UnicodeArrayCallsWrapper extends Node {
|
||||
/**
|
||||
* @param blockScopeNode
|
||||
*/
|
||||
public appendNode (blockScopeNode: BlockScopeNode): void {
|
||||
public appendNode (blockScopeNode: TBlockScopeNode): void {
|
||||
NodeUtils.insertNodeAtIndex(blockScopeNode.body, this.getNode(), 1);
|
||||
}
|
||||
|
||||
@@ -76,9 +76,9 @@ export class UnicodeArrayCallsWrapper extends Node {
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns any
|
||||
* @returns {INode}
|
||||
*/
|
||||
protected getNodeStructure (): any {
|
||||
protected getNodeStructure (): INode {
|
||||
let keyName: string = Utils.getRandomVariableName(),
|
||||
node: INode = esprima.parse(`
|
||||
var ${this.unicodeArrayCallsWrapperName} = function (${keyName}) {
|
||||
|
||||
@@ -2,7 +2,7 @@ import * as escodegen from 'escodegen';
|
||||
|
||||
import { INode } from '../../interfaces/nodes/INode';
|
||||
|
||||
import { BlockScopeNode } from "../../types/BlockScopeNode";
|
||||
import { TBlockScopeNode } from "../../types/TBlockScopeNode";
|
||||
|
||||
import { AppendState } from '../../enums/AppendState';
|
||||
import { NodeType } from "../../enums/NodeType";
|
||||
@@ -10,6 +10,7 @@ import { NodeType } from "../../enums/NodeType";
|
||||
import { Node } from '../Node';
|
||||
import { NodeUtils } from "../../NodeUtils";
|
||||
import { Utils } from '../../Utils';
|
||||
import {IVariableDeclarationNode} from "../../interfaces/nodes/IVariableDeclarationNode";
|
||||
|
||||
export class UnicodeArrayNode extends Node {
|
||||
/**
|
||||
@@ -53,7 +54,7 @@ export class UnicodeArrayNode extends Node {
|
||||
/**
|
||||
* @param blockScopeNode
|
||||
*/
|
||||
public appendNode (blockScopeNode: BlockScopeNode): void {
|
||||
public appendNode (blockScopeNode: TBlockScopeNode): void {
|
||||
NodeUtils.prependNode(blockScopeNode.body, this.getNode());
|
||||
}
|
||||
|
||||
@@ -79,7 +80,7 @@ export class UnicodeArrayNode extends Node {
|
||||
return;
|
||||
}
|
||||
|
||||
Utils.arrayRotate(this.unicodeArray, this.unicodeArrayRotateValue);
|
||||
Utils.arrayRotate <string> (this.unicodeArray, this.unicodeArrayRotateValue);
|
||||
|
||||
this.updateNode();
|
||||
|
||||
@@ -87,9 +88,9 @@ export class UnicodeArrayNode extends Node {
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns any
|
||||
* @returns {INode}
|
||||
*/
|
||||
protected getNodeStructure (): any {
|
||||
protected getNodeStructure (): IVariableDeclarationNode {
|
||||
return {
|
||||
'type': NodeType.VariableDeclaration,
|
||||
'declarations': [
|
||||
|
||||
@@ -2,7 +2,7 @@ import * as esprima from 'esprima';
|
||||
|
||||
import { INode } from "../../interfaces/nodes/INode";
|
||||
|
||||
import { BlockScopeNode } from "../../types/BlockScopeNode";
|
||||
import { TBlockScopeNode } from "../../types/TBlockScopeNode";
|
||||
|
||||
import { AppendState } from "../../enums/AppendState";
|
||||
|
||||
@@ -53,7 +53,7 @@ export class UnicodeArrayRotateFunctionNode extends Node {
|
||||
/**
|
||||
* @param blockScopeNode
|
||||
*/
|
||||
public appendNode (blockScopeNode: BlockScopeNode): void {
|
||||
public appendNode (blockScopeNode: TBlockScopeNode): void {
|
||||
NodeUtils.insertNodeAtIndex(blockScopeNode.body, this.getNode(), 1);
|
||||
}
|
||||
|
||||
@@ -69,9 +69,9 @@ export class UnicodeArrayRotateFunctionNode extends Node {
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns any
|
||||
* @returns {INode}
|
||||
*/
|
||||
protected getNodeStructure (): any {
|
||||
protected getNodeStructure (): INode {
|
||||
let arrayName: string = Utils.getRandomVariableName(),
|
||||
timesName: string = Utils.getRandomVariableName(),
|
||||
tempArrayName: string = Utils.getRandomVariableName(),
|
||||
|
||||
Vendored
-1
@@ -5,5 +5,4 @@ export interface IOptions {
|
||||
disableConsoleOutput?: boolean;
|
||||
rotateUnicodeArray?: boolean;
|
||||
wrapUnicodeArrayCalls?: boolean;
|
||||
[id: string]: any;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import { INode } from "./INode";
|
||||
|
||||
export interface IExpressionStatementNode extends INode {
|
||||
expression: any;
|
||||
}
|
||||
@@ -3,4 +3,4 @@ import { ICatchClauseNode } from "../interfaces/nodes/ICatchClauseNode";
|
||||
import { IFunctionNode } from "../interfaces/nodes/IFunctionNode";
|
||||
import { IProgramNode } from "../interfaces/nodes/IProgramNode";
|
||||
|
||||
export type BlockScopeNode = IBlockStatementNode|ICatchClauseNode|IFunctionNode|IProgramNode;
|
||||
export type TBlockScopeNode = IBlockStatementNode|ICatchClauseNode|IFunctionNode|IProgramNode;
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
import { ICustomNode } from "../interfaces/ICustomNode";
|
||||
import { INodeObfuscator } from "../interfaces/INodeObfuscator";
|
||||
import { IOptions } from "../interfaces/IOptions";
|
||||
|
||||
export type TNodeObfuscator = (new (nodes: Map <string, ICustomNode>, options: IOptions) => INodeObfuscator);
|
||||
+2
-3
@@ -1,6 +1,5 @@
|
||||
import * as JavaScriptObfuscator from "../index";
|
||||
|
||||
let obfuscatedCode: string = (<any>JavaScriptObfuscator).obfuscate(
|
||||
let JavaScriptObfuscator = require('../index'),
|
||||
obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
|
||||
`
|
||||
(function(){
|
||||
var result = 1,
|
||||
|
||||
Reference in New Issue
Block a user