2020-07-29 22:02:21 +01:00
|
|
|
/*
|
|
|
|
* main.c
|
|
|
|
*
|
2023-04-08 12:42:22 +01:00
|
|
|
* Copyright (c) 2020-2023, DarkMatterCore <pabloacurielz@gmail.com>.
|
2020-07-29 22:02:21 +01:00
|
|
|
*
|
|
|
|
* This file is part of nxdumptool (https://github.com/DarkMatterCore/nxdumptool).
|
|
|
|
*
|
2021-03-25 19:26:58 +00:00
|
|
|
* 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.
|
2020-07-29 22:02:21 +01:00
|
|
|
*
|
2021-03-25 19:26:58 +00:00
|
|
|
* 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.
|
2020-07-29 22:02:21 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-03-25 19:26:58 +00:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-07-29 22:02:21 +01:00
|
|
|
*/
|
|
|
|
|
2021-03-26 04:35:14 +00:00
|
|
|
#include "nxdt_utils.h"
|
2020-07-29 22:02:21 +01:00
|
|
|
#include "nca.h"
|
|
|
|
#include "title.h"
|
|
|
|
#include "pfs.h"
|
|
|
|
#include "romfs.h"
|
|
|
|
|
|
|
|
#define BLOCK_SIZE 0x800000
|
|
|
|
#define OUTPATH "sdmc:/systitle_dumps"
|
|
|
|
|
2021-09-04 05:17:17 +01:00
|
|
|
bool g_borealisInitialized = false;
|
|
|
|
|
2021-04-26 00:10:34 +01:00
|
|
|
static PadState g_padState = {0};
|
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
static u8 *buf = NULL;
|
|
|
|
static FILE *filefd = NULL;
|
|
|
|
static char path[FS_MAX_PATH * 2] = {0};
|
|
|
|
|
2021-04-26 00:10:34 +01:00
|
|
|
static void utilsScanPads(void)
|
|
|
|
{
|
|
|
|
padUpdate(&g_padState);
|
|
|
|
}
|
|
|
|
|
|
|
|
static u64 utilsGetButtonsDown(void)
|
|
|
|
{
|
|
|
|
return padGetButtonsDown(&g_padState);
|
|
|
|
}
|
|
|
|
|
|
|
|
static u64 utilsGetButtonsHeld(void)
|
|
|
|
{
|
|
|
|
return padGetButtons(&g_padState);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void utilsWaitForButtonPress(u64 flag)
|
|
|
|
{
|
|
|
|
/* Don't consider stick movement as button inputs. */
|
|
|
|
if (!flag) flag = ~(HidNpadButton_StickLLeft | HidNpadButton_StickLRight | HidNpadButton_StickLUp | HidNpadButton_StickLDown | HidNpadButton_StickRLeft | HidNpadButton_StickRRight | \
|
|
|
|
HidNpadButton_StickRUp | HidNpadButton_StickRDown);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-04-26 00:10:34 +01:00
|
|
|
while(appletMainLoop())
|
|
|
|
{
|
|
|
|
utilsScanPads();
|
|
|
|
if (utilsGetButtonsDown() & flag) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
static void consolePrint(const char *text, ...)
|
|
|
|
{
|
|
|
|
va_list v;
|
|
|
|
va_start(v, text);
|
|
|
|
vfprintf(stdout, text, v);
|
|
|
|
va_end(v);
|
|
|
|
consoleUpdate(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dumpPartitionFs(TitleInfo *info, NcaFsSectionContext *nca_fs_ctx)
|
|
|
|
{
|
|
|
|
if (!buf || !info || !nca_fs_ctx) return;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
u32 pfs_entry_count = 0;
|
|
|
|
PartitionFileSystemContext pfs_ctx = {0};
|
|
|
|
PartitionFileSystemEntry *pfs_entry = NULL;
|
|
|
|
char *pfs_entry_name = NULL;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
size_t path_len = 0;
|
2020-08-01 05:52:40 +01:00
|
|
|
*path = '\0';
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
if (!pfsInitializeContext(&pfs_ctx, nca_fs_ctx))
|
|
|
|
{
|
|
|
|
consolePrint("pfs initialize ctx failed!\n");
|
|
|
|
goto end;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
if (!(pfs_entry_count = pfsGetEntryCount(&pfs_ctx)))
|
|
|
|
{
|
|
|
|
consolePrint("pfs entry count is zero!\n");
|
|
|
|
goto end;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
snprintf(path, sizeof(path), OUTPATH "/%016lX - %s/%s (%s)/Section %u (%s)", info->meta_key.id, info->app_metadata->lang_entry.name, ((NcaContext*)nca_fs_ctx->nca_ctx)->content_id_str, \
|
2022-06-29 13:41:58 +01:00
|
|
|
titleGetNcmContentTypeName(((NcaContext*)nca_fs_ctx->nca_ctx)->content_type), nca_fs_ctx->section_idx, ncaGetFsSectionTypeName(nca_fs_ctx));
|
2020-07-29 22:02:21 +01:00
|
|
|
utilsCreateDirectoryTree(path, true);
|
|
|
|
path_len = strlen(path);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
for(u32 i = 0; i < pfs_entry_count; i++)
|
|
|
|
{
|
|
|
|
if (!(pfs_entry = pfsGetEntryByIndex(&pfs_ctx, i)) || !(pfs_entry_name = pfsGetEntryNameByIndex(&pfs_ctx, i)) || !strlen(pfs_entry_name))
|
|
|
|
{
|
|
|
|
consolePrint("pfs get entry / get name #%u failed!\n", i);
|
|
|
|
goto end;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
path[path_len] = '\0';
|
|
|
|
strcat(path, "/");
|
|
|
|
strcat(path, pfs_entry_name);
|
|
|
|
utilsReplaceIllegalCharacters(path + path_len + 1, true);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
filefd = fopen(path, "wb");
|
|
|
|
if (!filefd)
|
|
|
|
{
|
|
|
|
consolePrint("failed to create \"%s\"!\n", path);
|
|
|
|
goto end;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2023-05-24 20:05:34 +01:00
|
|
|
/* Set file size. */
|
|
|
|
ftruncate(fileno(filefd), (off_t)pfs_entry->size);
|
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
consolePrint("dumping \"%s\"...\n", pfs_entry_name);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
u64 blksize = BLOCK_SIZE;
|
|
|
|
for(u64 j = 0; j < pfs_entry->size; j += blksize)
|
|
|
|
{
|
|
|
|
if (blksize > (pfs_entry->size - j)) blksize = (pfs_entry->size - j);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
if (!pfsReadEntryData(&pfs_ctx, pfs_entry, buf, blksize, j))
|
|
|
|
{
|
|
|
|
consolePrint("failed to read 0x%lX block from offset 0x%lX!\n", blksize, j);
|
|
|
|
goto end;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
fwrite(buf, 1, blksize, filefd);
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
fclose(filefd);
|
|
|
|
filefd = NULL;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
consolePrint("pfs dump complete\n");
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
end:
|
|
|
|
if (filefd)
|
|
|
|
{
|
|
|
|
fclose(filefd);
|
|
|
|
remove(path);
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-11-21 10:29:29 +00:00
|
|
|
if (*path) utilsCommitSdCardFileSystemChanges();
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
pfsFreeContext(&pfs_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dumpRomFs(TitleInfo *info, NcaFsSectionContext *nca_fs_ctx)
|
|
|
|
{
|
|
|
|
if (!buf || !info || !nca_fs_ctx) return;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
RomFileSystemContext romfs_ctx = {0};
|
|
|
|
RomFileSystemFileEntry *romfs_file_entry = NULL;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
size_t path_len = 0;
|
2020-08-01 05:52:40 +01:00
|
|
|
*path = '\0';
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-07-05 00:25:28 +01:00
|
|
|
if (!romfsInitializeContext(&romfs_ctx, nca_fs_ctx, NULL))
|
2020-07-29 22:02:21 +01:00
|
|
|
{
|
|
|
|
consolePrint("romfs initialize ctx failed!\n");
|
|
|
|
goto end;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
snprintf(path, sizeof(path), OUTPATH "/%016lX - %s/%s (%s)/Section %u (%s)", info->meta_key.id, info->app_metadata->lang_entry.name, ((NcaContext*)nca_fs_ctx->nca_ctx)->content_id_str, \
|
2022-06-29 13:41:58 +01:00
|
|
|
titleGetNcmContentTypeName(((NcaContext*)nca_fs_ctx->nca_ctx)->content_type), nca_fs_ctx->section_idx, ncaGetFsSectionTypeName(nca_fs_ctx));
|
2020-07-29 22:02:21 +01:00
|
|
|
utilsCreateDirectoryTree(path, true);
|
|
|
|
path_len = strlen(path);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-07-06 10:57:31 +01:00
|
|
|
while(romfsCanMoveToNextFileEntry(&romfs_ctx))
|
2020-07-29 22:02:21 +01:00
|
|
|
{
|
2022-07-06 10:57:31 +01:00
|
|
|
if (!(romfs_file_entry = romfsGetCurrentFileEntry(&romfs_ctx)) || \
|
2020-07-29 22:02:21 +01:00
|
|
|
!romfsGeneratePathFromFileEntry(&romfs_ctx, romfs_file_entry, path + path_len, sizeof(path) - path_len, RomFileSystemPathIllegalCharReplaceType_KeepAsciiCharsOnly))
|
|
|
|
{
|
2022-07-06 10:57:31 +01:00
|
|
|
consolePrint("romfs get entry / generate path failed for 0x%lX!\n", romfs_ctx.cur_file_offset);
|
2020-07-29 22:02:21 +01:00
|
|
|
goto end;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
utilsCreateDirectoryTree(path, false);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
filefd = fopen(path, "wb");
|
|
|
|
if (!filefd)
|
|
|
|
{
|
|
|
|
consolePrint("failed to create \"%s\"!\n", path);
|
|
|
|
goto end;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2023-05-24 20:05:34 +01:00
|
|
|
/* Set file size. */
|
|
|
|
ftruncate(fileno(filefd), (off_t)romfs_file_entry->size);
|
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
consolePrint("dumping \"%s\"...\n", path + path_len);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
u64 blksize = BLOCK_SIZE;
|
|
|
|
for(u64 j = 0; j < romfs_file_entry->size; j += blksize)
|
|
|
|
{
|
|
|
|
if (blksize > (romfs_file_entry->size - j)) blksize = (romfs_file_entry->size - j);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
if (!romfsReadFileEntryData(&romfs_ctx, romfs_file_entry, buf, blksize, j))
|
|
|
|
{
|
|
|
|
consolePrint("failed to read 0x%lX block from offset 0x%lX!\n", blksize, j);
|
|
|
|
goto end;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
fwrite(buf, 1, blksize, filefd);
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
fclose(filefd);
|
|
|
|
filefd = NULL;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-07-06 10:57:31 +01:00
|
|
|
if (!romfsMoveToNextFileEntry(&romfs_ctx))
|
|
|
|
{
|
|
|
|
consolePrint("failed to move to next file entry!\n");
|
|
|
|
goto end;
|
|
|
|
}
|
2020-07-29 22:02:21 +01:00
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
consolePrint("romfs dump complete\n");
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
end:
|
|
|
|
if (filefd)
|
|
|
|
{
|
|
|
|
fclose(filefd);
|
|
|
|
remove(path);
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-11-21 10:29:29 +00:00
|
|
|
if (*path) utilsCommitSdCardFileSystemChanges();
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
romfsFreeContext(&romfs_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dumpFsSection(TitleInfo *info, NcaFsSectionContext *nca_fs_ctx)
|
|
|
|
{
|
|
|
|
if (!buf || !info || !nca_fs_ctx) return;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
switch(nca_fs_ctx->section_type)
|
|
|
|
{
|
|
|
|
case NcaFsSectionType_PartitionFs:
|
|
|
|
dumpPartitionFs(info, nca_fs_ctx);
|
|
|
|
break;
|
|
|
|
case NcaFsSectionType_RomFs:
|
|
|
|
case NcaFsSectionType_Nca0RomFs:
|
|
|
|
dumpRomFs(info, nca_fs_ctx);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
consolePrint("invalid section type!\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int ret = 0;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-05-18 13:32:43 +01:00
|
|
|
if (!utilsInitializeResources(argc, (const char**)argv))
|
2020-07-29 22:02:21 +01:00
|
|
|
{
|
|
|
|
ret = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-04-26 00:10:34 +01:00
|
|
|
/* Configure input. */
|
|
|
|
/* Up to 8 different, full controller inputs. */
|
|
|
|
/* Individual Joy-Cons not supported. */
|
|
|
|
padConfigureInput(8, HidNpadStyleSet_NpadFullCtrl);
|
|
|
|
padInitializeWithMask(&g_padState, 0x1000000FFUL);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-03-08 14:44:11 +00:00
|
|
|
consoleInit(NULL);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
u32 app_count = 0;
|
|
|
|
TitleApplicationMetadata **app_metadata = NULL;
|
|
|
|
TitleInfo *cur_title_info = NULL;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-08-03 22:41:00 +01:00
|
|
|
u32 selected_idx = 0, menu = 0, page_size = 30, scroll = 0;
|
|
|
|
u32 title_idx = 0, title_scroll = 0, nca_idx = 0;
|
2020-07-29 22:02:21 +01:00
|
|
|
char nca_id_str[0x21] = {0};
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
NcaContext *nca_ctx = NULL;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-02-19 05:03:06 +00:00
|
|
|
bool applet_status = true;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
app_metadata = titleGetApplicationMetadataEntries(true, &app_count);
|
|
|
|
if (!app_metadata || !app_count)
|
|
|
|
{
|
|
|
|
consolePrint("app metadata failed\n");
|
|
|
|
goto out2;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
consolePrint("app metadata succeeded\n");
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
buf = malloc(BLOCK_SIZE);
|
|
|
|
if (!buf)
|
|
|
|
{
|
|
|
|
consolePrint("buf failed\n");
|
|
|
|
goto out2;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
consolePrint("buf succeeded\n");
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
nca_ctx = calloc(1, sizeof(NcaContext));
|
|
|
|
if (!nca_ctx)
|
|
|
|
{
|
|
|
|
consolePrint("nca ctx buf failed\n");
|
|
|
|
goto out2;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
consolePrint("nca ctx buf succeeded\n");
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
utilsSleep(1);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-02-19 05:03:06 +00:00
|
|
|
while((applet_status = appletMainLoop()))
|
2020-07-29 22:02:21 +01:00
|
|
|
{
|
|
|
|
consoleClear();
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
printf("select a %s.", menu == 0 ? "system title to view its contents" : (menu == 1 ? "content" : "fs section"));
|
|
|
|
printf("\npress b to %s.\n\n", menu == 0 ? "exit" : "go back");
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-10 11:10:50 +01:00
|
|
|
if (menu == 0)
|
|
|
|
{
|
|
|
|
printf("title: %u / %u\n", selected_idx + 1, app_count);
|
|
|
|
printf("selected title: %016lX - %s\n\n", app_metadata[selected_idx]->title_id, app_metadata[selected_idx]->lang_entry.name);
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-08-03 22:41:00 +01:00
|
|
|
if (menu >= 1) printf("selected title: %016lX - %s\n\n", app_metadata[title_idx]->title_id, app_metadata[title_idx]->lang_entry.name);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-08-03 22:41:00 +01:00
|
|
|
if (menu == 2) printf("selected content: %s (%s)\n\n", nca_id_str, titleGetNcmContentTypeName(cur_title_info->content_infos[nca_idx].content_type));
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
u32 max_val = (menu == 0 ? app_count : (menu == 1 ? cur_title_info->content_count : NCA_FS_HEADER_COUNT));
|
2020-08-03 22:41:00 +01:00
|
|
|
for(u32 i = scroll; i < max_val; i++)
|
2020-07-29 22:02:21 +01:00
|
|
|
{
|
2020-08-03 22:41:00 +01:00
|
|
|
if (i >= (scroll + page_size)) break;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
printf("%s", i == selected_idx ? " -> " : " ");
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
if (menu == 0)
|
|
|
|
{
|
|
|
|
printf("%016lX - %s\n", app_metadata[i]->title_id, app_metadata[i]->lang_entry.name);
|
|
|
|
} else
|
|
|
|
if (menu == 1)
|
|
|
|
{
|
2021-05-11 23:36:15 +01:00
|
|
|
utilsGenerateHexStringFromData(nca_id_str, sizeof(nca_id_str), cur_title_info->content_infos[i].content_id.c, sizeof(cur_title_info->content_infos[i].content_id.c), false);
|
2020-07-29 22:02:21 +01:00
|
|
|
printf("%s (%s)\n", nca_id_str, titleGetNcmContentTypeName(cur_title_info->content_infos[i].content_type));
|
|
|
|
} else
|
|
|
|
if (menu == 2)
|
|
|
|
{
|
2020-10-13 15:00:03 +01:00
|
|
|
printf("fs section #%u (%s)\n", i + 1, ncaGetFsSectionTypeName(&(nca_ctx->fs_ctx[i])));
|
2020-07-29 22:02:21 +01:00
|
|
|
}
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
printf("\n");
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
consoleUpdate(NULL);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
u64 btn_down = 0, btn_held = 0;
|
2022-02-19 05:03:06 +00:00
|
|
|
while((applet_status = appletMainLoop()))
|
2020-07-29 22:02:21 +01:00
|
|
|
{
|
2020-12-04 06:38:44 +00:00
|
|
|
utilsScanPads();
|
|
|
|
btn_down = utilsGetButtonsDown();
|
|
|
|
btn_held = utilsGetButtonsHeld();
|
2022-02-19 05:03:06 +00:00
|
|
|
if (btn_down || btn_held) break;
|
2020-07-29 22:02:21 +01:00
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-02-19 05:03:06 +00:00
|
|
|
if (!applet_status) break;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-12-04 06:38:44 +00:00
|
|
|
if (btn_down & HidNpadButton_A)
|
2020-07-29 22:02:21 +01:00
|
|
|
{
|
|
|
|
bool error = false;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
if (menu == 0)
|
|
|
|
{
|
|
|
|
title_idx = selected_idx;
|
2020-08-03 22:41:00 +01:00
|
|
|
title_scroll = scroll;
|
2020-07-29 22:02:21 +01:00
|
|
|
} else
|
|
|
|
if (menu == 1)
|
|
|
|
{
|
|
|
|
nca_idx = selected_idx;
|
2021-05-11 23:36:15 +01:00
|
|
|
utilsGenerateHexStringFromData(nca_id_str, sizeof(nca_id_str), cur_title_info->content_infos[nca_idx].content_id.c, sizeof(cur_title_info->content_infos[nca_idx].content_id.c), false);
|
2020-07-29 22:02:21 +01:00
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
menu++;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
if (menu == 1)
|
|
|
|
{
|
|
|
|
cur_title_info = titleGetInfoFromStorageByTitleId(NcmStorageId_BuiltInSystem, app_metadata[title_idx]->title_id);
|
|
|
|
if (!cur_title_info)
|
|
|
|
{
|
|
|
|
consolePrint("failed to get title info\n");
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
if (menu == 2)
|
|
|
|
{
|
2022-06-29 08:55:46 +01:00
|
|
|
if (!ncaInitializeContext(nca_ctx, cur_title_info->storage_id, 0, &(cur_title_info->content_infos[nca_idx]), cur_title_info->version.value, NULL))
|
2020-07-29 22:02:21 +01:00
|
|
|
{
|
|
|
|
consolePrint("nca initialize ctx failed\n");
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
if (menu == 3)
|
|
|
|
{
|
|
|
|
consoleClear();
|
2021-08-03 07:37:04 +01:00
|
|
|
utilsSetLongRunningProcessState(true);
|
2020-10-13 15:00:03 +01:00
|
|
|
dumpFsSection(cur_title_info, &(nca_ctx->fs_ctx[selected_idx]));
|
2021-08-03 07:37:04 +01:00
|
|
|
utilsSetLongRunningProcessState(false);
|
2020-07-29 22:02:21 +01:00
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
if (error || menu >= 3)
|
|
|
|
{
|
2020-10-10 11:10:50 +01:00
|
|
|
consolePrint("press any button to continue\n");
|
2020-12-04 06:38:44 +00:00
|
|
|
utilsWaitForButtonPress(0);
|
2020-07-29 22:02:21 +01:00
|
|
|
menu--;
|
|
|
|
} else {
|
2020-08-03 22:41:00 +01:00
|
|
|
selected_idx = scroll = 0;
|
2020-07-29 22:02:21 +01:00
|
|
|
}
|
|
|
|
} else
|
2020-12-04 06:38:44 +00:00
|
|
|
if ((btn_down & HidNpadButton_Down) || (btn_held & (HidNpadButton_StickLDown | HidNpadButton_StickRDown)))
|
2020-07-29 22:02:21 +01:00
|
|
|
{
|
|
|
|
selected_idx++;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
if (selected_idx >= max_val)
|
|
|
|
{
|
2020-12-04 06:38:44 +00:00
|
|
|
if (btn_down & HidNpadButton_Down)
|
2020-07-29 22:02:21 +01:00
|
|
|
{
|
2020-08-03 22:41:00 +01:00
|
|
|
selected_idx = scroll = 0;
|
2020-07-29 22:02:21 +01:00
|
|
|
} else {
|
|
|
|
selected_idx = (max_val - 1);
|
|
|
|
}
|
|
|
|
} else
|
2020-08-03 22:41:00 +01:00
|
|
|
if (selected_idx >= (scroll + (page_size / 2)) && max_val > (scroll + page_size))
|
2020-07-29 22:02:21 +01:00
|
|
|
{
|
2020-08-03 22:41:00 +01:00
|
|
|
scroll++;
|
2020-07-29 22:02:21 +01:00
|
|
|
}
|
|
|
|
} else
|
2020-12-04 06:38:44 +00:00
|
|
|
if ((btn_down & HidNpadButton_Up) || (btn_held & (HidNpadButton_StickLUp | HidNpadButton_StickRUp)))
|
2020-07-29 22:02:21 +01:00
|
|
|
{
|
|
|
|
selected_idx--;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
if (selected_idx == UINT32_MAX)
|
|
|
|
{
|
2020-12-04 06:38:44 +00:00
|
|
|
if (btn_down & HidNpadButton_Up)
|
2020-07-29 22:02:21 +01:00
|
|
|
{
|
|
|
|
selected_idx = (max_val - 1);
|
2020-08-03 22:41:00 +01:00
|
|
|
scroll = (max_val >= page_size ? (max_val - page_size) : 0);
|
2020-07-29 22:02:21 +01:00
|
|
|
} else {
|
|
|
|
selected_idx = 0;
|
|
|
|
}
|
|
|
|
} else
|
2020-08-03 22:41:00 +01:00
|
|
|
if (selected_idx < (scroll + (page_size / 2)) && scroll > 0)
|
2020-07-29 22:02:21 +01:00
|
|
|
{
|
2020-08-03 22:41:00 +01:00
|
|
|
scroll--;
|
2020-07-29 22:02:21 +01:00
|
|
|
}
|
|
|
|
} else
|
2020-12-04 06:38:44 +00:00
|
|
|
if (btn_down & HidNpadButton_B)
|
2020-07-29 22:02:21 +01:00
|
|
|
{
|
|
|
|
menu--;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
if (menu == UINT32_MAX)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
selected_idx = (menu == 0 ? title_idx : nca_idx);
|
2020-08-03 22:41:00 +01:00
|
|
|
scroll = (menu == 0 ? title_scroll : 0);
|
2021-06-01 02:12:15 +01:00
|
|
|
if (menu == 0) titleFreeTitleInfo(&cur_title_info);
|
2020-07-29 22:02:21 +01:00
|
|
|
}
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-12-04 06:38:44 +00:00
|
|
|
if (btn_held & (HidNpadButton_StickLDown | HidNpadButton_StickRDown | HidNpadButton_StickLUp | HidNpadButton_StickRUp)) svcSleepThread(50000000); // 50 ms
|
2020-07-29 22:02:21 +01:00
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-02-19 05:03:06 +00:00
|
|
|
if (!applet_status) menu = UINT32_MAX;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
out2:
|
|
|
|
if (menu != UINT32_MAX)
|
|
|
|
{
|
|
|
|
consolePrint("press any button to exit\n");
|
2020-12-04 06:38:44 +00:00
|
|
|
utilsWaitForButtonPress(0);
|
2020-07-29 22:02:21 +01:00
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
if (nca_ctx) free(nca_ctx);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
if (buf) free(buf);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
if (app_metadata) free(app_metadata);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
out:
|
|
|
|
utilsCloseResources();
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
consoleExit(NULL);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-07-29 22:02:21 +01:00
|
|
|
return ret;
|
|
|
|
}
|