|
@@ -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);
|
|
|
-
|
|
|
- NodeAppender.insertAtIndex(nodeWithStatements, customCodeHelper.getNode(), randomIndex);
|
|
|
- });
|
|
|
-
|
|
|
- // nodeCallsControllerFunctionNode append
|
|
|
- this.appendCustomNodeIfExist(CustomCodeHelper.CallsControllerFunction, (customCodeHelper: ICustomCodeHelper) => {
|
|
|
- const targetNodeWithStatements: TNodeWithStatements = callsGraphData.length
|
|
|
- ? NodeAppender.getOptimalBlockScope(callsGraphData, randomCallsGraphIndex, 1)
|
|
|
- : nodeWithStatements;
|
|
|
-
|
|
|
- NodeAppender.prepend(targetNodeWithStatements, customCodeHelper.getNode());
|
|
|
- });
|
|
|
+ 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);
|
|
|
+
|
|
|
+ customCodeHelper.initialize(debugProtectionFunctionName);
|
|
|
+
|
|
|
+ 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);
|
|
|
}
|
|
|
}
|