Debugger: Memcheck and tag loading savedata to RAM.

This commit is contained in:
Unknown W. Brackets 2021-04-03 18:28:22 -07:00
parent d009203c24
commit 1b57739eb7
2 changed files with 27 additions and 11 deletions

View File

@ -25,6 +25,7 @@
#include "Core/Host.h" #include "Core/Host.h"
#include "Core/Reporting.h" #include "Core/Reporting.h"
#include "Core/System.h" #include "Core/System.h"
#include "Core/Debugger/MemBlockInfo.h"
#include "Core/Dialog/SavedataParam.h" #include "Core/Dialog/SavedataParam.h"
#include "Core/Dialog/PSPSaveDialog.h" #include "Core/Dialog/PSPSaveDialog.h"
#include "Core/FileSystems/MetaFileSystem.h" #include "Core/FileSystems/MetaFileSystem.h"
@ -645,7 +646,7 @@ int SavedataParam::LoadSaveData(SceUtilitySavedataParam *param, const std::strin
} }
WARN_LOG_REPORT(SCEUTILITY, "Savedata version requested: %d", param->secureVersion); WARN_LOG_REPORT(SCEUTILITY, "Savedata version requested: %d", param->secureVersion);
} }
u8 *data_ = param->dataBuf;
std::string filename = GetFileName(param); std::string filename = GetFileName(param);
std::string filePath = dirPath + "/" + filename; std::string filePath = dirPath + "/" + filename;
s64 readSize; s64 readSize;
@ -664,21 +665,27 @@ int SavedataParam::LoadSaveData(SceUtilitySavedataParam *param, const std::strin
int prevCryptMode = GetSaveCryptMode(param, saveDirName); int prevCryptMode = GetSaveCryptMode(param, saveDirName);
bool isCrypted = prevCryptMode != 0 && secureMode; bool isCrypted = prevCryptMode != 0 && secureMode;
bool saveDone = false; bool saveDone = false;
u32 loadedSize = 0;
if (isCrypted) { if (isCrypted) {
if (DetermineCryptMode(param) > 1 && !HasKey(param)) if (DetermineCryptMode(param) > 1 && !HasKey(param))
return SCE_UTILITY_SAVEDATA_ERROR_LOAD_PARAM; return SCE_UTILITY_SAVEDATA_ERROR_LOAD_PARAM;
u8 hash[16]; u8 hash[16];
bool hasExpectedHash = GetExpectedHash(dirPath, filename, hash); bool hasExpectedHash = GetExpectedHash(dirPath, filename, hash);
LoadCryptedSave(param, data_, saveData, saveSize, prevCryptMode, hasExpectedHash ? hash : nullptr, saveDone); loadedSize = LoadCryptedSave(param, param->dataBuf, saveData, saveSize, prevCryptMode, hasExpectedHash ? hash : nullptr, saveDone);
// TODO: Should return SCE_UTILITY_SAVEDATA_ERROR_LOAD_DATA_BROKEN here if !saveDone. // TODO: Should return SCE_UTILITY_SAVEDATA_ERROR_LOAD_DATA_BROKEN here if !saveDone.
} }
if (!saveDone) { if (!saveDone) {
LoadNotCryptedSave(param, data_, saveData, saveSize); loadedSize = LoadNotCryptedSave(param, param->dataBuf, saveData, saveSize);
} }
param->dataSize = (SceSize)saveSize; param->dataSize = (SceSize)saveSize;
delete[] saveData; delete[] saveData;
if (loadedSize != 0) {
std::string tag = "LoadSaveData/" + filePath;
NotifyMemInfo(MemBlockFlags::WRITE, param->dataBuf.ptr, loadedSize, tag.c_str(), tag.size());
}
return 0; return 0;
} }
@ -697,7 +704,7 @@ int SavedataParam::DetermineCryptMode(const SceUtilitySavedataParam *param) cons
return decryptMode; return decryptMode;
} }
void SavedataParam::LoadCryptedSave(SceUtilitySavedataParam *param, u8 *data, const u8 *saveData, int &saveSize, int prevCryptMode, const u8 *expectedHash, bool &saveDone) { u32 SavedataParam::LoadCryptedSave(SceUtilitySavedataParam *param, u8 *data, const u8 *saveData, int &saveSize, int prevCryptMode, const u8 *expectedHash, bool &saveDone) {
int orig_size = saveSize; int orig_size = saveSize;
int align_len = align16(saveSize); int align_len = align16(saveSize);
u8 *data_base = new u8[align_len]; u8 *data_base = new u8[align_len];
@ -761,18 +768,27 @@ void SavedataParam::LoadCryptedSave(SceUtilitySavedataParam *param, u8 *data, co
err = DecryptSave(decryptMode, data_base, &saveSize, &align_len, hasKey ? cryptKey : nullptr, nullptr); err = DecryptSave(decryptMode, data_base, &saveSize, &align_len, hasKey ? cryptKey : nullptr, nullptr);
} }
u32 sz = 0;
if (err == 0) { if (err == 0) {
if (param->dataBuf.IsValid()) if (param->dataBuf.IsValid()) {
memcpy(data, data_base, std::min((u32)saveSize, (u32)param->dataBufSize)); sz = std::min((u32)saveSize, (u32)param->dataBufSize);
memcpy(data, data_base, sz);
}
saveDone = true; saveDone = true;
} }
delete[] data_base; delete[] data_base;
delete[] cryptKey; delete[] cryptKey;
return sz;
} }
void SavedataParam::LoadNotCryptedSave(SceUtilitySavedataParam *param, u8 *data, u8 *saveData, int &saveSize) { u32 SavedataParam::LoadNotCryptedSave(SceUtilitySavedataParam *param, u8 *data, u8 *saveData, int &saveSize) {
if (param->dataBuf.IsValid()) if (param->dataBuf.IsValid()) {
memcpy(data, saveData, std::min((u32)saveSize, (u32)param->dataBufSize)); u32 sz = std::min((u32)saveSize, (u32)param->dataBufSize);
memcpy(data, saveData, sz);
return sz;
}
return 0;
} }
void SavedataParam::LoadSFO(SceUtilitySavedataParam *param, const std::string& dirPath) { void SavedataParam::LoadSFO(SceUtilitySavedataParam *param, const std::string& dirPath) {

View File

@ -364,8 +364,8 @@ private:
PSPFileInfo GetSaveInfo(std::string saveDir); PSPFileInfo GetSaveInfo(std::string saveDir);
int LoadSaveData(SceUtilitySavedataParam *param, const std::string &saveDirName, const std::string& dirPath, bool secureMode); int LoadSaveData(SceUtilitySavedataParam *param, const std::string &saveDirName, const std::string& dirPath, bool secureMode);
void LoadCryptedSave(SceUtilitySavedataParam *param, u8 *data, const u8 *saveData, int &saveSize, int prevCryptMode, const u8 *expectedHash, bool &saveDone); u32 LoadCryptedSave(SceUtilitySavedataParam *param, u8 *data, const u8 *saveData, int &saveSize, int prevCryptMode, const u8 *expectedHash, bool &saveDone);
void LoadNotCryptedSave(SceUtilitySavedataParam *param, u8 *data, u8 *saveData, int &saveSize); u32 LoadNotCryptedSave(SceUtilitySavedataParam *param, u8 *data, u8 *saveData, int &saveSize);
void LoadSFO(SceUtilitySavedataParam *param, const std::string& dirPath); void LoadSFO(SceUtilitySavedataParam *param, const std::string& dirPath);
void LoadFile(const std::string& dirPath, const std::string& filename, PspUtilitySavedataFileData *fileData); void LoadFile(const std::string& dirPath, const std::string& filename, PspUtilitySavedataFileData *fileData);