1
0
Fork 0
mirror of https://github.com/DarkMatterCore/nxdumptool.git synced 2024-11-26 12:12:02 +00:00
nxdumptool/source/main.c

251 lines
12 KiB
C
Raw Permalink Normal View History

2018-05-15 13:57:40 +01:00
#include <stdio.h>
2019-04-21 17:27:33 +01:00
#include <stdlib.h>
#include <string.h>
2018-05-15 13:57:40 +01:00
#include <switch.h>
2018-05-16 17:06:57 +01:00
#include <memory.h>
2018-05-15 17:00:19 +01:00
#include "dumper.h"
#include "ui.h"
#include "util.h"
2019-04-21 17:27:33 +01:00
#include "fsext.h"
2019-05-01 21:24:13 +01:00
#include "extkeys.h"
2018-05-15 13:57:40 +01:00
2019-04-21 17:27:33 +01:00
/* Extern variables */
2018-05-15 13:57:40 +01:00
2019-04-21 17:27:33 +01:00
extern FsDeviceOperator fsOperatorInstance;
2019-04-21 17:27:33 +01:00
extern FsEventNotifier fsGameCardEventNotifier;
extern Handle fsGameCardEventHandle;
extern Event fsGameCardKernelEvent;
extern UEvent exitEvent;
2019-04-21 17:27:33 +01:00
extern bool gameCardInserted;
2018-06-30 07:37:42 +01:00
2019-05-01 21:24:13 +01:00
extern char strbuf[NAME_BUF_LEN * 4];
extern nca_keyset_t nca_keyset;
2019-04-21 17:27:33 +01:00
int main(int argc, char *argv[])
{
2019-04-21 17:27:33 +01:00
/* Initialize UI */
if (!uiInit()) return -1;
int ret = 0;
Result result;
/* Initialize the fsp-srv service */
result = fsInitialize();
if (R_SUCCEEDED(result))
{
/* Open device operator */
result = fsOpenDeviceOperator(&fsOperatorInstance);
if (R_SUCCEEDED(result))
{
/* Initialize the ncm service */
result = ncmInitialize();
if (R_SUCCEEDED(result))
{
/* Initialize the ns service */
result = nsInitialize();
if (R_SUCCEEDED(result))
{
/* Initialize the time service */
result = timeInitialize();
if (R_SUCCEEDED(result))
{
/* Open gamecard detection event notifier */
result = fsOpenGameCardDetectionEventNotifier(&fsGameCardEventNotifier);
if (R_SUCCEEDED(result))
{
2019-04-23 06:14:57 +01:00
/* Retrieve gamecard detection event handle */
2019-04-21 17:27:33 +01:00
result = fsEventNotifierGetEventHandle(&fsGameCardEventNotifier, &fsGameCardEventHandle);
if (R_SUCCEEDED(result))
{
/* Retrieve initial gamecard status */
gameCardInserted = isGameCardInserted();
/* Load gamecard detection kernel event */
eventLoadRemote(&fsGameCardKernelEvent, fsGameCardEventHandle, false);
/* Create usermode exit event */
ueventCreate(&exitEvent, false);
/* Create gamecard detection thread */
Thread thread;
result = threadCreate(&thread, fsGameCardDetectionThreadFunc, NULL, 0x10000, 0x2C, -2);
if (R_SUCCEEDED(result))
{
/* Start gamecard detection thread */
result = threadStart(&thread);
if (R_SUCCEEDED(result))
{
2019-05-01 21:24:13 +01:00
/* Zero out NCA keyset */
memset(&nca_keyset, 0, sizeof(nca_keyset_t));
2019-04-21 17:27:33 +01:00
/* Main application loop */
bool exitLoop = false;
while(appletMainLoop())
{
UIResult result = uiProcess();
switch(result)
{
case resultShowMainMenu:
uiSetState(stateMainMenu);
break;
case resultShowXciDumpMenu:
uiSetState(stateXciDumpMenu);
break;
case resultDumpXci:
uiSetState(stateDumpXci);
break;
2019-05-01 21:24:13 +01:00
case resultShowNspDumpMenu:
uiSetState(stateNspDumpMenu);
break;
case resultDumpNsp:
uiSetState(stateDumpNsp);
break;
2019-04-21 17:27:33 +01:00
case resultShowRawPartitionDumpMenu:
uiSetState(stateRawPartitionDumpMenu);
break;
case resultDumpRawPartition:
uiSetState(stateDumpRawPartition);
break;
case resultShowPartitionDataDumpMenu:
uiSetState(statePartitionDataDumpMenu);
break;
case resultDumpPartitionData:
uiSetState(stateDumpPartitionData);
break;
case resultShowViewGameCardFsMenu:
uiSetState(stateViewGameCardFsMenu);
break;
case resultShowViewGameCardFsGetList:
uiSetState(stateViewGameCardFsGetList);
break;
case resultShowViewGameCardFsBrowser:
uiSetState(stateViewGameCardFsBrowser);
break;
case resultViewGameCardFsBrowserCopyFile:
uiSetState(stateViewGameCardFsBrowserCopyFile);
break;
case resultDumpGameCardCertificate:
uiSetState(stateDumpGameCardCertificate);
break;
case resultUpdateNSWDBXml:
uiSetState(stateUpdateNSWDBXml);
break;
case resultUpdateApplication:
uiSetState(stateUpdateApplication);
break;
case resultExit:
exitLoop = true;
break;
default:
break;
}
if (exitLoop) break;
}
/* Signal the exit event to terminate the gamecard detection thread */
ueventSignal(&exitEvent);
/* Wait for the gamecard detection thread to exit */
threadWaitForExit(&thread);
} else {
snprintf(strbuf, sizeof(strbuf) / sizeof(strbuf[0]), "Failed to start gamecard detection thread! (0x%08X)", result);
uiDrawString(strbuf, 0, 0, 255, 255, 255);
uiRefreshDisplay();
delay(5);
ret = -10;
}
/* Close gamecard detection thread */
threadClose(&thread);
} else {
snprintf(strbuf, sizeof(strbuf) / sizeof(strbuf[0]), "Failed to create gamecard detection thread! (0x%08X)", result);
uiDrawString(strbuf, 0, 0, 255, 255, 255);
uiRefreshDisplay();
delay(5);
ret = -9;
}
2019-04-23 06:14:57 +01:00
/* Close gamecard detection kernel event */
2019-04-21 17:27:33 +01:00
eventClose(&fsGameCardKernelEvent);
} else {
snprintf(strbuf, sizeof(strbuf) / sizeof(strbuf[0]), "Failed to retrieve gamecard detection event handle! (0x%08X)", result);
uiDrawString(strbuf, 0, 0, 255, 255, 255);
uiRefreshDisplay();
delay(5);
ret = -8;
}
2019-04-23 06:14:57 +01:00
/* Close gamecard detection event notifier */
2019-04-21 17:27:33 +01:00
fsEventNotifierClose(&fsGameCardEventNotifier);
} else {
snprintf(strbuf, sizeof(strbuf) / sizeof(strbuf[0]), "Failed to open gamecard detection event notifier! (0x%08X)", result);
uiDrawString(strbuf, 0, 0, 255, 255, 255);
uiRefreshDisplay();
delay(5);
ret = -7;
}
/* Denitialize the time service */
timeExit();
} else {
snprintf(strbuf, sizeof(strbuf) / sizeof(strbuf[0]), "Failed to initialize the time service! (0x%08X)", result);
uiDrawString(strbuf, 0, 0, 255, 255, 255);
uiRefreshDisplay();
delay(5);
ret = -6;
}
/* Denitialize the ns service */
nsExit();
} else {
snprintf(strbuf, sizeof(strbuf) / sizeof(strbuf[0]), "Failed to initialize the ns service! (0x%08X)", result);
uiDrawString(strbuf, 0, 0, 255, 255, 255);
uiRefreshDisplay();
delay(5);
ret = -5;
}
/* Denitialize the ncm service */
ncmExit();
} else {
snprintf(strbuf, sizeof(strbuf) / sizeof(strbuf[0]), "Failed to initialize the ncm service! (0x%08X)", result);
uiDrawString(strbuf, 0, 0, 255, 255, 255);
uiRefreshDisplay();
delay(5);
ret = -4;
}
/* Close device operator */
fsDeviceOperatorClose(&fsOperatorInstance);
} else {
snprintf(strbuf, sizeof(strbuf) / sizeof(strbuf[0]), "Failed to open device operator! (0x%08X)", result);
uiDrawString(strbuf, 0, 0, 255, 255, 255);
uiRefreshDisplay();
delay(5);
ret = -3;
}
/* Denitialize the fs-srv service */
fsExit();
} else {
snprintf(strbuf, sizeof(strbuf) / sizeof(strbuf[0]), "Failed to initialize the fsp-srv service! (0x%08X)", result);
uiDrawString(strbuf, 0, 0, 255, 255, 255);
uiRefreshDisplay();
delay(5);
ret = -2;
}
2019-05-01 21:24:13 +01:00
/* Free gamecard resources */
freeGameCardInfo();
2019-04-21 17:27:33 +01:00
/* Deinitialize UI */
uiDeinit();
return ret;
2018-05-15 13:57:40 +01:00
}