mirror of
https://github.com/jakcron/nstool
synced 2024-11-15 02:06:40 +00:00
[nstool] Add DynamicSymbolParser.
This commit is contained in:
parent
d165243231
commit
caeea8f119
2 changed files with 119 additions and 0 deletions
70
programs/nstool/source/DynamicSymbolParser.cpp
Normal file
70
programs/nstool/source/DynamicSymbolParser.cpp
Normal file
|
@ -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::sDynSymbol>& 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;
|
||||
}
|
49
programs/nstool/source/DynamicSymbolParser.h
Normal file
49
programs/nstool/source/DynamicSymbolParser.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
#include <fnd/List.h>
|
||||
#include <nx/dynamic_symbol.h>
|
||||
|
||||
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<sDynSymbol>& getDynamicSymbolList() const;
|
||||
private:
|
||||
|
||||
// data
|
||||
fnd::List<sDynSymbol> mDynSymbolList;
|
||||
|
||||
bool isEqual(const DynamicSymbolParser& other) const;
|
||||
void copyFrom(const DynamicSymbolParser& other);
|
||||
};
|
Loading…
Reference in a new issue