StackTraceAnalyzer rename to CallsGraphAnalyzer

This commit is contained in:
sanex3339
2020-01-07 12:37:42 +03:00
parent c3e9de2acf
commit 2c549379a7
42 changed files with 230 additions and 230 deletions
@@ -4,19 +4,19 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
import * as estraverse from 'estraverse';
import * as ESTree from 'estree';
import { TCalleeDataExtractorFactory } from '../../types/container/stack-trace-analyzer/TCalleeDataExtractorFactory';
import { TCalleeDataExtractorFactory } from '../../types/container/calls-graph-analyzer/TCalleeDataExtractorFactory';
import { ICalleeData } from '../../interfaces/analyzers/stack-trace-analyzer/ICalleeData';
import { IStackTraceAnalyzer } from '../../interfaces/analyzers/stack-trace-analyzer/IStackTraceAnalyzer';
import { IStackTraceData } from '../../interfaces/analyzers/stack-trace-analyzer/IStackTraceData';
import { ICalleeData } from '../../interfaces/analyzers/calls-graph-analyzer/ICalleeData';
import { ICallsGraphAnalyzer } from '../../interfaces/analyzers/calls-graph-analyzer/ICallsGraphAnalyzer';
import { ICallsGraphData } from '../../interfaces/analyzers/calls-graph-analyzer/ICallsGraphData';
import { CalleeDataExtractor } from '../../enums/analyzers/stack-trace-analyzer/CalleeDataExtractor';
import { CalleeDataExtractor } from '../../enums/analyzers/calls-graph-analyzer/CalleeDataExtractor';
import { NodeGuards } from '../../node/NodeGuards';
import { NodeStatementUtils } from '../../node/NodeStatementUtils';
/**
* This class generates a data with a stack trace of functions calls
* This class generates a data with a graph of functions calls
*
* For example:
*
@@ -47,7 +47,7 @@ import { NodeStatementUtils } from '../../node/NodeStatementUtils';
* ]
*/
@injectable()
export class StackTraceAnalyzer implements IStackTraceAnalyzer {
export class CallsGraphAnalyzer implements ICallsGraphAnalyzer {
/**
* @type {CalleeDataExtractor[]}
*/
@@ -84,13 +84,13 @@ export class StackTraceAnalyzer implements IStackTraceAnalyzer {
*/
public static getLimitIndex (blockScopeBodyLength: number): number {
const lastIndex: number = blockScopeBodyLength - 1;
const limitThresholdActivationIndex: number = StackTraceAnalyzer.limitThresholdActivationLength - 1;
const limitThresholdActivationIndex: number = CallsGraphAnalyzer.limitThresholdActivationLength - 1;
let limitIndex: number = lastIndex;
if (lastIndex > limitThresholdActivationIndex) {
limitIndex = Math.round(
limitThresholdActivationIndex + (lastIndex * StackTraceAnalyzer.limitThreshold)
limitThresholdActivationIndex + (lastIndex * CallsGraphAnalyzer.limitThreshold)
);
if (limitIndex > lastIndex) {
@@ -103,19 +103,19 @@ export class StackTraceAnalyzer implements IStackTraceAnalyzer {
/**
* @param {Program} astTree
* @returns {IStackTraceData[]}
* @returns {ICallsGraphData[]}
*/
public analyze (astTree: ESTree.Program): IStackTraceData[] {
public analyze (astTree: ESTree.Program): ICallsGraphData[] {
return this.analyzeRecursive(astTree.body);
}
/**
* @param {NodeGuards[]} blockScopeBody
* @returns {IStackTraceData[]}
* @returns {ICallsGraphData[]}
*/
private analyzeRecursive (blockScopeBody: ESTree.Node[]): IStackTraceData[] {
const limitIndex: number = StackTraceAnalyzer.getLimitIndex(blockScopeBody.length);
const stackTraceData: IStackTraceData[] = [];
private analyzeRecursive (blockScopeBody: ESTree.Node[]): ICallsGraphData[] {
const limitIndex: number = CallsGraphAnalyzer.getLimitIndex(blockScopeBody.length);
const callsGraphData: ICallsGraphData[] = [];
const blockScopeBodyLength: number = blockScopeBody.length;
for (let index: number = 0; index < blockScopeBodyLength; index++) {
@@ -135,25 +135,25 @@ export class StackTraceAnalyzer implements IStackTraceAnalyzer {
return estraverse.VisitorOption.Skip;
}
this.analyzeCallExpressionNode(stackTraceData, blockScopeBody, node);
this.analyzeCallExpressionNode(callsGraphData, blockScopeBody, node);
}
});
}
return stackTraceData;
return callsGraphData;
}
/**
* @param {IStackTraceData[]} stackTraceData
* @param {ICallsGraphData[]} callsGraphData
* @param {NodeGuards[]} blockScopeBody
* @param {CallExpression} callExpressionNode
*/
private analyzeCallExpressionNode (
stackTraceData: IStackTraceData[],
callsGraphData: ICallsGraphData[],
blockScopeBody: ESTree.Node[],
callExpressionNode: ESTree.CallExpression
): void {
StackTraceAnalyzer.calleeDataExtractorsList.forEach((calleeDataExtractorName: CalleeDataExtractor) => {
CallsGraphAnalyzer.calleeDataExtractorsList.forEach((calleeDataExtractorName: CalleeDataExtractor) => {
const calleeData: ICalleeData | null = this.calleeDataExtractorFactory(calleeDataExtractorName)
.extract(blockScopeBody, callExpressionNode.callee);
@@ -161,9 +161,9 @@ export class StackTraceAnalyzer implements IStackTraceAnalyzer {
return;
}
stackTraceData.push({
callsGraphData.push({
...calleeData,
stackTrace: this.analyzeRecursive(calleeData.callee.body)
callsGraph: this.analyzeRecursive(calleeData.callee.body)
});
});
}
@@ -2,8 +2,8 @@ import { injectable } from 'inversify';
import * as ESTree from 'estree';
import { ICalleeData } from '../../../interfaces/analyzers/stack-trace-analyzer/ICalleeData';
import { ICalleeDataExtractor } from '../../../interfaces/analyzers/stack-trace-analyzer/ICalleeDataExtractor';
import { ICalleeData } from '../../../interfaces/analyzers/calls-graph-analyzer/ICalleeData';
import { ICalleeDataExtractor } from '../../../interfaces/analyzers/calls-graph-analyzer/ICalleeDataExtractor';
@injectable()
export abstract class AbstractCalleeDataExtractor implements ICalleeDataExtractor {
@@ -3,7 +3,7 @@ import { injectable } from 'inversify';
import * as estraverse from 'estraverse';
import * as ESTree from 'estree';
import { ICalleeData } from '../../../interfaces/analyzers/stack-trace-analyzer/ICalleeData';
import { ICalleeData } from '../../../interfaces/analyzers/calls-graph-analyzer/ICalleeData';
import { AbstractCalleeDataExtractor } from './AbstractCalleeDataExtractor';
import { NodeGuards } from '../../../node/NodeGuards';
@@ -3,7 +3,7 @@ import { injectable } from 'inversify';
import * as estraverse from 'estraverse';
import * as ESTree from 'estree';
import { ICalleeData } from '../../../interfaces/analyzers/stack-trace-analyzer/ICalleeData';
import { ICalleeData } from '../../../interfaces/analyzers/calls-graph-analyzer/ICalleeData';
import { AbstractCalleeDataExtractor } from './AbstractCalleeDataExtractor';
import { NodeGuards } from '../../../node/NodeGuards';
@@ -3,9 +3,9 @@ import { injectable } from 'inversify';
import * as estraverse from 'estraverse';
import * as ESTree from 'estree';
import { TObjectMembersCallsChain } from '../../../types/analyzers/stack-trace-analyzer/TObjectMembersCallsChain';
import { TObjectMembersCallsChain } from '../../../types/analyzers/calls-graph-analyzer/TObjectMembersCallsChain';
import { ICalleeData } from '../../../interfaces/analyzers/stack-trace-analyzer/ICalleeData';
import { ICalleeData } from '../../../interfaces/analyzers/calls-graph-analyzer/ICalleeData';
import { AbstractCalleeDataExtractor } from './AbstractCalleeDataExtractor';
import { NodeGuards } from '../../../node/NodeGuards';
+1 -1
View File
@@ -16,6 +16,7 @@ export enum ServiceIdentifiers {
Factory__TControlFlowStorage = 'Factory<TControlFlowStorage>',
IArrayUtils = 'IArrayUtils',
ICalleeDataExtractor = 'ICalleeDataExtractor',
ICallsGraphAnalyzer = 'ICallsGraphAnalyzer',
ICryptUtils = 'ICryptUtils',
ICustomNode = 'ICustomNode',
ICustomNodeGroup = 'ICustomNodeGroup',
@@ -38,7 +39,6 @@ export enum ServiceIdentifiers {
IRandomGenerator = 'IRandomGenerator',
ISourceCode = 'ISourceCode',
ISourceMapCorrector = 'ISourceMapCorrector',
IStackTraceAnalyzer = 'IStackTraceAnalyzer',
ITransformersRunner = 'ITransformersRunner',
Newable__ICustomNode = 'Newable<ICustomNode>',
Newable__TControlFlowStorage = 'Newable<TControlFlowStorage>',
@@ -2,19 +2,19 @@ import { InversifyContainerFacade } from '../../InversifyContainerFacade';
import { ContainerModule, interfaces } from 'inversify';
import { ServiceIdentifiers } from '../../ServiceIdentifiers';
import { ICalleeDataExtractor } from '../../../interfaces/analyzers/stack-trace-analyzer/ICalleeDataExtractor';
import { IStackTraceAnalyzer } from '../../../interfaces/analyzers/stack-trace-analyzer/IStackTraceAnalyzer';
import { ICalleeDataExtractor } from '../../../interfaces/analyzers/calls-graph-analyzer/ICalleeDataExtractor';
import { ICallsGraphAnalyzer } from '../../../interfaces/analyzers/calls-graph-analyzer/ICallsGraphAnalyzer';
import { CalleeDataExtractor } from '../../../enums/analyzers/stack-trace-analyzer/CalleeDataExtractor';
import { FunctionDeclarationCalleeDataExtractor } from '../../../analyzers/stack-trace-analyzer/callee-data-extractors/FunctionDeclarationCalleeDataExtractor';
import { FunctionExpressionCalleeDataExtractor } from '../../../analyzers/stack-trace-analyzer/callee-data-extractors/FunctionExpressionCalleeDataExtractor';
import { ObjectExpressionCalleeDataExtractor } from '../../../analyzers/stack-trace-analyzer/callee-data-extractors/ObjectExpressionCalleeDataExtractor';
import { StackTraceAnalyzer } from '../../../analyzers/stack-trace-analyzer/StackTraceAnalyzer';
import { CalleeDataExtractor } from '../../../enums/analyzers/calls-graph-analyzer/CalleeDataExtractor';
import { CallsGraphAnalyzer } from '../../../analyzers/calls-graph-analyzer/CallsGraphAnalyzer';
import { FunctionDeclarationCalleeDataExtractor } from '../../../analyzers/calls-graph-analyzer/callee-data-extractors/FunctionDeclarationCalleeDataExtractor';
import { FunctionExpressionCalleeDataExtractor } from '../../../analyzers/calls-graph-analyzer/callee-data-extractors/FunctionExpressionCalleeDataExtractor';
import { ObjectExpressionCalleeDataExtractor } from '../../../analyzers/calls-graph-analyzer/callee-data-extractors/ObjectExpressionCalleeDataExtractor';
export const analyzersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
// stack trace analyzer
bind<IStackTraceAnalyzer>(ServiceIdentifiers.IStackTraceAnalyzer)
.to(StackTraceAnalyzer)
// calls graph analyzer
bind<ICallsGraphAnalyzer>(ServiceIdentifiers.ICallsGraphAnalyzer)
.to(CallsGraphAnalyzer)
.inSingletonScope();
// callee data extractors
+6 -6
View File
@@ -9,7 +9,7 @@ import { ICustomNodeGroup } from '../interfaces/custom-nodes/ICustomNodeGroup';
import { IIdentifierNamesGenerator } from '../interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator';
import { IOptions } from '../interfaces/options/IOptions';
import { IRandomGenerator } from '../interfaces/utils/IRandomGenerator';
import { IStackTraceData } from '../interfaces/analyzers/stack-trace-analyzer/IStackTraceData';
import { ICallsGraphData } from '../interfaces/analyzers/calls-graph-analyzer/ICallsGraphData';
import { CustomNode } from '../enums/custom-nodes/CustomNode';
import { ObfuscationEvent } from '../enums/event-emitters/ObfuscationEvent';
@@ -59,9 +59,9 @@ export abstract class AbstractCustomNodeGroup implements ICustomNodeGroup {
/**
* @param {TNodeWithStatements} nodeWithStatements
* @param {IStackTraceData[]} stackTraceData
* @param {ICallsGraphData[]} callsGraphData
*/
public abstract appendCustomNodes (nodeWithStatements: TNodeWithStatements, stackTraceData: IStackTraceData[]): void;
public abstract appendCustomNodes (nodeWithStatements: TNodeWithStatements, callsGraphData: ICallsGraphData[]): void;
/**
* @returns {ObfuscationEvent}
@@ -94,10 +94,10 @@ export abstract class AbstractCustomNodeGroup implements ICustomNodeGroup {
}
/**
* @param {number} stackTraceLength
* @param {number} callsGraphLength
* @returns {number}
*/
protected getRandomStackTraceIndex (stackTraceLength: number): number {
return this.randomGenerator.getRandomInteger(0, Math.max(0, Math.round(stackTraceLength - 1)));
protected getRandomCallsGraphIndex (callsGraphLength: number): number {
return this.randomGenerator.getRandomInteger(0, Math.max(0, Math.round(callsGraphLength - 1)));
}
}
@@ -8,7 +8,7 @@ import { TNodeWithStatements } from '../../../types/node/TNodeWithStatements';
import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
import { IOptions } from '../../../interfaces/options/IOptions';
import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
import { IStackTraceData } from '../../../interfaces/analyzers/stack-trace-analyzer/IStackTraceData';
import { ICallsGraphData } from '../../../interfaces/analyzers/calls-graph-analyzer/ICallsGraphData';
import { initializable } from '../../../decorators/Initializable';
@@ -56,25 +56,25 @@ export class ConsoleOutputCustomNodeGroup extends AbstractCustomNodeGroup {
/**
* @param {TNodeWithStatements} nodeWithStatements
* @param {IStackTraceData[]} stackTraceData
* @param {ICallsGraphData[]} callsGraphData
*/
public appendCustomNodes (nodeWithStatements: TNodeWithStatements, stackTraceData: IStackTraceData[]): void {
const randomStackTraceIndex: number = this.getRandomStackTraceIndex(stackTraceData.length);
public appendCustomNodes (nodeWithStatements: TNodeWithStatements, callsGraphData: ICallsGraphData[]): void {
const randomCallsGraphIndex: number = this.getRandomCallsGraphIndex(callsGraphData.length);
// consoleOutputDisableExpressionNode append
this.appendCustomNodeIfExist(CustomNode.ConsoleOutputDisableExpressionNode, (customNode: ICustomNode) => {
NodeAppender.appendToOptimalBlockScope(
stackTraceData,
callsGraphData,
nodeWithStatements,
customNode.getNode(),
randomStackTraceIndex
randomCallsGraphIndex
);
});
// nodeCallsControllerFunctionNode append
this.appendCustomNodeIfExist(CustomNode.NodeCallsControllerFunctionNode, (customNode: ICustomNode) => {
const targetNodeWithStatements: TNodeWithStatements = stackTraceData.length
? NodeAppender.getOptimalBlockScope(stackTraceData, randomStackTraceIndex, 1)
const targetNodeWithStatements: TNodeWithStatements = callsGraphData.length
? NodeAppender.getOptimalBlockScope(callsGraphData, randomCallsGraphIndex, 1)
: nodeWithStatements;
NodeAppender.prepend(targetNodeWithStatements, customNode.getNode());
@@ -8,7 +8,7 @@ import { TNodeWithStatements } from '../../../types/node/TNodeWithStatements';
import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
import { IOptions } from '../../../interfaces/options/IOptions';
import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
import { IStackTraceData } from '../../../interfaces/analyzers/stack-trace-analyzer/IStackTraceData';
import { ICallsGraphData } from '../../../interfaces/analyzers/calls-graph-analyzer/ICallsGraphData';
import { initializable } from '../../../decorators/Initializable';
@@ -57,18 +57,18 @@ export class DebugProtectionCustomNodeGroup extends AbstractCustomNodeGroup {
/**
* @param {TNodeWithStatements} nodeWithStatements
* @param {IStackTraceData[]} stackTraceData
* @param {ICallsGraphData[]} callsGraphData
*/
public appendCustomNodes (nodeWithStatements: TNodeWithStatements, stackTraceData: IStackTraceData[]): void {
const randomStackTraceIndex: number = this.getRandomStackTraceIndex(stackTraceData.length);
public appendCustomNodes (nodeWithStatements: TNodeWithStatements, callsGraphData: ICallsGraphData[]): void {
const randomCallsGraphIndex: number = this.getRandomCallsGraphIndex(callsGraphData.length);
// debugProtectionFunctionCallNode append
this.appendCustomNodeIfExist(CustomNode.DebugProtectionFunctionCallNode, (customNode: ICustomNode) => {
NodeAppender.appendToOptimalBlockScope(
stackTraceData,
callsGraphData,
nodeWithStatements,
customNode.getNode(),
randomStackTraceIndex
randomCallsGraphIndex
);
});
@@ -89,8 +89,8 @@ export class DebugProtectionCustomNodeGroup extends AbstractCustomNodeGroup {
// nodeCallsControllerFunctionNode append
this.appendCustomNodeIfExist(CustomNode.NodeCallsControllerFunctionNode, (customNode: ICustomNode) => {
const targetNodeWithStatements: TNodeWithStatements = stackTraceData.length
? NodeAppender.getOptimalBlockScope(stackTraceData, randomStackTraceIndex, 1)
const targetNodeWithStatements: TNodeWithStatements = callsGraphData.length
? NodeAppender.getOptimalBlockScope(callsGraphData, randomCallsGraphIndex, 1)
: nodeWithStatements;
NodeAppender.prepend(targetNodeWithStatements, customNode.getNode());
@@ -8,7 +8,7 @@ import { TNodeWithStatements } from '../../../types/node/TNodeWithStatements';
import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
import { IOptions } from '../../../interfaces/options/IOptions';
import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
import { IStackTraceData } from '../../../interfaces/analyzers/stack-trace-analyzer/IStackTraceData';
import { ICallsGraphData } from '../../../interfaces/analyzers/calls-graph-analyzer/ICallsGraphData';
import { initializable } from '../../../decorators/Initializable';
@@ -56,25 +56,25 @@ export class DomainLockCustomNodeGroup extends AbstractCustomNodeGroup {
/**
* @param {TNodeWithStatements} nodeWithStatements
* @param {IStackTraceData[]} stackTraceData
* @param {ICallsGraphData[]} callsGraphData
*/
public appendCustomNodes (nodeWithStatements: TNodeWithStatements, stackTraceData: IStackTraceData[]): void {
const randomStackTraceIndex: number = this.getRandomStackTraceIndex(stackTraceData.length);
public appendCustomNodes (nodeWithStatements: TNodeWithStatements, callsGraphData: ICallsGraphData[]): void {
const randomCallsGraphIndex: number = this.getRandomCallsGraphIndex(callsGraphData.length);
// domainLockNode append
this.appendCustomNodeIfExist(CustomNode.DomainLockNode, (customNode: ICustomNode) => {
NodeAppender.appendToOptimalBlockScope(
stackTraceData,
callsGraphData,
nodeWithStatements,
customNode.getNode(),
randomStackTraceIndex
randomCallsGraphIndex
);
});
// nodeCallsControllerFunctionNode append
this.appendCustomNodeIfExist(CustomNode.NodeCallsControllerFunctionNode, (customNode: ICustomNode) => {
const targetNodeWithStatements: TNodeWithStatements = stackTraceData.length
? NodeAppender.getOptimalBlockScope(stackTraceData, randomStackTraceIndex, 1)
const targetNodeWithStatements: TNodeWithStatements = callsGraphData.length
? NodeAppender.getOptimalBlockScope(callsGraphData, randomCallsGraphIndex, 1)
: nodeWithStatements;
NodeAppender.prepend(targetNodeWithStatements, customNode.getNode());
@@ -8,7 +8,7 @@ import { TNodeWithStatements } from '../../../types/node/TNodeWithStatements';
import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
import { IOptions } from '../../../interfaces/options/IOptions';
import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
import { IStackTraceData } from '../../../interfaces/analyzers/stack-trace-analyzer/IStackTraceData';
import { ICallsGraphData } from '../../../interfaces/analyzers/calls-graph-analyzer/ICallsGraphData';
import { initializable } from '../../../decorators/Initializable';
@@ -56,25 +56,25 @@ export class SelfDefendingCustomNodeGroup extends AbstractCustomNodeGroup {
/**
* @param {TNodeWithStatements} nodeWithStatements
* @param {IStackTraceData[]} stackTraceData
* @param {ICallsGraphData[]} callsGraphData
*/
public appendCustomNodes (nodeWithStatements: TNodeWithStatements, stackTraceData: IStackTraceData[]): void {
const randomStackTraceIndex: number = this.getRandomStackTraceIndex(stackTraceData.length);
public appendCustomNodes (nodeWithStatements: TNodeWithStatements, callsGraphData: ICallsGraphData[]): void {
const randomCallsGraphIndex: number = this.getRandomCallsGraphIndex(callsGraphData.length);
// selfDefendingUnicodeNode append
this.appendCustomNodeIfExist(CustomNode.SelfDefendingUnicodeNode, (customNode: ICustomNode) => {
NodeAppender.appendToOptimalBlockScope(
stackTraceData,
callsGraphData,
nodeWithStatements,
customNode.getNode(),
randomStackTraceIndex
randomCallsGraphIndex
);
});
// nodeCallsControllerFunctionNode append
this.appendCustomNodeIfExist(CustomNode.NodeCallsControllerFunctionNode, (customNode: ICustomNode) => {
const targetNodeWithStatements: TNodeWithStatements = stackTraceData.length
? NodeAppender.getOptimalBlockScope(stackTraceData, randomStackTraceIndex, 1)
const targetNodeWithStatements: TNodeWithStatements = callsGraphData.length
? NodeAppender.getOptimalBlockScope(callsGraphData, randomCallsGraphIndex, 1)
: nodeWithStatements;
NodeAppender.prepend(targetNodeWithStatements, customNode.getNode());
@@ -9,7 +9,7 @@ import { TStringArrayStorage } from '../../../types/storages/TStringArrayStorage
import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
import { IOptions } from '../../../interfaces/options/IOptions';
import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
import { IStackTraceData } from '../../../interfaces/analyzers/stack-trace-analyzer/IStackTraceData';
import { ICallsGraphData } from '../../../interfaces/analyzers/calls-graph-analyzer/ICallsGraphData';
import { initializable } from '../../../decorators/Initializable';
@@ -65,9 +65,9 @@ export class StringArrayCustomNodeGroup extends AbstractCustomNodeGroup {
/**
* @param {TNodeWithStatements} nodeWithStatements
* @param {IStackTraceData[]} stackTraceData
* @param {ICallsGraphData[]} callsGraphData
*/
public appendCustomNodes (nodeWithStatements: TNodeWithStatements, stackTraceData: IStackTraceData[]): void {
public appendCustomNodes (nodeWithStatements: TNodeWithStatements, callsGraphData: ICallsGraphData[]): void {
if (!this.stringArrayStorage.getLength()) {
return;
}
@@ -0,0 +1,12 @@
import * as ESTree from 'estree';
import { IAnalyzer } from '../IAnalyzer';
import { ICallsGraphData } from './ICallsGraphData';
export interface ICallsGraphAnalyzer extends IAnalyzer<ICallsGraphData> {
/**
* @param {Program} astTree
* @returns {ICallsGraphData[]}
*/
analyze (astTree: ESTree.Program): ICallsGraphData[];
}
@@ -0,0 +1,5 @@
import { ICalleeData } from './ICalleeData';
export interface ICallsGraphData extends ICalleeData {
callsGraph: ICallsGraphData[];
}
@@ -1,12 +0,0 @@
import * as ESTree from 'estree';
import { IAnalyzer } from '../IAnalyzer';
import { IStackTraceData } from './IStackTraceData';
export interface IStackTraceAnalyzer extends IAnalyzer<IStackTraceData> {
/**
* @param {Program} astTree
* @returns {IStackTraceData[]}
*/
analyze (astTree: ESTree.Program): IStackTraceData[];
}
@@ -1,5 +0,0 @@
import { ICalleeData } from './ICalleeData';
export interface IStackTraceData extends ICalleeData {
stackTrace: IStackTraceData[];
}
+3 -3
View File
@@ -2,7 +2,7 @@ import { TNodeWithStatements } from '../../types/node/TNodeWithStatements';
import { ICustomNode } from './ICustomNode';
import { IInitializable } from '../IInitializable';
import { IStackTraceData } from '../analyzers/stack-trace-analyzer/IStackTraceData';
import { ICallsGraphData } from '../analyzers/calls-graph-analyzer/ICallsGraphData';
import { CustomNode } from '../../enums/custom-nodes/CustomNode';
import { ObfuscationEvent } from '../../enums/event-emitters/ObfuscationEvent';
@@ -10,9 +10,9 @@ import { ObfuscationEvent } from '../../enums/event-emitters/ObfuscationEvent';
export interface ICustomNodeGroup extends IInitializable {
/**
* @param nodeWithStatements
* @param stackTraceData
* @param callsGraphData
*/
appendCustomNodes (nodeWithStatements: TNodeWithStatements, stackTraceData: IStackTraceData[]): void;
appendCustomNodes (nodeWithStatements: TNodeWithStatements, callsGraphData: ICallsGraphData[]): void;
/**
* @returns {ObfuscationEvent}
@@ -9,8 +9,8 @@ import { ICustomNodeGroup } from '../../interfaces/custom-nodes/ICustomNodeGroup
import { IObfuscationEventEmitter } from '../../interfaces/event-emitters/IObfuscationEventEmitter';
import { IOptions } from '../../interfaces/options/IOptions';
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
import { IStackTraceAnalyzer } from '../../interfaces/analyzers/stack-trace-analyzer/IStackTraceAnalyzer';
import { IStackTraceData } from '../../interfaces/analyzers/stack-trace-analyzer/IStackTraceData';
import { ICallsGraphAnalyzer } from '../../interfaces/analyzers/calls-graph-analyzer/ICallsGraphAnalyzer';
import { ICallsGraphData } from '../../interfaces/analyzers/calls-graph-analyzer/ICallsGraphData';
import { IVisitor } from '../../interfaces/node-transformers/IVisitor';
import { ObfuscationEvent } from '../../enums/event-emitters/ObfuscationEvent';
@@ -35,24 +35,24 @@ export class CustomNodesTransformer extends AbstractNodeTransformer {
private readonly obfuscationEventEmitter: IObfuscationEventEmitter;
/**
* @type {IStackTraceAnalyzer}
* @type {ICallsGraphAnalyzer}
*/
private readonly stackTraceAnalyzer: IStackTraceAnalyzer;
private readonly callsGraphAnalyzer: ICallsGraphAnalyzer;
/**
* @type {IStackTraceData[]}
* @type {ICallsGraphData[]}
*/
private stackTraceData: IStackTraceData[] = [];
private callsGraphData: ICallsGraphData[] = [];
/**
* @param {IStackTraceAnalyzer} stackTraceAnalyzer
* @param {ICallsGraphAnalyzer} callsGraphAnalyzer
* @param {IObfuscationEventEmitter} obfuscationEventEmitter
* @param {TCustomNodeGroupStorage} customNodeGroupStorage
* @param {IRandomGenerator} randomGenerator
* @param {IOptions} options
*/
constructor (
@inject(ServiceIdentifiers.IStackTraceAnalyzer) stackTraceAnalyzer: IStackTraceAnalyzer,
@inject(ServiceIdentifiers.ICallsGraphAnalyzer) callsGraphAnalyzer: ICallsGraphAnalyzer,
@inject(ServiceIdentifiers.IObfuscationEventEmitter) obfuscationEventEmitter: IObfuscationEventEmitter,
@inject(ServiceIdentifiers.TCustomNodeGroupStorage) customNodeGroupStorage: TCustomNodeGroupStorage,
@inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
@@ -60,7 +60,7 @@ export class CustomNodesTransformer extends AbstractNodeTransformer {
) {
super(randomGenerator, options);
this.stackTraceAnalyzer = stackTraceAnalyzer;
this.callsGraphAnalyzer = callsGraphAnalyzer;
this.obfuscationEventEmitter = obfuscationEventEmitter;
this.customNodeGroupStorage = customNodeGroupStorage;
}
@@ -102,7 +102,7 @@ export class CustomNodesTransformer extends AbstractNodeTransformer {
* @param {Node | null} parentNode
*/
public analyzeNode (node: ESTree.Program, parentNode: ESTree.Node | null): void {
this.stackTraceData = this.stackTraceAnalyzer.analyze(node);
this.callsGraphData = this.callsGraphAnalyzer.analyze(node);
}
/**
@@ -130,7 +130,7 @@ export class CustomNodesTransformer extends AbstractNodeTransformer {
);
});
this.obfuscationEventEmitter.emit(ObfuscationEvent.BeforeObfuscation, node, this.stackTraceData);
this.obfuscationEventEmitter.emit(ObfuscationEvent.BeforeObfuscation, node, this.callsGraphData);
}
/**
@@ -138,6 +138,6 @@ export class CustomNodesTransformer extends AbstractNodeTransformer {
* @param {Node | null} parentNode
*/
private appendCustomNodesAfterObfuscation (node: ESTree.Program, parentNode: ESTree.Node | null): void {
this.obfuscationEventEmitter.emit(ObfuscationEvent.AfterObfuscation, node, this.stackTraceData);
this.obfuscationEventEmitter.emit(ObfuscationEvent.AfterObfuscation, node, this.callsGraphData);
}
}
+10 -10
View File
@@ -3,7 +3,7 @@ import * as ESTree from 'estree';
import { TNodeWithStatements } from '../types/node/TNodeWithStatements';
import { TStatement } from '../types/node/TStatement';
import { IStackTraceData } from '../interfaces/analyzers/stack-trace-analyzer/IStackTraceData';
import { ICallsGraphData } from '../interfaces/analyzers/calls-graph-analyzer/ICallsGraphData';
import { NodeGuards } from './NodeGuards';
@@ -38,19 +38,19 @@ export class NodeAppender {
*
* Appends node into block statement of `baz` function expression
*
* @param {IStackTraceData[]} stackTraceData
* @param {ICallsGraphData[]} callsGraphData
* @param {TNodeWithStatements} nodeWithStatements
* @param {TStatement[]} bodyStatements
* @param {number} index
*/
public static appendToOptimalBlockScope (
stackTraceData: IStackTraceData[],
callsGraphData: ICallsGraphData[],
nodeWithStatements: TNodeWithStatements,
bodyStatements: TStatement[],
index: number = 0
): void {
const targetBlockScope: TNodeWithStatements = stackTraceData.length
? NodeAppender.getOptimalBlockScope(stackTraceData, index)
const targetBlockScope: TNodeWithStatements = callsGraphData.length
? NodeAppender.getOptimalBlockScope(callsGraphData, index)
: nodeWithStatements;
NodeAppender.prepend(targetBlockScope, bodyStatements);
@@ -59,24 +59,24 @@ export class NodeAppender {
/**
* Returns deepest block scope node at given deep.
*
* @param {IStackTraceData[]} stackTraceData
* @param {ICallsGraphData[]} callsGraphData
* @param {number} index
* @param {number} deep
* @returns {BlockStatement}
*/
public static getOptimalBlockScope (
stackTraceData: IStackTraceData[],
callsGraphData: ICallsGraphData[],
index: number,
deep: number = Infinity
): ESTree.BlockStatement {
const firstCall: IStackTraceData = stackTraceData[index];
const firstCall: ICallsGraphData = callsGraphData[index];
if (deep <= 0) {
throw new Error('Invalid `deep` argument value. Value should be bigger then 0.');
}
if (deep > 1 && firstCall.stackTrace.length) {
return NodeAppender.getOptimalBlockScope(firstCall.stackTrace, 0, --deep);
if (deep > 1 && firstCall.callsGraph.length) {
return NodeAppender.getOptimalBlockScope(firstCall.callsGraph, 0, --deep);
} else {
return firstCall.callee;
}
@@ -1,5 +1,5 @@
import { ICalleeDataExtractor } from '../../../interfaces/analyzers/stack-trace-analyzer/ICalleeDataExtractor';
import { ICalleeDataExtractor } from '../../../interfaces/analyzers/calls-graph-analyzer/ICalleeDataExtractor';
import { CalleeDataExtractor } from '../../../enums/analyzers/stack-trace-analyzer/CalleeDataExtractor';
import { CalleeDataExtractor } from '../../../enums/analyzers/calls-graph-analyzer/CalleeDataExtractor';
export type TCalleeDataExtractorFactory = (calleeDataExtractorName: CalleeDataExtractor) => ICalleeDataExtractor;