diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index c9533f2f68..f22b8ac13c 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -145,7 +145,7 @@ namespace int align16(int address) { - return ((address + 0xF) >> 4) << 4; + return (address + 15) & ~15; } int GetSDKMainVersion(int sdkVersion) @@ -537,10 +537,8 @@ int SavedataParam::Save(SceUtilitySavedataParam* param, const std::string &saveD delete[] updatedList; // Init param with 0. This will be used to detect crypted save or not on loading - u8 *tmpData = new u8[128]; - memset(tmpData, 0, 128); - sfoFile->SetValue("SAVEDATA_PARAMS", tmpData, 128, 128); - delete[] tmpData; + u8 zeroes[128]{}; + sfoFile->SetValue("SAVEDATA_PARAMS", zeroes, 128, 128); u8 *sfoData; size_t sfoSize; diff --git a/Core/Dialog/SavedataParam.h b/Core/Dialog/SavedataParam.h index 04c8dca5e4..b10cfe6c6b 100644 --- a/Core/Dialog/SavedataParam.h +++ b/Core/Dialog/SavedataParam.h @@ -375,6 +375,8 @@ private: int DecryptSave(unsigned int mode, unsigned char *data, int *dataLen, int *alignedLen, unsigned char *cryptkey, const u8 *expectedHash); int EncryptData(unsigned int mode, unsigned char *data, int *dataLen, int *alignedLen, unsigned char *hash, unsigned char *cryptkey); int UpdateHash(u8* sfoData, int sfoSize, int sfoDataParamsOffset, int encryptmode); + + // WARNING: this writes zeroes to data from len to alignedLen. This means that data must have space for the full alignedLen! int BuildHash(unsigned char *output, unsigned char *data, unsigned int len, unsigned int alignedLen, int mode, unsigned char *cryptkey); int DetermineCryptMode(const SceUtilitySavedataParam *param) const; diff --git a/Core/ELF/ParamSFO.cpp b/Core/ELF/ParamSFO.cpp index 856221d36c..0703b8f2af 100644 --- a/Core/ELF/ParamSFO.cpp +++ b/Core/ELF/ParamSFO.cpp @@ -195,7 +195,7 @@ bool ParamSFOData::ReadSFO(const u8 *paramsfo, size_t size) { return true; } -int ParamSFOData::GetDataOffset(const u8 *paramsfo, const std::string &dataName) { +int ParamSFOData::GetDataOffset(const u8 *paramsfo, const char *dataName) { const Header *header = (const Header *)paramsfo; if (header->magic != 0x46535000) return -1; @@ -210,7 +210,7 @@ int ParamSFOData::GetDataOffset(const u8 *paramsfo, const std::string &dataName) for (u32 i = 0; i < header->index_table_entries; i++) { const char *key = (const char *)(key_start + indexTables[i].key_table_offset); - if (!strcmp(key, dataName.c_str())) + if (!strcmp(key, dataName)) { return data_start + indexTables[i].data_table_offset; } diff --git a/Core/ELF/ParamSFO.h b/Core/ELF/ParamSFO.h index 3d7a719e50..8531ded275 100644 --- a/Core/ELF/ParamSFO.h +++ b/Core/ELF/ParamSFO.h @@ -55,7 +55,8 @@ public: } } - int GetDataOffset(const u8 *paramsfo, const std::string &dataName); + // If not found, returns a negative value. + int GetDataOffset(const u8 *paramsfo, const char *dataName); void Clear();