2018-06-19 10:37:27 +00:00
|
|
|
#include <sstream>
|
2018-08-13 17:14:21 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
2018-06-19 10:37:27 +00:00
|
|
|
#include <fnd/types.h>
|
|
|
|
|
|
|
|
#include "RoMetadataProcess.h"
|
|
|
|
|
|
|
|
RoMetadataProcess::RoMetadataProcess() :
|
|
|
|
mCliOutputMode(_BIT(OUTPUT_BASIC)),
|
2018-08-07 07:17:51 +00:00
|
|
|
mInstructionType(nn::hac::npdm::INSTR_64BIT),
|
2018-06-19 10:37:27 +00:00
|
|
|
mListApi(false),
|
|
|
|
mListSymbols(false),
|
|
|
|
mApiInfo(),
|
|
|
|
mDynSym(),
|
|
|
|
mDynStr(),
|
|
|
|
mRoBlob(),
|
|
|
|
mSdkVerApiList(),
|
|
|
|
mPublicApiList(),
|
|
|
|
mDebugApiList(),
|
|
|
|
mPrivateApiList(),
|
|
|
|
mSymbolList()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void RoMetadataProcess::process()
|
|
|
|
{
|
|
|
|
importApiList();
|
2018-08-13 17:14:21 +00:00
|
|
|
|
2018-06-19 10:37:27 +00:00
|
|
|
if (_HAS_BIT(mCliOutputMode, OUTPUT_BASIC))
|
|
|
|
displayRoMetaData();
|
|
|
|
}
|
|
|
|
|
2018-06-24 15:01:16 +00:00
|
|
|
void RoMetadataProcess::setRoBinary(const fnd::Vec<byte_t>& bin)
|
2018-06-19 10:37:27 +00:00
|
|
|
{
|
|
|
|
mRoBlob = bin;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RoMetadataProcess::setApiInfo(size_t offset, size_t size)
|
|
|
|
{
|
|
|
|
mApiInfo.offset = offset;
|
|
|
|
mApiInfo.size = size;
|
|
|
|
}
|
|
|
|
void RoMetadataProcess::setDynSym(size_t offset, size_t size)
|
|
|
|
{
|
|
|
|
mDynSym.offset = offset;
|
|
|
|
mDynSym.size = size;
|
|
|
|
}
|
|
|
|
void RoMetadataProcess::setDynStr(size_t offset, size_t size)
|
|
|
|
{
|
|
|
|
mDynStr.offset = offset;
|
|
|
|
mDynStr.size = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RoMetadataProcess::setCliOutputMode(CliOutputMode type)
|
|
|
|
{
|
|
|
|
mCliOutputMode = type;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void RoMetadataProcess::setInstructionType(nn::hac::npdm::InstructionType type)
|
2018-06-19 10:37:27 +00:00
|
|
|
{
|
|
|
|
mInstructionType = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RoMetadataProcess::setListApi(bool listApi)
|
|
|
|
{
|
|
|
|
mListApi = listApi;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RoMetadataProcess::setListSymbols(bool listSymbols)
|
|
|
|
{
|
|
|
|
mListSymbols = listSymbols;
|
|
|
|
}
|
|
|
|
|
2018-07-10 15:13:19 +00:00
|
|
|
const std::vector<SdkApiString>& RoMetadataProcess::getSdkVerApiList() const
|
|
|
|
{
|
|
|
|
return mSdkVerApiList;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<SdkApiString>& RoMetadataProcess::getPublicApiList() const
|
|
|
|
{
|
|
|
|
return mPublicApiList;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<SdkApiString>& RoMetadataProcess::getDebugApiList() const
|
|
|
|
{
|
|
|
|
return mDebugApiList;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<SdkApiString>& RoMetadataProcess::getPrivateApiList() const
|
|
|
|
{
|
|
|
|
return mPrivateApiList;
|
|
|
|
}
|
|
|
|
|
|
|
|
const fnd::List<ElfSymbolParser::sElfSymbol>& RoMetadataProcess::getSymbolList() const
|
|
|
|
{
|
|
|
|
return mSymbolList.getSymbolList();
|
|
|
|
}
|
|
|
|
|
2018-06-19 10:37:27 +00:00
|
|
|
void RoMetadataProcess::importApiList()
|
|
|
|
{
|
2018-08-13 17:14:21 +00:00
|
|
|
if (mRoBlob.size() == 0)
|
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "No ro binary set.");
|
|
|
|
}
|
|
|
|
|
2018-06-19 10:37:27 +00:00
|
|
|
if (mApiInfo.size > 0)
|
|
|
|
{
|
2018-06-24 15:01:16 +00:00
|
|
|
std::stringstream list_stream(std::string((char*)mRoBlob.data() + mApiInfo.offset, mApiInfo.size));
|
2018-06-19 10:37:27 +00:00
|
|
|
std::string api_str;
|
|
|
|
|
|
|
|
while(std::getline(list_stream, api_str, (char)0x00))
|
|
|
|
{
|
|
|
|
SdkApiString api(api_str);
|
|
|
|
|
|
|
|
if (api.getApiType() == SdkApiString::API_SDK_VERSION)
|
|
|
|
mSdkVerApiList.push_back(api);
|
|
|
|
else if (api.getApiType() == SdkApiString::API_MIDDLEWARE)
|
|
|
|
mPublicApiList.push_back(api);
|
|
|
|
else if (api.getApiType() == SdkApiString::API_DEBUG)
|
|
|
|
mDebugApiList.push_back(api);
|
|
|
|
else if (api.getApiType() == SdkApiString::API_PRIVATE)
|
|
|
|
mPrivateApiList.push_back(api);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDynSym.size > 0)
|
|
|
|
{
|
2018-08-07 07:17:51 +00:00
|
|
|
mSymbolList.parseData(mRoBlob.data() + mDynSym.offset, mDynSym.size, mRoBlob.data() + mDynStr.offset, mDynStr.size, mInstructionType == nn::hac::npdm::INSTR_64BIT);
|
2018-06-19 10:37:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RoMetadataProcess::displayRoMetaData()
|
|
|
|
{
|
|
|
|
size_t api_num = mSdkVerApiList.size() + mPublicApiList.size() + mDebugApiList.size() + mPrivateApiList.size();
|
|
|
|
|
|
|
|
if (api_num > 0 && (mListApi || _HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED)))
|
|
|
|
{
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << "[SDK API List]" << std::endl;
|
2018-06-19 10:37:27 +00:00
|
|
|
if (mSdkVerApiList.size() > 0)
|
|
|
|
{
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << " Sdk Revision: " << mSdkVerApiList[0].getModuleName() << std::endl;
|
2018-06-19 10:37:27 +00:00
|
|
|
}
|
|
|
|
if (mPublicApiList.size() > 0)
|
|
|
|
{
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << " Public APIs:" << std::endl;
|
2018-06-19 10:37:27 +00:00
|
|
|
for (size_t i = 0; i < mPublicApiList.size(); i++)
|
|
|
|
{
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << " " << mPublicApiList[i].getModuleName() << " (vender: " << mPublicApiList[i].getVenderName() << ")" << std::endl;
|
2018-06-19 10:37:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mDebugApiList.size() > 0)
|
|
|
|
{
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << " Debug APIs:" << std::endl;
|
2018-06-19 10:37:27 +00:00
|
|
|
for (size_t i = 0; i < mDebugApiList.size(); i++)
|
|
|
|
{
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << " " << mDebugApiList[i].getModuleName() << " (vender: " << mDebugApiList[i].getVenderName() << ")" << std::endl;
|
2018-06-19 10:37:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mPrivateApiList.size() > 0)
|
|
|
|
{
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << " Private APIs:" << std::endl;
|
2018-06-19 10:37:27 +00:00
|
|
|
for (size_t i = 0; i < mPrivateApiList.size(); i++)
|
|
|
|
{
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << " " << mPrivateApiList[i].getModuleName() << " (vender: " << mPrivateApiList[i].getVenderName() << ")" << std::endl;
|
2018-06-19 10:37:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-06-24 15:01:16 +00:00
|
|
|
if (mSymbolList.getSymbolList().size() > 0 && (mListSymbols || _HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED)))
|
2018-06-19 10:37:27 +00:00
|
|
|
{
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << "[Symbol List]" << std::endl;
|
2018-06-24 15:01:16 +00:00
|
|
|
for (size_t i = 0; i < mSymbolList.getSymbolList().size(); i++)
|
2018-06-19 10:37:27 +00:00
|
|
|
{
|
|
|
|
const ElfSymbolParser::sElfSymbol& symbol = mSymbolList.getSymbolList()[i];
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << " " << symbol.name << " [SHN=" << getSectionIndexStr(symbol.shn_index) << " (" << std::hex << std::setw(4) << std::setfill('0') << symbol.shn_index << ")][STT=" << getSymbolTypeStr(symbol.symbol_type) << "][STB=" << getSymbolBindingStr(symbol.symbol_binding) << "]" << std::endl;
|
2018-06-19 10:37:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-06 13:12:15 +00:00
|
|
|
const char* RoMetadataProcess::getSectionIndexStr(uint16_t shn_index) const
|
2018-06-19 10:37:27 +00:00
|
|
|
{
|
|
|
|
const char* str;
|
|
|
|
switch (shn_index)
|
|
|
|
{
|
2018-09-06 13:12:15 +00:00
|
|
|
case (fnd::elf::SHN_UNDEF):
|
2018-06-19 10:37:27 +00:00
|
|
|
str = "UNDEF";
|
|
|
|
break;
|
2018-09-06 13:12:15 +00:00
|
|
|
case (fnd::elf::SHN_LOPROC):
|
2018-06-19 10:37:27 +00:00
|
|
|
str = "LOPROC";
|
|
|
|
break;
|
2018-09-06 13:12:15 +00:00
|
|
|
case (fnd::elf::SHN_HIPROC):
|
2018-06-19 10:37:27 +00:00
|
|
|
str = "HIPROC";
|
|
|
|
break;
|
2018-09-06 13:12:15 +00:00
|
|
|
case (fnd::elf::SHN_LOOS):
|
2018-06-19 10:37:27 +00:00
|
|
|
str = "LOOS";
|
|
|
|
break;
|
2018-09-06 13:12:15 +00:00
|
|
|
case (fnd::elf::SHN_HIOS):
|
2018-06-19 10:37:27 +00:00
|
|
|
str = "HIOS";
|
|
|
|
break;
|
2018-09-06 13:12:15 +00:00
|
|
|
case (fnd::elf::SHN_ABS):
|
2018-06-19 10:37:27 +00:00
|
|
|
str = "ABS";
|
|
|
|
break;
|
2018-09-06 13:12:15 +00:00
|
|
|
case (fnd::elf::SHN_COMMON):
|
2018-06-19 10:37:27 +00:00
|
|
|
str = "COMMON";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
str = "UNKNOWN";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2018-09-06 13:12:15 +00:00
|
|
|
const char* RoMetadataProcess::getSymbolTypeStr(byte_t symbol_type) const
|
2018-06-19 10:37:27 +00:00
|
|
|
{
|
|
|
|
const char* str;
|
|
|
|
switch (symbol_type)
|
|
|
|
{
|
2018-09-06 13:12:15 +00:00
|
|
|
case (fnd::elf::STT_NOTYPE):
|
2018-06-19 10:37:27 +00:00
|
|
|
str = "NOTYPE";
|
|
|
|
break;
|
2018-09-06 13:12:15 +00:00
|
|
|
case (fnd::elf::STT_OBJECT):
|
2018-06-19 10:37:27 +00:00
|
|
|
str = "OBJECT";
|
|
|
|
break;
|
2018-09-06 13:12:15 +00:00
|
|
|
case (fnd::elf::STT_FUNC):
|
2018-06-19 10:37:27 +00:00
|
|
|
str = "FUNC";
|
|
|
|
break;
|
2018-09-06 13:12:15 +00:00
|
|
|
case (fnd::elf::STT_SECTION):
|
2018-06-19 10:37:27 +00:00
|
|
|
str = "SECTION";
|
|
|
|
break;
|
2018-09-06 13:12:15 +00:00
|
|
|
case (fnd::elf::STT_FILE):
|
2018-06-19 10:37:27 +00:00
|
|
|
str = "FILE";
|
|
|
|
break;
|
2018-09-06 13:12:15 +00:00
|
|
|
case (fnd::elf::STT_LOOS):
|
2018-06-19 10:37:27 +00:00
|
|
|
str = "LOOS";
|
|
|
|
break;
|
2018-09-06 13:12:15 +00:00
|
|
|
case (fnd::elf::STT_HIOS):
|
2018-06-19 10:37:27 +00:00
|
|
|
str = "HIOS";
|
|
|
|
break;
|
2018-09-06 13:12:15 +00:00
|
|
|
case (fnd::elf::STT_LOPROC):
|
2018-06-19 10:37:27 +00:00
|
|
|
str = "LOPROC";
|
|
|
|
break;
|
2018-09-06 13:12:15 +00:00
|
|
|
case (fnd::elf::STT_HIPROC):
|
2018-06-19 10:37:27 +00:00
|
|
|
str = "HIPROC";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
str = "UNKNOWN";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2018-09-06 13:12:15 +00:00
|
|
|
const char* RoMetadataProcess::getSymbolBindingStr(byte_t symbol_binding) const
|
2018-06-19 10:37:27 +00:00
|
|
|
{
|
|
|
|
const char* str;
|
|
|
|
switch (symbol_binding)
|
|
|
|
{
|
2018-09-06 13:12:15 +00:00
|
|
|
case (fnd::elf::STB_LOCAL):
|
2018-06-19 10:37:27 +00:00
|
|
|
str = "LOCAL";
|
|
|
|
break;
|
2018-09-06 13:12:15 +00:00
|
|
|
case (fnd::elf::STB_GLOBAL):
|
2018-06-19 10:37:27 +00:00
|
|
|
str = "GLOBAL";
|
|
|
|
break;
|
2018-09-06 13:12:15 +00:00
|
|
|
case (fnd::elf::STB_WEAK):
|
2018-06-19 10:37:27 +00:00
|
|
|
str = "WEAK";
|
|
|
|
break;
|
2018-09-06 13:12:15 +00:00
|
|
|
case (fnd::elf::STB_LOOS):
|
2018-06-19 10:37:27 +00:00
|
|
|
str = "LOOS";
|
|
|
|
break;
|
2018-09-06 13:12:15 +00:00
|
|
|
case (fnd::elf::STB_HIOS):
|
2018-06-19 10:37:27 +00:00
|
|
|
str = "HIOS";
|
|
|
|
break;
|
2018-09-06 13:12:15 +00:00
|
|
|
case (fnd::elf::STB_LOPROC):
|
2018-06-19 10:37:27 +00:00
|
|
|
str = "LOPROC";
|
|
|
|
break;
|
2018-09-06 13:12:15 +00:00
|
|
|
case (fnd::elf::STB_HIPROC):
|
2018-06-19 10:37:27 +00:00
|
|
|
str = "HIPROC";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
str = "UNKNOWN";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|