#ifndef ELF_FILE_H
#define ELF_FILE_H
#include <File.h>
#include <image.h>
#include "Elf.h"
namespace SymbolPatcher {
class ElfFile;
class ElfSection;
class ElfSymbol {
public:
ElfSymbol(ElfSection* section = NULL,
int32 index = -1);
~ElfSymbol();
void SetTo(ElfSection* section, int32 index);
void Unset();
const Elf_Sym* GetSymbolStruct();
const char* GetName();
uint32 GetBinding();
uint32 GetType();
uint32 GetTargetSectionIndex();
private:
ElfSection* fSection;
int32 fIndex;
Elf_Sym* fSymbol;
};
class ElfRelocation {
public:
ElfRelocation(ElfSection* section = NULL,
int32 index = -1);
~ElfRelocation();
void SetTo(ElfSection* section, int32 index);
void Unset();
Elf_Rel* GetRelocationStruct();
uint32 GetType();
uint32 GetSymbolIndex();
Elf_Addr GetOffset();
status_t GetSymbol(ElfSymbol* symbol);
private:
ElfSection* fSection;
int32 fIndex;
Elf_Rel* fRelocation;
};
class ElfRelocationIterator {
public:
ElfRelocationIterator(ElfFile* file);
~ElfRelocationIterator();
bool GetNext(ElfRelocation* relocation);
private:
ElfSection* _FindNextSection();
private:
ElfFile* fFile;
int32 fSectionIndex;
int32 fEntryIndex;
};
class ElfFile {
public:
ElfFile();
~ElfFile();
status_t SetTo(const char *filename);
void Unset();
void Unload();
BFile* GetFile() { return &fFile; }
const char* GetSectionHeaderStrings(size_t* size);
const char* GetStringSectionStrings(int32 index,
size_t* size);
int32 CountSections() const { return fSectionCount; }
ElfSection* SectionAt(int32 index, bool load = false);
void Dump();
private:
status_t _SetTo(const char *filename);
Elf_Shdr* _SectionHeaderAt(int32 index);
status_t _LoadSection(int32 index);
private:
BFile fFile;
Elf_Ehdr fHeader;
uint8* fSectionHeaders;
ElfSection* fSections;
int32 fSectionCount;
size_t fSectionHeaderSize;
};
}
using namespace SymbolPatcher;
#endif