2018-06-19 10:37:27 +00:00
|
|
|
#include "ElfSymbolParser.h"
|
|
|
|
|
2021-09-30 11:42:15 +00:00
|
|
|
nstool::ElfSymbolParser::ElfSymbolParser() :
|
|
|
|
mModuleName("nstool::ElfSymbolParser"),
|
|
|
|
mSymbolList()
|
2018-06-19 10:37:27 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-09-28 11:15:54 +00:00
|
|
|
void nstool::ElfSymbolParser::operator=(const ElfSymbolParser& other)
|
2018-06-19 10:37:27 +00:00
|
|
|
{
|
2018-06-24 15:01:16 +00:00
|
|
|
mSymbolList = other.mSymbolList;
|
2018-06-19 10:37:27 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 11:15:54 +00:00
|
|
|
bool nstool::ElfSymbolParser::operator==(const ElfSymbolParser& other) const
|
2018-06-19 10:37:27 +00:00
|
|
|
{
|
2018-06-24 15:01:16 +00:00
|
|
|
return mSymbolList == other.mSymbolList;
|
2018-06-19 10:37:27 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 11:15:54 +00:00
|
|
|
bool nstool::ElfSymbolParser::operator!=(const ElfSymbolParser& other) const
|
2018-06-19 10:37:27 +00:00
|
|
|
{
|
2018-06-24 15:01:16 +00:00
|
|
|
return !(*this == other);
|
2018-06-19 10:37:27 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 11:15:54 +00:00
|
|
|
void nstool::ElfSymbolParser::parseData(const byte_t *dyn_sym, size_t dyn_sym_size, const byte_t *dyn_str, size_t dyn_str_size, bool is64Bit)
|
2018-06-19 10:37:27 +00:00
|
|
|
{
|
2021-09-30 11:42:15 +00:00
|
|
|
size_t dynSymSize = is64Bit ? sizeof(Elf64_Sym) : sizeof(Elf32_Sym);
|
2018-06-19 10:37:27 +00:00
|
|
|
|
|
|
|
sElfSymbol symbol;
|
|
|
|
for (size_t i = 0; i < dyn_sym_size; i += dynSymSize)
|
|
|
|
{
|
|
|
|
uint32_t name_pos;
|
|
|
|
|
|
|
|
if (is64Bit)
|
|
|
|
{
|
2021-09-30 11:42:15 +00:00
|
|
|
name_pos = tc::bn::detail::__le_uint32(((Elf64_Sym*)(dyn_sym + i))->st_name);
|
|
|
|
symbol.shn_index = tc::bn::detail::__le_uint16(((Elf64_Sym*)(dyn_sym + i))->st_shndx);
|
|
|
|
symbol.symbol_type = elf::get_elf_st_type(((Elf64_Sym*)(dyn_sym + i))->st_info);
|
|
|
|
symbol.symbol_binding = elf::get_elf_st_bind(((Elf64_Sym*)(dyn_sym + i))->st_info);
|
2018-06-19 10:37:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-09-30 11:42:15 +00:00
|
|
|
name_pos = tc::bn::detail::__le_uint32(((Elf32_Sym*)(dyn_sym + i))->st_name);
|
|
|
|
symbol.shn_index = tc::bn::detail::__le_uint16(((Elf32_Sym*)(dyn_sym + i))->st_shndx);
|
|
|
|
symbol.symbol_type = elf::get_elf_st_type(((Elf32_Sym*)(dyn_sym + i))->st_info);
|
|
|
|
symbol.symbol_binding = elf::get_elf_st_bind(((Elf32_Sym*)(dyn_sym + i))->st_info);
|
2018-09-06 13:12:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (name_pos >= dyn_str_size)
|
|
|
|
{
|
2021-09-30 11:42:15 +00:00
|
|
|
throw tc::Exception(mModuleName, "Out of bounds symbol name offset");
|
2018-06-19 10:37:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-09 08:43:40 +00:00
|
|
|
//for (; dyn_str[name_pos] == 0x00 && name_pos < dyn_str_size; name_pos++);
|
2018-06-19 10:37:27 +00:00
|
|
|
|
|
|
|
symbol.name = std::string((char*)&dyn_str[name_pos]);
|
2021-09-28 11:15:54 +00:00
|
|
|
mSymbolList.push_back(symbol);
|
2018-06-19 10:37:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-28 11:15:54 +00:00
|
|
|
const std::vector<nstool::ElfSymbolParser::sElfSymbol>& nstool::ElfSymbolParser::getSymbolList() const
|
2018-06-19 10:37:27 +00:00
|
|
|
{
|
|
|
|
return mSymbolList;
|
2018-06-24 15:01:16 +00:00
|
|
|
}
|