From f83c6ed04454589f8e49be0a9f347b8a971362b6 Mon Sep 17 00:00:00 2001 From: jakcron Date: Tue, 14 Aug 2018 15:25:33 +0800 Subject: [PATCH] [nstool] Replaced _HEXDUMP_L macro with a method from fnd. --- programs/nstool/source/CnmtProcess.cpp | 14 +++---------- programs/nstool/source/NcaProcess.cpp | 28 +++++++++----------------- programs/nstool/source/NroProcess.cpp | 11 ++-------- programs/nstool/source/NsoProcess.cpp | 19 ++++------------- programs/nstool/source/XciProcess.cpp | 11 +++++----- 5 files changed, 24 insertions(+), 59 deletions(-) diff --git a/programs/nstool/source/CnmtProcess.cpp b/programs/nstool/source/CnmtProcess.cpp index 1a8bc0a..f40caab 100644 --- a/programs/nstool/source/CnmtProcess.cpp +++ b/programs/nstool/source/CnmtProcess.cpp @@ -67,7 +67,6 @@ void CnmtProcess::importCnmt() 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 _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 << " 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]; std::cout << " " << std::dec << i << std::endl; std::cout << " Type: " << getContentTypeStr(info.type) << " (" << std::dec << info.type << ")" << std::endl; - std::cout << " Id: "; - _HEXDUMP_L(info.nca_id, nn::hac::cnmt::kContentIdLen); - std::cout << std::endl; + std::cout << " Id: " << fnd::SimpleTextOutput::arrayToString(info.nca_id, nn::hac::cnmt::kContentIdLen, false, "") << std::endl; std::cout << " Size: 0x" << std::hex << info.size << std::endl; - std::cout << " Hash: "; - _HEXDUMP_L(info.hash.bytes, sizeof(info.hash)); - std::cout << std::endl; + std::cout << " Hash: " << fnd::SimpleTextOutput::arrayToString(info.hash.bytes, sizeof(info.hash), false, "") << std::endl; } } if (mCnmt.getContentMetaInfo().size() > 0) @@ -134,11 +129,8 @@ void CnmtProcess::displayCnmt() } } - std::cout << " Digest: "; - _HEXDUMP_L(mCnmt.getDigest().data, nn::hac::cnmt::kDigestLen); - std::cout << std::endl; + std::cout << " Digest: " << fnd::SimpleTextOutput::arrayToString(mCnmt.getDigest().data, nn::hac::cnmt::kDigestLen, false, "") << std::endl; -#undef _HEXDUMP_L #undef _SPLIT_VER } diff --git a/programs/nstool/source/NcaProcess.cpp b/programs/nstool/source/NcaProcess.cpp index 1c98593..90de628 100644 --- a/programs/nstool/source/NcaProcess.cpp +++ b/programs/nstool/source/NcaProcess.cpp @@ -239,17 +239,14 @@ void NcaProcess::generateNcaBodyEncryptionKeys() if (mBodyKeys.aes_ctr.isSet) { std::cout << "[NCA Body Key]" << std::endl; - std::cout << " AES-CTR Key: "; - fnd::SimpleTextOutput::hexDump(mBodyKeys.aes_ctr.var.key, sizeof(mBodyKeys.aes_ctr.var)); + std::cout << " AES-CTR Key: " << fnd::SimpleTextOutput::arrayToString(mBodyKeys.aes_ctr.var.key, sizeof(mBodyKeys.aes_ctr.var), true, "") << std::endl; } if (mBodyKeys.aes_xts.isSet) { std::cout << "[NCA Body Key]" << std::endl; - std::cout << " AES-XTS Key0: "; - fnd::SimpleTextOutput::hexDump(mBodyKeys.aes_xts.var.key[0], sizeof(mBodyKeys.aes_ctr.var)); - std::cout << " AES-XTS Key1: "; - fnd::SimpleTextOutput::hexDump(mBodyKeys.aes_xts.var.key[1], sizeof(mBodyKeys.aes_ctr.var)); + std::cout << " AES-XTS Key0: " << fnd::SimpleTextOutput::arrayToString(mBodyKeys.aes_xts.var.key[0], sizeof(mBodyKeys.aes_ctr.var), true, "") << std::endl; + std::cout << " AES-XTS Key1: " << fnd::SimpleTextOutput::arrayToString(mBodyKeys.aes_xts.var.key[1], sizeof(mBodyKeys.aes_ctr.var), true, "") << std::endl; } } @@ -434,11 +431,9 @@ void NcaProcess::displayHeader() #undef _SPLIT_VER if (mHdr.hasRightsId()) { - std::cout << " RightsId: "; - fnd::SimpleTextOutput::hexDump(mHdr.getRightsId(), nn::hac::nca::kRightsIdLen); + std::cout << " RightsId: " << fnd::SimpleTextOutput::arrayToString(mHdr.getRightsId(), nn::hac::nca::kRightsIdLen, true, "") << std::endl; } -#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)) { 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 << " | "; - _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) - _HEXDUMP_L(mBodyKeys.keak_list[i].dec.key, 16); + std::cout << fnd::SimpleTextOutput::arrayToString(mBodyKeys.keak_list[i].dec.key, 16, false, ""); else std::cout << " "; @@ -462,7 +456,6 @@ void NcaProcess::displayHeader() } std::cout << " <--------------------------------------------------------------------------->" << std::endl; } -#undef _HEXDUMP_L if (_HAS_BIT(mCliOutputMode, OUTPUT_LAYOUT)) { @@ -480,10 +473,9 @@ void NcaProcess::displayHeader() std::cout << " Enc. Type: " << getEncryptionTypeStr(info.enc_type) << std::endl; if (info.enc_type == nn::hac::nca::CRYPT_AESCTR) { - std::cout << " AES-CTR: "; fnd::aes::sAesIvCtr ctr; 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) { @@ -503,16 +495,14 @@ void NcaProcess::displayHeader() 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++) { - std::cout << " Master Hash " << std::dec << j << ": "; - fnd::SimpleTextOutput::hexDump(hash_hdr.getMasterHashList()[j].bytes, sizeof(fnd::sha::sSha256Hash)); + std::cout << " Master Hash " << std::dec << j << ": " << fnd::SimpleTextOutput::arrayToString(hash_hdr.getMasterHashList()[j].bytes, sizeof(fnd::sha::sSha256Hash), true, "") << std::endl; } } else if (info.hash_type == nn::hac::nca::HASH_HIERARCHICAL_SHA256) { HashTreeMeta& hash_hdr = info.hash_tree_meta; std::cout << " HierarchicalSha256 Header:" << std::endl; - std::cout << " Master Hash: "; - fnd::SimpleTextOutput::hexDump(hash_hdr.getMasterHashList()[0].bytes, sizeof(fnd::sha::sSha256Hash)); + std::cout << " Master Hash: " << fnd::SimpleTextOutput::arrayToString(hash_hdr.getMasterHashList()[0].bytes, sizeof(fnd::sha::sSha256Hash), true, "") << 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 << " Offset: 0x" << std::hex << (uint64_t)hash_hdr.getHashLayerInfo()[0].offset << std::endl; diff --git a/programs/nstool/source/NroProcess.cpp b/programs/nstool/source/NroProcess.cpp index e9c73b3..577cc95 100644 --- a/programs/nstool/source/NroProcess.cpp +++ b/programs/nstool/source/NroProcess.cpp @@ -137,14 +137,9 @@ void NroProcess::importCodeSegments() 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 << " RoCrt: "; - _HEXDUMP_L(mHdr.getRoCrt().data, nn::hac::nro::kRoCrtSize); - std::cout << std::endl; - std::cout << " ModuleId: "; - _HEXDUMP_L(mHdr.getModuleId().data, nn::hac::nro::kModuleIdSize); - std::cout << std::endl; + std::cout << " RoCrt: " << fnd::SimpleTextOutput::arrayToString(mHdr.getRoCrt().data, nn::hac::nro::kRoCrtSize, false, "") << std::endl; + std::cout << " ModuleId: " << fnd::SimpleTextOutput::arrayToString(mHdr.getModuleId().data, nn::hac::nro::kModuleIdSize, false, "") << std::endl; std::cout << " NroSize: 0x" << std::hex << mHdr.getNroSize() << std::endl; std::cout << " Program Sections:" << 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 << " .bss:" << std::endl; std::cout << " Size: 0x" << std::hex << mHdr.getBssSize() << std::endl; - -#undef _HEXDUMP_L } void NroProcess::processRoMeta() diff --git a/programs/nstool/source/NsoProcess.cpp b/programs/nstool/source/NsoProcess.cpp index 9f40548..c99cd78 100644 --- a/programs/nstool/source/NsoProcess.cpp +++ b/programs/nstool/source/NsoProcess.cpp @@ -175,12 +175,8 @@ void NsoProcess::importCodeSegments() 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 << " ModuleId: "; - _HEXDUMP_L(mHdr.getModuleId().data, nn::hac::nso::kModuleIdSize); - std::cout << std::endl; + std::cout << " ModuleId: " << fnd::SimpleTextOutput::arrayToString(mHdr.getModuleId().data, nn::hac::nso::kModuleIdSize, false, "") << std::endl; if (_HAS_BIT(mCliOutputMode, OUTPUT_LAYOUT)) { 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; if (mHdr.getTextSegmentInfo().is_hashed && _HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED)) { - std::cout << " Hash: "; - _HEXDUMP_L(mHdr.getTextSegmentInfo().hash.bytes, 32); - std::cout << std::endl; + std::cout << " Hash: " << fnd::SimpleTextOutput::arrayToString(mHdr.getTextSegmentInfo().hash.bytes, 32, false, "") << std::endl; } std::cout << " .ro:" << 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; if (mHdr.getRoSegmentInfo().is_hashed && _HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED)) { - std::cout << " Hash: "; - _HEXDUMP_L(mHdr.getRoSegmentInfo().hash.bytes, 32); - std::cout << std::endl; + std::cout << " Hash: " << fnd::SimpleTextOutput::arrayToString(mHdr.getRoSegmentInfo().hash.bytes, 32, false, "") << std::endl; } 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; if (mHdr.getDataSegmentInfo().is_hashed && _HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED)) { - std::cout << " Hash: "; - _HEXDUMP_L(mHdr.getDataSegmentInfo().hash.bytes, 32); - std::cout << std::endl; + std::cout << " Hash: " << fnd::SimpleTextOutput::arrayToString(mHdr.getDataSegmentInfo().hash.bytes, 32, false, "") << std::endl; } std::cout << " .bss:" << std::endl; std::cout << " MemorySize: 0x" << std::hex << mHdr.getBssSize() << std::endl; -#undef _HEXDUMP_L } void NsoProcess::processRoMeta() diff --git a/programs/nstool/source/XciProcess.cpp b/programs/nstool/source/XciProcess.cpp index b752787..b535204 100644 --- a/programs/nstool/source/XciProcess.cpp +++ b/programs/nstool/source/XciProcess.cpp @@ -121,12 +121,13 @@ void XciProcess::displayHeader() std::cout << " KekIndex: " << std::dec << (uint32_t)mHdr.getKekIndex() << std::endl; std::cout << " TitleKeyDecIndex: " << std::dec << (uint32_t)mHdr.getTitleKeyDecIndex() << 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)) { 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 << " SelT1Key: 0x" << std::hex << mHdr.getSelT1Key() << std::endl; @@ -159,7 +160,8 @@ void XciProcess::displayHeader() if (_HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED)) { 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; #undef _SPLIT_VER std::cout << " CUP TitleId: 0x" << std::hex << std::setw(16) << std::setfill('0') << mHdr.getUppId() << std::endl; - std::cout << " Partition Hash: "; - fnd::SimpleTextOutput::hexDump(mHdr.getUppHash(), 8); + std::cout << " Partition Hash: " << fnd::SimpleTextOutput::arrayToString(mHdr.getUppHash(), 8, true, "") << std::endl; } }