From 9774b3f640ad571e48040849bfe293917d3daf61 Mon Sep 17 00:00:00 2001 From: Sepalani Date: Thu, 15 Dec 2016 00:53:52 +0000 Subject: [PATCH 1/2] WiiSave: Fixes directory issues --- Source/Core/Core/HW/WiiSaveCrypted.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/HW/WiiSaveCrypted.cpp b/Source/Core/Core/HW/WiiSaveCrypted.cpp index fb1298143b..361d0d89ff 100644 --- a/Source/Core/Core/HW/WiiSaveCrypted.cpp +++ b/Source/Core/Core/HW/WiiSaveCrypted.cpp @@ -337,10 +337,11 @@ void CWiiSaveCrypted::ImportWiiSaveFiles() } else { - std::string filename = - Common::EscapeFileName(reinterpret_cast(file_hdr_tmp.name)); + // Allows files in subfolders to be escaped properly (ex: "nocopy/data00") + // Special characters in path components will be escaped such as /../ + std::string file_path = Common::EscapePath(reinterpret_cast(file_hdr_tmp.name)); - std::string file_path_full = m_wii_title_path + filename; + std::string file_path_full = m_wii_title_path + file_path; File::CreateFullPath(file_path_full); if (file_hdr_tmp.type == 1) { @@ -369,6 +370,20 @@ void CWiiSaveCrypted::ImportWiiSaveFiles() raw_save_file.WriteBytes(&file_data[0], file_size); } } + else if (file_hdr_tmp.type == 2) + { + if (!File::Exists(file_path_full)) + { + if (!File::CreateDir(file_path_full)) + ERROR_LOG(CONSOLE, "Failed to create directory %s", file_path_full.c_str()); + } + else if (!File::IsDirectory(file_path_full)) + { + ERROR_LOG(CONSOLE, + "Failed to create directory %s because a file with the same name exists", + file_path_full.c_str()); + } + } } } } From b4bc1c9339063d1955aa7960d2d3190ae617e099 Mon Sep 17 00:00:00 2001 From: Sepalani Date: Thu, 15 Dec 2016 01:16:00 +0000 Subject: [PATCH 2/2] WiiSave: Fixes vector assertions --- Source/Core/Core/HW/WiiSaveCrypted.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Core/Core/HW/WiiSaveCrypted.cpp b/Source/Core/Core/HW/WiiSaveCrypted.cpp index 361d0d89ff..442e4b3db1 100644 --- a/Source/Core/Core/HW/WiiSaveCrypted.cpp +++ b/Source/Core/Core/HW/WiiSaveCrypted.cpp @@ -350,7 +350,7 @@ void CWiiSaveCrypted::ImportWiiSaveFiles() std::vector file_data(file_size_rounded); std::vector file_data_enc(file_size_rounded); - if (!data_file.ReadBytes(&file_data_enc[0], file_size_rounded)) + if (!data_file.ReadBytes(file_data_enc.data(), file_size_rounded)) { ERROR_LOG(CONSOLE, "Failed to read data from file %d", i); m_valid = false; @@ -359,7 +359,7 @@ void CWiiSaveCrypted::ImportWiiSaveFiles() memcpy(m_iv, file_hdr_tmp.IV, 0x10); mbedtls_aes_crypt_cbc(&m_aes_ctx, MBEDTLS_AES_DECRYPT, file_size_rounded, m_iv, - (const u8*)&file_data_enc[0], &file_data[0]); + static_cast(file_data_enc.data()), file_data.data()); if (!File::Exists(file_path_full) || AskYesNoT("%s already exists, overwrite?", file_path_full.c_str())) @@ -367,7 +367,7 @@ void CWiiSaveCrypted::ImportWiiSaveFiles() INFO_LOG(CONSOLE, "Creating file %s", file_path_full.c_str()); File::IOFile raw_save_file(file_path_full, "wb"); - raw_save_file.WriteBytes(&file_data[0], file_size); + raw_save_file.WriteBytes(file_data.data(), file_size); } } else if (file_hdr_tmp.type == 2) @@ -449,17 +449,17 @@ void CWiiSaveCrypted::ExportWiiSaveFiles() std::vector file_data(file_size_rounded); std::vector file_data_enc(file_size_rounded); - if (!raw_save_file.ReadBytes(&file_data[0], file_size)) + if (!raw_save_file.ReadBytes(file_data.data(), file_size)) { ERROR_LOG(CONSOLE, "Failed to read data from file: %s", m_files_list[i].c_str()); m_valid = false; } mbedtls_aes_crypt_cbc(&m_aes_ctx, MBEDTLS_AES_ENCRYPT, file_size_rounded, file_hdr_tmp.IV, - (const u8*)&file_data[0], &file_data_enc[0]); + static_cast(file_data.data()), file_data_enc.data()); File::IOFile fpData_bin(m_encrypted_save_path, "ab"); - if (!fpData_bin.WriteBytes(&file_data_enc[0], file_size_rounded)) + if (!fpData_bin.WriteBytes(file_data_enc.data(), file_size_rounded)) { ERROR_LOG(CONSOLE, "Failed to write data to file: %s", m_encrypted_save_path.c_str()); }