1
0
Fork 0
mirror of https://github.com/DarkMatterCore/nxdumptool.git synced 2024-11-27 04:32:18 +00:00
nxdumptool/source/main.cpp

77 lines
2.8 KiB
C++
Raw Normal View History

/*
2021-06-11 05:41:58 +01:00
* main.cpp
*
2023-04-08 12:42:22 +01:00
* Copyright (c) 2020-2023, DarkMatterCore <pabloacurielz@gmail.com>.
2021-06-11 05:41:58 +01:00
*
* This file is part of nxdumptool (https://github.com/DarkMatterCore/nxdumptool).
*
* nxdumptool is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* nxdumptool is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <nxdt_utils.h>
#include <scope_guard.hpp>
2021-06-11 05:41:58 +01:00
#include <root_view.hpp>
namespace i18n = brls::i18n; /* For getStr(). */
using namespace i18n::literals; /* For _i18n. */
bool g_borealisInitialized = false;
int main(int argc, char *argv[])
{
2021-06-11 05:41:58 +01:00
/* Set scope guard to clean up resources at exit. */
ON_SCOPE_EXIT { utilsCloseResources(); };
/* Initialize application resources. */
if (!utilsInitializeResources(argc, (const char**)argv)) return EXIT_FAILURE;
/* Load Borealis translation files. */
2021-06-11 05:41:58 +01:00
brls::i18n::loadTranslations();
2021-08-08 16:50:20 +01:00
/* Set common footer. */
brls::Application::setCommonFooter("v" APP_VERSION " (" GIT_REV ")");
/* Initialize Borealis. */
if (!brls::Application::init(APP_TITLE)) return EXIT_FAILURE;
g_borealisInitialized = true;
try {
/* Check if we're running under applet mode. */
Runtime key derivation with hardcoded key sources * aes: add aes128EcbCrypt() as a one-shot function to perform AES-128-ECB crypto. The rest of the codebase now calls this function whenever suitable. * fs_ext: add const keyword to IPC input structs wherever suitable. * key_sources: add hardcoded master key vectors (prod, dev); master KEK sources (Erista, Mariko); master key source; ticket common key source; SMC key type sources; SMC seal key masks; AES key generation source; NCA header KEK source; NCA header key source and NCA KAEK sources. Also fixed the hardcoded gamecard CardInfo key source for dev units (it was previously generated using retail keydata, my bad). * keys: remove keysGetNcaMainSignatureModulus(); remove keysDecryptNcaKeyAreaEntry(); repurpose keyset struct to only hold keys that can actually be used for the current hardware type; remove KeysGameCardKeyset; remove keysIsXXModulusYYMandatory() helpers; remove keysRetrieveKeysFromProgramMemory(); remove keysDeriveSealedNcaKeyAreaEncryptionKeys(); add keysDeriveMasterKeys() and keysDerivePerGenerationKeys(); rename keysDeriveGameCardKeys() -> keysDeriveGcCardInfoKey(); add small reimplementations of GenerateAesKek, LoadAesKey and GenerateAesKey; add keysLoadAesKeyFromAesKek() and keysGenerateAesKeyFromAesKek() wrappers. Furthermore, master key derivation is now carried out manually using hardcoded key sources and the last known master key, which is loaded from the Lockpick_RCM keys file -- if the last known master key is unavailable, the key derivation algorithm will then fallback to TSEC root key / Mariko KEK based key derivation, depending on the hardware type. * nca: add hardcoded NCA man signature moduli (prod, dev); merge ncaDecryptKeyArea() and ncaEncryptKeyArea() into ncaKeyAreaCrypt(). * nxdt_utils: add utilsIsMarikoUnit(); remove _utilsAppletModeCheck(); rename utilsAppletModeCheck() -> utilsIsAppletMode(). * services: remove spl:mig dependency (yay). * smc: add SmcKeyType enum; add SmcSealKey enum; add SmcGenerateAesKekOption struct; add smcPrepareGenerateAesKekOption().
2023-04-08 12:34:53 +01:00
if (utilsIsAppletMode())
{
/* Push crash frame with the applet mode warning. */
brls::Application::pushView(new brls::CrashFrame("generic/applet_mode_warning"_i18n, [](brls::View *view) {
/* Swap crash frame with root view whenever the crash frame button is clicked. */
//brls::Application::swapView(new nxdt::views::RootView());
/* TODO: restore original behavior after fixing the applet mode issues. */
brls::Application::quit();
}));
} else {
/* Push root view. */
brls::Application::pushView(new nxdt::views::RootView());
}
/* Run the application. */
while(brls::Application::mainLoop());
} catch (...) {
std::exception_ptr p = std::current_exception();
LOG_MSG_ERROR("Exception caught! (%s).", p ? p.__cxa_exception_type()->name() : "unknown");
brls::Application::crash(i18n::getStr("generic/exception_caught"_i18n, p ? p.__cxa_exception_type()->name() : "generic/unknown_exception"_i18n));
while(brls::Application::mainLoop());
}
2021-06-11 05:41:58 +01:00
/* Exit. */
return EXIT_SUCCESS;
}