mirror of
https://github.com/ran-j/PS2Recomp.git
synced 2026-09-26 16:59:35 -04:00
61300792a0
ELFIO, pinned at Release_3.12 via FetchContent, uses uint16_t, uint32_t
and uint64_t in elf_types.hpp without including <cstdint> itself. Newer
libstdc++ releases trimmed the transitive includes that used to supply
those typedefs, so building elf_parser.cpp fails:
elf_types.hpp:30:20: error: 'uint16_t' does not name a type
30 | using Elf_Half = uint16_t;
Include <cstdint> ahead of elfio.hpp so the typedefs are visible when
that header is processed. Header-only change; no behaviour is affected.
67 lines
2.3 KiB
C++
67 lines
2.3 KiB
C++
#ifndef PS2RECOMP_ELF_PARSER_H
|
|
#define PS2RECOMP_ELF_PARSER_H
|
|
|
|
#include <cstdint>
|
|
#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 §ionName) const;
|
|
uint32_t getSectionAddress(const std::string §ionName) const;
|
|
uint32_t getSectionSize(const std::string §ionName) 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
|