Files
PS2Recomp/ps2xRecomp/include/ps2recomp/elf_parser.h
T
Ranieri 5196a6672a Refactor runtime for move speed and better code style (#140)
* feat: added guestBranchKind enum to categorize branch types
feat: added missingFunctionPolicy enum to define behaviors for missing function scenarios
refactor: added handle guest branches and report missing functions
feat lookupFunction to utilize new dispatch logic and improve error handling for unregistered functions

* fix: fix test conflict

* feat: added debug sound driver logs

* feat: emmiter for return

* feat: added recompiler reporter
feat: added strict diagnostics flag for heavy debug calls

* feat: staticc table insted of hashmap for runtime

* feat: back file to ignore

* feat: explode code across helpers and classes

* feat: update codegen test
feat: better guest nop check

* feat: fix link problem on linux

* feat: fix Segmentation fault
2026-07-04 00:43:22 -03:00

66 lines
2.3 KiB
C++

#ifndef PS2RECOMP_ELF_PARSER_H
#define PS2RECOMP_ELF_PARSER_H
#include <elfio/elfio.hpp>
#include <string>
#include <vector>
#include <memory>
#include <unordered_set>
namespace ps2recomp
{
struct Relocation;
struct Section;
struct Function;
struct Symbol;
class RecompilerReporter;
class ElfParser
{
public:
explicit ElfParser(const std::string &filePath);
~ElfParser();
bool parse();
bool loadGhidraFunctionMap(const std::string &mapPath);
std::vector<Function> extractFunctions() const;
std::vector<Function> extractExtraFunctions() const;
std::vector<Symbol> extractSymbols();
std::vector<Section> getSections();
std::vector<Relocation> getRelocations();
// Helper methods
bool isValidAddress(uint32_t address) const;
uint32_t readWord(uint32_t address) const;
uint8_t *getSectionData(const std::string &sectionName) const;
uint32_t getSectionAddress(const std::string &sectionName) const;
uint32_t getSectionSize(const std::string &sectionName) const;
uint32_t getEntryPoint() const;
void setReporter(RecompilerReporter *reporter);
void debugAddress(uint32_t address) const;
private:
std::string m_filePath;
std::unique_ptr<ELFIO::elfio> m_elf;
std::vector<Section> m_sections;
std::vector<Symbol> m_symbols;
std::vector<Relocation> m_relocations;
std::vector<Function> m_extraFunctions;
bool m_hasLoadedGhidraMap = false;
RecompilerReporter *m_reporter = nullptr;
std::unordered_set<uint32_t> m_ghidraMapStarts;
void loadSections();
void loadSymbols();
void loadRelocations();
void loadDebugFunctions();
bool isExecutableSection(const ELFIO::section *section) const;
bool isDataSection(const ELFIO::section *section) const;
};
} // namespace ps2recomp
#endif // PS2RECOMP_ELF_PARSER_H