From 6d9d517700f868fc36d2a3f760a42a672bd4b5b2 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Mon, 2 Jan 2023 12:23:05 -0800 Subject: [PATCH] Reporting: Send game ELF crc with reports. Getting a lot of spam from homebrew with different IDs that appear to be the same actual homebrew, in part from ID generation. --- Core/HLE/sceKernelModule.cpp | 25 +++++++++++++++++-------- Core/Reporting.cpp | 17 +++++++++++++++++ Core/Reporting.h | 3 +++ 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index a5d7264827..f1c4b67155 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -285,7 +285,7 @@ public: void DoState(PointerWrap &p) override { - auto s = p.Section("Module", 1, 5); + auto s = p.Section("Module", 1, 6); if (!s) return; @@ -301,6 +301,9 @@ public: memcpy(((uint8_t *)pnm) + 0x30, ((uint8_t *)ptemp) + 0x2C, 0xC0 - 0x2C); } + if (s >= 6) + Do(p, crc); + Do(p, memoryBlockAddr); Do(p, memoryBlockSize); Do(p, isFake); @@ -458,6 +461,7 @@ public: u32 memoryBlockAddr = 0; u32 memoryBlockSize = 0; + u32 crc = 0; PSPPointer modulePtr; bool isFake = false; }; @@ -1144,12 +1148,12 @@ static int gzipDecompress(u8 *OutBuffer, int OutBufferLength, u8 *InBuffer) { } static PSPModule *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 loadAddress, bool fromTop, std::string *error_string, u32 *magic, u32 &error) { - u32 crc = crc32(0, ptr, (uInt)elfSize); PSPModule *module = new PSPModule(); kernelObjects.Create(module); loadedModules.insert(module->GetUID()); memset(&module->nm, 0, sizeof(module->nm)); + module->crc = crc32(0, ptr, (uInt)elfSize); module->nm.modid = module->GetUID(); bool reportedModule = false; @@ -1173,14 +1177,14 @@ static PSPModule *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 load if (IsHLEVersionedModule(head->modname)) { int ver = (head->module_ver_hi << 8) | head->module_ver_lo; - INFO_LOG(SCEMODULE, "Loading module %s with version %04x, devkit %08x, crc %x", head->modname, ver, head->devkitversion, crc); + INFO_LOG(SCEMODULE, "Loading module %s with version %04x, devkit %08x, crc %x", head->modname, ver, head->devkitversion, module->crc); reportedModule = true; if (!strcmp(head->modname, "sceMpeg_library")) { - __MpegLoadModule(ver, crc); + __MpegLoadModule(ver, module->crc); } if (!strcmp(head->modname, "scePsmfP_library") || !strcmp(head->modname, "scePsmfPlayer")) { - __PsmfPlayerLoadModule(head->devkitversion, crc); + __PsmfPlayerLoadModule(head->devkitversion, module->crc); } } @@ -1614,10 +1618,10 @@ static PSPModule *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 load INFO_LOG(SCEMODULE, "Loading module %s with version %04x, devkit %08x", modinfo->name, modinfo->moduleVersion, devkitVersion); if (!strcmp(modinfo->name, "sceMpeg_library")) { - __MpegLoadModule(modinfo->moduleVersion, crc); + __MpegLoadModule(modinfo->moduleVersion, module->crc); } if (!strcmp(modinfo->name, "scePsmfP_library") || !strcmp(modinfo->name, "scePsmfPlayer")) { - __PsmfPlayerLoadModule(devkitVersion, crc); + __PsmfPlayerLoadModule(devkitVersion, module->crc); } } @@ -1827,9 +1831,14 @@ bool __KernelLoadExec(const char *filename, u32 paramPtr, std::string *error_str host->NotifySymbolMapUpdated(); + char moduleName[29] = { 0 }; + int moduleVersion = module->nm.version[0] | (module->nm.version[1] << 8); + truncate_cpy(moduleName, module->nm.name); + Reporting::NotifyExecModule(moduleName, moduleVersion, module->crc); + mipsr4k.pc = module->nm.entry_addr; - INFO_LOG(LOADER, "Module entry: %08x", mipsr4k.pc); + INFO_LOG(LOADER, "Module entry: %08x (%s %04x)", mipsr4k.pc, moduleName, moduleVersion); SceKernelSMOption option; option.size = sizeof(SceKernelSMOption); diff --git a/Core/Reporting.cpp b/Core/Reporting.cpp index 4f15062e3c..7263f6f009 100644 --- a/Core/Reporting.cpp +++ b/Core/Reporting.cpp @@ -70,6 +70,10 @@ namespace Reporting // The latest compatibility result from the server. static std::vector lastCompatResult; + static std::string lastModuleName; + static int lastModuleVersion; + static uint32_t lastModuleCrc; + static std::mutex pendingMessageLock; static std::condition_variable pendingMessageCond; static std::deque pendingMessages; @@ -352,6 +356,10 @@ namespace Reporting currentSupported = IsSupported(); pendingMessagesDone = false; Reporting::SetupCallbacks(&MessageAllowed, &SendReportMessage); + + lastModuleName.clear(); + lastModuleVersion = 0; + lastModuleCrc = 0; } void Shutdown() @@ -395,6 +403,12 @@ namespace Reporting everUnsupported = true; } + void NotifyExecModule(const char *name, int ver, uint32_t crc) { + lastModuleName = name; + lastModuleVersion = ver; + lastModuleCrc = crc; + } + std::string CurrentGameID() { // TODO: Maybe ParamSFOData shouldn't include nulls in std::strings? Don't work to break savedata, though... @@ -408,6 +422,9 @@ namespace Reporting postdata.Add("game", CurrentGameID()); postdata.Add("game_title", StripTrailingNull(g_paramSFO.GetValueString("TITLE"))); postdata.Add("sdkver", sceKernelGetCompiledSdkVersion()); + postdata.Add("module_name", lastModuleName); + postdata.Add("module_ver", lastModuleVersion); + postdata.Add("module_crc", lastModuleCrc); } void AddSystemInfo(UrlEncoder &postdata) diff --git a/Core/Reporting.h b/Core/Reporting.h index 364b80163e..211267c8f7 100644 --- a/Core/Reporting.h +++ b/Core/Reporting.h @@ -41,6 +41,9 @@ namespace Reporting // Should be called when debugging APIs are used in a way that could make the game crash. void NotifyDebugger(); + // Should be called for each LoadExec, with parameters of the module executed. + void NotifyExecModule(const char *name, int ver, uint32_t crc); + // Returns whether or not the reporting system is currently enabled. bool IsEnabled();