UNPKG

il2cpp-dump-analyzer-mcp

Version:

Agentic RAG system for analyzing IL2CPP dump.cs files from Unity games

326 lines (325 loc) 9.8 kB
/** * @fileoverview TypeAnalyzer - Type System Analysis and Relationship Mapping * * Provides comprehensive analysis of IL2CPP type systems including: * - Inheritance hierarchy analysis and interface implementations * - Generic type relationship mapping and constraint analysis * - Type dependency graph creation and circular reference detection * - Type compatibility analysis and relationship validation * * This module builds upon the metadata extraction capabilities to provide * deep insights into type relationships and dependencies within IL2CPP dumps. */ import { IL2CPPMetadata } from '../mcp/tools/extract-metadata-tool'; /** * Represents a type in an inheritance hierarchy */ export interface TypeHierarchyNode { typeName: string; namespace: string; typeDefIndex: number; baseType?: string; derivedTypes: TypeHierarchyNode[]; depth: number; interfaces: string[]; } /** * Inheritance hierarchy analysis result */ export interface InheritanceHierarchyResult { hierarchies: InheritanceHierarchy[]; multipleInheritancePatterns: MultipleInheritancePattern[]; orphanedTypes: string[]; maxDepth: number; totalHierarchies: number; } /** * Complete inheritance hierarchy with root type information */ export interface InheritanceHierarchy { rootType: string; depth: number; derivedTypes: TypeHierarchyNode[]; totalTypes: number; } /** * Multiple inheritance pattern detection */ export interface MultipleInheritancePattern { typeName: string; namespace: string; baseTypes: string[]; interfaces: string[]; complexity: 'low' | 'medium' | 'high'; } /** * Interface implementation analysis result */ export interface InterfaceImplementationResult { implementations: InterfaceImplementation[]; interfaceHierarchies: InterfaceHierarchy[]; implementationCoverage: Map<string, number>; orphanedInterfaces: string[]; } /** * Interface implementation details */ export interface InterfaceImplementation { implementingType: string; namespace: string; interfaces: string[]; implicitImplementations: string[]; explicitImplementations: string[]; } /** * Interface inheritance hierarchy */ export interface InterfaceHierarchy { baseInterface: string; derivedInterfaces: string[]; implementingTypes: string[]; depth: number; } /** * Generic type relationship mapping result */ export interface GenericTypeRelationshipResult { genericRelationships: GenericTypeRelationship[]; constraintAnalysis: ConstraintAnalysis[]; instantiationPatterns: InstantiationPattern[]; complexityMetrics: GenericComplexityMetrics; } /** * Generic type relationship details */ export interface GenericTypeRelationship { genericDefinition: string; namespace: string; typeParameters: string[]; constraints: string[]; instantiations: string[]; usageFrequency: number; } /** * Constraint analysis for generic types */ export interface ConstraintAnalysis { typeParameter: string; constraints: string[]; constraintType: 'class' | 'struct' | 'interface' | 'new' | 'base'; violationRisk: 'low' | 'medium' | 'high'; } /** * Generic type instantiation patterns */ export interface InstantiationPattern { genericDefinition: string; commonInstantiations: string[]; unusualInstantiations: string[]; instantiationCount: number; } /** * Generic complexity metrics */ export interface GenericComplexityMetrics { totalGenericTypes: number; averageTypeParameters: number; maxTypeParameters: number; constraintComplexity: number; nestingDepth: number; } /** * Type dependency graph structure */ export interface TypeDependencyGraph { nodes: TypeDependencyNode[]; edges: TypeDependencyEdge[]; metrics: DependencyMetrics; clusters: TypeCluster[]; } /** * Type dependency node */ export interface TypeDependencyNode { typeName: string; namespace: string; typeDefIndex: number; dependencies: string[]; dependents: string[]; dependencyCount: number; dependentCount: number; centrality: number; } /** * Type dependency edge */ export interface TypeDependencyEdge { from: string; to: string; dependencyType: 'inheritance' | 'interface' | 'composition' | 'aggregation' | 'generic'; strength: number; } /** * Dependency metrics */ export interface DependencyMetrics { totalNodes: number; totalEdges: number; averageDependencies: number; maxDependencies: number; cyclomaticComplexity: number; modularityScore: number; } /** * Type cluster for dependency analysis */ export interface TypeCluster { clusterId: string; types: string[]; cohesion: number; coupling: number; size: number; } /** * Circular reference detection result */ export interface CircularReferenceResult { circularReferences: CircularReference[]; affectedTypes: string[]; severityDistribution: Map<string, number>; resolutionSuggestions: ResolutionSuggestion[]; } /** * Circular reference details */ export interface CircularReference { cycle: string[]; cycleType: 'inheritance' | 'interface' | 'composition' | 'generic'; severity: 'low' | 'medium' | 'high' | 'critical'; impact: string[]; } /** * Resolution suggestion for circular references */ export interface ResolutionSuggestion { circularReference: string[]; suggestionType: 'interface_extraction' | 'dependency_injection' | 'refactoring'; description: string; effort: 'low' | 'medium' | 'high'; } /** * Type compatibility analysis result */ export interface TypeCompatibilityResult { compatibilityMatrix: Map<string, CompatibilityType>; assignabilityRules: AssignabilityRule[]; conversionPaths: ConversionPath[]; incompatibilityReasons: Map<string, string>; } /** * Type compatibility classification */ export type CompatibilityType = 'identical' | 'assignable' | 'convertible' | 'incompatible'; /** * Assignability rule */ export interface AssignabilityRule { fromType: string; toType: string; rule: string; conditions: string[]; } /** * Type conversion path */ export interface ConversionPath { fromType: string; toType: string; path: string[]; conversionType: 'implicit' | 'explicit' | 'custom'; } /** * TypeAnalyzer - Main class for type system analysis and relationship mapping * * Provides comprehensive analysis capabilities for IL2CPP type systems including * inheritance hierarchies, interface implementations, generic relationships, * dependency graphs, circular reference detection, and compatibility analysis. */ export declare class TypeAnalyzer { private readonly logger; constructor(); /** * Analyze inheritance hierarchies and interface implementations * * @param metadata - IL2CPP metadata containing type information * @returns Comprehensive inheritance hierarchy analysis */ analyzeInheritanceHierarchies(metadata: IL2CPPMetadata): Promise<InheritanceHierarchyResult>; /** * Analyze interface implementations and their relationships * * @param metadata - IL2CPP metadata containing type information * @returns Comprehensive interface implementation analysis */ analyzeInterfaceImplementations(metadata: IL2CPPMetadata): Promise<InterfaceImplementationResult>; /** * Map generic type relationships and constraints * * @param metadata - IL2CPP metadata containing type information * @returns Comprehensive generic type relationship analysis */ mapGenericTypeRelationships(metadata: IL2CPPMetadata): Promise<GenericTypeRelationshipResult>; /** * Create type dependency graph and circular reference detection * * @param metadata - IL2CPP metadata containing type information * @returns Comprehensive type dependency graph */ createTypeDependencyGraph(metadata: IL2CPPMetadata): Promise<TypeDependencyGraph>; /** * Detect circular references in type relationships * * @param metadata - IL2CPP metadata containing type information * @returns Circular reference detection results */ detectCircularReferences(metadata: IL2CPPMetadata): Promise<CircularReferenceResult>; /** * Analyze type compatibility and assignability * * @param metadata - IL2CPP metadata containing type information * @returns Type compatibility analysis results */ analyzeTypeCompatibility(metadata: IL2CPPMetadata): Promise<TypeCompatibilityResult>; private buildHierarchyTree; private analyzeMultipleInheritancePattern; private countTypesInHierarchy; private collectHierarchyTypesFromNodes; private flattenHierarchyTree; private findTypeInHierarchy; private calculateMaxDepth; private collectHierarchyTypes; private isImplicitImplementation; private buildInterfaceHierarchy; private analyzeGenericTypeRelationship; private analyzeConstraints; private analyzeInstantiationPattern; private calculateGenericComplexityMetrics; private calculateInterfaceDepth; private createDependencyNode; private createDependencyEdges; private calculateDependencyMetrics; private createTypeClusters; private buildDependencyGraphForCycleDetection; private detectCyclesUsingDFS; private dfsForCycles; private analyzeCycle; private calculateCycleImpact; private generateResolutionSuggestion; private analyzeTypeCompatibilityPair; private isAssignableViaInheritance; private isAssignableViaInterface; private isGenericCompatible; private findBuiltInConversionPath; private determineIncompatibilityReason; private addBuiltInCompatibilityRules; }