1
0
Fork 0
mirror of https://github.com/DarkMatterCore/nxdumptool.git synced 2024-09-20 05:53:25 +01:00
nxdumptool/source/main.c

178 lines
4.1 KiB
C
Raw Normal View History

2020-04-16 01:06:41 +01:00
/*
* Copyright (c) 2020 DarkMatterCore
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope 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 <http://www.gnu.org/licenses/>.
*/
2020-04-11 06:28:26 +01:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <switch.h>
2020-04-15 21:50:07 +01:00
//#include "lvgl_helper.h"
#include "utils.h"
#include "gamecard.h"
2020-04-11 06:28:26 +01:00
int main(int argc, char *argv[])
{
2020-04-15 21:50:07 +01:00
(void)argc;
(void)argv;
2020-04-11 06:28:26 +01:00
int ret = 0;
2020-04-15 21:50:07 +01:00
LOGFILE("nxdumptool starting.");
if (!utilsInitializeResources())
2020-04-11 06:28:26 +01:00
{
ret = -1;
goto out;
}
2020-04-15 21:50:07 +01:00
/*lv_test();
2020-04-11 06:28:26 +01:00
while(appletMainLoop())
{
2020-04-15 21:50:07 +01:00
lv_task_handler();
if (lvglHelperGetExitFlag()) break;
}*/
consoleInit(NULL);
printf("waiting...\n");
consoleUpdate(NULL);
while(appletMainLoop())
{
if (gamecardIsReady()) break;
}
2020-04-16 01:06:41 +01:00
FILE *tmp_file = NULL;
GameCardHeader header = {0};
FsGameCardCertificate cert = {0};
u64 total_size = 0, trimmed_size = 0;
u32 update_version = 0;
if (gamecardGetHeader(&header))
{
printf("header success\n");
consoleUpdate(NULL);
tmp_file = fopen("sdmc:/header.bin", "wb");
if (tmp_file)
{
fwrite(&header, 1, sizeof(GameCardHeader), tmp_file);
fclose(tmp_file);
tmp_file = NULL;
printf("header saved\n");
} else {
printf("header not saved\n");
}
} else {
printf("header failed\n");
}
consoleUpdate(NULL);
2020-04-16 05:37:16 +01:00
if (gamecardGetTotalSize(&total_size))
2020-04-16 01:06:41 +01:00
{
printf("total_size: 0x%lX\n", total_size);
} else {
printf("total_size failed\n");
}
consoleUpdate(NULL);
2020-04-16 05:37:16 +01:00
if (gamecardGetTrimmedSize(&trimmed_size))
2020-04-16 01:06:41 +01:00
{
printf("trimmed_size: 0x%lX\n", trimmed_size);
} else {
printf("trimmed_size failed\n");
}
consoleUpdate(NULL);
if (gamecardGetCertificate(&cert))
2020-04-15 21:50:07 +01:00
{
2020-04-16 01:06:41 +01:00
printf("cert success\n");
consoleUpdate(NULL);
tmp_file = fopen("sdmc:/cert.bin", "wb");
if (tmp_file)
{
fwrite(&cert, 1, sizeof(FsGameCardCertificate), tmp_file);
fclose(tmp_file);
tmp_file = NULL;
printf("cert saved\n");
} else {
printf("cert not saved\n");
}
} else {
printf("cert failed\n");
2020-04-15 21:50:07 +01:00
}
consoleUpdate(NULL);
2020-04-16 01:06:41 +01:00
if (gamecardGetBundledFirmwareUpdateVersion(&update_version))
2020-04-15 21:50:07 +01:00
{
2020-04-16 01:06:41 +01:00
printf("update_version: %u\n", update_version);
} else {
printf("update_version failed\n");
2020-04-11 06:28:26 +01:00
}
2020-04-16 01:06:41 +01:00
consoleUpdate(NULL);
u8 *buf = malloc((u64)0x400300); // 4 MiB + 512 bytes + 256 bytes
if (buf)
{
printf("buf succeeded\n");
consoleUpdate(NULL);
if (gamecardRead(buf, (u64)0x400300, (u64)0x16F18100)) // force unaligned read that spans both storage areas
{
printf("read succeeded\n");
consoleUpdate(NULL);
tmp_file = fopen("sdmc:/data.bin", "wb");
if (tmp_file)
{
fwrite(buf, 1, (u64)0x400300, tmp_file);
fclose(tmp_file);
tmp_file = NULL;
printf("data saved\n");
} else {
printf("data not saved\n");
}
} else {
printf("read failed\n");
}
free(buf);
} else {
printf("buf failed\n");
}
2020-04-15 21:50:07 +01:00
consoleUpdate(NULL);
2020-04-16 01:06:41 +01:00
2020-04-15 21:50:07 +01:00
SLEEP(3);
consoleExit(NULL);
2020-04-11 06:28:26 +01:00
out:
2020-04-15 21:50:07 +01:00
utilsCloseResources();
2020-04-11 06:28:26 +01:00
return ret;
}