From a79f986411261cae876a79afa8122dabee23238e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 31 Mar 2025 12:09:25 +0200 Subject: [PATCH] More module loading cleanup, choose better filenames for dumped PRX files --- Common/StringUtils.cpp | 9 +++++++++ Common/StringUtils.h | 2 ++ Core/HLE/sceKernelModule.cpp | 5 ++++- Core/System.cpp | 7 +++++-- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Common/StringUtils.cpp b/Common/StringUtils.cpp index 48b6aab963..845eddc674 100644 --- a/Common/StringUtils.cpp +++ b/Common/StringUtils.cpp @@ -250,6 +250,15 @@ std::string_view StripPrefix(std::string_view prefix, std::string_view s) { } } +std::string_view KeepAfterLast(std::string_view s, char c) { + size_t pos = s.rfind(c); + if (pos != std::string_view::npos) { + return s.substr(pos + 1); + } else { + return s; + } +} + void SkipSpace(const char **ptr) { while (**ptr && isspace(**ptr)) { (*ptr)++; diff --git a/Common/StringUtils.h b/Common/StringUtils.h index 335e247c45..e2424ba1b8 100644 --- a/Common/StringUtils.h +++ b/Common/StringUtils.h @@ -94,6 +94,8 @@ std::string StringFromInt(int value); std::string StripSpaces(const std::string &s); std::string StripQuotes(const std::string &s); +std::string_view KeepAfterLast(std::string_view s, char c); + std::string_view StripSpaces(std::string_view s); std::string_view StripQuotes(std::string_view s); diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index 798772db6b..ce103ffeb6 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -985,6 +985,7 @@ static int gzipDecompress(u8 *OutBuffer, int OutBufferLength, u8 *InBuffer) { } err = inflate(&stream, Z_FINISH); if (err != Z_STREAM_END) { + ERROR_LOG(Log::Loader, "gzipDecompress: Didn't reach the end of the input, output buffer too small?"); inflateEnd(&stream); return -2; } @@ -1118,6 +1119,7 @@ static PSPModule *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 load elfSize = maxElfSize; ptr = newptr; int ret = pspDecryptPRX(in, (u8*)ptr, head->psp_size); + _dbg_assert_(ret <= maxElfSize); if (ret <= 0 && Read32(ptr + 0x150) == ELF_MAGIC) { ret = head->psp_size - 0x150; memcpy(newptr, in + 0x150, ret); @@ -1133,7 +1135,8 @@ static PSPModule *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 load if (reportedModule) { // Opportunity to dump the decrypted elf, even if we choose to fake it. - std::string elfFilename(filename); + // NOTE: filename is not necessarily a good choice! + std::string elfFilename(KeepAfterLast(filename, '/')); if (elfFilename.empty()) { // Use the name from the header. elfFilename = head->modname; diff --git a/Core/System.cpp b/Core/System.cpp index 0776e3bac5..0ea5f48330 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -882,7 +882,10 @@ void DumpFileIfEnabled(const u8 *dataPtr, const u32 length, const char *name, Du } const char *extension = DumpFileTypeToFileExtension(type); - const std::string filenameToDumpTo = StringFromFormat("%s_%s%s", g_paramSFO.GetDiscID().c_str(), name, extension); + std::string filenameToDumpTo = StringFromFormat("%s_%s", g_paramSFO.GetDiscID().c_str(), name); + if (!endsWithNoCase(filenameToDumpTo, extension)) { + filenameToDumpTo += extension; + } const Path dumpDirectory = GetSysDirectory(DIRECTORY_DUMP); const Path fullPath = dumpDirectory / filenameToDumpTo; @@ -939,7 +942,7 @@ void DumpFileIfEnabled(const u8 *dataPtr, const u32 length, const char *name, Du strcpy(path, fullPath.c_str()); // Re-suing the translation string here. - g_OSD.Show(OSDType::MESSAGE_SUCCESS, titleStr, fullPath.ToVisualString(), 5.0f, "decr"); + g_OSD.Show(OSDType::MESSAGE_SUCCESS, titleStr, fullPath.ToVisualString(), 5.0f); if (System_GetPropertyBool(SYSPROP_CAN_SHOW_FILE)) { g_OSD.SetClickCallback("decr", [](bool clicked, void *userdata) { char *path = (char *)userdata;