2009-09-17 13:06:04 +00:00
|
|
|
#include "symboltableentry.h"
|
|
|
|
#include "macho.h"
|
|
|
|
#include "machofile.h"
|
|
|
|
|
2016-11-19 16:23:39 +01:00
|
|
|
SymbolTableEntry::SymbolTableEntry(MachOFile& file, char* stringTable)
|
|
|
|
: file(file), stringTable(stringTable)
|
2009-09-17 13:06:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SymbolTableEntry::~SymbolTableEntry() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-11-19 16:23:39 +01:00
|
|
|
std::string SymbolTableEntry::getName(bool shouldDemangle) const {
|
|
|
|
const char *name = getInternalName();
|
|
|
|
std::string result = name;
|
|
|
|
if (shouldDemangle) {
|
|
|
|
int status = 0;
|
|
|
|
|
|
|
|
// Convert real name to readable string. +1 to skip the leading underscore.
|
|
|
|
char *realName = abi::__cxa_demangle(name + 1, nullptr, nullptr, &status);
|
|
|
|
if (realName != nullptr)
|
|
|
|
result = realName;
|
|
|
|
free(realName);
|
|
|
|
}
|
|
|
|
return result;
|
2009-09-17 13:06:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SymbolTableEntry::Type SymbolTableEntry::getType() const {
|
2016-11-19 16:23:39 +01:00
|
|
|
unsigned int type = getInternalType();
|
2009-09-17 13:06:04 +00:00
|
|
|
|
2016-11-19 16:23:39 +01:00
|
|
|
if (type & N_STAB) {
|
|
|
|
return TypeDebug;
|
|
|
|
}
|
|
|
|
if (type & N_PEXT) {
|
|
|
|
return TypePrivateExtern;
|
|
|
|
}
|
|
|
|
if (type & N_EXT) {
|
|
|
|
if ((type & N_TYPE) == N_UNDF)
|
|
|
|
return TypeImported;
|
2009-09-17 13:06:04 +00:00
|
|
|
else
|
2016-11-19 16:23:39 +01:00
|
|
|
return TypeExported;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return TypeLocal;
|
2009-09-17 13:06:04 +00:00
|
|
|
}
|