[nstool] Replaced _HEXDUMP_L macro with a method from fnd.

This commit is contained in:
jakcron 2018-08-14 15:25:33 +08:00
parent 456a821df4
commit f83c6ed044
5 changed files with 24 additions and 59 deletions

View file

@ -67,7 +67,6 @@ void CnmtProcess::importCnmt()
void CnmtProcess::displayCnmt() void CnmtProcess::displayCnmt()
{ {
#define _SPLIT_VER(ver) (uint32_t)((ver>>26) & 0x3f) << "." << (uint32_t)((ver>>20) & 0x3f) << "." << (uint32_t)((ver>>16) & 0xf) << "." << (uint32_t)(ver & 0xffff) #define _SPLIT_VER(ver) (uint32_t)((ver>>26) & 0x3f) << "." << (uint32_t)((ver>>20) & 0x3f) << "." << (uint32_t)((ver>>16) & 0xf) << "." << (uint32_t)(ver & 0xffff)
#define _HEXDUMP_L(var, len) do { for (size_t a__a__A = 0; a__a__A < len; a__a__A++) printf("%02x", var[a__a__A]); } while(0)
std::cout << "[ContentMeta]" << std::endl; std::cout << "[ContentMeta]" << std::endl;
std::cout << " TitleId: 0x" << std::hex << std::setw(16) << std::setfill('0') << mCnmt.getTitleId() << std::endl; std::cout << " TitleId: 0x" << std::hex << std::setw(16) << std::setfill('0') << mCnmt.getTitleId() << std::endl;
@ -109,13 +108,9 @@ void CnmtProcess::displayCnmt()
const nn::hac::ContentMetaBinary::ContentInfo& info = mCnmt.getContentInfo()[i]; const nn::hac::ContentMetaBinary::ContentInfo& info = mCnmt.getContentInfo()[i];
std::cout << " " << std::dec << i << std::endl; std::cout << " " << std::dec << i << std::endl;
std::cout << " Type: " << getContentTypeStr(info.type) << " (" << std::dec << info.type << ")" << std::endl; std::cout << " Type: " << getContentTypeStr(info.type) << " (" << std::dec << info.type << ")" << std::endl;
std::cout << " Id: "; std::cout << " Id: " << fnd::SimpleTextOutput::arrayToString(info.nca_id, nn::hac::cnmt::kContentIdLen, false, "") << std::endl;
_HEXDUMP_L(info.nca_id, nn::hac::cnmt::kContentIdLen);
std::cout << std::endl;
std::cout << " Size: 0x" << std::hex << info.size << std::endl; std::cout << " Size: 0x" << std::hex << info.size << std::endl;
std::cout << " Hash: "; std::cout << " Hash: " << fnd::SimpleTextOutput::arrayToString(info.hash.bytes, sizeof(info.hash), false, "") << std::endl;
_HEXDUMP_L(info.hash.bytes, sizeof(info.hash));
std::cout << std::endl;
} }
} }
if (mCnmt.getContentMetaInfo().size() > 0) if (mCnmt.getContentMetaInfo().size() > 0)
@ -134,11 +129,8 @@ void CnmtProcess::displayCnmt()
} }
} }
std::cout << " Digest: "; std::cout << " Digest: " << fnd::SimpleTextOutput::arrayToString(mCnmt.getDigest().data, nn::hac::cnmt::kDigestLen, false, "") << std::endl;
_HEXDUMP_L(mCnmt.getDigest().data, nn::hac::cnmt::kDigestLen);
std::cout << std::endl;
#undef _HEXDUMP_L
#undef _SPLIT_VER #undef _SPLIT_VER
} }

View file

@ -239,17 +239,14 @@ void NcaProcess::generateNcaBodyEncryptionKeys()
if (mBodyKeys.aes_ctr.isSet) if (mBodyKeys.aes_ctr.isSet)
{ {
std::cout << "[NCA Body Key]" << std::endl; std::cout << "[NCA Body Key]" << std::endl;
std::cout << " AES-CTR Key: "; std::cout << " AES-CTR Key: " << fnd::SimpleTextOutput::arrayToString(mBodyKeys.aes_ctr.var.key, sizeof(mBodyKeys.aes_ctr.var), true, "") << std::endl;
fnd::SimpleTextOutput::hexDump(mBodyKeys.aes_ctr.var.key, sizeof(mBodyKeys.aes_ctr.var));
} }
if (mBodyKeys.aes_xts.isSet) if (mBodyKeys.aes_xts.isSet)
{ {
std::cout << "[NCA Body Key]" << std::endl; std::cout << "[NCA Body Key]" << std::endl;
std::cout << " AES-XTS Key0: "; std::cout << " AES-XTS Key0: " << fnd::SimpleTextOutput::arrayToString(mBodyKeys.aes_xts.var.key[0], sizeof(mBodyKeys.aes_ctr.var), true, "") << std::endl;
fnd::SimpleTextOutput::hexDump(mBodyKeys.aes_xts.var.key[0], sizeof(mBodyKeys.aes_ctr.var)); std::cout << " AES-XTS Key1: " << fnd::SimpleTextOutput::arrayToString(mBodyKeys.aes_xts.var.key[1], sizeof(mBodyKeys.aes_ctr.var), true, "") << std::endl;
std::cout << " AES-XTS Key1: ";
fnd::SimpleTextOutput::hexDump(mBodyKeys.aes_xts.var.key[1], sizeof(mBodyKeys.aes_ctr.var));
} }
} }
@ -434,11 +431,9 @@ void NcaProcess::displayHeader()
#undef _SPLIT_VER #undef _SPLIT_VER
if (mHdr.hasRightsId()) if (mHdr.hasRightsId())
{ {
std::cout << " RightsId: "; std::cout << " RightsId: " << fnd::SimpleTextOutput::arrayToString(mHdr.getRightsId(), nn::hac::nca::kRightsIdLen, true, "") << std::endl;
fnd::SimpleTextOutput::hexDump(mHdr.getRightsId(), nn::hac::nca::kRightsIdLen);
} }
#define _HEXDUMP_L(var, len) do { for (size_t a__a__A = 0; a__a__A < len; a__a__A++) std::cout << std::hex << std::setw(2) << std::setfill('0') << (uint32_t)var[a__a__A]; } while(0)
if (mBodyKeys.keak_list.size() > 0 && _HAS_BIT(mCliOutputMode, OUTPUT_KEY_DATA)) if (mBodyKeys.keak_list.size() > 0 && _HAS_BIT(mCliOutputMode, OUTPUT_KEY_DATA))
{ {
std::cout << " Key Area:" << std::endl; std::cout << " Key Area:" << std::endl;
@ -449,12 +444,11 @@ void NcaProcess::displayHeader()
{ {
std::cout << " | " << std::dec << std::setw(3) << std::setfill(' ') << (uint32_t)mBodyKeys.keak_list[i].index << " | "; std::cout << " | " << std::dec << std::setw(3) << std::setfill(' ') << (uint32_t)mBodyKeys.keak_list[i].index << " | ";
_HEXDUMP_L(mBodyKeys.keak_list[i].enc.key, 16); std::cout << fnd::SimpleTextOutput::arrayToString(mBodyKeys.keak_list[i].enc.key, 16, false, "") << " | ";
std::cout << " | ";
if (mBodyKeys.keak_list[i].decrypted) if (mBodyKeys.keak_list[i].decrypted)
_HEXDUMP_L(mBodyKeys.keak_list[i].dec.key, 16); std::cout << fnd::SimpleTextOutput::arrayToString(mBodyKeys.keak_list[i].dec.key, 16, false, "");
else else
std::cout << "<unable to decrypt> "; std::cout << "<unable to decrypt> ";
@ -462,7 +456,6 @@ void NcaProcess::displayHeader()
} }
std::cout << " <--------------------------------------------------------------------------->" << std::endl; std::cout << " <--------------------------------------------------------------------------->" << std::endl;
} }
#undef _HEXDUMP_L
if (_HAS_BIT(mCliOutputMode, OUTPUT_LAYOUT)) if (_HAS_BIT(mCliOutputMode, OUTPUT_LAYOUT))
{ {
@ -480,10 +473,9 @@ void NcaProcess::displayHeader()
std::cout << " Enc. Type: " << getEncryptionTypeStr(info.enc_type) << std::endl; std::cout << " Enc. Type: " << getEncryptionTypeStr(info.enc_type) << std::endl;
if (info.enc_type == nn::hac::nca::CRYPT_AESCTR) if (info.enc_type == nn::hac::nca::CRYPT_AESCTR)
{ {
std::cout << " AES-CTR: ";
fnd::aes::sAesIvCtr ctr; fnd::aes::sAesIvCtr ctr;
fnd::aes::AesIncrementCounter(info.aes_ctr.iv, info.offset>>4, ctr.iv); fnd::aes::AesIncrementCounter(info.aes_ctr.iv, info.offset>>4, ctr.iv);
fnd::SimpleTextOutput::hexDump(ctr.iv, sizeof(fnd::aes::sAesIvCtr)); std::cout << " AES-CTR: " << fnd::SimpleTextOutput::arrayToString(ctr.iv, sizeof(fnd::aes::sAesIvCtr), true, "") << std::endl;
} }
if (info.hash_type == nn::hac::nca::HASH_HIERARCHICAL_INTERGRITY) if (info.hash_type == nn::hac::nca::HASH_HIERARCHICAL_INTERGRITY)
{ {
@ -503,16 +495,14 @@ void NcaProcess::displayHeader()
std::cout << " BlockSize: 0x" << std::hex << (uint32_t)hash_hdr.getDataLayer().block_size << std::endl; std::cout << " BlockSize: 0x" << std::hex << (uint32_t)hash_hdr.getDataLayer().block_size << std::endl;
for (size_t j = 0; j < hash_hdr.getMasterHashList().size(); j++) for (size_t j = 0; j < hash_hdr.getMasterHashList().size(); j++)
{ {
std::cout << " Master Hash " << std::dec << j << ": "; std::cout << " Master Hash " << std::dec << j << ": " << fnd::SimpleTextOutput::arrayToString(hash_hdr.getMasterHashList()[j].bytes, sizeof(fnd::sha::sSha256Hash), true, "") << std::endl;
fnd::SimpleTextOutput::hexDump(hash_hdr.getMasterHashList()[j].bytes, sizeof(fnd::sha::sSha256Hash));
} }
} }
else if (info.hash_type == nn::hac::nca::HASH_HIERARCHICAL_SHA256) else if (info.hash_type == nn::hac::nca::HASH_HIERARCHICAL_SHA256)
{ {
HashTreeMeta& hash_hdr = info.hash_tree_meta; HashTreeMeta& hash_hdr = info.hash_tree_meta;
std::cout << " HierarchicalSha256 Header:" << std::endl; std::cout << " HierarchicalSha256 Header:" << std::endl;
std::cout << " Master Hash: "; std::cout << " Master Hash: " << fnd::SimpleTextOutput::arrayToString(hash_hdr.getMasterHashList()[0].bytes, sizeof(fnd::sha::sSha256Hash), true, "") << std::endl;
fnd::SimpleTextOutput::hexDump(hash_hdr.getMasterHashList()[0].bytes, sizeof(fnd::sha::sSha256Hash));
std::cout << " HashBlockSize: 0x" << std::hex << (uint32_t)hash_hdr.getDataLayer().block_size << std::endl; std::cout << " HashBlockSize: 0x" << std::hex << (uint32_t)hash_hdr.getDataLayer().block_size << std::endl;
std::cout << " Hash Layer:" << std::endl; std::cout << " Hash Layer:" << std::endl;
std::cout << " Offset: 0x" << std::hex << (uint64_t)hash_hdr.getHashLayerInfo()[0].offset << std::endl; std::cout << " Offset: 0x" << std::hex << (uint64_t)hash_hdr.getHashLayerInfo()[0].offset << std::endl;

View file

@ -137,14 +137,9 @@ void NroProcess::importCodeSegments()
void NroProcess::displayHeader() void NroProcess::displayHeader()
{ {
#define _HEXDUMP_L(var, len) do { for (size_t a__a__A = 0; a__a__A < len; a__a__A++) std::cout << std::hex << std::setw(2) << std::setfill('0') << (uint32_t)var[a__a__A]; } while(0)
std::cout << "[NRO Header]" << std::endl; std::cout << "[NRO Header]" << std::endl;
std::cout << " RoCrt: "; std::cout << " RoCrt: " << fnd::SimpleTextOutput::arrayToString(mHdr.getRoCrt().data, nn::hac::nro::kRoCrtSize, false, "") << std::endl;
_HEXDUMP_L(mHdr.getRoCrt().data, nn::hac::nro::kRoCrtSize); std::cout << " ModuleId: " << fnd::SimpleTextOutput::arrayToString(mHdr.getModuleId().data, nn::hac::nro::kModuleIdSize, false, "") << std::endl;
std::cout << std::endl;
std::cout << " ModuleId: ";
_HEXDUMP_L(mHdr.getModuleId().data, nn::hac::nro::kModuleIdSize);
std::cout << std::endl;
std::cout << " NroSize: 0x" << std::hex << mHdr.getNroSize() << std::endl; std::cout << " NroSize: 0x" << std::hex << mHdr.getNroSize() << std::endl;
std::cout << " Program Sections:" << std::endl; std::cout << " Program Sections:" << std::endl;
std::cout << " .text:" << std::endl; std::cout << " .text:" << std::endl;
@ -170,8 +165,6 @@ void NroProcess::displayHeader()
std::cout << " Size: 0x" << std::hex << mHdr.getDataInfo().size << std::endl; std::cout << " Size: 0x" << std::hex << mHdr.getDataInfo().size << std::endl;
std::cout << " .bss:" << std::endl; std::cout << " .bss:" << std::endl;
std::cout << " Size: 0x" << std::hex << mHdr.getBssSize() << std::endl; std::cout << " Size: 0x" << std::hex << mHdr.getBssSize() << std::endl;
#undef _HEXDUMP_L
} }
void NroProcess::processRoMeta() void NroProcess::processRoMeta()

View file

@ -175,12 +175,8 @@ void NsoProcess::importCodeSegments()
void NsoProcess::displayNsoHeader() void NsoProcess::displayNsoHeader()
{ {
#define _HEXDUMP_L(var, len) do { for (size_t a__a__A = 0; a__a__A < len; a__a__A++) std::cout << std::hex << std::setw(2) << std::setfill('0') << (uint32_t)var[a__a__A]; } while(0)
std::cout << "[NSO Header]" << std::endl; std::cout << "[NSO Header]" << std::endl;
std::cout << " ModuleId: "; std::cout << " ModuleId: " << fnd::SimpleTextOutput::arrayToString(mHdr.getModuleId().data, nn::hac::nso::kModuleIdSize, false, "") << std::endl;
_HEXDUMP_L(mHdr.getModuleId().data, nn::hac::nso::kModuleIdSize);
std::cout << std::endl;
if (_HAS_BIT(mCliOutputMode, OUTPUT_LAYOUT)) if (_HAS_BIT(mCliOutputMode, OUTPUT_LAYOUT))
{ {
std::cout << " Program Segments:" << std::endl; std::cout << " Program Segments:" << std::endl;
@ -203,18 +199,14 @@ void NsoProcess::displayNsoHeader()
std::cout << " MemorySize: 0x" << std::hex << mHdr.getTextSegmentInfo().memory_layout.size << std::endl; std::cout << " MemorySize: 0x" << std::hex << mHdr.getTextSegmentInfo().memory_layout.size << std::endl;
if (mHdr.getTextSegmentInfo().is_hashed && _HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED)) if (mHdr.getTextSegmentInfo().is_hashed && _HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED))
{ {
std::cout << " Hash: "; std::cout << " Hash: " << fnd::SimpleTextOutput::arrayToString(mHdr.getTextSegmentInfo().hash.bytes, 32, false, "") << std::endl;
_HEXDUMP_L(mHdr.getTextSegmentInfo().hash.bytes, 32);
std::cout << std::endl;
} }
std::cout << " .ro:" << std::endl; std::cout << " .ro:" << std::endl;
std::cout << " MemoryOffset: 0x" << std::hex << mHdr.getRoSegmentInfo().memory_layout.offset << std::endl; std::cout << " MemoryOffset: 0x" << std::hex << mHdr.getRoSegmentInfo().memory_layout.offset << std::endl;
std::cout << " MemorySize: 0x" << std::hex << mHdr.getRoSegmentInfo().memory_layout.size << std::endl; std::cout << " MemorySize: 0x" << std::hex << mHdr.getRoSegmentInfo().memory_layout.size << std::endl;
if (mHdr.getRoSegmentInfo().is_hashed && _HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED)) if (mHdr.getRoSegmentInfo().is_hashed && _HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED))
{ {
std::cout << " Hash: "; std::cout << " Hash: " << fnd::SimpleTextOutput::arrayToString(mHdr.getRoSegmentInfo().hash.bytes, 32, false, "") << std::endl;
_HEXDUMP_L(mHdr.getRoSegmentInfo().hash.bytes, 32);
std::cout << std::endl;
} }
if (_HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED)) if (_HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED))
{ {
@ -234,13 +226,10 @@ void NsoProcess::displayNsoHeader()
std::cout << " MemorySize: 0x" << std::hex << mHdr.getDataSegmentInfo().memory_layout.size << std::endl; std::cout << " MemorySize: 0x" << std::hex << mHdr.getDataSegmentInfo().memory_layout.size << std::endl;
if (mHdr.getDataSegmentInfo().is_hashed && _HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED)) if (mHdr.getDataSegmentInfo().is_hashed && _HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED))
{ {
std::cout << " Hash: "; std::cout << " Hash: " << fnd::SimpleTextOutput::arrayToString(mHdr.getDataSegmentInfo().hash.bytes, 32, false, "") << std::endl;
_HEXDUMP_L(mHdr.getDataSegmentInfo().hash.bytes, 32);
std::cout << std::endl;
} }
std::cout << " .bss:" << std::endl; std::cout << " .bss:" << std::endl;
std::cout << " MemorySize: 0x" << std::hex << mHdr.getBssSize() << std::endl; std::cout << " MemorySize: 0x" << std::hex << mHdr.getBssSize() << std::endl;
#undef _HEXDUMP_L
} }
void NsoProcess::processRoMeta() void NsoProcess::processRoMeta()

View file

@ -121,12 +121,13 @@ void XciProcess::displayHeader()
std::cout << " KekIndex: " << std::dec << (uint32_t)mHdr.getKekIndex() << std::endl; std::cout << " KekIndex: " << std::dec << (uint32_t)mHdr.getKekIndex() << std::endl;
std::cout << " TitleKeyDecIndex: " << std::dec << (uint32_t)mHdr.getTitleKeyDecIndex() << std::endl; std::cout << " TitleKeyDecIndex: " << std::dec << (uint32_t)mHdr.getTitleKeyDecIndex() << std::endl;
std::cout << " Hash:" << std::endl; std::cout << " Hash:" << std::endl;
fnd::SimpleTextOutput::hexDump(mHdr.getInitialDataHash().bytes, sizeof(mHdr.getInitialDataHash().bytes), 0x10, 6); std::cout << " " << fnd::SimpleTextOutput::arrayToString(mHdr.getInitialDataHash().bytes, 0x10, true, "") << std::endl;
std::cout << " " << fnd::SimpleTextOutput::arrayToString(mHdr.getInitialDataHash().bytes+0x10, 0x10, true, "") << std::endl;
} }
if (_HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED)) if (_HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED))
{ {
std::cout << " Extended Header AES-IV:" << std::endl; std::cout << " Extended Header AES-IV:" << std::endl;
fnd::SimpleTextOutput::hexDump(mHdr.getAesCbcIv().iv, sizeof(mHdr.getAesCbcIv().iv), 0x10, 4); std::cout << " " << fnd::SimpleTextOutput::arrayToString(mHdr.getAesCbcIv().iv, sizeof(mHdr.getAesCbcIv().iv), true, "") << std::endl;
} }
std::cout << " SelSec: 0x" << std::hex << mHdr.getSelSec() << std::endl; std::cout << " SelSec: 0x" << std::hex << mHdr.getSelSec() << std::endl;
std::cout << " SelT1Key: 0x" << std::hex << mHdr.getSelT1Key() << std::endl; std::cout << " SelT1Key: 0x" << std::hex << mHdr.getSelT1Key() << std::endl;
@ -159,7 +160,8 @@ void XciProcess::displayHeader()
if (_HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED)) if (_HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED))
{ {
std::cout << " Hash:" << std::endl; std::cout << " Hash:" << std::endl;
fnd::SimpleTextOutput::hexDump(mHdr.getPartitionFsHash().bytes, sizeof(mHdr.getPartitionFsHash().bytes), 0x10, 6); std::cout << " " << fnd::SimpleTextOutput::arrayToString(mHdr.getPartitionFsHash().bytes, 0x10, true, "") << std::endl;
std::cout << " " << fnd::SimpleTextOutput::arrayToString(mHdr.getPartitionFsHash().bytes+0x10, 0x10, true, "") << std::endl;
} }
} }
@ -180,8 +182,7 @@ void XciProcess::displayHeader()
std::cout << " CUP Version: v" << std::dec << mHdr.getUppVersion() << " (" << _SPLIT_VER(mHdr.getUppVersion()) << ")" << std::endl; std::cout << " CUP Version: v" << std::dec << mHdr.getUppVersion() << " (" << _SPLIT_VER(mHdr.getUppVersion()) << ")" << std::endl;
#undef _SPLIT_VER #undef _SPLIT_VER
std::cout << " CUP TitleId: 0x" << std::hex << std::setw(16) << std::setfill('0') << mHdr.getUppId() << std::endl; std::cout << " CUP TitleId: 0x" << std::hex << std::setw(16) << std::setfill('0') << mHdr.getUppId() << std::endl;
std::cout << " Partition Hash: "; std::cout << " Partition Hash: " << fnd::SimpleTextOutput::arrayToString(mHdr.getUppHash(), 8, true, "") << std::endl;
fnd::SimpleTextOutput::hexDump(mHdr.getUppHash(), 8);
} }
} }