From 02ceb312cf7f3be4b208fbe4d6ec865674cc72c4 Mon Sep 17 00:00:00 2001 From: shenweip Date: Tue, 12 Nov 2013 11:21:26 +0800 Subject: [PATCH] Skip the load of secure files which are not in SFO. --- Core/Dialog/PSPSaveDialog.cpp | 4 +- Core/Dialog/SavedataParam.cpp | 82 ++++++++++++++++++++++++----------- Core/Dialog/SavedataParam.h | 3 ++ 3 files changed, 62 insertions(+), 27 deletions(-) diff --git a/Core/Dialog/PSPSaveDialog.cpp b/Core/Dialog/PSPSaveDialog.cpp index 969e14b68b..1597e900c8 100755 --- a/Core/Dialog/PSPSaveDialog.cpp +++ b/Core/Dialog/PSPSaveDialog.cpp @@ -954,7 +954,9 @@ int PSPSaveDialog::Update(int animSpeed) break; case SCE_UTILITY_SAVEDATA_TYPE_READDATA: case SCE_UTILITY_SAVEDATA_TYPE_READDATASECURE: - if (param.Load(param.GetPspParam(), GetSelectedSaveDirName(), currentSelectedSave, param.GetPspParam()->mode == SCE_UTILITY_SAVEDATA_TYPE_READDATASECURE)) + if(param.secureShouldSkip(param.GetPspParam())) + param.GetPspParam()->common.result = 0; + else if (param.Load(param.GetPspParam(), GetSelectedSaveDirName(), currentSelectedSave, param.GetPspParam()->mode == SCE_UTILITY_SAVEDATA_TYPE_READDATASECURE)) param.GetPspParam()->common.result = 0; else param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA; // not sure if correct code diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index eafb0d4f7f..0af34ffe81 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -584,6 +584,41 @@ void SavedataParam::LoadSFO(SceUtilitySavedataParam *param, const std::string di } } +std::set SavedataParam::getSecureFileNames(std::string dirPath) { + PSPFileInfo sfoFileInfo = pspFileSystem.GetFileInfo(dirPath + "/" + SFO_FILENAME); + std::set secureFileNames; + if(!sfoFileInfo.exists) + return secureFileNames; + + ParamSFOData sfoFile; + size_t sfoSize = (size_t)sfoFileInfo.size; + u8 *sfoData = new u8[sfoSize]; + if (ReadPSPFile(dirPath + "/" + SFO_FILENAME, &sfoData, sfoSize, NULL)){ + sfoFile.ReadSFO(sfoData, sfoSize); + } + delete[] sfoData; + + u32 sfoFileListSize = 0; + char *sfoFileList = (char *)sfoFile.GetValueData("SAVEDATA_FILE_LIST", &sfoFileListSize); + const int FILE_LIST_ITEM_SIZE = 13 + 16 + 3; + const u32 FILE_LIST_COUNT_MAX = 99; + + // Filenames are 13 bytes long at most. Add a NULL so there's no surprises. + char temp[14]; + temp[13] = '\0'; + + for (u32 i = 0; i < FILE_LIST_COUNT_MAX; ++i) { + // Ends at a NULL filename. + if (i * FILE_LIST_ITEM_SIZE >= sfoFileListSize || sfoFileList[i * FILE_LIST_ITEM_SIZE] == '\0') { + break; + } + + strncpy(temp, &sfoFileList[i * FILE_LIST_ITEM_SIZE], 13); + secureFileNames.insert(temp); + } + return secureFileNames; +} + void SavedataParam::LoadFile(const std::string dirPath, const std::string filename, PspUtilitySavedataFileData *fileData) { std::string filePath = dirPath + "/" + filename; s64 readSize = -1; @@ -959,32 +994,7 @@ int SavedataParam::GetFilesList(SceUtilitySavedataParam *param) std::set secureFilenames; // TODO: Error code if not? if (sfoFileInfo.exists) { - ParamSFOData sfoFile; - size_t sfoSize = (size_t)sfoFileInfo.size; - u8 *sfoData = new u8[sfoSize]; - if (ReadPSPFile(dirPath + "/" + SFO_FILENAME, &sfoData, sfoSize, NULL)){ - sfoFile.ReadSFO(sfoData, sfoSize); - } - delete[] sfoData; - - u32 sfoFileListSize = 0; - char *sfoFileList = (char *)sfoFile.GetValueData("SAVEDATA_FILE_LIST", &sfoFileListSize); - const int FILE_LIST_ITEM_SIZE = 13 + 16 + 3; - const u32 FILE_LIST_COUNT_MAX = 99; - - // Filenames are 13 bytes long at most. Add a NULL so there's no surprises. - char temp[14]; - temp[13] = '\0'; - - for (u32 i = 0; i < FILE_LIST_COUNT_MAX; ++i) { - // Ends at a NULL filename. - if (i * FILE_LIST_ITEM_SIZE >= sfoFileListSize || sfoFileList[i * FILE_LIST_ITEM_SIZE] == '\0') { - break; - } - - strncpy(temp, &sfoFileList[i * FILE_LIST_ITEM_SIZE], 13); - secureFilenames.insert(temp); - } + secureFilenames = getSecureFileNames(dirPath); } // Does not list directories, nor recurse into them, and ignores files not ALL UPPERCASE. @@ -1531,3 +1541,23 @@ bool SavedataParam::IsInSaveDataList(std::string saveName, int count) { } return false; } + +bool SavedataParam::secureShouldSkip(SceUtilitySavedataParam* param) { + std::string dirPath = savePath + GetGameName(param) + GetSaveName(param); + std::string sfoPath = dirPath + "/" + SFO_FILENAME; + std::string secureFileName = GetFileName(param); + std::set secureFileNames; + PSPFileInfo sfoInfo = pspFileSystem.GetFileInfo(sfoPath); + // If sfo doesn't exsit,shouldn't skip. + if(!sfoInfo.exists) + return false; + + // Get secure file names from PARAM.SFO. + secureFileNames = getSecureFileNames(dirPath); + // Secure file name should be saved in PARAM.SFO + // Cannot find name in PARAM.SFO, skip. + if(secureFileNames.find(secureFileName) == secureFileNames.end()) + return true; + + return false; +} \ No newline at end of file diff --git a/Core/Dialog/SavedataParam.h b/Core/Dialog/SavedataParam.h index cb81383c5f..175014e669 100644 --- a/Core/Dialog/SavedataParam.h +++ b/Core/Dialog/SavedataParam.h @@ -305,6 +305,7 @@ public: bool GetSize(SceUtilitySavedataParam* param); bool IsSaveEncrypted(SceUtilitySavedataParam* param, const std::string &saveDirName); bool IsInSaveDataList(std::string saveName, int count); + bool secureShouldSkip(SceUtilitySavedataParam* param); std::string GetGameName(SceUtilitySavedataParam* param); std::string GetSaveName(SceUtilitySavedataParam* param); @@ -351,6 +352,8 @@ private: int UpdateHash(u8* sfoData, int sfoSize, int sfoDataParamsOffset, int encryptmode); int BuildHash(unsigned char *output, unsigned char *data, unsigned int len, unsigned int alignedLen, int mode, unsigned char *cryptkey); + std::set getSecureFileNames(std::string dirPath); + SceUtilitySavedataParam* pspParam; int selectedSave; SaveFileInfo *saveDataList;