Fix type sizes

This commit is contained in:
Alex
2023-05-13 07:40:07 +03:00
parent 06e34ab57f
commit 816e5461c9
85 changed files with 655 additions and 422 deletions

View File

@ -55,16 +55,26 @@ namespace SymbolResolver
return;
}
#if defined(a64)
Elf64_Shdr *ElfSections = (Elf64_Shdr *)(Sections);
Elf64_Sym *ElfSymbols = nullptr;
#elif defined(a32)
Elf32_Shdr *ElfSections = (Elf32_Shdr *)(Sections);
Elf32_Sym *ElfSymbols = nullptr;
#endif
char *strtab = nullptr;
for (uint64_t i = 0; i < Num; i++)
switch (ElfSections[i].sh_type)
{
case SHT_SYMTAB:
#if defined(a64)
ElfSymbols = (Elf64_Sym *)(Sections + ElfSections[i].sh_offset);
this->TotalEntries = ElfSections[i].sh_size / sizeof(Elf64_Sym);
#elif defined(a32)
ElfSymbols = (Elf32_Sym *)(Sections + ElfSections[i].sh_offset);
this->TotalEntries = ElfSections[i].sh_size / sizeof(Elf32_Sym);
#endif
if (this->TotalEntries >= 0x10000)
this->TotalEntries = 0x10000 - 1;
@ -94,7 +104,11 @@ namespace SymbolResolver
for (Index = i + 1; Index < this->TotalEntries; Index++)
if (ElfSymbols[Index].st_value < ElfSymbols[MinimumIndex].st_value)
MinimumIndex = Index;
#if defined(a64)
Elf64_Sym tmp = ElfSymbols[MinimumIndex];
#elif defined(a32)
Elf32_Sym tmp = ElfSymbols[MinimumIndex];
#endif
ElfSymbols[MinimumIndex] = ElfSymbols[i];
ElfSymbols[i] = tmp;
}
@ -114,7 +128,7 @@ namespace SymbolResolver
}
trace("Symbol table loaded, %d entries (%ldKB)", this->TotalEntries, TO_KB(this->TotalEntries * sizeof(SymbolTable)));
for (uintptr_t i = 0, g = this->TotalEntries; i < g; i++)
for (int64_t i = 0, g = this->TotalEntries; i < g; i++)
{
this->SymTable[i].Address = ElfSymbols[i].st_value;
this->SymTable[i].FunctionName = &strtab[ElfSymbols[i].st_name];
@ -134,7 +148,11 @@ namespace SymbolResolver
this->Image = (void *)ImageAddress;
debug("Solving symbols for address: %#llx", ImageAddress);
#if defined(a64)
Elf64_Ehdr *Header = (Elf64_Ehdr *)ImageAddress;
#elif defined(a32)
Elf32_Ehdr *Header = (Elf32_Ehdr *)ImageAddress;
#endif
if (Header->e_ident[0] != 0x7F &&
Header->e_ident[1] != 'E' &&
Header->e_ident[2] != 'L' &&
@ -143,16 +161,26 @@ namespace SymbolResolver
error("Invalid ELF header");
return;
}
#if defined(a64)
Elf64_Shdr *ElfSections = (Elf64_Shdr *)(ImageAddress + Header->e_shoff);
Elf64_Sym *ElfSymbols = nullptr;
#elif defined(a32)
Elf32_Shdr *ElfSections = (Elf32_Shdr *)(ImageAddress + Header->e_shoff);
Elf32_Sym *ElfSymbols = nullptr;
#endif
char *strtab = nullptr;
for (uint16_t i = 0; i < Header->e_shnum; i++)
switch (ElfSections[i].sh_type)
{
case SHT_SYMTAB:
#if defined(a64)
ElfSymbols = (Elf64_Sym *)(ImageAddress + ElfSections[i].sh_offset);
this->TotalEntries = ElfSections[i].sh_size / sizeof(Elf64_Sym);
#elif defined(a32)
ElfSymbols = (Elf32_Sym *)(ImageAddress + ElfSections[i].sh_offset);
this->TotalEntries = ElfSections[i].sh_size / sizeof(Elf32_Sym);
#endif
if (this->TotalEntries >= 0x10000)
this->TotalEntries = 0x10000 - 1;
@ -182,7 +210,11 @@ namespace SymbolResolver
for (Index = i + 1; Index < this->TotalEntries; Index++)
if (ElfSymbols[Index].st_value < ElfSymbols[MinimumIndex].st_value)
MinimumIndex = Index;
#if defined(a64)
Elf64_Sym tmp = ElfSymbols[MinimumIndex];
#elif defined(a32)
Elf32_Sym tmp = ElfSymbols[MinimumIndex];
#endif
ElfSymbols[MinimumIndex] = ElfSymbols[i];
ElfSymbols[i] = tmp;
}
@ -194,7 +226,7 @@ namespace SymbolResolver
}
trace("Symbol table loaded, %d entries (%ldKB)", this->TotalEntries, TO_KB(this->TotalEntries * sizeof(SymbolTable)));
for (uintptr_t i = 0, g = this->TotalEntries; i < g; i++)
for (int64_t i = 0, g = this->TotalEntries; i < g; i++)
{
this->SymTable[i].Address = ElfSymbols[i].st_value;
this->SymTable[i].FunctionName = &strtab[ElfSymbols[i].st_name];