mirror of
https://github.com/DarkMatterCore/nxdumptool.git
synced 2024-11-26 12:12:02 +00:00
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.
This commit is contained in:
parent
3affe1f4d0
commit
40fc21b5a3
6 changed files with 22 additions and 12 deletions
|
@ -225,7 +225,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
utilsWriteLogBufferToLogFile("________________________________________________________________");
|
utilsWriteLogBufferToLogFile("________________________________________________________________\r\n");
|
||||||
LOGFILE(APP_TITLE " starting.");
|
LOGFILE(APP_TITLE " starting.");
|
||||||
|
|
||||||
consoleInit(NULL);
|
consoleInit(NULL);
|
||||||
|
|
|
@ -188,7 +188,7 @@ int main(int argc, char *argv[])
|
||||||
Menu *cur_menu = &g_rootMenu;
|
Menu *cur_menu = &g_rootMenu;
|
||||||
u32 element_count = menuGetElementCount(cur_menu), page_size = 30;
|
u32 element_count = menuGetElementCount(cur_menu), page_size = 30;
|
||||||
|
|
||||||
utilsWriteLogBufferToLogFile("________________________________________________________________");
|
utilsWriteLogBufferToLogFile("________________________________________________________________\r\n");
|
||||||
LOGFILE(APP_TITLE " starting.");
|
LOGFILE(APP_TITLE " starting.");
|
||||||
|
|
||||||
consoleInit(NULL);
|
consoleInit(NULL);
|
||||||
|
|
|
@ -306,7 +306,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
utilsWriteLogBufferToLogFile("________________________________________________________________");
|
utilsWriteLogBufferToLogFile("________________________________________________________________\r\n");
|
||||||
LOGFILE(APP_TITLE " starting.");
|
LOGFILE(APP_TITLE " starting.");
|
||||||
|
|
||||||
consoleInit(NULL);
|
consoleInit(NULL);
|
||||||
|
|
|
@ -42,7 +42,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
utilsWriteLogBufferToLogFile("________________________________________________________________");
|
utilsWriteLogBufferToLogFile("________________________________________________________________\r\n");
|
||||||
LOGFILE(APP_TITLE " starting.");
|
LOGFILE(APP_TITLE " starting.");
|
||||||
|
|
||||||
consoleInit(NULL);
|
consoleInit(NULL);
|
||||||
|
@ -276,6 +276,8 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
if (programInfoGenerateAuthoringToolXml(&program_info_ctx))
|
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);
|
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");
|
xml_fd = fopen(path, "wb");
|
||||||
|
|
|
@ -203,7 +203,7 @@ static u8 *nsoGetRodataSegment(NsoContext *nso_ctx)
|
||||||
u8 *rodata_buf = NULL;
|
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);
|
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);
|
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};
|
u8 rodata_hash[SHA256_HASH_SIZE] = {0};
|
||||||
|
@ -217,6 +217,8 @@ static u8 *nsoGetRodataSegment(NsoContext *nso_ctx)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rodata_read_ptr = (compressed ? (rodata_buf + (rodata_buf_size - nso_ctx->nso_header.rodata_file_size)) : rodata_buf);
|
||||||
|
|
||||||
/* Read .rodata segment data. */
|
/* 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))
|
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))
|
||||||
{
|
{
|
||||||
|
|
|
@ -114,6 +114,9 @@ bool programInfoInitializeContext(ProgramInfoContext *out, NcaContext *nca_ctx)
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Update output context. */
|
||||||
|
out->nca_ctx = nca_ctx;
|
||||||
|
|
||||||
success = true;
|
success = true;
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
@ -169,7 +172,6 @@ bool programInfoGenerateAuthoringToolXml(ProgramInfoContext *program_info_ctx)
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* To do: add more NPDM ACID flags? */
|
|
||||||
if (!utilsAppendFormattedStringToBuffer(&xml_buf, &xml_buf_size, \
|
if (!utilsAppendFormattedStringToBuffer(&xml_buf, &xml_buf_size, \
|
||||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" \
|
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" \
|
||||||
"<ProgramInfo>\n" \
|
"<ProgramInfo>\n" \
|
||||||
|
@ -204,8 +206,9 @@ bool programInfoGenerateAuthoringToolXml(ProgramInfoContext *program_info_ctx)
|
||||||
for(u32 i = 0; i < program_info_ctx->nso_count; i++)
|
for(u32 i = 0; i < program_info_ctx->nso_count; i++)
|
||||||
{
|
{
|
||||||
/* Only proceed if we're dealing with the main NSO. */
|
/* 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;
|
NsoContext *nso_ctx = &(program_info_ctx->nso_ctx[i]);
|
||||||
if (!programInfoAddNsoSymbolsToAuthoringToolXml(&xml_buf, &xml_buf_size, &(program_info_ctx->nso_ctx[i]), is_64bit)) goto end;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,20 +300,23 @@ static bool programInfoAddNsoSymbolsToAuthoringToolXml(char **xml_buf, u64 *xml_
|
||||||
if ((nso_ctx->rodata_dynsym_section_size - i) < symbol_size) break;
|
if ((nso_ctx->rodata_dynsym_section_size - i) < symbol_size) break;
|
||||||
|
|
||||||
char *symbol_str = NULL;
|
char *symbol_str = NULL;
|
||||||
|
u8 st_type = 0;
|
||||||
|
|
||||||
/* To do: change ELF symbol filters? */
|
/* To do: change ELF symbol filters? */
|
||||||
if (!is_64bit)
|
if (!is_64bit)
|
||||||
{
|
{
|
||||||
/* Parse 32-bit ELF symbol. */
|
/* 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);
|
elf32_symbol->st_shndx == SHN_UNDEF) ? (nso_ctx->rodata_dynstr_section + elf32_symbol->st_name) : NULL);
|
||||||
} else {
|
} else {
|
||||||
/* Parse 64-bit ELF symbol. */
|
/* 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);
|
elf64_symbol->st_shndx == SHN_UNDEF) ? (nso_ctx->rodata_dynstr_section + elf64_symbol->st_name) : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue