From ae3b7266a04f1b4c666c049ebc78e0864693f14f Mon Sep 17 00:00:00 2001 From: Pablo Curiel Date: Sat, 20 Mar 2021 03:13:16 -0400 Subject: [PATCH] Fix NACP bitflag checks. --- code_templates/nsp_dumper_stor.c | 2 +- code_templates/nsp_dumper_usb.c | 2 +- host/usb_abi_specs.txt | 4 +++- source/nacp.c | 16 ++++++++++++---- source/utils.h | 2 +- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/code_templates/nsp_dumper_stor.c b/code_templates/nsp_dumper_stor.c index 4a02097..51ee54f 100644 --- a/code_templates/nsp_dumper_stor.c +++ b/code_templates/nsp_dumper_stor.c @@ -429,7 +429,7 @@ static void nspDump(TitleInfo *title_info, u64 free_space) } sprintf(entry_name, "%s.nacp.xml", cur_nca_ctx->content_id_str); - ret = pfsAddEntryInformationToFileContext(&pfs_file_ctx, entry_name, cur_nacp_ctx->authoring_tool_xml_size, NULL); + ret = pfsAddEntryInformationToFileContext(&pfs_file_ctx, entry_name, cur_nacp_ctx->authoring_tool_xml_size, !cur_nacp_ctx->icon_count ? &(cur_nca_ctx->content_type_ctx_data_idx) : NULL); break; } case NcmContentType_LegalInformation: diff --git a/code_templates/nsp_dumper_usb.c b/code_templates/nsp_dumper_usb.c index ed537d6..0e7f4a4 100644 --- a/code_templates/nsp_dumper_usb.c +++ b/code_templates/nsp_dumper_usb.c @@ -419,7 +419,7 @@ static void dump_thread_func(void *arg) } sprintf(entry_name, "%s.nacp.xml", cur_nca_ctx->content_id_str); - ret = pfsAddEntryInformationToFileContext(&pfs_file_ctx, entry_name, cur_nacp_ctx->authoring_tool_xml_size, NULL); + ret = pfsAddEntryInformationToFileContext(&pfs_file_ctx, entry_name, cur_nacp_ctx->authoring_tool_xml_size, !cur_nacp_ctx->icon_count ? &(cur_nca_ctx->content_type_ctx_data_idx) : NULL); break; } case NcmContentType_LegalInformation: diff --git a/host/usb_abi_specs.txt b/host/usb_abi_specs.txt index 78faf33..19b1783 100644 --- a/host/usb_abi_specs.txt +++ b/host/usb_abi_specs.txt @@ -46,7 +46,9 @@ This is the first USB command issued by nxdumptool. If it succeeds, further USB *--------*--------*-----------------------------* | 0x03 | 0x01 | nxdumptool USB ABI version. | ------> Currently, always v1. *--------*--------*-----------------------------* -| 0x04 | 0x0C | Reserved. | +| 0x04 | 0x08 | Git commit hash (string). | +*--------*--------*-----------------------------* +| 0x0C | 0x04 | Reserved. | *--------*--------*-----------------------------* ____________________________________________________________________________________________________________________________________ diff --git a/source/nacp.c b/source/nacp.c index 8932f6d..d8c537d 100644 --- a/source/nacp.c +++ b/source/nacp.c @@ -260,17 +260,25 @@ bool nacpInitializeContext(NacpContext *out, NcaContext *nca_ctx) { NacpIconContext *icon_ctx = NULL; - /* Check if the current language is supported. */ - if (!nacpCheckBitflagField(&(out->data->supported_language), sizeof(out->data->supported_language) * 8, i)) continue; - /* Get language string. */ language_str = nacpGetLanguageString(i); + /* Check if the current language is supported. */ + if (!nacpCheckBitflagField(&(out->data->supported_language), sizeof(out->data->supported_language) * 8, i)) + { + //LOG_MSG("\"%s\" language not supported (flag 0x%08X, index %u).", language_str, out->data->supported_language, i); + continue; + } + /* Generate icon path. */ sprintf(icon_path, "/icon_%s.dat", language_str); /* Retrieve RomFS file entry for this icon. */ - if (!(icon_entry = romfsGetFileEntryByPath(&(out->romfs_ctx), icon_path))) continue; + if (!(icon_entry = romfsGetFileEntryByPath(&(out->romfs_ctx), icon_path))) + { + //LOG_MSG("\"%s\" file entry not found (flag 0x%08X, index %u).", icon_path, out->data->supported_language, i); + continue; + } /* Check icon size. */ if (!icon_entry->size || icon_entry->size > NACP_MAX_ICON_SIZE) diff --git a/source/utils.h b/source/utils.h index 071a45e..be40524 100644 --- a/source/utils.h +++ b/source/utils.h @@ -34,7 +34,7 @@ #define BIT_LONG(n) (1UL << (n)) #define ALIGN_UP(x, y) (((x) + ((y) - 1)) & ~((y) - 1)) -#define ALIGN_DOWN(x, y) ((x) > (y) ? (((x) - ((y) - 1)) & ~((y) - 1)) : 0) +#define ALIGN_DOWN(x, y) ((x) & ~((y) - 1)) #define IS_ALIGNED(x, y) (((x) & ((y) - 1)) == 0) #define IS_POWER_OF_TWO(x) (((x) & ((x) - 1)) == 0)