From d904d1d98f8aea2f0e9737ec29282762f3a38864 Mon Sep 17 00:00:00 2001 From: Philippe Daouadi Date: Sun, 9 Dec 2018 14:31:51 +0100 Subject: [PATCH 1/2] vitaldr: add library name when the imported symbol is unknown --- src/vita/psp2_loader.cpp | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/vita/psp2_loader.cpp b/src/vita/psp2_loader.cpp index 7f0b5fb..101e3a2 100644 --- a/src/vita/psp2_loader.cpp +++ b/src/vita/psp2_loader.cpp @@ -643,6 +643,18 @@ void psp2_loader::loadExports(uint32 entTop, uint32 entEnd) { } } +qstring get_string(ea_t ea) +{ + qstring out; + while (true) + { + auto const byte = get_byte(ea++); + if (!byte || out.size() >= 32) + return out; + out += byte; + } +} + void psp2_loader::loadImports(uint32 stubTop, uint32 stubEnd) { uchar structsize; @@ -656,6 +668,7 @@ void psp2_loader::loadImports(uint32 stubTop, uint32 stubEnd) { if (structsize == sizeof(_scelibstub_prx2arm)) { doStruct(ea, sizeof(_scelibstub_prx2arm), get_struc_id("_scelibstub")); + auto libname = get_long(ea + offsetof(_scelibstub_prx2arm, libname)); auto funcnidtable = get_long(ea + offsetof(_scelibstub_prx2arm, func_nidtable)); auto functable = get_long(ea + offsetof(_scelibstub_prx2arm, func_table)); auto varnidtable = get_long(ea + offsetof(_scelibstub_prx2arm, var_nidtable)); @@ -663,6 +676,8 @@ void psp2_loader::loadImports(uint32 stubTop, uint32 stubEnd) { auto tlsnidtable = get_long(ea + offsetof(_scelibstub_prx2arm, tls_nidtable)); auto tlstable = get_long(ea + offsetof(_scelibstub_prx2arm, tls_table)); + auto qlibname = get_string(libname); + if (funcnidtable != NULL && functable != NULL) { for (size_t i = 0; i < nfunc; ++i) { auto nidoffset = funcnidtable + (i * 4); @@ -671,12 +686,18 @@ void psp2_loader::loadImports(uint32 stubTop, uint32 stubEnd) { auto nid = get_long(nidoffset); auto func = get_long(funcoffset); + if (func & 1) + func -= 1; + auto resolvedNid = getNameFromDatabase(nid); if (resolvedNid) { set_cmt(nidoffset, resolvedNid, false); - if (func & 1) - func -= 1; do_name_anyway(func, resolvedNid); + } else { + //msg("unknown 0x34 nid '%s_%s'\n", qlibname.c_str(), qfuncname.c_str()); + qstring qfuncname; + qfuncname.sprnt("%s_%08X", qlibname.c_str(), nid); + do_name_anyway(func, qfuncname.c_str()); } doDwrd(nidoffset, 4); @@ -728,11 +749,14 @@ void psp2_loader::loadImports(uint32 stubTop, uint32 stubEnd) { doDwrd(ea+28, 4); // varnidtable doDwrd(ea+32, 4); // vartable + auto libname = get_long(ea + 0x10); auto funcnidtable = get_long(ea + 0x14); auto functable = get_long(ea + 0x18); auto varnidtable = get_long(ea + 0x1C); auto vartable = get_long(ea + 0x20); + auto qlibname = get_string(libname); + if (funcnidtable != NULL && functable != NULL) { for (size_t i = 0; i < nfunc; ++i) { auto nidoffset = funcnidtable + (i * 4); @@ -741,12 +765,18 @@ void psp2_loader::loadImports(uint32 stubTop, uint32 stubEnd) { auto nid = get_long(nidoffset); auto func = get_long(funcoffset); + if (func & 1) + func -= 1; + auto resolvedNid = getNameFromDatabase(nid); if (resolvedNid) { set_cmt(nidoffset, resolvedNid, false); - if (func & 1) - func -= 1; do_name_anyway(func, resolvedNid); + } else { + //msg("unknown 0x24 nid '%s_%s'\n", qlibname.c_str(), qfuncname.c_str()); + qstring qfuncname; + qfuncname.sprnt("%s_%08X", qlibname.c_str(), nid); + do_name_anyway(func, qfuncname.c_str()); } doDwrd(nidoffset, 4); From 59b42e65ad41259d4740efb62681c35aca13ae39 Mon Sep 17 00:00:00 2001 From: Philippe Daouadi Date: Mon, 17 Dec 2018 22:55:03 +0100 Subject: [PATCH 2/2] vitaldr: name unknown exports --- src/vita/psp2_loader.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/vita/psp2_loader.cpp b/src/vita/psp2_loader.cpp index 101e3a2..6f23ff6 100644 --- a/src/vita/psp2_loader.cpp +++ b/src/vita/psp2_loader.cpp @@ -622,12 +622,18 @@ void psp2_loader::loadExports(uint32 entTop, uint32 entEnd) { auto nid = get_long(nidoffset); auto add = get_long(addoffset); + if (add & 1) + add -= 1; + auto resolvedNid = getNameFromDatabase(nid); if (resolvedNid) { set_cmt(nidoffset, resolvedNid, false); - if (add & 1) - add -= 1; do_name_anyway(add, resolvedNid); + } else { + msg("unknown export %08X\n", nid); + qstring qfuncname; + qfuncname.sprnt("export_%08X", nid); + do_name_anyway(add, qfuncname.c_str()); } if (i < nfunc)