diff --git a/programs/nstool/source/DynamicSymbolParser.cpp b/programs/nstool/source/DynamicSymbolParser.cpp new file mode 100644 index 0000000..455173b --- /dev/null +++ b/programs/nstool/source/DynamicSymbolParser.cpp @@ -0,0 +1,70 @@ +#include "DynamicSymbolParser.h" + +DynamicSymbolParser::DynamicSymbolParser() +{ + mDynSymbolList.clear(); +} + +bool DynamicSymbolParser::operator==(const DynamicSymbolParser& other) const +{ + return isEqual(other); +} + +bool DynamicSymbolParser::operator!=(const DynamicSymbolParser& other) const +{ + return !isEqual(other); +} + +void DynamicSymbolParser::operator=(const DynamicSymbolParser& other) +{ + copyFrom(other); +} + +void DynamicSymbolParser::parseData(const byte_t *dyn_sym, size_t dyn_sym_size, const byte_t *dyn_str, size_t dyn_str_size, bool is64Bit) +{ + //printf("DynamicSymbolParser::parseData()"); + size_t dynSymSize = is64Bit ? sizeof(nx::sDynSymbol64Bit) : sizeof(nx::sDynSymbol32Bit); + + sDynSymbol symbol; + for (size_t i = 0; i < dyn_sym_size; i += dynSymSize) + { + //printf("pos %x\n", i); + + uint32_t name_pos; + + if (is64Bit) + { + name_pos = ((nx::sDynSymbol64Bit*)(dyn_sym + i))->name.get(); + symbol.shn_index = (nx::dynsym::SpecialSectionIndex)((nx::sDynSymbol64Bit*)(dyn_sym + i))->special_section_index.get(); + symbol.symbol_type = (nx::dynsym::SymbolType)((((nx::sDynSymbol64Bit*)(dyn_sym + i))->info) & nx::dynsym::STT_HIPROC); + } + else + { + name_pos = ((nx::sDynSymbol64Bit*)(dyn_sym + i))->name.get(); + symbol.shn_index = (nx::dynsym::SpecialSectionIndex)((nx::sDynSymbol32Bit*)(dyn_sym + i))->special_section_index.get(); + symbol.symbol_type = (nx::dynsym::SymbolType)((((nx::sDynSymbol32Bit*)(dyn_sym + i))->info.get()) & nx::dynsym::STT_HIPROC); + } + + for (; dyn_str[name_pos] == 0x00 && name_pos < dyn_str_size; name_pos++); + + //printf("name_pos = 0x%x\n", name_pos); + symbol.name = std::string((char*)&dyn_str[name_pos]); + mDynSymbolList.addElement(symbol); + } + //printf("DynamicSymbolParser::parseData() end\n"); +} + +const fnd::List& DynamicSymbolParser::getDynamicSymbolList() const +{ + return mDynSymbolList; +} + +bool DynamicSymbolParser::isEqual(const DynamicSymbolParser& other) const +{ + return mDynSymbolList == other.mDynSymbolList; +} + +void DynamicSymbolParser::copyFrom(const DynamicSymbolParser& other) +{ + mDynSymbolList = other.mDynSymbolList; +} diff --git a/programs/nstool/source/DynamicSymbolParser.h b/programs/nstool/source/DynamicSymbolParser.h new file mode 100644 index 0000000..46a77e9 --- /dev/null +++ b/programs/nstool/source/DynamicSymbolParser.h @@ -0,0 +1,49 @@ +#pragma once +#include +#include +#include + +class DynamicSymbolParser +{ +public: + struct sDynSymbol + { + nx::dynsym::SpecialSectionIndex shn_index; + nx::dynsym::SymbolType symbol_type; + std::string name; + + void operator=(const sDynSymbol& other) + { + shn_index = other.shn_index; + symbol_type = other.symbol_type; + name = other.name; + } + + bool operator==(const sDynSymbol& other) const + { + return (shn_index == other.shn_index && symbol_type == other.symbol_type && name == other.name); + } + + bool operator!=(const sDynSymbol& other) const + { + return !(*this == other); + } + }; + + DynamicSymbolParser(); + + bool operator==(const DynamicSymbolParser& other) const; + bool operator!=(const DynamicSymbolParser& other) const; + void operator=(const DynamicSymbolParser& other); + + void parseData(const byte_t *dyn_sym, size_t dyn_sym_size, const byte_t *dyn_str, size_t dyn_str_size, bool is64Bit); + + const fnd::List& getDynamicSymbolList() const; +private: + + // data + fnd::List mDynSymbolList; + + bool isEqual(const DynamicSymbolParser& other) const; + void copyFrom(const DynamicSymbolParser& other); +}; \ No newline at end of file