diff --git a/Core/ELF/PBPReader.cpp b/Core/ELF/PBPReader.cpp index 12debe624d..9fed087f62 100644 --- a/Core/ELF/PBPReader.cpp +++ b/Core/ELF/PBPReader.cpp @@ -54,30 +54,27 @@ PBPReader::PBPReader(const char *filename) : header_(), isELF_(false) { DEBUG_LOG(LOADER, "Loading PBP, version = %08x", header_.version); } -u8 *PBPReader::GetSubFile(PBPSubFile file, size_t *outSize) { +bool PBPReader::GetSubFile(PBPSubFile file, std::vector *out) { if (!file_) { - *outSize = 0; - return new u8[0]; + return false; } const size_t expected = GetSubFileSize(file); const u32 off = header_.offsets[(int)file]; - *outSize = expected; if (fseek(file_, off, SEEK_SET) != 0) { ERROR_LOG(LOADER, "PBP file offset invalid: %d", off); - *outSize = 0; - return new u8[0]; + return false; } else { - u8 *buffer = new u8[expected]; - size_t bytes = fread(buffer, 1, expected, file_); + out->resize(expected); + size_t bytes = fread((void *)out->data(), 1, expected, file_); if (bytes != expected) { ERROR_LOG(LOADER, "PBP file read truncated: %d -> %d", (int)expected, (int)bytes); if (bytes < expected) { - *outSize = bytes; + out->resize(bytes); } } - return buffer; + return true; } } diff --git a/Core/ELF/PBPReader.h b/Core/ELF/PBPReader.h index ab68ea73ba..2285af2ef0 100644 --- a/Core/ELF/PBPReader.h +++ b/Core/ELF/PBPReader.h @@ -45,8 +45,7 @@ public: bool IsValid() const { return file_ != 0; } bool IsELF() const { return file_ == 0 && isELF_; } - // Delete the returned buffer with delete []. - u8 *GetSubFile(PBPSubFile file, size_t *outSize); + bool GetSubFile(PBPSubFile file, std::vector *out); void GetSubFileAsString(PBPSubFile file, std::string *out); size_t GetSubFileSize(PBPSubFile file) { diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index 2722a86243..414d6109b7 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -1377,17 +1377,17 @@ static bool __KernelLoadPBP(const char *filename, std::string *error_string) return false; } - size_t elfSize; - u8 *elfData = pbp.GetSubFile(PBP_EXECUTABLE_PSP, &elfSize); + std::vector elfData; + if (!pbp.GetSubFile(PBP_EXECUTABLE_PSP, &elfData)) { + return false; + } u32 magic; u32 error; - Module *module = __KernelLoadELFFromPtr(elfData, PSP_GetDefaultLoadAddress(), false, error_string, &magic, error); + Module *module = __KernelLoadELFFromPtr(&elfData[0], PSP_GetDefaultLoadAddress(), false, error_string, &magic, error); if (!module) { - delete [] elfData; return false; } mipsr4k.pc = module->nm.entry_addr; - delete [] elfData; return true; } diff --git a/Core/Loaders.cpp b/Core/Loaders.cpp index 832fa0171e..517c76d75c 100644 --- a/Core/Loaders.cpp +++ b/Core/Loaders.cpp @@ -144,21 +144,15 @@ IdentifiedFileType Identify_File(FileLoader *fileLoader) { // TODO: Change PBPReader to read FileLoader objects? std::string filename = fileLoader->Path(); PBPReader pbp(filename.c_str()); - if (pbp.IsValid()) { - if (!pbp.IsELF()) { - size_t sfoSize; - u8 *sfoData = pbp.GetSubFile(PBP_PARAM_SFO, &sfoSize); - { - recursive_mutex _lock; - lock_guard lock(_lock); - ParamSFOData paramSFO; - paramSFO.ReadSFO(sfoData, sfoSize); - // PS1 Eboots are supposed to use "ME" as their PARAM SFO category. - // If they don't, and they're still malformed (e.g. PSISOIMG0000 isn't found), there's nothing we can do. - if (paramSFO.GetValueString("CATEGORY") == "ME") - return FILETYPE_PSP_PS1_PBP; - } - delete[] sfoData; + if (pbp.IsValid() && !pbp.IsELF()) { + std::vector sfoData; + if (pbp.GetSubFile(PBP_PARAM_SFO, &sfoData)) { + ParamSFOData paramSFO; + paramSFO.ReadSFO(sfoData); + // PS1 Eboots are supposed to use "ME" as their PARAM SFO category. + // If they don't, and they're still malformed (e.g. PSISOIMG0000 isn't found), there's nothing we can do. + if (paramSFO.GetValueString("CATEGORY") == "ME") + return FILETYPE_PSP_PS1_PBP; } } diff --git a/Core/PSPLoaders.cpp b/Core/PSPLoaders.cpp index 1d3c0b2276..9460e17e98 100644 --- a/Core/PSPLoaders.cpp +++ b/Core/PSPLoaders.cpp @@ -135,16 +135,13 @@ void InitMemoryForGamePBP(FileLoader *fileLoader) { std::string filename = fileLoader->Path(); PBPReader pbp(filename.c_str()); if (pbp.IsValid() && !pbp.IsELF()) { - size_t sfoSize; - u8 *sfoData = pbp.GetSubFile(PBP_PARAM_SFO, &sfoSize); - if (sfoData) { + std::vector sfoData; + if (pbp.GetSubFile(PBP_PARAM_SFO, &sfoData)) { ParamSFOData paramSFO; - if (paramSFO.ReadSFO(sfoData, sfoSize)) { + if (paramSFO.ReadSFO(sfoData)) { // This is the parameter CFW uses to determine homebrew wants the full 64MB. UseLargeMem(paramSFO.GetValueInt("MEMSIZE")); } - - delete [] sfoData; } } } diff --git a/UI/GameInfoCache.cpp b/UI/GameInfoCache.cpp index e7c07e5a3a..508dd8cc65 100644 --- a/UI/GameInfoCache.cpp +++ b/UI/GameInfoCache.cpp @@ -336,14 +336,12 @@ public: } // First, PARAM.SFO. - size_t sfoSize; - u8 *sfoData = pbp.GetSubFile(PBP_PARAM_SFO, &sfoSize); - { + std::vector sfoData; + if (pbp.GetSubFile(PBP_PARAM_SFO, &sfoData)) { lock_guard lock(info_->lock); - info_->paramSFO.ReadSFO(sfoData, sfoSize); + info_->paramSFO.ReadSFO(sfoData); info_->ParseParamSFO(); } - delete [] sfoData; // Then, ICON0.PNG. {