From bf53ac46401e1df8f9aa9ca00092c9b60abf1e7e Mon Sep 17 00:00:00 2001 From: jakcron Date: Fri, 1 Oct 2021 20:46:35 +0800 Subject: [PATCH] Port NacpProcess to libtoolchain. --- src/NacpProcess.cpp | 219 ++++++++++++++++++++++---------------------- src/NacpProcess.h | 2 +- 2 files changed, 111 insertions(+), 110 deletions(-) diff --git a/src/NacpProcess.cpp b/src/NacpProcess.cpp index e454709..f2e673c 100644 --- a/src/NacpProcess.cpp +++ b/src/NacpProcess.cpp @@ -1,17 +1,11 @@ #include "NacpProcess.h" -#include -#include -#include - -#include -#include - #include nstool::NacpProcess::NacpProcess() : + mModuleName("nstool::NacpProcess"), mFile(), - mCliOutputMode((1 << OUTPUT_BASIC)), + mCliOutputMode(true, false, false, false), mVerify(false) { } @@ -46,480 +40,487 @@ const nn::hac::ApplicationControlProperty& nstool::NacpProcess::getApplicationCo void nstool::NacpProcess::importNacp() { - tc::ByteData scratch; - - if (*mFile == nullptr) + if (mFile == nullptr) { - throw tc::Exception(kModuleName, "No file reader set."); + throw tc::Exception(mModuleName, "No file reader set."); } - scratch.alloc((*mFile)->size()); - (*mFile)->read(scratch.data(), 0, scratch.size()); + // check if file_size is greater than 20MB, don't import. + size_t file_size = tc::io::IOUtil::castInt64ToSize(mFile->length()); + if (file_size > (0x100000 * 20)) + { + throw tc::Exception(mModuleName, "File too large."); + } + + // read cnmt + tc::ByteData scratch = tc::ByteData(file_size); + mFile->seek(0, tc::io::SeekOrigin::Begin); + mFile->read(scratch.data(), scratch.size()); mNacp.fromBytes(scratch.data(), scratch.size()); } void nstool::NacpProcess::displayNacp() { - std::cout << "[ApplicationControlProperty]" << std::endl; + fmt::print("[ApplicationControlProperty]\n"); // Title if (mNacp.getTitle().size() > 0) { - std::cout << " Title:" << std::endl; + fmt::print(" Title:\n"); for (auto itr = mNacp.getTitle().begin(); itr != mNacp.getTitle().end(); itr++) { - std::cout << " " << nn::hac::ApplicationControlPropertyUtil::getLanguageAsString(itr->language) << ":" << std::endl; - std::cout << " Name: " << itr->name << std::endl; - std::cout << " Publisher: " << itr->publisher << std::endl; + fmt::print(" {:s}:\n", nn::hac::ApplicationControlPropertyUtil::getLanguageAsString(itr->language)); + fmt::print(" Name: {:s}\n", itr->name); + fmt::print(" Publisher: {:s}\n", itr->publisher); } } else if (mCliOutputMode.show_extended_info) { - std::cout << " Title: None" << std::endl; + fmt::print(" Title: None\n"); } // Isbn if (mNacp.getIsbn().empty() == false) { - std::cout << " ISBN: " << mNacp.getIsbn() << std::endl; + fmt::print(" ISBN: {:s}\n", mNacp.getIsbn()); } else if (mCliOutputMode.show_extended_info) { - std::cout << " ISBN: (NotSet)" << std::endl; + fmt::print(" ISBN: (NotSet)\n"); } // StartupUserAccount if (mNacp.getStartupUserAccount() != nn::hac::nacp::StartupUserAccount::None || mCliOutputMode.show_extended_info) { - std::cout << " StartupUserAccount: " << nn::hac::ApplicationControlPropertyUtil::getStartupUserAccountAsString(mNacp.getStartupUserAccount()) << std::endl; + fmt::print(" StartupUserAccount: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getStartupUserAccountAsString(mNacp.getStartupUserAccount())); } // UserAccountSwitchLock if (mNacp.getUserAccountSwitchLock() != nn::hac::nacp::UserAccountSwitchLock::Disable || mCliOutputMode.show_extended_info) { - std::cout << " UserAccountSwitchLock: " << nn::hac::ApplicationControlPropertyUtil::getUserAccountSwitchLockAsString(mNacp.getUserAccountSwitchLock()) << std::endl; + fmt::print(" UserAccountSwitchLock: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getUserAccountSwitchLockAsString(mNacp.getUserAccountSwitchLock())); } // AddOnContentRegistrationType if (mNacp.getAddOnContentRegistrationType() != nn::hac::nacp::AddOnContentRegistrationType::AllOnLaunch || mCliOutputMode.show_extended_info) { - std::cout << " AddOnContentRegistrationType: " << nn::hac::ApplicationControlPropertyUtil::getAddOnContentRegistrationTypeAsString(mNacp.getAddOnContentRegistrationType()) << std::endl; + fmt::print(" AddOnContentRegistrationType: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getAddOnContentRegistrationTypeAsString(mNacp.getAddOnContentRegistrationType())); } // Attribute if (mNacp.getAttribute().size() > 0) { - std::cout << " Attribute:" << std::endl; + fmt::print(" Attribute:\n"); for (auto itr = mNacp.getAttribute().begin(); itr != mNacp.getAttribute().end(); itr++) { - std::cout << " " << nn::hac::ApplicationControlPropertyUtil::getAttributeFlagAsString(*itr) << std::endl; + fmt::print(" {:s}\n", nn::hac::ApplicationControlPropertyUtil::getAttributeFlagAsString(*itr)); } } else if (mCliOutputMode.show_extended_info) { - std::cout << " Attribute: None" << std::endl; + fmt::print(" Attribute: None\n"); } // SupportedLanguage if (mNacp.getSupportedLanguage().size() > 0) { - std::cout << " SupportedLanguage:" << std::endl; + fmt::print(" SupportedLanguage:\n"); for (auto itr = mNacp.getSupportedLanguage().begin(); itr != mNacp.getSupportedLanguage().end(); itr++) { - std::cout << " " << nn::hac::ApplicationControlPropertyUtil::getLanguageAsString(*itr) << std::endl; + fmt::print(" {:s}\n", nn::hac::ApplicationControlPropertyUtil::getLanguageAsString(*itr)); } } else if (mCliOutputMode.show_extended_info) { - std::cout << " SupportedLanguage: None" << std::endl; + fmt::print(" SupportedLanguage: None\n"); } // ParentalControl if (mNacp.getParentalControl().size() > 0) { - std::cout << " ParentalControl:" << std::endl; + fmt::print(" ParentalControl:\n"); for (auto itr = mNacp.getParentalControl().begin(); itr != mNacp.getParentalControl().end(); itr++) { - std::cout << " " << nn::hac::ApplicationControlPropertyUtil::getParentalControlFlagAsString(*itr) << std::endl; + fmt::print(" {:s}\n", nn::hac::ApplicationControlPropertyUtil::getParentalControlFlagAsString(*itr)); } } else if (mCliOutputMode.show_extended_info) { - std::cout << " ParentalControl: None" << std::endl; + fmt::print(" ParentalControl: None\n"); } // Screenshot if (mNacp.getScreenshot() != nn::hac::nacp::Screenshot::Allow || mCliOutputMode.show_extended_info) { - std::cout << " Screenshot: " << nn::hac::ApplicationControlPropertyUtil::getScreenshotAsString(mNacp.getScreenshot()) << std::endl; + fmt::print(" Screenshot: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getScreenshotAsString(mNacp.getScreenshot())); } // VideoCapture if (mNacp.getVideoCapture() != nn::hac::nacp::VideoCapture::Disable || mCliOutputMode.show_extended_info) { - std::cout << " VideoCapture: " << nn::hac::ApplicationControlPropertyUtil::getVideoCaptureAsString(mNacp.getVideoCapture()) << std::endl; + fmt::print(" VideoCapture: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getVideoCaptureAsString(mNacp.getVideoCapture())); } // DataLossConfirmation if (mNacp.getDataLossConfirmation() != nn::hac::nacp::DataLossConfirmation::None || mCliOutputMode.show_extended_info) { - std::cout << " DataLossConfirmation: " << nn::hac::ApplicationControlPropertyUtil::getDataLossConfirmationAsString(mNacp.getDataLossConfirmation()) << std::endl; + fmt::print(" DataLossConfirmation: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getDataLossConfirmationAsString(mNacp.getDataLossConfirmation())); } // PlayLogPolicy if (mNacp.getPlayLogPolicy() != nn::hac::nacp::PlayLogPolicy::All || mCliOutputMode.show_extended_info) { - std::cout << " PlayLogPolicy: " << nn::hac::ApplicationControlPropertyUtil::getPlayLogPolicyAsString(mNacp.getPlayLogPolicy()) << std::endl; + fmt::print(" PlayLogPolicy: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getPlayLogPolicyAsString(mNacp.getPlayLogPolicy())); } // PresenceGroupId if (mNacp.getPresenceGroupId() != 0 || mCliOutputMode.show_extended_info) { - std::cout << " PresenceGroupId: 0x" << std::hex << std::setw(16) << std::setfill('0') << mNacp.getPresenceGroupId() << std::endl; + fmt::print(" PresenceGroupId: 0x{:016x}\n", mNacp.getPresenceGroupId()); } // RatingAge if (mNacp.getRatingAge().size() > 0) { - std::cout << " RatingAge:" << std::endl; + fmt::print(" RatingAge:\n"); for (auto itr = mNacp.getRatingAge().begin(); itr != mNacp.getRatingAge().end(); itr++) { - std::cout << " " << nn::hac::ApplicationControlPropertyUtil::getOrganisationAsString(itr->organisation) << ":" << std::endl; - std::cout << " Age: " << std::dec << (uint32_t)itr->age << std::endl; + fmt::print(" {:s}:\n", nn::hac::ApplicationControlPropertyUtil::getOrganisationAsString(itr->organisation)); + fmt::print(" Age: {:d}\n", itr->age); } } else if (mCliOutputMode.show_extended_info) { - std::cout << " RatingAge: None" << std::endl; + fmt::print(" RatingAge: None\n"); } // DisplayVersion if (mNacp.getDisplayVersion().empty() == false) { - std::cout << " DisplayVersion: " << mNacp.getDisplayVersion() << std::endl; + fmt::print(" DisplayVersion: {:s}\n", mNacp.getDisplayVersion()); } else if (mCliOutputMode.show_extended_info) { - std::cout << " DisplayVersion: (NotSet)" << std::endl; + fmt::print(" DisplayVersion: (NotSet)\n"); } // AddOnContentBaseId if (mNacp.getAddOnContentBaseId() != 0 || mCliOutputMode.show_extended_info) { - std::cout << " AddOnContentBaseId: 0x" << std::hex << std::setw(16) << std::setfill('0') << mNacp.getAddOnContentBaseId() << std::endl; + fmt::print(" AddOnContentBaseId: 0x{:016x}\n", mNacp.getAddOnContentBaseId()); } // SaveDataOwnerId if (mNacp.getSaveDataOwnerId() != 0 || mCliOutputMode.show_extended_info) { - std::cout << " SaveDataOwnerId: 0x" << std::hex << std::setw(16) << std::setfill('0') << mNacp.getSaveDataOwnerId() << std::endl; + fmt::print(" SaveDataOwnerId: 0x{:016x}\n", mNacp.getSaveDataOwnerId()); } // UserAccountSaveDataSize if (mNacp.getUserAccountSaveDataSize().size != 0 || mCliOutputMode.show_extended_info) { - std::cout << " UserAccountSaveDataSize: " << nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getUserAccountSaveDataSize().size) << std::endl; + fmt::print(" UserAccountSaveDataSize: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getUserAccountSaveDataSize().size)); } // UserAccountSaveDataJournalSize if (mNacp.getUserAccountSaveDataSize().journal_size != 0 || mCliOutputMode.show_extended_info) { - std::cout << " UserAccountSaveDataJournalSize: " << nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getUserAccountSaveDataSize().journal_size) << std::endl; + fmt::print(" UserAccountSaveDataJournalSize: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getUserAccountSaveDataSize().journal_size)); } // DeviceSaveDataSize if (mNacp.getDeviceSaveDataSize().size != 0 || mCliOutputMode.show_extended_info) { - std::cout << " DeviceSaveDataSize: " << nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getDeviceSaveDataSize().size) << std::endl; + fmt::print(" DeviceSaveDataSize: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getDeviceSaveDataSize().size)); } // DeviceSaveDataJournalSize if (mNacp.getDeviceSaveDataSize().journal_size != 0 || mCliOutputMode.show_extended_info) { - std::cout << " DeviceSaveDataJournalSize: " << nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getDeviceSaveDataSize().journal_size) << std::endl; + fmt::print(" DeviceSaveDataJournalSize: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getDeviceSaveDataSize().journal_size)); } // BcatDeliveryCacheStorageSize if (mNacp.getBcatDeliveryCacheStorageSize() != 0 || mCliOutputMode.show_extended_info) { - std::cout << " BcatDeliveryCacheStorageSize: " << nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getBcatDeliveryCacheStorageSize()) << std::endl; + fmt::print(" BcatDeliveryCacheStorageSize: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getBcatDeliveryCacheStorageSize())); } // ApplicationErrorCodeCategory if (mNacp.getApplicationErrorCodeCategory().empty() == false) { - std::cout << " ApplicationErrorCodeCategory: " << mNacp.getApplicationErrorCodeCategory() << std::endl; + fmt::print(" ApplicationErrorCodeCategory: {:s}\n", mNacp.getApplicationErrorCodeCategory()); } else if (mCliOutputMode.show_extended_info) { - std::cout << " ApplicationErrorCodeCategory: (NotSet)" << std::endl; + fmt::print(" ApplicationErrorCodeCategory: (NotSet)\n"); } // LocalCommunicationId if (mNacp.getLocalCommunicationId().size() > 0) { - std::cout << " LocalCommunicationId:" << std::endl; + fmt::print(" LocalCommunicationId:\n"); for (auto itr = mNacp.getLocalCommunicationId().begin(); itr != mNacp.getLocalCommunicationId().end(); itr++) { - std::cout << " 0x" << std::hex << std::setw(16) << std::setfill('0') << *itr << std::endl; + fmt::print(" 0x{:016x}\n", *itr); } } else if (mCliOutputMode.show_extended_info) { - std::cout << " LocalCommunicationId: None" << std::endl; + fmt::print(" LocalCommunicationId: None\n"); } // LogoType //if (mNacp.getLogoType() != nn::hac::nacp::LogoType::Nintendo || mCliOutputMode.show_extended_info) //{ - std::cout << " LogoType: " << nn::hac::ApplicationControlPropertyUtil::getLogoTypeAsString(mNacp.getLogoType()) << std::endl; + fmt::print(" LogoType: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getLogoTypeAsString(mNacp.getLogoType())); //} // LogoHandling if (mNacp.getLogoHandling() != nn::hac::nacp::LogoHandling::Auto || mCliOutputMode.show_extended_info) { - std::cout << " LogoHandling: " << nn::hac::ApplicationControlPropertyUtil::getLogoHandlingAsString(mNacp.getLogoHandling()) << std::endl; + fmt::print(" LogoHandling: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getLogoHandlingAsString(mNacp.getLogoHandling())); } // RuntimeAddOnContentInstall if (mNacp.getRuntimeAddOnContentInstall() != nn::hac::nacp::RuntimeAddOnContentInstall::Deny || mCliOutputMode.show_extended_info) { - std::cout << " RuntimeAddOnContentInstall: " << nn::hac::ApplicationControlPropertyUtil::getRuntimeAddOnContentInstallAsString(mNacp.getRuntimeAddOnContentInstall()) << std::endl; + fmt::print(" RuntimeAddOnContentInstall: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getRuntimeAddOnContentInstallAsString(mNacp.getRuntimeAddOnContentInstall())); } // RuntimeParameterDelivery if (mNacp.getRuntimeParameterDelivery() != nn::hac::nacp::RuntimeParameterDelivery::Always || mCliOutputMode.show_extended_info) { - std::cout << " RuntimeParameterDelivery: " << nn::hac::ApplicationControlPropertyUtil::getRuntimeParameterDeliveryAsString(mNacp.getRuntimeParameterDelivery()) << std::endl; + fmt::print(" RuntimeParameterDelivery: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getRuntimeParameterDeliveryAsString(mNacp.getRuntimeParameterDelivery())); } // CrashReport if (mNacp.getCrashReport() != nn::hac::nacp::CrashReport::Deny || mCliOutputMode.show_extended_info) { - std::cout << " CrashReport: " << nn::hac::ApplicationControlPropertyUtil::getCrashReportAsString(mNacp.getCrashReport()) << std::endl; + fmt::print(" CrashReport: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getCrashReportAsString(mNacp.getCrashReport())); } // Hdcp if (mNacp.getHdcp() != nn::hac::nacp::Hdcp::None || mCliOutputMode.show_extended_info) { - std::cout << " Hdcp: " << nn::hac::ApplicationControlPropertyUtil::getHdcpAsString(mNacp.getHdcp()) << std::endl; + fmt::print(" Hdcp: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getHdcpAsString(mNacp.getHdcp())); } // SeedForPsuedoDeviceId if (mNacp.getSeedForPsuedoDeviceId() != 0 || mCliOutputMode.show_extended_info) { - std::cout << " SeedForPsuedoDeviceId: 0x" << std::hex << std::setw(16) << std::setfill('0') << mNacp.getSeedForPsuedoDeviceId() << std::endl; + fmt::print(" SeedForPsuedoDeviceId: 0x{:016x}\n", mNacp.getSeedForPsuedoDeviceId()); } // BcatPassphase if (mNacp.getBcatPassphase().empty() == false) { - std::cout << " BcatPassphase: " << mNacp.getBcatPassphase() << std::endl; + fmt::print(" BcatPassphase: {:s}\n", mNacp.getBcatPassphase()); } else if (mCliOutputMode.show_extended_info) { - std::cout << " BcatPassphase: (NotSet)" << std::endl; + fmt::print(" BcatPassphase: (NotSet)\n"); } // StartupUserAccountOption if (mNacp.getStartupUserAccountOption().size() > 0) { - std::cout << " StartupUserAccountOption:" << std::endl; + fmt::print(" StartupUserAccountOption:\n"); for (auto itr = mNacp.getStartupUserAccountOption().begin(); itr != mNacp.getStartupUserAccountOption().end(); itr++) { - std::cout << " " << nn::hac::ApplicationControlPropertyUtil::getStartupUserAccountOptionFlagAsString(*itr) << std::endl; + fmt::print(" {:s}\n", nn::hac::ApplicationControlPropertyUtil::getStartupUserAccountOptionFlagAsString(*itr)); } } else if (mCliOutputMode.show_extended_info) { - std::cout << " StartupUserAccountOption: None" << std::endl; + fmt::print(" StartupUserAccountOption: None\n"); } // UserAccountSaveDataSizeMax if (mNacp.getUserAccountSaveDataMax().size != 0 || mCliOutputMode.show_extended_info) { - std::cout << " UserAccountSaveDataSizeMax: " << nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getUserAccountSaveDataMax().size) << std::endl; + fmt::print(" UserAccountSaveDataSizeMax: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getUserAccountSaveDataMax().size)); } // UserAccountSaveDataJournalSizeMax if (mNacp.getUserAccountSaveDataMax().journal_size != 0 || mCliOutputMode.show_extended_info) { - std::cout << " UserAccountSaveDataJournalSizeMax: " << nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getUserAccountSaveDataMax().journal_size) << std::endl; + fmt::print(" UserAccountSaveDataJournalSizeMax: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getUserAccountSaveDataMax().journal_size)); } // DeviceSaveDataSizeMax if (mNacp.getDeviceSaveDataMax().size != 0 || mCliOutputMode.show_extended_info) { - std::cout << " DeviceSaveDataSizeMax: " << nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getDeviceSaveDataMax().size) << std::endl; + fmt::print(" DeviceSaveDataSizeMax: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getDeviceSaveDataMax().size)); } // DeviceSaveDataJournalSizeMax if (mNacp.getDeviceSaveDataMax().journal_size != 0 || mCliOutputMode.show_extended_info) { - std::cout << " DeviceSaveDataJournalSizeMax: " << nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getDeviceSaveDataMax().journal_size) << std::endl; + fmt::print(" DeviceSaveDataJournalSizeMax: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getDeviceSaveDataMax().journal_size)); } // TemporaryStorageSize if (mNacp.getTemporaryStorageSize() != 0 || mCliOutputMode.show_extended_info) { - std::cout << " TemporaryStorageSize: " << nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getTemporaryStorageSize()) << std::endl; + fmt::print(" TemporaryStorageSize: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getTemporaryStorageSize())); } // CacheStorageSize if (mNacp.getCacheStorageSize().size != 0 || mCliOutputMode.show_extended_info) { - std::cout << " CacheStorageSize: " << nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getCacheStorageSize().size) << std::endl; + fmt::print(" CacheStorageSize: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getCacheStorageSize().size)); } // CacheStorageJournalSize if (mNacp.getCacheStorageSize().journal_size != 0 || mCliOutputMode.show_extended_info) { - std::cout << " CacheStorageJournalSize: " << nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getCacheStorageSize().journal_size) << std::endl; + fmt::print(" CacheStorageJournalSize: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getCacheStorageSize().journal_size)); } // CacheStorageDataAndJournalSizeMax if (mNacp.getCacheStorageDataAndJournalSizeMax() != 0 || mCliOutputMode.show_extended_info) { - std::cout << " CacheStorageDataAndJournalSizeMax: " << nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getCacheStorageDataAndJournalSizeMax()) << std::endl; + fmt::print(" CacheStorageDataAndJournalSizeMax: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getSaveDataSizeAsString(mNacp.getCacheStorageDataAndJournalSizeMax())); } // CacheStorageIndexMax if (mNacp.getCacheStorageIndexMax() != 0 || mCliOutputMode.show_extended_info) { - std::cout << " CacheStorageIndexMax: 0x" << std::hex << std::setw(4) << std::setfill('0') << mNacp.getCacheStorageIndexMax() << std::endl; + fmt::print(" CacheStorageIndexMax: 0x{:04x}\n", mNacp.getCacheStorageIndexMax()); } // PlayLogQueryableApplicationId if (mNacp.getPlayLogQueryableApplicationId().size() > 0) { - std::cout << " PlayLogQueryableApplicationId:" << std::endl; + fmt::print(" PlayLogQueryableApplicationId:\n"); for (auto itr = mNacp.getPlayLogQueryableApplicationId().begin(); itr != mNacp.getPlayLogQueryableApplicationId().end(); itr++) { - std::cout << " 0x" << std::hex << std::setw(16) << std::setfill('0') << *itr << std::endl; + fmt::print(" 0x{:016x}\n", *itr); } } else if (mCliOutputMode.show_extended_info) { - std::cout << " PlayLogQueryableApplicationId: None" << std::endl; + fmt::print(" PlayLogQueryableApplicationId: None\n"); } // PlayLogQueryCapability if (mNacp.getPlayLogQueryCapability() != nn::hac::nacp::PlayLogQueryCapability::None || mCliOutputMode.show_extended_info) { - std::cout << " PlayLogQueryCapability: " << nn::hac::ApplicationControlPropertyUtil::getPlayLogQueryCapabilityAsString(mNacp.getPlayLogQueryCapability()) << std::endl; + fmt::print(" PlayLogQueryCapability: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getPlayLogQueryCapabilityAsString(mNacp.getPlayLogQueryCapability())); } // Repair if (mNacp.getRepair().size() > 0) { - std::cout << " Repair:" << std::endl; + fmt::print(" Repair:\n"); for (auto itr = mNacp.getRepair().begin(); itr != mNacp.getRepair().end(); itr++) { - std::cout << " " << nn::hac::ApplicationControlPropertyUtil::getRepairFlagAsString(*itr) << std::endl; + fmt::print(" {:s}\n", nn::hac::ApplicationControlPropertyUtil::getRepairFlagAsString(*itr)); } } else if (mCliOutputMode.show_extended_info) { - std::cout << " Repair: None" << std::endl; + fmt::print(" Repair: None\n"); } // ProgramIndex if (mNacp.getProgramIndex() != 0 || mCliOutputMode.show_extended_info) { - std::cout << " ProgramIndex: 0x" << std::hex << std::setw(2) << std::setfill('0') << (uint32_t)mNacp.getProgramIndex() << std::endl; + fmt::print(" ProgramIndex: 0x{:02x}\n", mNacp.getProgramIndex()); } // RequiredNetworkServiceLicenseOnLaunch if (mNacp.getRequiredNetworkServiceLicenseOnLaunch().size() > 0) { - std::cout << " RequiredNetworkServiceLicenseOnLaunch:" << std::endl; + fmt::print(" RequiredNetworkServiceLicenseOnLaunch:\n"); for (auto itr = mNacp.getRequiredNetworkServiceLicenseOnLaunch().begin(); itr != mNacp.getRequiredNetworkServiceLicenseOnLaunch().end(); itr++) { - std::cout << " " << nn::hac::ApplicationControlPropertyUtil::getRequiredNetworkServiceLicenseOnLaunchFlagAsString(*itr) << std::endl; + fmt::print(" {:s}\n", nn::hac::ApplicationControlPropertyUtil::getRequiredNetworkServiceLicenseOnLaunchFlagAsString(*itr)); } } else if (mCliOutputMode.show_extended_info) { - std::cout << " RequiredNetworkServiceLicenseOnLaunch: None" << std::endl; + fmt::print(" RequiredNetworkServiceLicenseOnLaunch: None\n"); } // NeighborDetectionClientConfiguration auto detect_config = mNacp.getNeighborDetectionClientConfiguration(); if (detect_config.countSendGroupConfig() > 0 || detect_config.countReceivableGroupConfig() > 0) { - std::cout << " NeighborDetectionClientConfiguration:" << std::endl; + fmt::print(" NeighborDetectionClientConfiguration:\n"); if (detect_config.countSendGroupConfig() > 0) { - std::cout << " SendGroupConfig:" << std::endl; - std::cout << " GroupId: 0x" << std::hex << std::setw(16) << std::setfill('0') << detect_config.send_data_configuration.group_id << std::endl; - std::cout << " Key: " << fnd::SimpleTextOutput::arrayToString(detect_config.send_data_configuration.key, nn::hac::nacp::kNeighborDetectionGroupConfigurationKeyLength, false, "") << std::endl; + fmt::print(" SendGroupConfig:\n"); + fmt::print(" GroupId: 0x{:016x}\n", detect_config.send_data_configuration.group_id); + fmt::print(" Key: {:s}\n", tc::cli::FormatUtil::formatBytesAsString(detect_config.send_data_configuration.key.data(), detect_config.send_data_configuration.key.size(), false, "")); } else if (mCliOutputMode.show_extended_info) { - std::cout << " SendGroupConfig: None" << std::endl; + fmt::print(" SendGroupConfig: None\n"); } if (detect_config.countReceivableGroupConfig() > 0) { - std::cout << " ReceivableGroupConfig:" << std::endl; + fmt::print(" ReceivableGroupConfig:\n"); for (size_t i = 0; i < nn::hac::nacp::kReceivableGroupConfigurationCount; i++) { if (detect_config.receivable_data_configuration[i].isNull()) continue; - std::cout << " GroupId: 0x" << std::hex << std::setw(16) << std::setfill('0') << detect_config.receivable_data_configuration[i].group_id << std::endl; - std::cout << " Key: " << fnd::SimpleTextOutput::arrayToString(detect_config.receivable_data_configuration[i].key, nn::hac::nacp::kNeighborDetectionGroupConfigurationKeyLength, false, "") << std::endl; + fmt::print(" GroupId: 0x{:016x}\n", detect_config.receivable_data_configuration[i].group_id); + fmt::print(" Key: {:s}\n", tc::cli::FormatUtil::formatBytesAsString(detect_config.receivable_data_configuration[i].key.data(), detect_config.receivable_data_configuration[i].key.size(), false, "")); } } else if (mCliOutputMode.show_extended_info) { - std::cout << " ReceivableGroupConfig: None" << std::endl; + fmt::print(" ReceivableGroupConfig: None\n"); } } else if (mCliOutputMode.show_extended_info) { - std::cout << " NeighborDetectionClientConfiguration: None" << std::endl; + fmt::print(" NeighborDetectionClientConfiguration: None\n"); } // JitConfiguration if (mNacp.getJitConfiguration().is_enabled || mCliOutputMode.show_extended_info) { - std::cout << " JitConfiguration:" << std::endl; - std::cout << " IsEnabled: " << std::boolalpha << mNacp.getJitConfiguration().is_enabled << std::endl; - std::cout << " MemorySize: 0x" << std::hex << std::setw(16) << std::setfill('0') << mNacp.getJitConfiguration().memory_size << std::endl; + fmt::print(" JitConfiguration:\n"); + fmt::print(" IsEnabled: {}\n", mNacp.getJitConfiguration().is_enabled); + fmt::print(" MemorySize: 0x{:016x}\n", mNacp.getJitConfiguration().memory_size); } // PlayReportPermission if (mNacp.getPlayReportPermission() != nn::hac::nacp::PlayReportPermission::None || mCliOutputMode.show_extended_info) { - std::cout << " PlayReportPermission: " << nn::hac::ApplicationControlPropertyUtil::getPlayReportPermissionAsString(mNacp.getPlayReportPermission()) << std::endl; + fmt::print(" PlayReportPermission: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getPlayReportPermissionAsString(mNacp.getPlayReportPermission())); } // CrashScreenshotForProd if (mNacp.getCrashScreenshotForProd() != nn::hac::nacp::CrashScreenshotForProd::Deny || mCliOutputMode.show_extended_info) { - std::cout << " CrashScreenshotForProd: " << nn::hac::ApplicationControlPropertyUtil::getCrashScreenshotForProdAsString(mNacp.getCrashScreenshotForProd()) << std::endl; + fmt::print(" CrashScreenshotForProd: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getCrashScreenshotForProdAsString(mNacp.getCrashScreenshotForProd())); } // CrashScreenshotForDev if (mNacp.getCrashScreenshotForDev() != nn::hac::nacp::CrashScreenshotForDev::Deny || mCliOutputMode.show_extended_info) { - std::cout << " CrashScreenshotForDev: " << nn::hac::ApplicationControlPropertyUtil::getCrashScreenshotForDevAsString(mNacp.getCrashScreenshotForDev()) << std::endl; + fmt::print(" CrashScreenshotForDev: {:s}\n", nn::hac::ApplicationControlPropertyUtil::getCrashScreenshotForDevAsString(mNacp.getCrashScreenshotForDev())); } // AccessibleLaunchRequiredVersion if (mNacp.getAccessibleLaunchRequiredVersionApplicationId().size() > 0) { - std::cout << " AccessibleLaunchRequiredVersion:" << std::endl; - std::cout << " ApplicationId:" << std::endl; + fmt::print(" AccessibleLaunchRequiredVersion:\n"); + fmt::print(" ApplicationId:\n"); for (auto itr = mNacp.getAccessibleLaunchRequiredVersionApplicationId().begin(); itr != mNacp.getAccessibleLaunchRequiredVersionApplicationId().end(); itr++) { - std::cout << " 0x" << std::hex << std::setw(16) << std::setfill('0') << *itr << std::endl; + fmt::print(" 0x{:016x}\n", *itr); } } else if (mCliOutputMode.show_extended_info) { - std::cout << " AccessibleLaunchRequiredVersion: None" << std::endl; + fmt::print(" AccessibleLaunchRequiredVersion: None\n"); } } \ No newline at end of file diff --git a/src/NacpProcess.h b/src/NacpProcess.h index e458124..6d88485 100644 --- a/src/NacpProcess.h +++ b/src/NacpProcess.h @@ -19,7 +19,7 @@ public: const nn::hac::ApplicationControlProperty& getApplicationControlProperty() const; private: - const std::string kModuleName = "NacpProcess"; + std::string mModuleName; std::shared_ptr mFile; CliOutputMode mCliOutputMode;