mirror of
https://github.com/jakcron/nstool
synced 2024-11-14 01:36:41 +00:00
[nx|nstool] Silence format warnings. Cleanup string resource processing.
This commit is contained in:
parent
8b37665be6
commit
76ce22dc69
12 changed files with 314 additions and 162 deletions
|
@ -62,7 +62,7 @@ void crypto::aes::AesIncrementCounter(const uint8_t in[kAesBlockSize], size_t bl
|
|||
uint64_t total = ctr[i] + block_num;
|
||||
// if there wasn't a wrap around, add the two together and exit
|
||||
if (total <= 0xffffffff) {
|
||||
ctr[i] += block_num;
|
||||
ctr[i] += (uint32_t)block_num;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ std::u16string StringConv::ConvertChar8ToChar16(const std::string & in)
|
|||
throw std::logic_error("not a UTF-8 string");
|
||||
}
|
||||
|
||||
uni <= 6;
|
||||
uni <<= 6;
|
||||
uni |= get_utf8_data(1, in[i + j]);
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ std::u16string StringConv::ConvertChar8ToChar16(const std::string & in)
|
|||
char32_t uni = unicode[i];
|
||||
if (uni < kUtf16NonNativeStart)
|
||||
{
|
||||
utf16.push_back(uni);
|
||||
utf16.push_back((char16_t)uni);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -117,25 +117,25 @@ std::string StringConv::ConvertChar16ToChar8(const std::u16string & in)
|
|||
{
|
||||
if (unicode[i] <= kUtf8AsciiEnd)
|
||||
{
|
||||
utf8.push_back(unicode[i]);
|
||||
utf8.push_back((char)unicode[i]);
|
||||
}
|
||||
else if (unicode[i] <= kUtf82ByteEnd)
|
||||
{
|
||||
utf8.push_back(make_utf8(2, (unicode[i] >> 6)));
|
||||
utf8.push_back(make_utf8(1, (unicode[i] >> 0)));
|
||||
utf8.push_back(make_utf8(2, (uint8_t)(unicode[i] >> 6)));
|
||||
utf8.push_back(make_utf8(1, (uint8_t)(unicode[i] >> 0)));
|
||||
}
|
||||
else if (unicode[i] <= kUtf83ByteEnd)
|
||||
{
|
||||
utf8.push_back(make_utf8(3, (unicode[i] >> 12)));
|
||||
utf8.push_back(make_utf8(1, (unicode[i] >> 6)));
|
||||
utf8.push_back(make_utf8(1, (unicode[i] >> 0)));
|
||||
utf8.push_back(make_utf8(3, (uint8_t)(unicode[i] >> 12)));
|
||||
utf8.push_back(make_utf8(1, (uint8_t)(unicode[i] >> 6)));
|
||||
utf8.push_back(make_utf8(1, (uint8_t)(unicode[i] >> 0)));
|
||||
}
|
||||
else if (unicode[i] <= kUtf84ByteEnd)
|
||||
{
|
||||
utf8.push_back(make_utf8(4, (unicode[i] >> 18)));
|
||||
utf8.push_back(make_utf8(1, (unicode[i] >> 12)));
|
||||
utf8.push_back(make_utf8(1, (unicode[i] >> 6)));
|
||||
utf8.push_back(make_utf8(1, (unicode[i] >> 0)));
|
||||
utf8.push_back(make_utf8(4, (uint8_t)(unicode[i] >> 18)));
|
||||
utf8.push_back(make_utf8(1, (uint8_t)(unicode[i] >> 12)));
|
||||
utf8.push_back(make_utf8(1, (uint8_t)(unicode[i] >> 6)));
|
||||
utf8.push_back(make_utf8(1, (uint8_t)(unicode[i] >> 0)));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -106,12 +106,12 @@ void AciHeader::exportBinary()
|
|||
|
||||
// set offset/size
|
||||
calculateSectionOffsets();
|
||||
hdr->fac.offset = mFac.offset;
|
||||
hdr->fac.size = mFac.size;
|
||||
hdr->sac.offset = mSac.offset;
|
||||
hdr->sac.size = mSac.size;
|
||||
hdr->kc.offset = mKc.offset;
|
||||
hdr->kc.size = mKc.size;
|
||||
hdr->fac.offset = (uint32_t)mFac.offset;
|
||||
hdr->fac.size = (uint32_t)mFac.size;
|
||||
hdr->sac.offset = (uint32_t)mSac.offset;
|
||||
hdr->sac.size = (uint32_t)mSac.size;
|
||||
hdr->kc.offset = (uint32_t)mKc.offset;
|
||||
hdr->kc.size = (uint32_t)mKc.size;
|
||||
|
||||
uint32_t flags = 0;
|
||||
if (mIsProduction)
|
||||
|
@ -129,7 +129,7 @@ void AciHeader::exportBinary()
|
|||
else if (mType == TYPE_ACID)
|
||||
{
|
||||
mAcidSize = getAciSize();
|
||||
hdr->size = mAcidSize;
|
||||
hdr->size = (uint32_t)mAcidSize;
|
||||
hdr->program_id_info.program_id_restrict.min = mProgramIdMin;
|
||||
hdr->program_id_info.program_id_restrict.max = mProgramIdMax;
|
||||
}
|
||||
|
|
|
@ -64,10 +64,10 @@ void nx::FacHeader::exportBinary()
|
|||
hdr->fac_flags = (flag);
|
||||
|
||||
calculateOffsets();
|
||||
hdr->content_owner_ids.start = (mContentOwnerIdPos.offset);
|
||||
hdr->content_owner_ids.end = (mContentOwnerIdPos.offset + mContentOwnerIdPos.size);
|
||||
hdr->save_data_owner_ids.start = (mSaveDataOwnerIdPos.offset);
|
||||
hdr->save_data_owner_ids.end = (mSaveDataOwnerIdPos.offset + mSaveDataOwnerIdPos.size);
|
||||
hdr->content_owner_ids.start = (uint32_t)(mContentOwnerIdPos.offset);
|
||||
hdr->content_owner_ids.end = (uint32_t)(mContentOwnerIdPos.offset + mContentOwnerIdPos.size);
|
||||
hdr->save_data_owner_ids.start = (uint32_t)(mSaveDataOwnerIdPos.offset);
|
||||
hdr->save_data_owner_ids.end = (uint32_t)(mSaveDataOwnerIdPos.offset + mSaveDataOwnerIdPos.size);
|
||||
}
|
||||
|
||||
void nx::FacHeader::importBinary(const byte_t * bytes, size_t len)
|
||||
|
|
|
@ -273,7 +273,7 @@ uint64_t NcaHeader::blockNumToSize(uint32_t block_num) const
|
|||
|
||||
uint32_t NcaHeader::sizeToBlockNum(uint64_t real_size) const
|
||||
{
|
||||
return align(real_size, nca::kSectorSize) / nca::kSectorSize;
|
||||
return (uint32_t)(align(real_size, nca::kSectorSize) / nca::kSectorSize);
|
||||
}
|
||||
|
||||
bool NcaHeader::isEqual(const NcaHeader & other) const
|
||||
|
|
|
@ -99,10 +99,10 @@ void nx::NpdmHeader::exportBinary()
|
|||
strncpy(hdr->product_code, mProductCode.c_str(), npdm::kProductCodeMaxLen);
|
||||
|
||||
calculateOffsets();
|
||||
hdr->aci.offset = mAciPos.offset;
|
||||
hdr->aci.size = mAciPos.size;
|
||||
hdr->acid.offset = mAcidPos.offset;
|
||||
hdr->acid.size = mAcidPos.size;
|
||||
hdr->aci.offset = (uint32_t)mAciPos.offset;
|
||||
hdr->aci.size = (uint32_t)mAciPos.size;
|
||||
hdr->acid.offset = (uint32_t)mAcidPos.offset;
|
||||
hdr->acid.size = (uint32_t)mAcidPos.size;
|
||||
}
|
||||
|
||||
void nx::NpdmHeader::importBinary(const byte_t * bytes, size_t len)
|
||||
|
|
|
@ -44,8 +44,8 @@ void nx::PfsHeader::exportBinary()
|
|||
break;
|
||||
}
|
||||
|
||||
hdr->file_num = mFileList.getSize();
|
||||
hdr->name_table_size = name_table_size;
|
||||
hdr->file_num = (uint32_t)mFileList.getSize();
|
||||
hdr->name_table_size = (uint32_t)name_table_size;
|
||||
|
||||
// set file entries
|
||||
if (mFsType == TYPE_PFS0)
|
||||
|
@ -59,10 +59,10 @@ void nx::PfsHeader::exportBinary()
|
|||
{
|
||||
raw_files[i].data_offset = (mFileList[i].offset - pfs_header_size);
|
||||
raw_files[i].size = mFileList[i].size;
|
||||
raw_files[i].name_offset = raw_name_table_pos;
|
||||
raw_files[i].name_offset = (uint32_t)raw_name_table_pos;
|
||||
|
||||
strcpy(raw_name_table + raw_name_table_pos, mFileList[i].name.c_str());
|
||||
raw_name_table_pos += mFileList[i].name.length() + 1;
|
||||
raw_name_table_pos += (uint32_t)(mFileList[i].name.length() + 1);
|
||||
}
|
||||
}
|
||||
else if (mFsType == TYPE_HFS0)
|
||||
|
@ -76,8 +76,8 @@ void nx::PfsHeader::exportBinary()
|
|||
{
|
||||
raw_files[i].data_offset = (mFileList[i].offset - pfs_header_size);
|
||||
raw_files[i].size = mFileList[i].size;
|
||||
raw_files[i].name_offset = raw_name_table_pos;
|
||||
raw_files[i].hash_protected_size = mFileList[i].hash_protected_size;
|
||||
raw_files[i].name_offset = (uint32_t)raw_name_table_pos;
|
||||
raw_files[i].hash_protected_size = (uint32_t)mFileList[i].hash_protected_size;
|
||||
raw_files[i].hash = mFileList[i].hash;
|
||||
|
||||
strcpy(raw_name_table + raw_name_table_pos, mFileList[i].name.c_str());
|
||||
|
|
|
@ -56,7 +56,7 @@ void nx::SystemCallHandler::exportKernelCapabilityList(fnd::List<KernelCapabilit
|
|||
fnd::List<SystemCallEntry> entries;
|
||||
for (size_t i = 0; i < kSyscallTotalEntryNum; i++)
|
||||
{
|
||||
entries[i].setSystemCallUpperBits(i);
|
||||
entries[i].setSystemCallUpperBits((uint32_t)i);
|
||||
entries[i].setSystemCallLowerBits(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,11 +31,6 @@ const std::string kContentMetaTypeStr[2][0x80] =
|
|||
}
|
||||
};
|
||||
|
||||
inline const std::string& getContentMetaTypeStr(byte_t index)
|
||||
{
|
||||
return (index < 0x80) ? kContentMetaTypeStr[0][index] : kContentMetaTypeStr[1][index-0x80];
|
||||
}
|
||||
|
||||
const std::string kUpdateTypeStr[3] =
|
||||
{
|
||||
"ApplyAsDelta",
|
||||
|
@ -49,43 +44,58 @@ const std::string kContentMetaAttrStr[3] =
|
|||
"Rebootless"
|
||||
};
|
||||
|
||||
|
||||
std::string kUnknownStr = "Unknown";
|
||||
|
||||
inline const char* getBoolStr(bool isTrue)
|
||||
{
|
||||
return isTrue? "TRUE" : "FALSE";
|
||||
}
|
||||
|
||||
inline const char* getContentTypeStr(byte_t i)
|
||||
{
|
||||
return i < 7 ? kContentTypeStr[i].c_str() : kUnknownStr.c_str();
|
||||
}
|
||||
|
||||
inline const char* getContentMetaTypeStr(byte_t i)
|
||||
{
|
||||
return (i < 0x80) ? kContentMetaTypeStr[0][i].c_str() : kContentMetaTypeStr[1][i - 0x80].c_str();
|
||||
}
|
||||
|
||||
void CnmtProcess::displayCmnt()
|
||||
{
|
||||
#define _SPLIT_VER(ver) ( (ver>>26) & 0x3f), ( (ver>>20) & 0x3f), ( (ver>>16) & 0xf), (ver & 0xffff)
|
||||
#define _HEXDUMP_U(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)
|
||||
#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)
|
||||
|
||||
printf("[ContentMeta]\n");
|
||||
printf(" TitleId: 0x%016" PRIx64 "\n", mCnmt.getTitleId());
|
||||
printf(" Version: v%" PRId32 " (%d.%d.%d.%d)\n", mCnmt.getTitleVersion(), _SPLIT_VER(mCnmt.getTitleVersion()));
|
||||
printf(" Type: %s (%d)\n", getContentMetaTypeStr(mCnmt.getType()).c_str(), mCnmt.getType());
|
||||
printf(" TitleId: 0x%016" PRIx64 "\n", (uint64_t)mCnmt.getTitleId());
|
||||
printf(" Version: v%" PRId32 " (%d.%d.%d.%d)\n", (uint32_t)mCnmt.getTitleVersion(), _SPLIT_VER(mCnmt.getTitleVersion()));
|
||||
printf(" Type: %s (%d)\n", getContentMetaTypeStr(mCnmt.getType()), mCnmt.getType());
|
||||
printf(" Attributes: %x\n", mCnmt.getAttributes());
|
||||
printf(" IncludesExFatDriver: %s\n", getBoolStr(_HAS_BIT(mCnmt.getAttributes(), nx::cnmt::ATTRIBUTE_INCLUDES_EX_FAT_DRIVER)));
|
||||
printf(" Rebootless: %s\n", getBoolStr(_HAS_BIT(mCnmt.getAttributes(), nx::cnmt::ATTRIBUTE_REBOOTLESS)));
|
||||
printf(" RequiredDownloadSystemVersion: v%" PRId32 " (%d.%d.%d.%d)\n", mCnmt.getRequiredDownloadSystemVersion(), _SPLIT_VER(mCnmt.getRequiredDownloadSystemVersion()));
|
||||
printf(" RequiredDownloadSystemVersion: v%" PRId32 " (%d.%d.%d.%d)\n", (uint32_t)mCnmt.getRequiredDownloadSystemVersion(), _SPLIT_VER(mCnmt.getRequiredDownloadSystemVersion()));
|
||||
switch(mCnmt.getType())
|
||||
{
|
||||
case (nx::cnmt::METATYPE_APPLICATION):
|
||||
printf(" ApplicationExtendedHeader:\n");
|
||||
printf(" RequiredSystemVersion: v%" PRId32 " (%d.%d.%d.%d)\n", mCnmt.getApplicationMetaExtendedHeader().required_system_version, _SPLIT_VER(mCnmt.getApplicationMetaExtendedHeader().required_system_version));
|
||||
printf(" PatchId: 0x%016" PRIx64 "\n", mCnmt.getApplicationMetaExtendedHeader().patch_id);
|
||||
printf(" RequiredSystemVersion: v%" PRId32 " (%d.%d.%d.%d)\n", (uint32_t)mCnmt.getApplicationMetaExtendedHeader().required_system_version, _SPLIT_VER(mCnmt.getApplicationMetaExtendedHeader().required_system_version));
|
||||
printf(" PatchId: 0x%016" PRIx64 "\n", (uint64_t)mCnmt.getApplicationMetaExtendedHeader().patch_id);
|
||||
break;
|
||||
case (nx::cnmt::METATYPE_PATCH):
|
||||
printf(" PatchMetaExtendedHeader:\n");
|
||||
printf(" RequiredSystemVersion: v%" PRId32 " (%d.%d.%d.%d))\n", mCnmt.getPatchMetaExtendedHeader().required_system_version, _SPLIT_VER(mCnmt.getPatchMetaExtendedHeader().required_system_version));
|
||||
printf(" ApplicationId: 0x%016" PRIx64 "\n", mCnmt.getPatchMetaExtendedHeader().application_id);
|
||||
printf(" RequiredSystemVersion: v%" PRId32 " (%d.%d.%d.%d))\n", (uint32_t)mCnmt.getPatchMetaExtendedHeader().required_system_version, _SPLIT_VER(mCnmt.getPatchMetaExtendedHeader().required_system_version));
|
||||
printf(" ApplicationId: 0x%016" PRIx64 "\n", (uint64_t)mCnmt.getPatchMetaExtendedHeader().application_id);
|
||||
break;
|
||||
case (nx::cnmt::METATYPE_ADD_ON_CONTENT):
|
||||
printf(" AddOnContentMetaExtendedHeader:\n");
|
||||
printf(" RequiredSystemVersion: v%" PRId32 " (%d.%d.%d.%d)\n", mCnmt.getAddOnContentMetaExtendedHeader().required_system_version, _SPLIT_VER(mCnmt.getAddOnContentMetaExtendedHeader().required_system_version));
|
||||
printf(" ApplicationId: 0x%016" PRIx64 "\n", mCnmt.getAddOnContentMetaExtendedHeader().application_id);
|
||||
printf(" RequiredSystemVersion: v%" PRId32 " (%d.%d.%d.%d)\n", (uint32_t)mCnmt.getAddOnContentMetaExtendedHeader().required_system_version, _SPLIT_VER(mCnmt.getAddOnContentMetaExtendedHeader().required_system_version));
|
||||
printf(" ApplicationId: 0x%016" PRIx64 "\n", (uint64_t)mCnmt.getAddOnContentMetaExtendedHeader().application_id);
|
||||
break;
|
||||
case (nx::cnmt::METATYPE_DELTA):
|
||||
printf(" DeltaMetaExtendedHeader:\n");
|
||||
printf(" ApplicationId: 0x%016" PRIx64 "\n", mCnmt.getDeltaMetaExtendedHeader().application_id);
|
||||
printf(" ApplicationId: 0x%016" PRIx64 "\n", (uint64_t)mCnmt.getDeltaMetaExtendedHeader().application_id);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -96,13 +106,16 @@ void CnmtProcess::displayCmnt()
|
|||
for (size_t i = 0; i < mCnmt.getContentInfo().getSize(); i++)
|
||||
{
|
||||
const nx::ContentMetaBinary::ContentInfo& info = mCnmt.getContentInfo()[i];
|
||||
printf(" %d\n", i);
|
||||
printf(" Type: %s (%d)\n", kContentTypeStr[info.type].c_str(), info.type);
|
||||
printf(" %d\n", (int)i);
|
||||
printf(" Type: %s (%d)\n", getContentTypeStr(info.type), info.type);
|
||||
printf(" Id: ");
|
||||
fnd::SimpleTextOutput::hexDump(info.nca_id, nx::cnmt::kContentIdLen);
|
||||
printf(" Size: 0x%" PRIx64 "\n", info.size);
|
||||
_HEXDUMP_L(info.nca_id, nx::cnmt::kContentIdLen);
|
||||
printf("\n");
|
||||
printf(" Size: 0x%" PRIx64 "\n", (uint64_t)info.size);
|
||||
printf(" Hash: ");
|
||||
fnd::SimpleTextOutput::hexDump(info.hash.bytes, sizeof(info.hash));
|
||||
_HEXDUMP_L(info.hash.bytes, sizeof(info.hash));
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
if (mCnmt.getContentMetaInfo().getSize() > 0)
|
||||
|
@ -111,18 +124,21 @@ void CnmtProcess::displayCmnt()
|
|||
for (size_t i = 0; i < mCnmt.getContentMetaInfo().getSize(); i++)
|
||||
{
|
||||
const nx::ContentMetaBinary::ContentMetaInfo& info = mCnmt.getContentMetaInfo()[i];
|
||||
printf(" %d\n", i);
|
||||
printf(" Id: 0x%016" PRIx64 "\n", info.id);
|
||||
printf(" Version: v%" PRId32 " (%d.%d.%d.%d)\n", info.version, _SPLIT_VER(info.version));
|
||||
printf(" Type: %s (%d)\n", getContentMetaTypeStr(info.type).c_str(), info.type);
|
||||
printf(" %d\n", (int)i);
|
||||
printf(" Id: 0x%016" PRIx64 "\n", (uint64_t)info.id);
|
||||
printf(" Version: v%" PRId32 " (%d.%d.%d.%d)\n", (uint32_t)info.version, _SPLIT_VER(info.version));
|
||||
printf(" Type: %s (%d)\n", getContentMetaTypeStr(info.type), info.type);
|
||||
printf(" Attributes: %x\n", mCnmt.getAttributes());
|
||||
printf(" IncludesExFatDriver: %s\n", getBoolStr(_HAS_BIT(mCnmt.getAttributes(), nx::cnmt::ATTRIBUTE_INCLUDES_EX_FAT_DRIVER)));
|
||||
printf(" Rebootless: %s\n", getBoolStr(_HAS_BIT(mCnmt.getAttributes(), nx::cnmt::ATTRIBUTE_REBOOTLESS)));
|
||||
}
|
||||
}
|
||||
printf(" Digest: ");
|
||||
fnd::SimpleTextOutput::hexDump(mCnmt.getDigest().data, nx::cnmt::kDigestLen);
|
||||
_HEXDUMP_L(mCnmt.getDigest().data, nx::cnmt::kDigestLen);
|
||||
printf("\n");
|
||||
|
||||
#undef _HEXDUMP_L
|
||||
#undef _HEXDUMP_U
|
||||
#undef _SPLIT_VER
|
||||
}
|
||||
|
||||
|
|
|
@ -12,74 +12,213 @@
|
|||
#include "CopiedIFile.h"
|
||||
#include "HashTreeWrappedIFile.h"
|
||||
|
||||
std::string kFormatVersionStr[]
|
||||
const char* getFormatVersionStr(nx::NcaHeader::FormatVersion format_ver)
|
||||
{
|
||||
"NCA2",
|
||||
"NCA3"
|
||||
};
|
||||
const char* str;
|
||||
switch (format_ver)
|
||||
{
|
||||
case (nx::NcaHeader::NCA2_FORMAT):
|
||||
str = "NCA2";
|
||||
break;
|
||||
case (nx::NcaHeader::NCA3_FORMAT):
|
||||
str = "NCA3";
|
||||
break;
|
||||
default:
|
||||
str = "Unknown";
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string kDistributionTypeStr[]
|
||||
const char* getDistributionTypeStr(nx::nca::DistributionType dist_type)
|
||||
{
|
||||
"Download",
|
||||
"Game Card"
|
||||
};
|
||||
const char* str;
|
||||
switch (dist_type)
|
||||
{
|
||||
case (nx::nca::DIST_DOWNLOAD):
|
||||
str = "Download";
|
||||
break;
|
||||
case (nx::nca::DIST_GAME_CARD):
|
||||
str = "Game Card";
|
||||
break;
|
||||
default:
|
||||
str = "Unknown";
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string kContentTypeStr[]
|
||||
{
|
||||
"Program",
|
||||
"Meta",
|
||||
"Control",
|
||||
"Manual",
|
||||
"Data",
|
||||
"PublicData"
|
||||
};
|
||||
|
||||
std::string kEncryptionTypeStr[]
|
||||
const char* getContentTypeStr(nx::nca::ContentType cont_type)
|
||||
{
|
||||
"Auto",
|
||||
"None",
|
||||
"AesXts",
|
||||
"AesCtr",
|
||||
"AesCtrEx"
|
||||
};
|
||||
const char* str;
|
||||
switch (cont_type)
|
||||
{
|
||||
case (nx::nca::TYPE_PROGRAM):
|
||||
str = "Program";
|
||||
break;
|
||||
case (nx::nca::TYPE_META):
|
||||
str = "Meta";
|
||||
break;
|
||||
case (nx::nca::TYPE_CONTROL):
|
||||
str = "Control";
|
||||
break;
|
||||
case (nx::nca::TYPE_MANUAL):
|
||||
str = "Manual";
|
||||
break;
|
||||
case (nx::nca::TYPE_DATA):
|
||||
str = "Data";
|
||||
break;
|
||||
case (nx::nca::TYPE_PUBLIC_DATA):
|
||||
str = "PublicData";
|
||||
break;
|
||||
default:
|
||||
str = "Unknown";
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string kHashTypeStr[]
|
||||
const char* getEncryptionTypeStr(nx::nca::EncryptionType enc_type)
|
||||
{
|
||||
"Auto",
|
||||
"None",
|
||||
"HierarchicalSha256",
|
||||
"HierarchicalIntegrity"
|
||||
};
|
||||
const char* str;
|
||||
switch (enc_type)
|
||||
{
|
||||
case (nx::nca::CRYPT_AUTO):
|
||||
str = "Auto";
|
||||
break;
|
||||
case (nx::nca::CRYPT_NONE):
|
||||
str = "None";
|
||||
break;
|
||||
case (nx::nca::CRYPT_AESXTS):
|
||||
str = "AesXts";
|
||||
break;
|
||||
case (nx::nca::CRYPT_AESCTR):
|
||||
str = "AesCtr";
|
||||
break;
|
||||
case (nx::nca::CRYPT_AESCTREX):
|
||||
str = "AesCtrEx";
|
||||
break;
|
||||
default:
|
||||
str = "Unknown";
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string kFormatTypeStr[]
|
||||
inline const char* getHashTypeStr(nx::nca::HashType hash_type)
|
||||
{
|
||||
"RomFs",
|
||||
"PartitionFs"
|
||||
};
|
||||
const char* str;
|
||||
switch (hash_type)
|
||||
{
|
||||
case (nx::nca::HASH_AUTO):
|
||||
str = "Auto";
|
||||
break;
|
||||
case (nx::nca::HASH_NONE):
|
||||
str = "None";
|
||||
break;
|
||||
case (nx::nca::HASH_HIERARCHICAL_SHA256):
|
||||
str = "HierarchicalSha256";
|
||||
break;
|
||||
case (nx::nca::HASH_HIERARCHICAL_INTERGRITY):
|
||||
str = "HierarchicalIntegrity";
|
||||
break;
|
||||
default:
|
||||
str = "Unknown";
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string kKaekIndexStr[]
|
||||
inline const char* getFormatTypeStr(nx::nca::FormatType format_type)
|
||||
{
|
||||
"Application",
|
||||
"Ocean",
|
||||
"System"
|
||||
};
|
||||
const char* str;
|
||||
switch (format_type)
|
||||
{
|
||||
case (nx::nca::FORMAT_ROMFS):
|
||||
str = "RomFs";
|
||||
break;
|
||||
case (nx::nca::FORMAT_PFS0):
|
||||
str = "PartitionFs";
|
||||
break;
|
||||
default:
|
||||
str = "Unknown";
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string kContentTypeForMountStr[]
|
||||
inline const char* getKaekIndexStr(nx::nca::KeyAreaEncryptionKeyIndex keak_index)
|
||||
{
|
||||
"program",
|
||||
"meta",
|
||||
"control",
|
||||
"manual",
|
||||
"data",
|
||||
"publicdata"
|
||||
};
|
||||
const char* str;
|
||||
switch (keak_index)
|
||||
{
|
||||
case (nx::nca::KAEK_IDX_APPLICATION):
|
||||
str = "Application";
|
||||
break;
|
||||
case (nx::nca::KAEK_IDX_OCEAN):
|
||||
str = "Ocean";
|
||||
break;
|
||||
case (nx::nca::KAEK_IDX_SYSTEM):
|
||||
str = "System";
|
||||
break;
|
||||
default:
|
||||
str = "Unknown";
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string kProgramPartitionNameStr[]
|
||||
inline const char* getContentTypeForMountStr(nx::nca::ContentType cont_type)
|
||||
{
|
||||
"code",
|
||||
"data",
|
||||
"logo"
|
||||
};
|
||||
const char* str;
|
||||
switch (cont_type)
|
||||
{
|
||||
case (nx::nca::TYPE_PROGRAM):
|
||||
str = "program";
|
||||
break;
|
||||
case (nx::nca::TYPE_META):
|
||||
str = "meta";
|
||||
break;
|
||||
case (nx::nca::TYPE_CONTROL):
|
||||
str = "control";
|
||||
break;
|
||||
case (nx::nca::TYPE_MANUAL):
|
||||
str = "manual";
|
||||
break;
|
||||
case (nx::nca::TYPE_DATA):
|
||||
str = "data";
|
||||
break;
|
||||
case (nx::nca::TYPE_PUBLIC_DATA):
|
||||
str = "publicData";
|
||||
break;
|
||||
default:
|
||||
str = "";
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
const char* getProgramPartitionNameStr(size_t i)
|
||||
{
|
||||
const char* str;
|
||||
switch (i)
|
||||
{
|
||||
case (nx::nca::PARTITION_CODE):
|
||||
str = "code";
|
||||
break;
|
||||
case (nx::nca::PARTITION_DATA):
|
||||
str = "data";
|
||||
break;
|
||||
case (nx::nca::PARTITION_LOGO):
|
||||
str = "logo";
|
||||
break;
|
||||
default:
|
||||
str = "";
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
NcaProcess::NcaProcess() :
|
||||
|
@ -411,7 +550,7 @@ void NcaProcess::generatePartitionConfiguration()
|
|||
else if (info.enc_type == nx::nca::CRYPT_AESXTS || info.enc_type == nx::nca::CRYPT_AESCTREX)
|
||||
{
|
||||
error.clear();
|
||||
error << "EncryptionType(" << kEncryptionTypeStr[info.enc_type] << "): UNSUPPORTED";
|
||||
error << "EncryptionType(" << getEncryptionTypeStr(info.enc_type) << "): UNSUPPORTED";
|
||||
throw fnd::Exception(kModuleName, error.str());
|
||||
}
|
||||
else
|
||||
|
@ -512,20 +651,27 @@ void NcaProcess::validateNcaSignatures()
|
|||
|
||||
void NcaProcess::displayHeader()
|
||||
{
|
||||
#define _HEXDUMP_U(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)
|
||||
#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)
|
||||
|
||||
printf("[NCA Header]\n");
|
||||
printf(" Format Type: %s\n", kFormatVersionStr[mHdr.getFormatVersion()].c_str());
|
||||
printf(" Dist. Type: %s\n", kDistributionTypeStr[mHdr.getDistributionType()].c_str());
|
||||
printf(" Content Type: %s\n", kContentTypeStr[mHdr.getContentType()].c_str());
|
||||
printf(" Format Type: %s\n", getFormatVersionStr(mHdr.getFormatVersion()));
|
||||
printf(" Dist. Type: %s\n", getDistributionTypeStr(mHdr.getDistributionType()));
|
||||
printf(" Content Type: %s\n", getContentTypeStr(mHdr.getContentType()));
|
||||
printf(" Key Generation: %d\n", mHdr.getKeyGeneration());
|
||||
printf(" Kaek Index: %s (%d)\n", kKaekIndexStr[mHdr.getKaekIndex()].c_str(), mHdr.getKaekIndex());
|
||||
printf(" Kaek Index: %s (%d)\n", getKaekIndexStr((nx::nca::KeyAreaEncryptionKeyIndex)mHdr.getKaekIndex()), mHdr.getKaekIndex());
|
||||
printf(" Size: 0x%" PRIx64 "\n", mHdr.getContentSize());
|
||||
printf(" ProgID: 0x%016" PRIx64 "\n", mHdr.getProgramId());
|
||||
printf(" Content Index: %" PRIu32 "\n", mHdr.getContentIndex());
|
||||
#define _SPLIT_VER(ver) ( (ver>>24) & 0xff), ( (ver>>16) & 0xff), ( (ver>>8) & 0xff)
|
||||
printf(" SdkAddon Ver.: v%" PRIu32 " (%d.%d.%d)\n", mHdr.getSdkAddonVersion(), _SPLIT_VER(mHdr.getSdkAddonVersion()));
|
||||
#undef _SPLIT_VER
|
||||
if (mHdr.hasRightsId())
|
||||
{
|
||||
printf(" RightsId: ");
|
||||
fnd::SimpleTextOutput::hexDump(mHdr.getRightsId(), nx::nca::kRightsIdLen);
|
||||
}
|
||||
|
||||
|
||||
if (mBodyKeys.keak_list.getSize() > 0)
|
||||
{
|
||||
|
@ -537,12 +683,13 @@ void NcaProcess::displayHeader()
|
|||
{
|
||||
printf(" | %3lu | ", mBodyKeys.keak_list[i].index);
|
||||
|
||||
for (size_t j = 0; j < 16; j++) printf("%02x", mBodyKeys.keak_list[i].enc.key[j]);
|
||||
_HEXDUMP_L(mBodyKeys.keak_list[i].enc.key, 16);
|
||||
//for (size_t j = 0; j < 16; j++) printf("%02x", mBodyKeys.keak_list[i].enc.key[j]);
|
||||
|
||||
printf(" | ");
|
||||
|
||||
if (mBodyKeys.keak_list[i].decrypted)
|
||||
for (size_t j = 0; j < 16; j++) printf("%02x", mBodyKeys.keak_list[i].dec.key[j]);
|
||||
_HEXDUMP_L(mBodyKeys.keak_list[i].dec.key, 16);
|
||||
else
|
||||
printf("<unable to decrypt> ");
|
||||
|
||||
|
@ -551,30 +698,17 @@ void NcaProcess::displayHeader()
|
|||
printf(" <--------------------------------------------------------------------------->\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
if (mBodyKeyList.getSize() > 0)
|
||||
{
|
||||
printf(" Key Area Keys:\n");
|
||||
for (size_t i = 0; i < mBodyKeyList.getSize(); i++)
|
||||
{
|
||||
printf(" %2lu: ", i);
|
||||
fnd::SimpleTextOutput::hexDump(mBodyKeyList[i].key, crypto::aes::kAes128KeySize);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
printf(" Partitions:\n");
|
||||
for (size_t i = 0; i < mHdr.getPartitions().getSize(); i++)
|
||||
{
|
||||
sPartitionInfo& info = mPartitions[i];
|
||||
|
||||
printf(" %lu:\n", i);
|
||||
printf(" Offset: 0x%" PRIx64 "\n", info.offset);
|
||||
printf(" Size: 0x%" PRIx64 "\n", info.size);
|
||||
printf(" Format Type: %s\n", kFormatTypeStr[info.format_type].c_str());
|
||||
printf(" Hash Type: %s\n", kHashTypeStr[info.hash_type].c_str());
|
||||
printf(" Enc. Type: %s\n", kEncryptionTypeStr[info.enc_type].c_str());
|
||||
printf(" %d:\n", (int)i);
|
||||
printf(" Offset: 0x%" PRIx64 "\n", (uint64_t)info.offset);
|
||||
printf(" Size: 0x%" PRIx64 "\n", (uint64_t)info.size);
|
||||
printf(" Format Type: %s\n", getFormatTypeStr(info.format_type));
|
||||
printf(" Hash Type: %s\n", getHashTypeStr(info.hash_type));
|
||||
printf(" Enc. Type: %s\n", getEncryptionTypeStr(info.enc_type));
|
||||
if (info.enc_type == nx::nca::CRYPT_AESCTR)
|
||||
{
|
||||
printf(" AES-CTR: ");
|
||||
|
@ -591,19 +725,19 @@ void NcaProcess::displayHeader()
|
|||
//printf(" LayerNum: %d\n", hash_hdr.getLayerInfo().getSize());
|
||||
for (size_t j = 0; j < hash_hdr.getHashLayerInfo().getSize(); j++)
|
||||
{
|
||||
printf(" Hash Layer %d:\n", j);
|
||||
printf(" Offset: 0x%" PRIx64 "\n", hash_hdr.getHashLayerInfo()[j].offset);
|
||||
printf(" Size: 0x%" PRIx64 "\n", hash_hdr.getHashLayerInfo()[j].size);
|
||||
printf(" BlockSize: 0x%" PRIx32 "\n", hash_hdr.getHashLayerInfo()[j].block_size);
|
||||
printf(" Hash Layer %d:\n", (int)j);
|
||||
printf(" Offset: 0x%" PRIx64 "\n", (uint64_t)hash_hdr.getHashLayerInfo()[j].offset);
|
||||
printf(" Size: 0x%" PRIx64 "\n", (uint64_t)hash_hdr.getHashLayerInfo()[j].size);
|
||||
printf(" BlockSize: 0x%" PRIx32 "\n", (uint32_t)hash_hdr.getHashLayerInfo()[j].block_size);
|
||||
}
|
||||
|
||||
printf(" Data Layer:\n");
|
||||
printf(" Offset: 0x%" PRIx64 "\n", hash_hdr.getDataLayer().offset);
|
||||
printf(" Size: 0x%" PRIx64 "\n", hash_hdr.getDataLayer().size);
|
||||
printf(" BlockSize: 0x%" PRIx32 "\n", hash_hdr.getDataLayer().block_size);
|
||||
printf(" Offset: 0x%" PRIx64 "\n", (uint64_t)hash_hdr.getDataLayer().offset);
|
||||
printf(" Size: 0x%" PRIx64 "\n", (uint64_t)hash_hdr.getDataLayer().size);
|
||||
printf(" BlockSize: 0x%" PRIx32 "\n", (uint32_t)hash_hdr.getDataLayer().block_size);
|
||||
for (size_t j = 0; j < hash_hdr.getMasterHashList().getSize(); j++)
|
||||
{
|
||||
printf(" Master Hash %d: ", j);
|
||||
printf(" Master Hash %d: ", (int)j);
|
||||
fnd::SimpleTextOutput::hexDump(hash_hdr.getMasterHashList()[j].bytes, sizeof(crypto::sha::sSha256Hash));
|
||||
}
|
||||
}
|
||||
|
@ -613,14 +747,14 @@ void NcaProcess::displayHeader()
|
|||
printf(" HierarchicalSha256 Header:\n");
|
||||
printf(" Master Hash: ");
|
||||
fnd::SimpleTextOutput::hexDump(hash_hdr.getMasterHashList()[0].bytes, sizeof(crypto::sha::sSha256Hash));
|
||||
printf(" HashBlockSize: 0x%x\n", hash_hdr.getDataLayer().block_size);
|
||||
printf(" HashBlockSize: 0x%" PRIx32 "\n", (uint32_t)hash_hdr.getDataLayer().block_size);
|
||||
//printf(" LayerNum: %d\n", hash_hdr.getLayerInfo().getSize());
|
||||
printf(" Hash Layer:\n");
|
||||
printf(" Offset: 0x%" PRIx64 "\n", hash_hdr.getHashLayerInfo()[0].offset);
|
||||
printf(" Size: 0x%" PRIx64 "\n", hash_hdr.getHashLayerInfo()[0].size);
|
||||
printf(" Offset: 0x%" PRIx64 "\n", (uint64_t)hash_hdr.getHashLayerInfo()[0].offset);
|
||||
printf(" Size: 0x%" PRIx64 "\n", (uint64_t)hash_hdr.getHashLayerInfo()[0].size);
|
||||
printf(" Data Layer:\n");
|
||||
printf(" Offset: 0x%" PRIx64 "\n", hash_hdr.getDataLayer().offset);
|
||||
printf(" Size: 0x%" PRIx64 "\n", hash_hdr.getDataLayer().size);
|
||||
printf(" Offset: 0x%" PRIx64 "\n", (uint64_t)hash_hdr.getDataLayer().offset);
|
||||
printf(" Size: 0x%" PRIx64 "\n", (uint64_t)hash_hdr.getDataLayer().size);
|
||||
}
|
||||
//else
|
||||
//{
|
||||
|
@ -628,6 +762,8 @@ void NcaProcess::displayHeader()
|
|||
// fnd::SimpleTextOutput::hxdStyleDump(fs_header.hash_superblock, nx::nca::kFsHeaderHashSuperblockLen);
|
||||
//}
|
||||
}
|
||||
#undef _HEXDUMP_U
|
||||
#undef _HEXDUMP_L
|
||||
}
|
||||
|
||||
|
||||
|
@ -641,7 +777,7 @@ void NcaProcess::processPartitions()
|
|||
// if the reader is null, skip
|
||||
if (partition.reader == nullptr)
|
||||
{
|
||||
printf("[WARNING] NCA Partition %d not readable.", index);
|
||||
printf("[WARNING] NCA Partition %d not readable.", (int)index);
|
||||
if (partition.fail_reason.empty() == false)
|
||||
{
|
||||
printf(" (%s)", partition.fail_reason.c_str());
|
||||
|
@ -658,11 +794,11 @@ void NcaProcess::processPartitions()
|
|||
pfs.setListFs(mListFs);
|
||||
if (mHdr.getContentType() == nx::nca::TYPE_PROGRAM)
|
||||
{
|
||||
pfs.setMountPointName(kContentTypeForMountStr[mHdr.getContentType()] + ":/" + kProgramPartitionNameStr[i]);
|
||||
pfs.setMountPointName(std::string(getContentTypeForMountStr(mHdr.getContentType())) + ":/" + std::string(getProgramPartitionNameStr(i)));
|
||||
}
|
||||
else
|
||||
{
|
||||
pfs.setMountPointName(kContentTypeForMountStr[mHdr.getContentType()] + ":/");
|
||||
pfs.setMountPointName(std::string(getContentTypeForMountStr(mHdr.getContentType())) + ":/");
|
||||
}
|
||||
|
||||
if (mPartitionPath[index].doExtract)
|
||||
|
@ -679,11 +815,11 @@ void NcaProcess::processPartitions()
|
|||
romfs.setListFs(mListFs);
|
||||
if (mHdr.getContentType() == nx::nca::TYPE_PROGRAM)
|
||||
{
|
||||
romfs.setMountPointName(kContentTypeForMountStr[mHdr.getContentType()] + ":/" + kProgramPartitionNameStr[i]);
|
||||
romfs.setMountPointName(std::string(getContentTypeForMountStr(mHdr.getContentType())) + ":/" + std::string(getProgramPartitionNameStr(i)));
|
||||
}
|
||||
else
|
||||
{
|
||||
romfs.setMountPointName(kContentTypeForMountStr[mHdr.getContentType()] + ":/");
|
||||
romfs.setMountPointName(std::string(getContentTypeForMountStr(mHdr.getContentType())) + ":/");
|
||||
}
|
||||
|
||||
if (mPartitionPath[index].doExtract)
|
||||
|
|
|
@ -7,7 +7,7 @@ void PfsProcess::displayHeader()
|
|||
{
|
||||
printf("[PartitionFS]\n");
|
||||
printf(" Type: %s\n", mPfs.getFsType() == mPfs.TYPE_PFS0? "PFS0" : "HFS0");
|
||||
printf(" FileNum: %u\n", mPfs.getFileList().getSize());
|
||||
printf(" FileNum: %" PRId64 "\n", mPfs.getFileList().getSize());
|
||||
if (mMountName.empty() == false)
|
||||
printf(" MountPoint: %s%s\n", mMountName.c_str(), mMountName.at(mMountName.length()-1) != '/' ? "/" : "");
|
||||
}
|
||||
|
|
|
@ -44,8 +44,8 @@ void RomfsProcess::displayDir(const sDirectory& dir, size_t tab) const
|
|||
void RomfsProcess::displayHeader()
|
||||
{
|
||||
printf("[RomFS]\n");
|
||||
printf(" DirNum: %u\n", mDirNum);
|
||||
printf(" FileNum: %u\n", mFileNum);
|
||||
printf(" DirNum: %" PRId64 "\n", mDirNum);
|
||||
printf(" FileNum: %" PRId64 "\n", mFileNum);
|
||||
if (mMountName.empty() == false)
|
||||
printf(" MountPoint: %s%s\n", mMountName.c_str(), mMountName.at(mMountName.length()-1) != '/' ? "/" : "");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue