From 1bfd0abb6a9e64567b4bba65b4509249cb32b739 Mon Sep 17 00:00:00 2001 From: jakcron Date: Wed, 11 Jul 2018 20:01:13 +0800 Subject: [PATCH 1/4] [nx|nstool] Fix typo. --- .../nx/ApplicationControlPropertyBinary.h | 6 +++--- lib/libnx/include/nx/nacp.h | 2 +- .../ApplicationControlPropertyBinary.cpp | 18 +++++++++--------- programs/nstool/source/NacpProcess.cpp | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/libnx/include/nx/ApplicationControlPropertyBinary.h b/lib/libnx/include/nx/ApplicationControlPropertyBinary.h index ed5a96d..3dcc41a 100644 --- a/lib/libnx/include/nx/ApplicationControlPropertyBinary.h +++ b/lib/libnx/include/nx/ApplicationControlPropertyBinary.h @@ -197,8 +197,8 @@ namespace nx int64_t getCacheStorageDataAndJournalSizeMax() const; void setCacheStorageDataAndJournalSizeMax(int64_t var); - uint16_t getCacheStorageIndex() const; - void setCacheStorageIndex(uint16_t var); + uint16_t getCacheStorageIndexMax() const; + void setCacheStorageIndexMax(uint16_t var); const fnd::List& getPlayLogQueryableApplicationId() const; void setPlayLogQueryableApplicationId(const fnd::List& var); @@ -253,7 +253,7 @@ namespace nx int64_t mTemporaryStorageSize; sStorageSize mCacheStorageSize; int64_t mCacheStorageDataAndJournalSizeMax; - uint16_t mCacheStorageIndex; + uint16_t mCacheStorageIndexMax; fnd::List mPlayLogQueryableApplicationId; nacp::PlayLogQueryCapability mPlayLogQueryCapability; nacp::RepairFlag mRepairFlag; diff --git a/lib/libnx/include/nx/nacp.h b/lib/libnx/include/nx/nacp.h index c319395..bbb7019 100644 --- a/lib/libnx/include/nx/nacp.h +++ b/lib/libnx/include/nx/nacp.h @@ -208,7 +208,7 @@ namespace nx le_uint64_t cache_storage_size; le_uint64_t cache_storage_journal_size; le_uint64_t cache_storage_data_and_journal_size_max; - le_uint16_t cache_storage_index; + le_uint16_t cache_storage_index_max; byte_t reserved_03[6]; le_uint64_t play_log_queryable_application_id[nacp::kPlayLogQueryableApplicationIdCount]; byte_t play_log_query_capability; diff --git a/lib/libnx/source/ApplicationControlPropertyBinary.cpp b/lib/libnx/source/ApplicationControlPropertyBinary.cpp index 5edb57b..25dfa64 100644 --- a/lib/libnx/source/ApplicationControlPropertyBinary.cpp +++ b/lib/libnx/source/ApplicationControlPropertyBinary.cpp @@ -46,7 +46,7 @@ void nx::ApplicationControlPropertyBinary::operator=(const ApplicationControlPro mTemporaryStorageSize = other.mTemporaryStorageSize; mCacheStorageSize = other.mCacheStorageSize; mCacheStorageDataAndJournalSizeMax = other.mCacheStorageDataAndJournalSizeMax; - mCacheStorageIndex = other.mCacheStorageIndex; + mCacheStorageIndexMax = other.mCacheStorageIndexMax; mPlayLogQueryableApplicationId = other.mPlayLogQueryableApplicationId; mPlayLogQueryCapability = other.mPlayLogQueryCapability; mRepairFlag = other.mRepairFlag; @@ -88,7 +88,7 @@ bool nx::ApplicationControlPropertyBinary::operator==(const ApplicationControlPr && (mTemporaryStorageSize == other.mTemporaryStorageSize) \ && (mCacheStorageSize == other.mCacheStorageSize) \ && (mCacheStorageDataAndJournalSizeMax == other.mCacheStorageDataAndJournalSizeMax) \ - && (mCacheStorageIndex == other.mCacheStorageIndex) \ + && (mCacheStorageIndexMax == other.mCacheStorageIndexMax) \ && (mPlayLogQueryableApplicationId == other.mPlayLogQueryableApplicationId) \ && (mPlayLogQueryCapability == other.mPlayLogQueryCapability) \ && (mRepairFlag == other.mRepairFlag) \ @@ -157,7 +157,7 @@ void nx::ApplicationControlPropertyBinary::toBytes() { data->play_log_queryable_application_id[i] = mPlayLogQueryableApplicationId[i]; } - data->cache_storage_index = mCacheStorageIndex; + data->cache_storage_index = mCacheStorageIndexMax; data->program_index = mProgramIndex; // sizes @@ -245,7 +245,7 @@ void nx::ApplicationControlPropertyBinary::fromBytes(const byte_t* bytes, size_t if (data->play_log_queryable_application_id[i].get() != 0) mPlayLogQueryableApplicationId.addElement(data->play_log_queryable_application_id[i].get()); } - mCacheStorageIndex = data->cache_storage_index.get(); + mCacheStorageIndexMax = data->cache_storage_index.get(); mProgramIndex = data->program_index; // sizes @@ -305,7 +305,7 @@ void nx::ApplicationControlPropertyBinary::clear() mTemporaryStorageSize = 0; mCacheStorageSize = {0, 0}; mCacheStorageDataAndJournalSizeMax = 0; - mCacheStorageIndex = 0; + mCacheStorageIndexMax = 0; mPlayLogQueryableApplicationId.clear(); mPlayLogQueryCapability = nacp::PLQC_None; mRepairFlag = nacp::REPF_None; @@ -642,14 +642,14 @@ void nx::ApplicationControlPropertyBinary::setCacheStorageDataAndJournalSizeMax( mCacheStorageDataAndJournalSizeMax = var; } -uint16_t nx::ApplicationControlPropertyBinary::getCacheStorageIndex() const +uint16_t nx::ApplicationControlPropertyBinary::getCacheStorageIndexMax() const { - return mCacheStorageIndex; + return mCacheStorageIndexMax; } -void nx::ApplicationControlPropertyBinary::setCacheStorageIndex(uint16_t var) +void nx::ApplicationControlPropertyBinary::setCacheStorageIndexMax(uint16_t var) { - mCacheStorageIndex = var; + mCacheStorageIndexMax = var; } const fnd::List& nx::ApplicationControlPropertyBinary::getPlayLogQueryableApplicationId() const diff --git a/programs/nstool/source/NacpProcess.cpp b/programs/nstool/source/NacpProcess.cpp index 2c87992..dfbe51a 100644 --- a/programs/nstool/source/NacpProcess.cpp +++ b/programs/nstool/source/NacpProcess.cpp @@ -569,7 +569,7 @@ void NacpProcess::displayNacp() printf(" Size: %s\n", getSaveDataSizeStr(mNacp.getCacheStorageSize().size).c_str()); printf(" JournalSize: %s\n", getSaveDataSizeStr(mNacp.getCacheStorageSize().journal_size).c_str()); printf(" MaxDataAndJournalSize: %s\n", getSaveDataSizeStr(mNacp.getCacheStorageDataAndJournalSizeMax()).c_str()); - printf(" StorageIndex: 0x%" PRIx16 "\n", mNacp.getCacheStorageIndex()); + printf(" StorageIndexMax: 0x%" PRIx16 "\n", mNacp.getCacheStorageIndexMax()); } printf(" Other Flags:\n"); printf(" StartupUserAccount: %s\n", getStartupUserAccountStr(mNacp.getStartupUserAccount())); From 706979c2759ad737b22de731c4fcda8a60158630 Mon Sep 17 00:00:00 2001 From: jakcron Date: Tue, 31 Jul 2018 13:06:28 +0800 Subject: [PATCH 2/4] [nx] Fix typo. --- lib/libnx/source/ApplicationControlPropertyBinary.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/libnx/source/ApplicationControlPropertyBinary.cpp b/lib/libnx/source/ApplicationControlPropertyBinary.cpp index 25dfa64..463a8c4 100644 --- a/lib/libnx/source/ApplicationControlPropertyBinary.cpp +++ b/lib/libnx/source/ApplicationControlPropertyBinary.cpp @@ -157,7 +157,7 @@ void nx::ApplicationControlPropertyBinary::toBytes() { data->play_log_queryable_application_id[i] = mPlayLogQueryableApplicationId[i]; } - data->cache_storage_index = mCacheStorageIndexMax; + data->cache_storage_index_max = mCacheStorageIndexMax; data->program_index = mProgramIndex; // sizes @@ -245,7 +245,7 @@ void nx::ApplicationControlPropertyBinary::fromBytes(const byte_t* bytes, size_t if (data->play_log_queryable_application_id[i].get() != 0) mPlayLogQueryableApplicationId.addElement(data->play_log_queryable_application_id[i].get()); } - mCacheStorageIndexMax = data->cache_storage_index.get(); + mCacheStorageIndexMax = data->cache_storage_index_max.get(); mProgramIndex = data->program_index; // sizes From 1a30f0525610258a920208f2f9392ede60470154 Mon Sep 17 00:00:00 2001 From: jakcron Date: Tue, 31 Jul 2018 13:09:03 +0800 Subject: [PATCH 3/4] [nx] Fixed bug where a string was imported with null bytes. --- lib/libnx/source/ApplicationControlPropertyBinary.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/libnx/source/ApplicationControlPropertyBinary.cpp b/lib/libnx/source/ApplicationControlPropertyBinary.cpp index 463a8c4..73932e6 100644 --- a/lib/libnx/source/ApplicationControlPropertyBinary.cpp +++ b/lib/libnx/source/ApplicationControlPropertyBinary.cpp @@ -195,17 +195,17 @@ void nx::ApplicationControlPropertyBinary::fromBytes(const byte_t* bytes, size_t { if (_HAS_BIT(data->supported_language_flag.get(), i)) { - mTitle.addElement({(nacp::Language)i, std::string(data->title[i].name, nacp::kNameLength), std::string(data->title[i].publisher, nacp::kPublisherLength)}); + mTitle.addElement({ (nacp::Language)i, std::string(data->title[i].name, _MIN(strlen(data->title[i].name), nacp::kNameLength)), std::string(data->title[i].publisher, _MIN(strlen(data->title[i].publisher), nacp::kPublisherLength)) }); } } if (data->isbn[0] != 0) - mIsbn = std::string(data->isbn, nacp::kIsbnLength); + mIsbn = std::string(data->isbn, _MIN(strlen(data->isbn), nacp::kIsbnLength)); if (data->display_version[0] != 0) - mDisplayVersion = std::string(data->display_version, nacp::kDisplayVersionLength); + mDisplayVersion = std::string(data->display_version, _MIN(strlen(data->display_version), nacp::kDisplayVersionLength)); if (data->application_error_code_category[0] != 0) - mApplicationErrorCodeCategory = std::string(data->application_error_code_category, nacp::kApplicationErrorCodeCategoryLength); + mApplicationErrorCodeCategory = std::string(data->application_error_code_category, _MIN(strlen(data->application_error_code_category), nacp::kApplicationErrorCodeCategoryLength)); if (data->bcat_passphrase[0] != 0) - mBcatPassphase = std::string(data->bcat_passphrase, nacp::kBcatPassphraseLength); + mBcatPassphase = std::string(data->bcat_passphrase, _MIN(strlen(data->bcat_passphrase), nacp::kBcatPassphraseLength)); // enum type casts mStartupUserAccount = (nacp::StartupUserAccount)data->startup_user_account; From b8b97066dde9b44cf50d7d1b27f8e6ebb51f174d Mon Sep 17 00:00:00 2001 From: jakcron Date: Tue, 31 Jul 2018 13:23:51 +0800 Subject: [PATCH 4/4] [nx] Fix behaviour in NACP processing, supported langs don't indicate what title strings are set. --- .../nx/ApplicationControlPropertyBinary.h | 4 +++ .../ApplicationControlPropertyBinary.cpp | 26 +++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/libnx/include/nx/ApplicationControlPropertyBinary.h b/lib/libnx/include/nx/ApplicationControlPropertyBinary.h index 3dcc41a..ae28816 100644 --- a/lib/libnx/include/nx/ApplicationControlPropertyBinary.h +++ b/lib/libnx/include/nx/ApplicationControlPropertyBinary.h @@ -116,6 +116,9 @@ namespace nx nacp::AttributeFlag getAttributeFlag() const; void setAttributeFlag(nacp::AttributeFlag var); + const fnd::List& getSupportedLanguages() const; + void setSupportedLanguages(const fnd::List& var); + nacp::ParentalControlFlag getParentalControlFlag() const; void setParentalControlFlag(nacp::ParentalControlFlag var); @@ -226,6 +229,7 @@ namespace nx nacp::TouchScreenUsageMode mTouchScreenUsageMode; nacp::AocRegistrationType mAocRegistrationType; nacp::AttributeFlag mAttributeFlag; + fnd::List mSupportedLanguages; nacp::ParentalControlFlag mParentalControlFlag; nacp::ScreenshotMode mScreenshotMode; nacp::VideoCaptureMode mVideoCaptureMode; diff --git a/lib/libnx/source/ApplicationControlPropertyBinary.cpp b/lib/libnx/source/ApplicationControlPropertyBinary.cpp index 73932e6..a6ca675 100644 --- a/lib/libnx/source/ApplicationControlPropertyBinary.cpp +++ b/lib/libnx/source/ApplicationControlPropertyBinary.cpp @@ -19,6 +19,7 @@ void nx::ApplicationControlPropertyBinary::operator=(const ApplicationControlPro mTouchScreenUsageMode = other.mTouchScreenUsageMode; mAocRegistrationType = other.mAocRegistrationType; mAttributeFlag = other.mAttributeFlag; + mSupportedLanguages = other.mSupportedLanguages; mParentalControlFlag = other.mParentalControlFlag; mScreenshotMode = other.mScreenshotMode; mVideoCaptureMode = other.mVideoCaptureMode; @@ -61,6 +62,7 @@ bool nx::ApplicationControlPropertyBinary::operator==(const ApplicationControlPr && (mTouchScreenUsageMode == other.mTouchScreenUsageMode) \ && (mAocRegistrationType == other.mAocRegistrationType) \ && (mAttributeFlag == other.mAttributeFlag) \ + && (mSupportedLanguages == other.mSupportedLanguages) \ && (mParentalControlFlag == other.mParentalControlFlag) \ && (mScreenshotMode == other.mScreenshotMode) \ && (mVideoCaptureMode == other.mVideoCaptureMode) \ @@ -107,13 +109,17 @@ void nx::ApplicationControlPropertyBinary::toBytes() sApplicationControlProperty* data = (sApplicationControlProperty*)mRawBinary.data(); // strings - uint32_t supported_langs = 0; for (size_t i = 0; i < mTitle.size(); i++) { - supported_langs = _BIT(mTitle[i].language); strncpy(data->title[mTitle[i].language].name, mTitle[i].name.c_str(), nacp::kNameLength); strncpy(data->title[mTitle[i].language].publisher, mTitle[i].publisher.c_str(), nacp::kPublisherLength); } + + uint32_t supported_langs = 0; + for (size_t i = 0; i < mSupportedLanguages.size(); i++) + { + supported_langs |= _BIT(mSupportedLanguages[i]); + } data->supported_language_flag = supported_langs; strncpy(data->isbn, mIsbn.c_str(), nacp::kIsbnLength); @@ -194,10 +200,15 @@ void nx::ApplicationControlPropertyBinary::fromBytes(const byte_t* bytes, size_t for (size_t i = 0; i < nacp::kMaxLanguageCount; i++) { if (_HAS_BIT(data->supported_language_flag.get(), i)) + { + mSupportedLanguages.addElement((nacp::Language)i); + } + if (data->title[i].name[0] != '\0' && data->title[i].publisher[0] != '\0') { mTitle.addElement({ (nacp::Language)i, std::string(data->title[i].name, _MIN(strlen(data->title[i].name), nacp::kNameLength)), std::string(data->title[i].publisher, _MIN(strlen(data->title[i].publisher), nacp::kPublisherLength)) }); } } + if (data->isbn[0] != 0) mIsbn = std::string(data->isbn, _MIN(strlen(data->isbn), nacp::kIsbnLength)); if (data->display_version[0] != 0) @@ -278,6 +289,7 @@ void nx::ApplicationControlPropertyBinary::clear() mTouchScreenUsageMode = nacp::TOUCH_None; mAocRegistrationType = nacp::AOC_AllOnLaunch; mAttributeFlag = nacp::ATTR_None; + mSupportedLanguages.clear(); mParentalControlFlag = nacp::PC_None; mScreenshotMode = nacp::SCRN_Allow; mVideoCaptureMode = nacp::VCAP_Disable; @@ -372,6 +384,16 @@ void nx::ApplicationControlPropertyBinary::setAttributeFlag(nacp::AttributeFlag mAttributeFlag = var; } +const fnd::List& nx::ApplicationControlPropertyBinary::getSupportedLanguages() const +{ + return mSupportedLanguages; +} + +void nx::ApplicationControlPropertyBinary::setSupportedLanguages(const fnd::List& var) +{ + mSupportedLanguages = var; +} + nx::nacp::ParentalControlFlag nx::ApplicationControlPropertyBinary::getParentalControlFlag() const { return mParentalControlFlag;