From 40fc21b5a31fe51ac1534903365b91d85c2f59b5 Mon Sep 17 00:00:00 2001 From: Pablo Curiel Date: Sun, 11 Oct 2020 20:40:54 -0400 Subject: [PATCH] Fix ProgramInfo and NSO issues. XML generation confirmed to be working. The new algorithm faithfully reproduces the same output from legacy nxdumptool with much less overhead and memory usage. --- code_templates/system_title_dumper.c | 2 +- code_templates/usb_gc_dumper.c | 2 +- code_templates/usb_romfs_dumper.c | 2 +- code_templates/xml_generator.c | 4 +++- source/nso.c | 4 +++- source/program_info.c | 20 +++++++++++++------- 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/code_templates/system_title_dumper.c b/code_templates/system_title_dumper.c index 70b9138..55217e8 100644 --- a/code_templates/system_title_dumper.c +++ b/code_templates/system_title_dumper.c @@ -225,7 +225,7 @@ int main(int argc, char *argv[]) int ret = 0; - utilsWriteLogBufferToLogFile("________________________________________________________________"); + utilsWriteLogBufferToLogFile("________________________________________________________________\r\n"); LOGFILE(APP_TITLE " starting."); consoleInit(NULL); diff --git a/code_templates/usb_gc_dumper.c b/code_templates/usb_gc_dumper.c index 8201d7a..f77b9f4 100644 --- a/code_templates/usb_gc_dumper.c +++ b/code_templates/usb_gc_dumper.c @@ -188,7 +188,7 @@ int main(int argc, char *argv[]) Menu *cur_menu = &g_rootMenu; u32 element_count = menuGetElementCount(cur_menu), page_size = 30; - utilsWriteLogBufferToLogFile("________________________________________________________________"); + utilsWriteLogBufferToLogFile("________________________________________________________________\r\n"); LOGFILE(APP_TITLE " starting."); consoleInit(NULL); diff --git a/code_templates/usb_romfs_dumper.c b/code_templates/usb_romfs_dumper.c index a361c83..13c19ea 100644 --- a/code_templates/usb_romfs_dumper.c +++ b/code_templates/usb_romfs_dumper.c @@ -306,7 +306,7 @@ int main(int argc, char *argv[]) int ret = 0; - utilsWriteLogBufferToLogFile("________________________________________________________________"); + utilsWriteLogBufferToLogFile("________________________________________________________________\r\n"); LOGFILE(APP_TITLE " starting."); consoleInit(NULL); diff --git a/code_templates/xml_generator.c b/code_templates/xml_generator.c index 786dcd6..3b6fd6b 100644 --- a/code_templates/xml_generator.c +++ b/code_templates/xml_generator.c @@ -42,7 +42,7 @@ int main(int argc, char *argv[]) int ret = 0; - utilsWriteLogBufferToLogFile("________________________________________________________________"); + utilsWriteLogBufferToLogFile("________________________________________________________________\r\n"); LOGFILE(APP_TITLE " starting."); consoleInit(NULL); @@ -276,6 +276,8 @@ int main(int argc, char *argv[]) if (programInfoGenerateAuthoringToolXml(&program_info_ctx)) { + consolePrint("program info xml succeeded\n"); + sprintf(path, "sdmc:/at_xml/%016lX/%s.programinfo.xml", app_metadata[selected_idx]->title_id, program_info_ctx.nca_ctx->content_id_str); xml_fd = fopen(path, "wb"); diff --git a/source/nso.c b/source/nso.c index 218f167..1fa19be 100644 --- a/source/nso.c +++ b/source/nso.c @@ -203,7 +203,7 @@ static u8 *nsoGetRodataSegment(NsoContext *nso_ctx) u8 *rodata_buf = NULL; u64 rodata_buf_size = (compressed ? LZ4_DECOMPRESS_INPLACE_BUFFER_SIZE(nso_ctx->nso_header.rodata_segment_header.size) : nso_ctx->nso_header.rodata_segment_header.size); - u8 *rodata_read_ptr = (compressed ? (rodata_buf + (rodata_buf_size - nso_ctx->nso_header.rodata_file_size)) : rodata_buf); + u8 *rodata_read_ptr = NULL; u64 rodata_read_size = (compressed ? nso_ctx->nso_header.rodata_file_size : nso_ctx->nso_header.rodata_segment_header.size); u8 rodata_hash[SHA256_HASH_SIZE] = {0}; @@ -217,6 +217,8 @@ static u8 *nsoGetRodataSegment(NsoContext *nso_ctx) return NULL; } + rodata_read_ptr = (compressed ? (rodata_buf + (rodata_buf_size - nso_ctx->nso_header.rodata_file_size)) : rodata_buf); + /* Read .rodata segment data. */ if (!pfsReadEntryData(nso_ctx->pfs_ctx, nso_ctx->pfs_entry, rodata_read_ptr, rodata_read_size, nso_ctx->nso_header.rodata_segment_header.file_offset)) { diff --git a/source/program_info.c b/source/program_info.c index 111bd00..a6a5df6 100644 --- a/source/program_info.c +++ b/source/program_info.c @@ -114,6 +114,9 @@ bool programInfoInitializeContext(ProgramInfoContext *out, NcaContext *nca_ctx) goto end; } + /* Update output context. */ + out->nca_ctx = nca_ctx; + success = true; end: @@ -169,7 +172,6 @@ bool programInfoGenerateAuthoringToolXml(ProgramInfoContext *program_info_ctx) goto end; } - /* To do: add more NPDM ACID flags? */ if (!utilsAppendFormattedStringToBuffer(&xml_buf, &xml_buf_size, \ "\n" \ "\n" \ @@ -204,8 +206,9 @@ bool programInfoGenerateAuthoringToolXml(ProgramInfoContext *program_info_ctx) for(u32 i = 0; i < program_info_ctx->nso_count; i++) { /* Only proceed if we're dealing with the main NSO. */ - if (!program_info_ctx->nso_ctx->nso_filename || strlen(program_info_ctx->nso_ctx->nso_filename) != 4 || !strcmp(program_info_ctx->nso_ctx->nso_filename, "main")) continue; - if (!programInfoAddNsoSymbolsToAuthoringToolXml(&xml_buf, &xml_buf_size, &(program_info_ctx->nso_ctx[i]), is_64bit)) goto end; + NsoContext *nso_ctx = &(program_info_ctx->nso_ctx[i]); + if (!nso_ctx->nso_filename || strlen(nso_ctx->nso_filename) != 4 || strcmp(nso_ctx->nso_filename, "main") != 0) continue; + if (!programInfoAddNsoSymbolsToAuthoringToolXml(&xml_buf, &xml_buf_size, nso_ctx, is_64bit)) goto end; break; } @@ -297,20 +300,23 @@ static bool programInfoAddNsoSymbolsToAuthoringToolXml(char **xml_buf, u64 *xml_ if ((nso_ctx->rodata_dynsym_section_size - i) < symbol_size) break; char *symbol_str = NULL; + u8 st_type = 0; /* To do: change ELF symbol filters? */ if (!is_64bit) { /* Parse 32-bit ELF symbol. */ - Elf32Symbol *elf32_symbol = (Elf32Symbol*)(nso_ctx->rodata_dynsym_section_size + i); + Elf32Symbol *elf32_symbol = (Elf32Symbol*)(nso_ctx->rodata_dynsym_section + i); + st_type = ELF_ST_TYPE(elf32_symbol->st_info); - symbol_str = ((elf32_symbol->st_name < nso_ctx->rodata_dynstr_section_size && !elf32_symbol->st_value && ELF_ST_TYPE(elf32_symbol->st_info) == STT_FUNC && \ + symbol_str = ((elf32_symbol->st_name < nso_ctx->rodata_dynstr_section_size && !elf32_symbol->st_value && (st_type == STT_NOTYPE || st_type == STT_FUNC) && \ elf32_symbol->st_shndx == SHN_UNDEF) ? (nso_ctx->rodata_dynstr_section + elf32_symbol->st_name) : NULL); } else { /* Parse 64-bit ELF symbol. */ - Elf64Symbol *elf64_symbol = (Elf64Symbol*)(nso_ctx->rodata_dynsym_section_size + i); + Elf64Symbol *elf64_symbol = (Elf64Symbol*)(nso_ctx->rodata_dynsym_section + i); + st_type = ELF_ST_TYPE(elf64_symbol->st_info); - symbol_str = ((elf64_symbol->st_name < nso_ctx->rodata_dynstr_section_size && !elf64_symbol->st_value && ELF_ST_TYPE(elf64_symbol->st_info) == STT_FUNC && \ + symbol_str = ((elf64_symbol->st_name < nso_ctx->rodata_dynstr_section_size && !elf64_symbol->st_value && (st_type == STT_NOTYPE || st_type == STT_FUNC) && \ elf64_symbol->st_shndx == SHN_UNDEF) ? (nso_ctx->rodata_dynstr_section + elf64_symbol->st_name) : NULL); }