mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Fixed errors related to identifiers. Changed self defending helper
This commit is contained in:
@@ -16,7 +16,7 @@ import { DomainLockCustomCodeHelperGroup } from '../../../custom-code-helpers/do
|
||||
import { SelfDefendingCodeHelperGroup } from '../../../custom-code-helpers/self-defending/group/SelfDefendingCodeHelperGroup';
|
||||
import { StringArrayCodeHelperGroup } from '../../../custom-code-helpers/string-array/group/StringArrayCodeHelperGroup';
|
||||
|
||||
import { ConsoleOutputDisableExpressionCodeHelper } from '../../../custom-code-helpers/console-output/ConsoleOutputDisableExpressionCodeHelper';
|
||||
import { ConsoleOutputDisableCodeHelper } from '../../../custom-code-helpers/console-output/ConsoleOutputDisableCodeHelper';
|
||||
import { CustomCodeHelperFormatter } from '../../../custom-code-helpers/CustomCodeHelperFormatter';
|
||||
import { CustomCodeHelperObfuscator } from '../../../custom-code-helpers/CustomCodeHelperObfuscator';
|
||||
import { DebugProtectionFunctionCallCodeHelper } from '../../../custom-code-helpers/debug-protection/DebugProtectionFunctionCallCodeHelper';
|
||||
@@ -32,8 +32,8 @@ import { StringArrayRotateFunctionCodeHelper } from '../../../custom-code-helper
|
||||
export const customCodeHelpersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
|
||||
// custom code helpers
|
||||
bind<ICustomCodeHelper>(ServiceIdentifiers.ICustomCodeHelper)
|
||||
.to(ConsoleOutputDisableExpressionCodeHelper)
|
||||
.whenTargetNamed(CustomCodeHelper.ConsoleOutputDisableExpression);
|
||||
.to(ConsoleOutputDisableCodeHelper)
|
||||
.whenTargetNamed(CustomCodeHelper.ConsoleOutputDisable);
|
||||
|
||||
bind<ICustomCodeHelper>(ServiceIdentifiers.ICustomCodeHelper)
|
||||
.to(DebugProtectionFunctionCallCodeHelper)
|
||||
|
||||
@@ -13,7 +13,7 @@ import { ObfuscationEvent } from '../../enums/event-emitters/ObfuscationEvent';
|
||||
|
||||
import { initializable } from '../../decorators/Initializable';
|
||||
|
||||
import { SingleNodeCallControllerTemplate } from '../common/templates/SingleNodeCallControllerTemplate';
|
||||
import { SingleCallControllerTemplate } from '../common/templates/SingleCallControllerTemplate';
|
||||
|
||||
import { AbstractCustomCodeHelper } from '../AbstractCustomCodeHelper';
|
||||
import { NodeUtils } from '../../node/NodeUtils';
|
||||
@@ -79,14 +79,14 @@ export class CallsControllerFunctionCodeHelper extends AbstractCustomCodeHelper
|
||||
protected getCodeHelperTemplate (): string {
|
||||
if (this.appendEvent === ObfuscationEvent.AfterObfuscation) {
|
||||
return this.customCodeHelperObfuscator.obfuscateTemplate(
|
||||
this.customCodeHelperFormatter.formatTemplate(SingleNodeCallControllerTemplate(), {
|
||||
singleNodeCallControllerFunctionName: this.callsControllerFunctionName
|
||||
this.customCodeHelperFormatter.formatTemplate(SingleCallControllerTemplate(), {
|
||||
callControllerFunctionName: this.callsControllerFunctionName
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
return this.customCodeHelperFormatter.formatTemplate(SingleNodeCallControllerTemplate(), {
|
||||
singleNodeCallControllerFunctionName: this.callsControllerFunctionName
|
||||
return this.customCodeHelperFormatter.formatTemplate(SingleCallControllerTemplate(), {
|
||||
callControllerFunctionName: this.callsControllerFunctionName
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
export function SingleNodeCallControllerTemplate (): string {
|
||||
export function SingleCallControllerTemplate (): string {
|
||||
return `
|
||||
const {singleNodeCallControllerFunctionName} = (function(){
|
||||
const {callControllerFunctionName} = (function(){
|
||||
let firstCall = true;
|
||||
|
||||
return function (context, fn){
|
||||
+13
-5
@@ -20,13 +20,19 @@ import { AbstractCustomCodeHelper } from '../AbstractCustomCodeHelper';
|
||||
import { NodeUtils } from '../../node/NodeUtils';
|
||||
|
||||
@injectable()
|
||||
export class ConsoleOutputDisableExpressionCodeHelper extends AbstractCustomCodeHelper {
|
||||
export class ConsoleOutputDisableCodeHelper extends AbstractCustomCodeHelper {
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
@initializable()
|
||||
private callsControllerFunctionName!: string;
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
@initializable()
|
||||
private consoleOutputDisableFunctionName!: string;
|
||||
|
||||
/**
|
||||
* @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
|
||||
* @param {ICustomCodeHelperFormatter} customCodeHelperFormatter
|
||||
@@ -53,9 +59,11 @@ export class ConsoleOutputDisableExpressionCodeHelper extends AbstractCustomCode
|
||||
|
||||
/**
|
||||
* @param {string} callsControllerFunctionName
|
||||
* @param {StaticRange} consoleOutputDisableFunctionName
|
||||
*/
|
||||
public initialize (callsControllerFunctionName: string): void {
|
||||
public initialize (callsControllerFunctionName: string, consoleOutputDisableFunctionName: string): void {
|
||||
this.callsControllerFunctionName = callsControllerFunctionName;
|
||||
this.consoleOutputDisableFunctionName = consoleOutputDisableFunctionName;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,9 +83,9 @@ export class ConsoleOutputDisableExpressionCodeHelper extends AbstractCustomCode
|
||||
: GlobalVariableNoEvalTemplate();
|
||||
|
||||
return this.customCodeHelperFormatter.formatTemplate(ConsoleOutputDisableExpressionTemplate(), {
|
||||
consoleLogDisableFunctionName: this.identifierNamesGenerator.generate(),
|
||||
globalVariableTemplate,
|
||||
singleNodeCallControllerFunctionName: this.callsControllerFunctionName
|
||||
callControllerFunctionName: this.callsControllerFunctionName,
|
||||
consoleLogDisableFunctionName: this.consoleOutputDisableFunctionName,
|
||||
globalVariableTemplate
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
|
||||
import { TCustomCodeHelperFactory } from '../../../types/container/custom-code-helpers/TCustomCodeHelperFactory';
|
||||
import { TIdentifierNamesGeneratorFactory } from '../../../types/container/generators/TIdentifierNamesGeneratorFactory';
|
||||
import { TInitialData } from '../../../types/TInitialData';
|
||||
import { TNodeWithLexicalScope } from '../../../types/node/TNodeWithLexicalScope';
|
||||
import { TNodeWithStatements } from '../../../types/node/TNodeWithStatements';
|
||||
|
||||
import { ICustomCodeHelper } from '../../../interfaces/custom-code-helpers/ICustomCodeHelper';
|
||||
@@ -17,9 +18,11 @@ import { CustomCodeHelper } from '../../../enums/custom-code-helpers/CustomCodeH
|
||||
import { ObfuscationEvent } from '../../../enums/event-emitters/ObfuscationEvent';
|
||||
|
||||
import { AbstractCustomCodeHelperGroup } from '../../AbstractCustomCodeHelperGroup';
|
||||
import { ConsoleOutputDisableExpressionCodeHelper } from '../ConsoleOutputDisableExpressionCodeHelper';
|
||||
import { NodeAppender } from '../../../node/NodeAppender';
|
||||
import { CallsControllerFunctionCodeHelper } from '../../calls-controller/CallsControllerFunctionCodeHelper';
|
||||
import { ConsoleOutputDisableCodeHelper } from '../ConsoleOutputDisableCodeHelper';
|
||||
import { NodeAppender } from '../../../node/NodeAppender';
|
||||
import { NodeLexicalScopeUtils } from '../../../node/NodeLexicalScopeUtils';
|
||||
import { NodeGuards } from '../../../node/NodeGuards';
|
||||
|
||||
@injectable()
|
||||
export class ConsoleOutputCodeHelperGroup extends AbstractCustomCodeHelperGroup {
|
||||
@@ -62,26 +65,50 @@ export class ConsoleOutputCodeHelperGroup extends AbstractCustomCodeHelperGroup
|
||||
* @param {ICallsGraphData[]} callsGraphData
|
||||
*/
|
||||
public appendNodes (nodeWithStatements: TNodeWithStatements, callsGraphData: ICallsGraphData[]): void {
|
||||
if (!this.options.disableConsoleOutput) {
|
||||
return;
|
||||
}
|
||||
|
||||
const randomCallsGraphIndex: number = this.getRandomCallsGraphIndex(callsGraphData.length);
|
||||
|
||||
const consoleOutputDisableHostNode: TNodeWithStatements = callsGraphData.length
|
||||
? NodeAppender.getOptimalBlockScope(callsGraphData, randomCallsGraphIndex)
|
||||
: nodeWithStatements;
|
||||
const callsControllerHostNode: TNodeWithStatements = callsGraphData.length
|
||||
? NodeAppender.getOptimalBlockScope(callsGraphData, randomCallsGraphIndex, 1)
|
||||
: nodeWithStatements;
|
||||
|
||||
const consoleOutputDisableLexicalScopeNode: TNodeWithLexicalScope | null = NodeLexicalScopeUtils
|
||||
.getLexicalScope(consoleOutputDisableHostNode) ?? null;
|
||||
|
||||
const consoleOutputDisableFunctionName: string = consoleOutputDisableLexicalScopeNode
|
||||
&& NodeGuards.isProgramNode(consoleOutputDisableLexicalScopeNode)
|
||||
? this.identifierNamesGenerator.generate(consoleOutputDisableLexicalScopeNode)
|
||||
: this.randomGenerator.getRandomString(5);
|
||||
const callsControllerFunctionName: string = consoleOutputDisableLexicalScopeNode
|
||||
&& NodeGuards.isProgramNode(consoleOutputDisableLexicalScopeNode)
|
||||
? this.identifierNamesGenerator.generate(consoleOutputDisableLexicalScopeNode)
|
||||
: this.randomGenerator.getRandomString(5);
|
||||
|
||||
// consoleOutputDisableExpression helper nodes append
|
||||
this.appendCustomNodeIfExist(CustomCodeHelper.ConsoleOutputDisableExpression, (customCodeHelper: ICustomCodeHelper) => {
|
||||
NodeAppender.appendToOptimalBlockScope(
|
||||
callsGraphData,
|
||||
nodeWithStatements,
|
||||
customCodeHelper.getNode(),
|
||||
randomCallsGraphIndex
|
||||
);
|
||||
});
|
||||
this.appendCustomNodeIfExist(
|
||||
CustomCodeHelper.ConsoleOutputDisable,
|
||||
(customCodeHelper: ICustomCodeHelper<TInitialData<ConsoleOutputDisableCodeHelper>>) => {
|
||||
customCodeHelper.initialize(callsControllerFunctionName, consoleOutputDisableFunctionName);
|
||||
|
||||
NodeAppender.prepend(consoleOutputDisableHostNode, customCodeHelper.getNode());
|
||||
}
|
||||
);
|
||||
|
||||
// nodeCallsControllerFunction helper nodes append
|
||||
this.appendCustomNodeIfExist(CustomCodeHelper.CallsControllerFunction, (customCodeHelper: ICustomCodeHelper) => {
|
||||
const targetNodeWithStatements: TNodeWithStatements = callsGraphData.length
|
||||
? NodeAppender.getOptimalBlockScope(callsGraphData, randomCallsGraphIndex, 1)
|
||||
: nodeWithStatements;
|
||||
this.appendCustomNodeIfExist(
|
||||
CustomCodeHelper.CallsControllerFunction,
|
||||
(customCodeHelper: ICustomCodeHelper<TInitialData<CallsControllerFunctionCodeHelper>>) => {
|
||||
customCodeHelper.initialize(this.appendEvent, callsControllerFunctionName);
|
||||
|
||||
NodeAppender.prepend(targetNodeWithStatements, customCodeHelper.getNode());
|
||||
});
|
||||
NodeAppender.prepend(callsControllerHostNode, customCodeHelper.getNode());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public initialize (): void {
|
||||
@@ -91,17 +118,12 @@ export class ConsoleOutputCodeHelperGroup extends AbstractCustomCodeHelperGroup
|
||||
return;
|
||||
}
|
||||
|
||||
const callsControllerFunctionName: string = this.identifierNamesGenerator.generate();
|
||||
|
||||
const consoleOutputDisableExpressionCodeHelper: ICustomCodeHelper<TInitialData<ConsoleOutputDisableExpressionCodeHelper>> =
|
||||
this.customCodeHelperFactory(CustomCodeHelper.ConsoleOutputDisableExpression);
|
||||
const nodeCallsControllerFunctionCodeHelper: ICustomCodeHelper<TInitialData<CallsControllerFunctionCodeHelper>> =
|
||||
const consoleOutputDisableExpressionCodeHelper: ICustomCodeHelper<TInitialData<ConsoleOutputDisableCodeHelper>> =
|
||||
this.customCodeHelperFactory(CustomCodeHelper.ConsoleOutputDisable);
|
||||
const callsControllerFunctionCodeHelper: ICustomCodeHelper<TInitialData<CallsControllerFunctionCodeHelper>> =
|
||||
this.customCodeHelperFactory(CustomCodeHelper.CallsControllerFunction);
|
||||
|
||||
consoleOutputDisableExpressionCodeHelper.initialize(callsControllerFunctionName);
|
||||
nodeCallsControllerFunctionCodeHelper.initialize(this.appendEvent, callsControllerFunctionName);
|
||||
|
||||
this.customCodeHelpers.set(CustomCodeHelper.ConsoleOutputDisableExpression, consoleOutputDisableExpressionCodeHelper);
|
||||
this.customCodeHelpers.set(CustomCodeHelper.CallsControllerFunction, nodeCallsControllerFunctionCodeHelper);
|
||||
this.customCodeHelpers.set(CustomCodeHelper.ConsoleOutputDisable, consoleOutputDisableExpressionCodeHelper);
|
||||
this.customCodeHelpers.set(CustomCodeHelper.CallsControllerFunction, callsControllerFunctionCodeHelper);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
export function ConsoleOutputDisableExpressionTemplate (): string {
|
||||
return `
|
||||
const {consoleLogDisableFunctionName} = {singleNodeCallControllerFunctionName}(this, function () {
|
||||
const {consoleLogDisableFunctionName} = {callControllerFunctionName}(this, function () {
|
||||
const func = function () {};
|
||||
|
||||
{globalVariableTemplate}
|
||||
|
||||
@@ -77,7 +77,7 @@ export class DebugProtectionFunctionCallCodeHelper extends AbstractCustomCodeHel
|
||||
protected getCodeHelperTemplate (): string {
|
||||
return this.customCodeHelperFormatter.formatTemplate(DebugProtectionFunctionCallTemplate(), {
|
||||
debugProtectionFunctionName: this.debugProtectionFunctionName,
|
||||
singleNodeCallControllerFunctionName: this.callsControllerFunctionName
|
||||
callControllerFunctionName: this.callsControllerFunctionName
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
|
||||
import { TCustomCodeHelperFactory } from '../../../types/container/custom-code-helpers/TCustomCodeHelperFactory';
|
||||
import { TIdentifierNamesGeneratorFactory } from '../../../types/container/generators/TIdentifierNamesGeneratorFactory';
|
||||
import { TInitialData } from '../../../types/TInitialData';
|
||||
import { TNodeWithLexicalScope } from '../../../types/node/TNodeWithLexicalScope';
|
||||
import { TNodeWithStatements } from '../../../types/node/TNodeWithStatements';
|
||||
|
||||
import { ICustomCodeHelper } from '../../../interfaces/custom-code-helpers/ICustomCodeHelper';
|
||||
@@ -17,12 +18,13 @@ import { CustomCodeHelper } from '../../../enums/custom-code-helpers/CustomCodeH
|
||||
import { ObfuscationEvent } from '../../../enums/event-emitters/ObfuscationEvent';
|
||||
|
||||
import { AbstractCustomCodeHelperGroup } from '../../AbstractCustomCodeHelperGroup';
|
||||
import { CallsControllerFunctionCodeHelper } from '../../calls-controller/CallsControllerFunctionCodeHelper';
|
||||
import { DebugProtectionFunctionCodeHelper } from '../DebugProtectionFunctionCodeHelper';
|
||||
import { DebugProtectionFunctionCallCodeHelper } from '../DebugProtectionFunctionCallCodeHelper';
|
||||
import { DebugProtectionFunctionIntervalCodeHelper } from '../DebugProtectionFunctionIntervalCodeHelper';
|
||||
import { NodeAppender } from '../../../node/NodeAppender';
|
||||
import { CallsControllerFunctionCodeHelper } from '../../calls-controller/CallsControllerFunctionCodeHelper';
|
||||
import { NodeGuards } from '../../../node/NodeGuards';
|
||||
import { NodeLexicalScopeUtils } from '../../../node/NodeLexicalScopeUtils';
|
||||
|
||||
@injectable()
|
||||
export class DebugProtectionCodeHelperGroup extends AbstractCustomCodeHelperGroup {
|
||||
@@ -65,41 +67,75 @@ export class DebugProtectionCodeHelperGroup extends AbstractCustomCodeHelperGrou
|
||||
* @param {ICallsGraphData[]} callsGraphData
|
||||
*/
|
||||
public appendNodes (nodeWithStatements: TNodeWithStatements, callsGraphData: ICallsGraphData[]): void {
|
||||
if (!this.options.debugProtection) {
|
||||
return;
|
||||
}
|
||||
|
||||
const randomCallsGraphIndex: number = this.getRandomCallsGraphIndex(callsGraphData.length);
|
||||
|
||||
const debugProtectionFunctionCallHostNode: TNodeWithStatements = callsGraphData.length
|
||||
? NodeAppender.getOptimalBlockScope(callsGraphData, randomCallsGraphIndex)
|
||||
: nodeWithStatements;
|
||||
const callsControllerHostNode: TNodeWithStatements = callsGraphData.length
|
||||
? NodeAppender.getOptimalBlockScope(callsGraphData, randomCallsGraphIndex, 1)
|
||||
: nodeWithStatements;
|
||||
|
||||
const debugProtectionFunctionCallScopeNode: TNodeWithLexicalScope | null = NodeLexicalScopeUtils
|
||||
.getLexicalScope(debugProtectionFunctionCallHostNode) ?? null;
|
||||
|
||||
const debugProtectionFunctionName: string = debugProtectionFunctionCallScopeNode
|
||||
&& NodeGuards.isProgramNode(debugProtectionFunctionCallScopeNode)
|
||||
? this.identifierNamesGenerator.generate(debugProtectionFunctionCallScopeNode)
|
||||
: this.randomGenerator.getRandomString(5);
|
||||
const callsControllerFunctionName: string = debugProtectionFunctionCallScopeNode
|
||||
&& NodeGuards.isProgramNode(debugProtectionFunctionCallScopeNode)
|
||||
? this.identifierNamesGenerator.generate(debugProtectionFunctionCallScopeNode)
|
||||
: this.randomGenerator.getRandomString(5);
|
||||
|
||||
// debugProtectionFunctionCall helper nodes append
|
||||
this.appendCustomNodeIfExist(CustomCodeHelper.DebugProtectionFunctionCall, (customCodeHelper: ICustomCodeHelper) => {
|
||||
NodeAppender.appendToOptimalBlockScope(
|
||||
callsGraphData,
|
||||
nodeWithStatements,
|
||||
customCodeHelper.getNode(),
|
||||
randomCallsGraphIndex
|
||||
);
|
||||
});
|
||||
this.appendCustomNodeIfExist(
|
||||
CustomCodeHelper.DebugProtectionFunctionCall,
|
||||
(customCodeHelper: ICustomCodeHelper<TInitialData<DebugProtectionFunctionCallCodeHelper>>) => {
|
||||
customCodeHelper.initialize(debugProtectionFunctionName, callsControllerFunctionName);
|
||||
|
||||
NodeAppender.prepend(debugProtectionFunctionCallHostNode, customCodeHelper.getNode());
|
||||
}
|
||||
);
|
||||
|
||||
// nodeCallsControllerFunction helper nodes append
|
||||
this.appendCustomNodeIfExist(
|
||||
CustomCodeHelper.CallsControllerFunction,
|
||||
(customCodeHelper: ICustomCodeHelper<TInitialData<CallsControllerFunctionCodeHelper>>) => {
|
||||
customCodeHelper.initialize(this.appendEvent, callsControllerFunctionName);
|
||||
|
||||
NodeAppender.prepend(callsControllerHostNode, customCodeHelper.getNode());
|
||||
}
|
||||
);
|
||||
|
||||
// debugProtectionFunction helper nodes append
|
||||
this.appendCustomNodeIfExist(CustomCodeHelper.DebugProtectionFunction, (customCodeHelper: ICustomCodeHelper) => {
|
||||
NodeAppender.append(nodeWithStatements, customCodeHelper.getNode());
|
||||
});
|
||||
this.appendCustomNodeIfExist(
|
||||
CustomCodeHelper.DebugProtectionFunction,
|
||||
(customCodeHelper: ICustomCodeHelper<TInitialData<DebugProtectionFunctionCodeHelper>>) => {
|
||||
customCodeHelper.initialize(debugProtectionFunctionName);
|
||||
|
||||
NodeAppender.append(nodeWithStatements, customCodeHelper.getNode());
|
||||
}
|
||||
);
|
||||
|
||||
// debugProtectionFunctionInterval helper nodes append
|
||||
this.appendCustomNodeIfExist(CustomCodeHelper.DebugProtectionFunctionInterval, (customCodeHelper: ICustomCodeHelper) => {
|
||||
const programBodyLength: number = NodeGuards.isSwitchCaseNode(nodeWithStatements)
|
||||
? nodeWithStatements.consequent.length
|
||||
: nodeWithStatements.body.length;
|
||||
const randomIndex: number = this.randomGenerator.getRandomInteger(0, programBodyLength);
|
||||
this.appendCustomNodeIfExist(
|
||||
CustomCodeHelper.DebugProtectionFunctionInterval,
|
||||
(customCodeHelper: ICustomCodeHelper<TInitialData<DebugProtectionFunctionIntervalCodeHelper>>) => {
|
||||
const programBodyLength: number = NodeGuards.isSwitchCaseNode(nodeWithStatements)
|
||||
? nodeWithStatements.consequent.length
|
||||
: nodeWithStatements.body.length;
|
||||
const randomIndex: number = this.randomGenerator.getRandomInteger(0, programBodyLength);
|
||||
|
||||
NodeAppender.insertAtIndex(nodeWithStatements, customCodeHelper.getNode(), randomIndex);
|
||||
});
|
||||
customCodeHelper.initialize(debugProtectionFunctionName);
|
||||
|
||||
// nodeCallsControllerFunctionNode append
|
||||
this.appendCustomNodeIfExist(CustomCodeHelper.CallsControllerFunction, (customCodeHelper: ICustomCodeHelper) => {
|
||||
const targetNodeWithStatements: TNodeWithStatements = callsGraphData.length
|
||||
? NodeAppender.getOptimalBlockScope(callsGraphData, randomCallsGraphIndex, 1)
|
||||
: nodeWithStatements;
|
||||
|
||||
NodeAppender.prepend(targetNodeWithStatements, customCodeHelper.getNode());
|
||||
});
|
||||
NodeAppender.insertAtIndex(nodeWithStatements, customCodeHelper.getNode(), randomIndex);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public initialize (): void {
|
||||
@@ -109,23 +145,15 @@ export class DebugProtectionCodeHelperGroup extends AbstractCustomCodeHelperGrou
|
||||
return;
|
||||
}
|
||||
|
||||
const debugProtectionFunctionName: string = this.identifierNamesGenerator.generate();
|
||||
const callsControllerFunctionName: string = this.identifierNamesGenerator.generate();
|
||||
|
||||
const debugProtectionFunctionCodeHelper: ICustomCodeHelper<TInitialData<DebugProtectionFunctionCodeHelper>> =
|
||||
this.customCodeHelperFactory(CustomCodeHelper.DebugProtectionFunction);
|
||||
const debugProtectionFunctionCallCodeHelper: ICustomCodeHelper<TInitialData<DebugProtectionFunctionCallCodeHelper>> =
|
||||
this.customCodeHelperFactory(CustomCodeHelper.DebugProtectionFunctionCall);
|
||||
const debugProtectionFunctionIntervalCodeHelper: ICustomCodeHelper<TInitialData<DebugProtectionFunctionIntervalCodeHelper>> =
|
||||
this.customCodeHelperFactory(CustomCodeHelper.DebugProtectionFunctionInterval);
|
||||
const nodeCallsControllerFunctionCodeHelper: ICustomCodeHelper<TInitialData<CallsControllerFunctionCodeHelper>> =
|
||||
const callsControllerFunctionCodeHelper: ICustomCodeHelper<TInitialData<CallsControllerFunctionCodeHelper>> =
|
||||
this.customCodeHelperFactory(CustomCodeHelper.CallsControllerFunction);
|
||||
|
||||
debugProtectionFunctionCodeHelper.initialize(debugProtectionFunctionName);
|
||||
debugProtectionFunctionCallCodeHelper.initialize(debugProtectionFunctionName, callsControllerFunctionName);
|
||||
debugProtectionFunctionIntervalCodeHelper.initialize(debugProtectionFunctionName);
|
||||
nodeCallsControllerFunctionCodeHelper.initialize(this.appendEvent, callsControllerFunctionName);
|
||||
|
||||
this.customCodeHelpers.set(CustomCodeHelper.DebugProtectionFunction, debugProtectionFunctionCodeHelper);
|
||||
this.customCodeHelpers.set(CustomCodeHelper.DebugProtectionFunctionCall, debugProtectionFunctionCallCodeHelper);
|
||||
|
||||
@@ -133,6 +161,6 @@ export class DebugProtectionCodeHelperGroup extends AbstractCustomCodeHelperGrou
|
||||
this.customCodeHelpers.set(CustomCodeHelper.DebugProtectionFunctionInterval, debugProtectionFunctionIntervalCodeHelper);
|
||||
}
|
||||
|
||||
this.customCodeHelpers.set(CustomCodeHelper.CallsControllerFunction, nodeCallsControllerFunctionCodeHelper);
|
||||
this.customCodeHelpers.set(CustomCodeHelper.CallsControllerFunction, callsControllerFunctionCodeHelper);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
export function DebugProtectionFunctionCallTemplate (): string {
|
||||
return `
|
||||
(function () {
|
||||
{singleNodeCallControllerFunctionName}(
|
||||
{callControllerFunctionName}(
|
||||
this,
|
||||
function () {
|
||||
const regExp1 = new RegExp('function *\\\\( *\\\\)');
|
||||
|
||||
@@ -26,13 +26,19 @@ export class DomainLockCodeHelper extends AbstractCustomCodeHelper {
|
||||
* @type {string}
|
||||
*/
|
||||
@initializable()
|
||||
protected callsControllerFunctionName!: string;
|
||||
private callsControllerFunctionName!: string;
|
||||
|
||||
/**
|
||||
* @type {ICryptUtils}
|
||||
*/
|
||||
private readonly cryptUtils: ICryptUtils;
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
@initializable()
|
||||
private domainLockFunctionName!: string;
|
||||
|
||||
/**
|
||||
* @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
|
||||
* @param {ICustomCodeHelperFormatter} customCodeHelperFormatter
|
||||
@@ -63,9 +69,11 @@ export class DomainLockCodeHelper extends AbstractCustomCodeHelper {
|
||||
|
||||
/**
|
||||
* @param {string} callsControllerFunctionName
|
||||
* @param {string} domainLockFunctionName
|
||||
*/
|
||||
public initialize (callsControllerFunctionName: string): void {
|
||||
public initialize (callsControllerFunctionName: string, domainLockFunctionName: string): void {
|
||||
this.callsControllerFunctionName = callsControllerFunctionName;
|
||||
this.domainLockFunctionName = domainLockFunctionName;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,11 +98,11 @@ export class DomainLockCodeHelper extends AbstractCustomCodeHelper {
|
||||
: GlobalVariableNoEvalTemplate();
|
||||
|
||||
return this.customCodeHelperFormatter.formatTemplate(DomainLockTemplate(), {
|
||||
domainLockFunctionName: this.identifierNamesGenerator.generate(),
|
||||
callControllerFunctionName: this.callsControllerFunctionName,
|
||||
domainLockFunctionName: this.domainLockFunctionName,
|
||||
diff,
|
||||
domains: hiddenDomainsString,
|
||||
globalVariableTemplate,
|
||||
singleNodeCallControllerFunctionName: this.callsControllerFunctionName
|
||||
globalVariableTemplate
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
|
||||
import { TCustomCodeHelperFactory } from '../../../types/container/custom-code-helpers/TCustomCodeHelperFactory';
|
||||
import { TIdentifierNamesGeneratorFactory } from '../../../types/container/generators/TIdentifierNamesGeneratorFactory';
|
||||
import { TInitialData } from '../../../types/TInitialData';
|
||||
import { TNodeWithLexicalScope } from '../../../types/node/TNodeWithLexicalScope';
|
||||
import { TNodeWithStatements } from '../../../types/node/TNodeWithStatements';
|
||||
|
||||
import { ICustomCodeHelper } from '../../../interfaces/custom-code-helpers/ICustomCodeHelper';
|
||||
@@ -17,9 +18,11 @@ import { CustomCodeHelper } from '../../../enums/custom-code-helpers/CustomCodeH
|
||||
import { ObfuscationEvent } from '../../../enums/event-emitters/ObfuscationEvent';
|
||||
|
||||
import { AbstractCustomCodeHelperGroup } from '../../AbstractCustomCodeHelperGroup';
|
||||
import { CallsControllerFunctionCodeHelper } from '../../calls-controller/CallsControllerFunctionCodeHelper';
|
||||
import { DomainLockCodeHelper } from '../DomainLockCodeHelper';
|
||||
import { NodeAppender } from '../../../node/NodeAppender';
|
||||
import { CallsControllerFunctionCodeHelper } from '../../calls-controller/CallsControllerFunctionCodeHelper';
|
||||
import { NodeLexicalScopeUtils } from '../../../node/NodeLexicalScopeUtils';
|
||||
import { NodeGuards } from '../../../node/NodeGuards';
|
||||
|
||||
@injectable()
|
||||
export class DomainLockCustomCodeHelperGroup extends AbstractCustomCodeHelperGroup {
|
||||
@@ -62,26 +65,50 @@ export class DomainLockCustomCodeHelperGroup extends AbstractCustomCodeHelperGro
|
||||
* @param {ICallsGraphData[]} callsGraphData
|
||||
*/
|
||||
public appendNodes (nodeWithStatements: TNodeWithStatements, callsGraphData: ICallsGraphData[]): void {
|
||||
if (!this.options.domainLock.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const randomCallsGraphIndex: number = this.getRandomCallsGraphIndex(callsGraphData.length);
|
||||
|
||||
const domainLockFunctionHostNode: TNodeWithStatements = callsGraphData.length
|
||||
? NodeAppender.getOptimalBlockScope(callsGraphData, randomCallsGraphIndex)
|
||||
: nodeWithStatements;
|
||||
const callsControllerHostNode: TNodeWithStatements = callsGraphData.length
|
||||
? NodeAppender.getOptimalBlockScope(callsGraphData, randomCallsGraphIndex, 1)
|
||||
: nodeWithStatements;
|
||||
|
||||
const domainLockFunctionLexicalScopeNode: TNodeWithLexicalScope | null = NodeLexicalScopeUtils
|
||||
.getLexicalScope(domainLockFunctionHostNode) ?? null;
|
||||
|
||||
const domainLockFunctionName: string = domainLockFunctionLexicalScopeNode
|
||||
&& NodeGuards.isProgramNode(domainLockFunctionLexicalScopeNode)
|
||||
? this.identifierNamesGenerator.generate(domainLockFunctionLexicalScopeNode)
|
||||
: this.randomGenerator.getRandomString(5);
|
||||
const callsControllerFunctionName: string = domainLockFunctionLexicalScopeNode
|
||||
&& NodeGuards.isProgramNode(domainLockFunctionLexicalScopeNode)
|
||||
? this.identifierNamesGenerator.generate(domainLockFunctionLexicalScopeNode)
|
||||
: this.randomGenerator.getRandomString(5);
|
||||
|
||||
// domainLock helper nodes append
|
||||
this.appendCustomNodeIfExist(CustomCodeHelper.DomainLock, (customCodeHelper: ICustomCodeHelper) => {
|
||||
NodeAppender.appendToOptimalBlockScope(
|
||||
callsGraphData,
|
||||
nodeWithStatements,
|
||||
customCodeHelper.getNode(),
|
||||
randomCallsGraphIndex
|
||||
);
|
||||
});
|
||||
this.appendCustomNodeIfExist(
|
||||
CustomCodeHelper.DomainLock,
|
||||
(customCodeHelper: ICustomCodeHelper<TInitialData<DomainLockCodeHelper>>) => {
|
||||
customCodeHelper.initialize(callsControllerFunctionName, domainLockFunctionName);
|
||||
|
||||
NodeAppender.prepend(domainLockFunctionHostNode, customCodeHelper.getNode());
|
||||
}
|
||||
);
|
||||
|
||||
// nodeCallsControllerFunction helper nodes append
|
||||
this.appendCustomNodeIfExist(CustomCodeHelper.CallsControllerFunction, (customCodeHelper: ICustomCodeHelper) => {
|
||||
const targetNodeWithStatements: TNodeWithStatements = callsGraphData.length
|
||||
? NodeAppender.getOptimalBlockScope(callsGraphData, randomCallsGraphIndex, 1)
|
||||
: nodeWithStatements;
|
||||
this.appendCustomNodeIfExist(
|
||||
CustomCodeHelper.CallsControllerFunction,
|
||||
(customCodeHelper: ICustomCodeHelper<TInitialData<CallsControllerFunctionCodeHelper>>) => {
|
||||
customCodeHelper.initialize(this.appendEvent, callsControllerFunctionName);
|
||||
|
||||
NodeAppender.prepend(targetNodeWithStatements, customCodeHelper.getNode());
|
||||
});
|
||||
NodeAppender.prepend(callsControllerHostNode, customCodeHelper.getNode());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public initialize (): void {
|
||||
@@ -91,17 +118,12 @@ export class DomainLockCustomCodeHelperGroup extends AbstractCustomCodeHelperGro
|
||||
return;
|
||||
}
|
||||
|
||||
const callsControllerFunctionName: string = this.identifierNamesGenerator.generate();
|
||||
|
||||
const domainLockCodeHelper: ICustomCodeHelper<TInitialData<DomainLockCodeHelper>> =
|
||||
this.customCodeHelperFactory(CustomCodeHelper.DomainLock);
|
||||
const nodeCallsControllerFunctionCodeHelper: ICustomCodeHelper<TInitialData<CallsControllerFunctionCodeHelper>> =
|
||||
const callsControllerFunctionCodeHelper: ICustomCodeHelper<TInitialData<CallsControllerFunctionCodeHelper>> =
|
||||
this.customCodeHelperFactory(CustomCodeHelper.CallsControllerFunction);
|
||||
|
||||
domainLockCodeHelper.initialize(callsControllerFunctionName);
|
||||
nodeCallsControllerFunctionCodeHelper.initialize(this.appendEvent, callsControllerFunctionName);
|
||||
|
||||
this.customCodeHelpers.set(CustomCodeHelper.DomainLock, domainLockCodeHelper);
|
||||
this.customCodeHelpers.set(CustomCodeHelper.CallsControllerFunction, nodeCallsControllerFunctionCodeHelper);
|
||||
this.customCodeHelpers.set(CustomCodeHelper.CallsControllerFunction, callsControllerFunctionCodeHelper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
export function DomainLockTemplate (): string {
|
||||
return `
|
||||
const {domainLockFunctionName} = {singleNodeCallControllerFunctionName}(this, function () {
|
||||
const {domainLockFunctionName} = {callControllerFunctionName}(this, function () {
|
||||
|
||||
{globalVariableTemplate}
|
||||
|
||||
|
||||
@@ -30,6 +30,12 @@ export class SelfDefendingUnicodeCodeHelper extends AbstractCustomCodeHelper {
|
||||
@initializable()
|
||||
private callsControllerFunctionName!: string;
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
@initializable()
|
||||
private selfDefendingFunctionName!: string;
|
||||
|
||||
/**
|
||||
* @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
|
||||
* @param {ICustomCodeHelperFormatter} customCodeHelperFormatter
|
||||
@@ -60,9 +66,11 @@ export class SelfDefendingUnicodeCodeHelper extends AbstractCustomCodeHelper {
|
||||
|
||||
/**
|
||||
* @param {string} callsControllerFunctionName
|
||||
* @param {string} selfDefendingFunctionName
|
||||
*/
|
||||
public initialize (callsControllerFunctionName: string): void {
|
||||
public initialize (callsControllerFunctionName: string, selfDefendingFunctionName: string): void {
|
||||
this.callsControllerFunctionName = callsControllerFunctionName;
|
||||
this.selfDefendingFunctionName = selfDefendingFunctionName;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,14 +85,9 @@ export class SelfDefendingUnicodeCodeHelper extends AbstractCustomCodeHelper {
|
||||
* @returns {string}
|
||||
*/
|
||||
protected getCodeHelperTemplate (): string {
|
||||
return this.customCodeHelperObfuscator.obfuscateTemplate(
|
||||
this.customCodeHelperFormatter.formatTemplate(SelfDefendingTemplate(this.escapeSequenceEncoder), {
|
||||
selfDefendingFunctionName: this.identifierNamesGenerator.generate(),
|
||||
singleNodeCallControllerFunctionName: this.callsControllerFunctionName
|
||||
}),
|
||||
{
|
||||
unicodeEscapeSequence: true
|
||||
}
|
||||
);
|
||||
return this.customCodeHelperFormatter.formatTemplate(SelfDefendingTemplate(this.escapeSequenceEncoder), {
|
||||
callControllerFunctionName: this.callsControllerFunctionName,
|
||||
selfDefendingFunctionName: this.selfDefendingFunctionName
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
|
||||
import { TCustomCodeHelperFactory } from '../../../types/container/custom-code-helpers/TCustomCodeHelperFactory';
|
||||
import { TIdentifierNamesGeneratorFactory } from '../../../types/container/generators/TIdentifierNamesGeneratorFactory';
|
||||
import { TInitialData } from '../../../types/TInitialData';
|
||||
import { TNodeWithLexicalScope } from '../../../types/node/TNodeWithLexicalScope';
|
||||
import { TNodeWithStatements } from '../../../types/node/TNodeWithStatements';
|
||||
|
||||
import { ICustomCodeHelper } from '../../../interfaces/custom-code-helpers/ICustomCodeHelper';
|
||||
@@ -17,8 +18,9 @@ import { CustomCodeHelper } from '../../../enums/custom-code-helpers/CustomCodeH
|
||||
import { ObfuscationEvent } from '../../../enums/event-emitters/ObfuscationEvent';
|
||||
|
||||
import { AbstractCustomCodeHelperGroup } from '../../AbstractCustomCodeHelperGroup';
|
||||
import { NodeAppender } from '../../../node/NodeAppender';
|
||||
import { CallsControllerFunctionCodeHelper } from '../../calls-controller/CallsControllerFunctionCodeHelper';
|
||||
import { NodeAppender } from '../../../node/NodeAppender';
|
||||
import { NodeLexicalScopeUtils } from '../../../node/NodeLexicalScopeUtils';
|
||||
import { SelfDefendingUnicodeCodeHelper } from '../SelfDefendingUnicodeCodeHelper';
|
||||
|
||||
@injectable()
|
||||
@@ -26,7 +28,7 @@ export class SelfDefendingCodeHelperGroup extends AbstractCustomCodeHelperGroup
|
||||
/**
|
||||
* @type {ObfuscationEvent}
|
||||
*/
|
||||
protected appendEvent: ObfuscationEvent = ObfuscationEvent.AfterObfuscation;
|
||||
protected appendEvent: ObfuscationEvent = ObfuscationEvent.BeforeObfuscation;
|
||||
|
||||
/**
|
||||
* @type {Map<CustomCodeHelper, ICustomCodeHelper>}
|
||||
@@ -62,26 +64,48 @@ export class SelfDefendingCodeHelperGroup extends AbstractCustomCodeHelperGroup
|
||||
* @param {ICallsGraphData[]} callsGraphData
|
||||
*/
|
||||
public appendNodes (nodeWithStatements: TNodeWithStatements, callsGraphData: ICallsGraphData[]): void {
|
||||
if (!this.options.selfDefending) {
|
||||
return;
|
||||
}
|
||||
|
||||
const randomCallsGraphIndex: number = this.getRandomCallsGraphIndex(callsGraphData.length);
|
||||
|
||||
const selfDefendingFunctionHostNode: TNodeWithStatements = callsGraphData.length
|
||||
? NodeAppender.getOptimalBlockScope(callsGraphData, randomCallsGraphIndex)
|
||||
: nodeWithStatements;
|
||||
const callsControllerHostNode: TNodeWithStatements = callsGraphData.length
|
||||
? NodeAppender.getOptimalBlockScope(callsGraphData, randomCallsGraphIndex, 1)
|
||||
: nodeWithStatements;
|
||||
|
||||
const selfDefendingFunctionLexicalScopeNode: TNodeWithLexicalScope | null = NodeLexicalScopeUtils
|
||||
.getLexicalScope(selfDefendingFunctionHostNode) ?? null;
|
||||
|
||||
const selfDefendingFunctionName: string = selfDefendingFunctionLexicalScopeNode
|
||||
? this.identifierNamesGenerator.generate(selfDefendingFunctionLexicalScopeNode)
|
||||
: this.identifierNamesGenerator.generateForGlobalScope();
|
||||
const callsControllerFunctionName: string = selfDefendingFunctionLexicalScopeNode
|
||||
? this.identifierNamesGenerator.generate(selfDefendingFunctionLexicalScopeNode)
|
||||
: this.identifierNamesGenerator.generateForGlobalScope();
|
||||
|
||||
// selfDefendingUnicode helper nodes append
|
||||
this.appendCustomNodeIfExist(CustomCodeHelper.SelfDefendingUnicode, (customCodeHelper: ICustomCodeHelper) => {
|
||||
NodeAppender.appendToOptimalBlockScope(
|
||||
callsGraphData,
|
||||
nodeWithStatements,
|
||||
customCodeHelper.getNode(),
|
||||
randomCallsGraphIndex
|
||||
);
|
||||
});
|
||||
this.appendCustomNodeIfExist(
|
||||
CustomCodeHelper.SelfDefendingUnicode,
|
||||
(customCodeHelper: ICustomCodeHelper<TInitialData<SelfDefendingUnicodeCodeHelper>>) => {
|
||||
customCodeHelper.initialize(callsControllerFunctionName, selfDefendingFunctionName);
|
||||
|
||||
NodeAppender.prepend(selfDefendingFunctionHostNode, customCodeHelper.getNode());
|
||||
}
|
||||
);
|
||||
|
||||
// nodeCallsControllerFunction helper nodes append
|
||||
this.appendCustomNodeIfExist(CustomCodeHelper.CallsControllerFunction, (customCodeHelper: ICustomCodeHelper) => {
|
||||
const targetNodeWithStatements: TNodeWithStatements = callsGraphData.length
|
||||
? NodeAppender.getOptimalBlockScope(callsGraphData, randomCallsGraphIndex, 1)
|
||||
: nodeWithStatements;
|
||||
this.appendCustomNodeIfExist(
|
||||
CustomCodeHelper.CallsControllerFunction,
|
||||
(customCodeHelper: ICustomCodeHelper<TInitialData<CallsControllerFunctionCodeHelper>>) => {
|
||||
customCodeHelper.initialize(this.appendEvent, callsControllerFunctionName);
|
||||
|
||||
NodeAppender.prepend(targetNodeWithStatements, customCodeHelper.getNode());
|
||||
});
|
||||
NodeAppender.prepend(callsControllerHostNode, customCodeHelper.getNode());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public initialize (): void {
|
||||
@@ -91,17 +115,12 @@ export class SelfDefendingCodeHelperGroup extends AbstractCustomCodeHelperGroup
|
||||
return;
|
||||
}
|
||||
|
||||
const callsControllerFunctionName: string = this.identifierNamesGenerator.generate();
|
||||
|
||||
const selfDefendingUnicodeCodeHelper: ICustomCodeHelper<TInitialData<SelfDefendingUnicodeCodeHelper>> =
|
||||
this.customCodeHelperFactory(CustomCodeHelper.SelfDefendingUnicode);
|
||||
const nodeCallsControllerFunctionCodeHelper: ICustomCodeHelper<TInitialData<CallsControllerFunctionCodeHelper>> =
|
||||
const callsControllerFunctionCodeHelper: ICustomCodeHelper<TInitialData<CallsControllerFunctionCodeHelper>> =
|
||||
this.customCodeHelperFactory(CustomCodeHelper.CallsControllerFunction);
|
||||
|
||||
selfDefendingUnicodeCodeHelper.initialize(callsControllerFunctionName);
|
||||
nodeCallsControllerFunctionCodeHelper.initialize(this.appendEvent, callsControllerFunctionName);
|
||||
|
||||
this.customCodeHelpers.set(CustomCodeHelper.SelfDefendingUnicode, selfDefendingUnicodeCodeHelper);
|
||||
this.customCodeHelpers.set(CustomCodeHelper.CallsControllerFunction, nodeCallsControllerFunctionCodeHelper);
|
||||
this.customCodeHelpers.set(CustomCodeHelper.CallsControllerFunction, callsControllerFunctionCodeHelper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,54 +9,15 @@ import { IEscapeSequenceEncoder } from '../../../interfaces/utils/IEscapeSequenc
|
||||
*/
|
||||
export function SelfDefendingTemplate (escapeSequenceEncoder: IEscapeSequenceEncoder): string {
|
||||
return `
|
||||
const {selfDefendingFunctionName} = {singleNodeCallControllerFunctionName}(this, function () {
|
||||
const func1 = function(){return 'dev';},
|
||||
func2 = function () {
|
||||
return 'window';
|
||||
};
|
||||
const {selfDefendingFunctionName} = {callControllerFunctionName}(this, function () {
|
||||
const test = function () {
|
||||
const regExp = new RegExp('^([^ ]+( +[^ ]+)+)+[^ ]}');
|
||||
|
||||
const test1 = function () {
|
||||
const regExp = new RegExp('${
|
||||
escapeSequenceEncoder.encode('\\w+ *\\(\\) *{\\w+ *[\'|"].+[\'|"];? *}', true)
|
||||
}');
|
||||
|
||||
return !regExp.test(func1.toString());
|
||||
return !regExp.test({selfDefendingFunctionName});
|
||||
};
|
||||
|
||||
const test2 = function () {
|
||||
const regExp = new RegExp('${
|
||||
escapeSequenceEncoder.encode('(\\\\[x|u](\\w){2,4})+', true)
|
||||
}');
|
||||
|
||||
return regExp.test(func2.toString());
|
||||
};
|
||||
|
||||
const recursiveFunc1 = function (string) {
|
||||
const i = ~-1 >> 1 + 255 % 0;
|
||||
|
||||
if (string.indexOf('i' === i)) {
|
||||
recursiveFunc2(string)
|
||||
}
|
||||
};
|
||||
|
||||
const recursiveFunc2 = function (string) {
|
||||
const i = ~-4 >> 1 + 255 % 0;
|
||||
|
||||
if (string.indexOf((true+"")[3]) !== i) {
|
||||
recursiveFunc1(string)
|
||||
}
|
||||
};
|
||||
|
||||
if (!test1()) {
|
||||
if (!test2()) {
|
||||
recursiveFunc1('indеxOf');
|
||||
} else {
|
||||
recursiveFunc1('indexOf');
|
||||
}
|
||||
} else {
|
||||
recursiveFunc1('indеxOf');
|
||||
}
|
||||
})
|
||||
return test();
|
||||
});
|
||||
|
||||
{selfDefendingFunctionName}();
|
||||
`;
|
||||
|
||||
@@ -90,8 +90,8 @@ export class StringArrayRotateFunctionCodeHelper extends AbstractCustomCodeHelpe
|
||||
* @returns {string}
|
||||
*/
|
||||
protected getCodeHelperTemplate (): string {
|
||||
const timesName: string = this.identifierNamesGenerator.generate();
|
||||
const whileFunctionName: string = this.identifierNamesGenerator.generate();
|
||||
const timesName: string = this.identifierNamesGenerator.generateForGlobalScope();
|
||||
const whileFunctionName: string = this.identifierNamesGenerator.generateForGlobalScope();
|
||||
const preservedNames: string[] = [this.stringArrayName];
|
||||
|
||||
let code: string = '';
|
||||
|
||||
@@ -77,19 +77,28 @@ export class StringArrayCodeHelperGroup extends AbstractCustomCodeHelperGroup {
|
||||
}
|
||||
|
||||
// stringArray helper nodes append
|
||||
this.appendCustomNodeIfExist(CustomCodeHelper.StringArray, (customCodeHelper: ICustomCodeHelper) => {
|
||||
NodeAppender.prepend(nodeWithStatements, customCodeHelper.getNode());
|
||||
});
|
||||
this.appendCustomNodeIfExist(
|
||||
CustomCodeHelper.StringArray,
|
||||
(customCodeHelper: ICustomCodeHelper<TInitialData<StringArrayCodeHelper>>) => {
|
||||
NodeAppender.prepend(nodeWithStatements, customCodeHelper.getNode());
|
||||
}
|
||||
);
|
||||
|
||||
// stringArrayCallsWrapper helper nodes append
|
||||
this.appendCustomNodeIfExist(CustomCodeHelper.StringArrayCallsWrapper, (customCodeHelper: ICustomCodeHelper) => {
|
||||
NodeAppender.insertAtIndex(nodeWithStatements, customCodeHelper.getNode(), 1);
|
||||
});
|
||||
this.appendCustomNodeIfExist(
|
||||
CustomCodeHelper.StringArrayCallsWrapper,
|
||||
(customCodeHelper: ICustomCodeHelper<TInitialData<StringArrayCallsWrapperCodeHelper>>) => {
|
||||
NodeAppender.insertAtIndex(nodeWithStatements, customCodeHelper.getNode(), 1);
|
||||
}
|
||||
);
|
||||
|
||||
// stringArrayRotateFunction helper nodes append
|
||||
this.appendCustomNodeIfExist(CustomCodeHelper.StringArrayRotateFunction, (customCodeHelper: ICustomCodeHelper) => {
|
||||
NodeAppender.insertAtIndex(nodeWithStatements, customCodeHelper.getNode(), 1);
|
||||
});
|
||||
this.appendCustomNodeIfExist(
|
||||
CustomCodeHelper.StringArrayRotateFunction,
|
||||
(customCodeHelper: ICustomCodeHelper<TInitialData<StringArrayRotateFunctionCodeHelper>>) => {
|
||||
NodeAppender.insertAtIndex(nodeWithStatements, customCodeHelper.getNode(), 1);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public initialize (): void {
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ export class ObjectExpressionVariableDeclarationHostNode extends AbstractCustomN
|
||||
*/
|
||||
protected getNodeStructure (): TStatement[] {
|
||||
const variableDeclarationName: string = NodeGuards.isProgramNode(this.lexicalScopeNode)
|
||||
? this.identifierNamesGenerator.generate()
|
||||
? this.identifierNamesGenerator.generateForGlobalScope()
|
||||
: this.identifierNamesGenerator.generateForLexicalScope(this.lexicalScopeNode);
|
||||
|
||||
const structure: TStatement = NodeFactory.variableDeclarationNode(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export enum CustomCodeHelper {
|
||||
CallsControllerFunction = 'CallsControllerFunction',
|
||||
ConsoleOutputDisableExpression = 'ConsoleOutputDisableExpression',
|
||||
ConsoleOutputDisable = 'ConsoleOutputDisable',
|
||||
DebugProtectionFunctionCall = 'DebugProtectionFunctionCall',
|
||||
DebugProtectionFunctionInterval = 'DebugProtectionFunctionInterval',
|
||||
DebugProtectionFunction = 'DebugProtectionFunction',
|
||||
|
||||
@@ -7,6 +7,8 @@ import { IIdentifierNamesGenerator } from '../../interfaces/generators/identifie
|
||||
import { IOptions } from '../../interfaces/options/IOptions';
|
||||
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
|
||||
|
||||
import { NodeGuards } from '../../node/NodeGuards';
|
||||
|
||||
@injectable()
|
||||
export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNamesGenerator {
|
||||
/**
|
||||
@@ -41,6 +43,17 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {TNodeWithLexicalScope} lexicalScopeNode
|
||||
* @param {number} nameLength
|
||||
* @returns {string}
|
||||
*/
|
||||
public generate (lexicalScopeNode: TNodeWithLexicalScope, nameLength?: number): string {
|
||||
return NodeGuards.isProgramNode(lexicalScopeNode)
|
||||
? this.generateForGlobalScope()
|
||||
: this.generateForLexicalScope(lexicalScopeNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
*/
|
||||
@@ -112,7 +125,7 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam
|
||||
* @param {number} nameLength
|
||||
* @returns {string}
|
||||
*/
|
||||
public abstract generate (nameLength?: number): string;
|
||||
public abstract generateForGlobalScope (nameLength?: number): string;
|
||||
|
||||
/**
|
||||
* @param {TNodeWithLexicalScope} lexicalScopeNode
|
||||
|
||||
@@ -69,7 +69,7 @@ export class DictionaryIdentifierNamesGenerator extends AbstractIdentifierNamesG
|
||||
return null;
|
||||
}
|
||||
|
||||
public generate (): string {
|
||||
public generateForGlobalScope (): string {
|
||||
const identifierName: string = this.generateNewDictionaryName();
|
||||
|
||||
this.preserveName(identifierName);
|
||||
|
||||
@@ -37,7 +37,7 @@ export class HexadecimalIdentifierNamesGenerator extends AbstractIdentifierNames
|
||||
* @param {number} nameLength
|
||||
* @returns {string}
|
||||
*/
|
||||
public generate (nameLength?: number): string {
|
||||
public generateForGlobalScope (nameLength?: number): string {
|
||||
const rangeMinInteger: number = 10000;
|
||||
const rangeMaxInteger: number = 99_999_999;
|
||||
const randomInteger: number = this.randomGenerator.getRandomInteger(rangeMinInteger, rangeMaxInteger);
|
||||
@@ -50,7 +50,7 @@ export class HexadecimalIdentifierNamesGenerator extends AbstractIdentifierNames
|
||||
const identifierName: string = `_${Utils.hexadecimalPrefix}${baseIdentifierName}`;
|
||||
|
||||
if (this.randomVariableNameSet.has(identifierName)) {
|
||||
return this.generate(nameLength);
|
||||
return this.generateForGlobalScope(nameLength);
|
||||
}
|
||||
|
||||
this.randomVariableNameSet.add(identifierName);
|
||||
@@ -64,7 +64,7 @@ export class HexadecimalIdentifierNamesGenerator extends AbstractIdentifierNames
|
||||
* @returns {string}
|
||||
*/
|
||||
public generateForLexicalScope (lexicalScopeNode: TNodeWithLexicalScope, nameLength?: number): string {
|
||||
return this.generate(nameLength);
|
||||
return this.generateForGlobalScope(nameLength);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,7 +72,7 @@ export class HexadecimalIdentifierNamesGenerator extends AbstractIdentifierNames
|
||||
* @returns {string}
|
||||
*/
|
||||
public generateWithPrefix (nameLength?: number): string {
|
||||
const identifierName: string = this.generate(nameLength);
|
||||
const identifierName: string = this.generateForGlobalScope(nameLength);
|
||||
|
||||
return `${this.options.identifiersPrefix}${identifierName}`.replace('__', '_');
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
|
||||
* @param {number} nameLength
|
||||
* @returns {string}
|
||||
*/
|
||||
public generate (nameLength?: number): string {
|
||||
public generateForGlobalScope (nameLength?: number): string {
|
||||
const identifierName: string = this.generateNewMangledName(this.previousMangledName);
|
||||
|
||||
this.previousMangledName = identifierName;
|
||||
|
||||
@@ -2,10 +2,17 @@ import { TNodeWithLexicalScope } from '../../../types/node/TNodeWithLexicalScope
|
||||
|
||||
export interface IIdentifierNamesGenerator {
|
||||
/**
|
||||
* @param {TNodeWithLexicalScope} lexicalScopeNode
|
||||
* @param {number} nameLength
|
||||
* @returns {string}
|
||||
*/
|
||||
generate (nameLength?: number): string;
|
||||
generate (lexicalScopeNode: TNodeWithLexicalScope, nameLength?: number): string;
|
||||
|
||||
/**
|
||||
* @param {number} nameLength
|
||||
* @returns {string}
|
||||
*/
|
||||
generateForGlobalScope (nameLength?: number): string;
|
||||
|
||||
/**
|
||||
* @param {TNodeWithLexicalScope} lexicalScopeNode
|
||||
|
||||
+10
-5
@@ -351,17 +351,22 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer {
|
||||
*/
|
||||
private makeClonedBlockStatementNodeUnique (clonedBlockStatementNode: ESTree.BlockStatement): ESTree.BlockStatement {
|
||||
// should wrap cloned block statement node into function node for correct scope encapsulation
|
||||
const hostNode: ESTree.FunctionExpression = NodeFactory
|
||||
.functionExpressionNode([], clonedBlockStatementNode);
|
||||
const hostNode: ESTree.Program = NodeFactory.programNode([
|
||||
NodeFactory.expressionStatementNode(
|
||||
NodeFactory.functionExpressionNode([], clonedBlockStatementNode)
|
||||
)
|
||||
]);
|
||||
|
||||
NodeUtils.parentizeAst(hostNode);
|
||||
NodeUtils.parentizeNode(hostNode, hostNode);
|
||||
NodeUtils.parentizeNode(clonedBlockStatementNode, hostNode);
|
||||
|
||||
return this.transformersRunner.transform(
|
||||
this.transformersRunner.transform(
|
||||
hostNode,
|
||||
DeadCodeInjectionTransformer.transformersToRenameBlockScopeIdentifiers,
|
||||
TransformationStage.Obfuscating
|
||||
).body;
|
||||
);
|
||||
|
||||
return clonedBlockStatementNode;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+3
-11
@@ -9,8 +9,6 @@ import { IStringArrayStorage } from '../../../../interfaces/storages/string-arra
|
||||
import { IStringArrayStorageAnalyzer } from '../../../../interfaces/analyzers/string-array-storage-analyzer/IStringArrayStorageAnalyzer';
|
||||
import { IStringArrayStorageItemData } from '../../../../interfaces/storages/string-array-storage/IStringArrayStorageItem';
|
||||
|
||||
import { initializable } from '../../../../decorators/Initializable';
|
||||
|
||||
import { StringArrayEncoding } from '../../../../enums/StringArrayEncoding';
|
||||
|
||||
import { AbstractObfuscatingReplacer } from '../AbstractObfuscatingReplacer';
|
||||
@@ -36,12 +34,6 @@ export class StringLiteralObfuscatingReplacer extends AbstractObfuscatingReplace
|
||||
*/
|
||||
private readonly stringArrayStorageAnalyzer: IStringArrayStorageAnalyzer;
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
@initializable()
|
||||
private stringArrayStorageCallsWrapperName!: string;
|
||||
|
||||
/**
|
||||
* @param {IStringArrayStorage} stringArrayStorage
|
||||
* @param {IStringArrayStorageAnalyzer} stringArrayStorageAnalyzer
|
||||
@@ -84,8 +76,6 @@ export class StringLiteralObfuscatingReplacer extends AbstractObfuscatingReplace
|
||||
|
||||
@postConstruct()
|
||||
public initialize (): void {
|
||||
this.stringArrayStorageCallsWrapperName = this.stringArrayStorage.getStorageCallsWrapperName();
|
||||
|
||||
if (this.options.shuffleStringArray) {
|
||||
this.stringArrayStorage.shuffleStorage();
|
||||
}
|
||||
@@ -148,7 +138,9 @@ export class StringLiteralObfuscatingReplacer extends AbstractObfuscatingReplace
|
||||
callExpressionArgs.push(StringLiteralObfuscatingReplacer.getRc4KeyLiteralNode(decodeKey));
|
||||
}
|
||||
|
||||
const stringArrayIdentifierNode: ESTree.Identifier = NodeFactory.identifierNode(this.stringArrayStorageCallsWrapperName);
|
||||
const stringArrayIdentifierNode: ESTree.Identifier = NodeFactory.identifierNode(
|
||||
this.stringArrayStorage.getStorageCallsWrapperName()
|
||||
);
|
||||
|
||||
return NodeFactory.callExpressionNode(
|
||||
stringArrayIdentifierNode,
|
||||
|
||||
@@ -62,6 +62,8 @@ export class VariablePreserveTransformer extends AbstractNodeTransformer {
|
||||
public getVisitor (transformationStage: TransformationStage): IVisitor | null {
|
||||
switch (transformationStage) {
|
||||
case TransformationStage.Preparing:
|
||||
case TransformationStage.Converting:
|
||||
case TransformationStage.Obfuscating:
|
||||
return {
|
||||
enter: (node: ESTree.Node, parentNode: ESTree.Node | null): ESTree.Node | undefined => {
|
||||
if (parentNode && NodeGuards.isProgramNode(node)) {
|
||||
|
||||
@@ -149,6 +149,13 @@ export class StringArrayStorage extends MapStorage <string, IStringArrayStorageI
|
||||
return this.rotationAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
public getStorageName (): string {
|
||||
return this.getStorageId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
@@ -161,13 +168,6 @@ export class StringArrayStorage extends MapStorage <string, IStringArrayStorageI
|
||||
return this.stringArrayStorageName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
public getStorageName (): string {
|
||||
return this.getStorageId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user