#ifndef PS2RECOMP_ELF_ANALYZER_H #define PS2RECOMP_ELF_ANALYZER_H #include "ps2recomp/elf_parser.h" #include "ps2recomp/r5900_decoder.h" #include "ps2recomp/types.h" #include #include #include #include #include #include #include namespace ps2recomp { class ElfAnalyzer { public: ElfAnalyzer(const std::string &elfPath); ~ElfAnalyzer(); bool analyze(); bool generateToml(const std::string &outputPath); private: std::string m_elfPath; std::unique_ptr m_elfParser; std::unique_ptr m_decoder; std::vector m_functions; std::vector m_symbols; std::vector
m_sections; std::vector m_relocations; std::unordered_set m_libFunctions; std::unordered_set m_skipFunctions; std::unordered_map> m_functionDataUsage; std::unordered_map m_commonDataAccess; std::map m_patches; std::map m_patchReasons; std::unordered_map m_functionCFGs; std::vector m_jumpTables; std::unordered_map> m_functionCalls; void initializeLibraryFunctions(); void analyzeEntryPoint(); void analyzeLibraryFunctions(); void analyzeDataUsage(); void identifyPotentialPatches(); void analyzeControlFlow(); void detectJumpTables(); void analyzePerformanceCriticalPaths(); void identifyRecursiveFunctions(); void analyzeRegisterUsage(); void analyzeFunctionSignatures(); void optimizePatches(); bool identifyMemcpyPattern(const Function &func); bool identifyMemsetPattern(const Function &func); bool identifyStringOperationPattern(const Function &func); bool identifyMathPattern(const Function &func); bool isSystemFunction(const std::string &name) const; bool isLibraryFunction(const std::string &name) const; std::vector decodeFunction(const Function &function); CFG buildCFG(const Function &function); std::string formatAddress(uint32_t address) const; std::string escapeBackslashes(const std::string &path); bool hasMMIInstructions(const Function &function); bool hasVUInstructions(const Function &function); bool identifyFunctionType(const Function &function); void categorizeFunction(Function &function); uint32_t getSuccessor(const Instruction &inst, uint32_t currentAddr); bool isSelfModifyingCode(const Function &function); bool isLoopHeavyFunction(const Function &function); }; } #endif // PS2RECOMP_ELF_ANALYZER_H