mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-05-31 16:57:58 +00:00
Added "AddSymbol"
This commit is contained in:
parent
88008ac470
commit
c74d19e9d2
@ -2,54 +2,10 @@
|
||||
#include <memory.hpp>
|
||||
#include <convert.h>
|
||||
#include <debug.h>
|
||||
#include <elf.h>
|
||||
|
||||
// #pragma GCC diagnostic ignored "-Wignored-qualifiers"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned char e_ident[16];
|
||||
uint16_t e_type;
|
||||
uint16_t e_machine;
|
||||
uint32_t e_version;
|
||||
uint64_t e_entry;
|
||||
uint64_t e_phoff;
|
||||
uint64_t e_shoff;
|
||||
uint32_t e_flags;
|
||||
uint16_t e_ehsize;
|
||||
uint16_t e_phentsize;
|
||||
uint16_t e_phnum;
|
||||
uint16_t e_shentsize;
|
||||
uint16_t e_shnum;
|
||||
uint16_t e_shstrndx;
|
||||
} Elf64_Ehdr;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t sh_name;
|
||||
uint32_t sh_type;
|
||||
uint64_t sh_flags;
|
||||
uint64_t sh_addr;
|
||||
uint64_t sh_offset;
|
||||
uint64_t sh_size;
|
||||
uint32_t sh_link;
|
||||
uint32_t sh_info;
|
||||
uint64_t sh_addralign;
|
||||
uint64_t sh_entsize;
|
||||
} Elf64_Shdr;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t st_name;
|
||||
unsigned char st_info;
|
||||
unsigned char st_other;
|
||||
uint16_t st_shndx;
|
||||
uint64_t st_value;
|
||||
uint64_t st_size;
|
||||
} Elf64_Sym;
|
||||
|
||||
#define SHT_SYMTAB 2
|
||||
#define SHT_STRTAB 3
|
||||
|
||||
namespace SymbolResolver
|
||||
{
|
||||
Symbols::Symbols(uintptr_t ImageAddress)
|
||||
@ -74,6 +30,9 @@ namespace SymbolResolver
|
||||
case SHT_SYMTAB:
|
||||
ElfSymbols = (Elf64_Sym *)(ImageAddress + ElfSections[i].sh_offset);
|
||||
this->TotalEntries = ElfSections[i].sh_size / sizeof(Elf64_Sym);
|
||||
if (this->TotalEntries >= 0x10000)
|
||||
this->TotalEntries = 0x10000 - 1;
|
||||
|
||||
debug("Symbol table found, %d entries", this->TotalEntries);
|
||||
break;
|
||||
case SHT_STRTAB:
|
||||
@ -141,4 +100,17 @@ namespace SymbolResolver
|
||||
Result = this->SymTable[i];
|
||||
return Result.FunctionName;
|
||||
}
|
||||
|
||||
__no_instrument_function void Symbols::AddSymbol(uintptr_t Address, const char *Name)
|
||||
{
|
||||
if (this->TotalEntries >= 0x10000)
|
||||
{
|
||||
error("Symbol table is full");
|
||||
return;
|
||||
}
|
||||
|
||||
this->SymTable[this->TotalEntries].Address = Address;
|
||||
strcpy(this->SymTable[this->TotalEntries].FunctionName, Name);
|
||||
this->TotalEntries++;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user