IOS HLE: More robust escaping of NAND paths

Prevents path traversal without needing an absolute path
function, and also improves accuracy (character sequences
like ../ appear to have no special meaning in IOS).

This removes the creation and usage of /sys/replace,
because the new escapes are too complicated to all
be representable in its format and because no other
NAND handling software seems to use /sys/replace.
This commit is contained in:
JosJuice
2016-11-26 15:39:00 +01:00
parent de355a8521
commit c74c317ab5
9 changed files with 90 additions and 88 deletions

View File

@ -30,8 +30,6 @@
#include "Core/HW/WiiSaveCrypted.h"
static Common::replace_v replacements;
const u8 CWiiSaveCrypted::s_sd_key[16] = {0xAB, 0x01, 0xB9, 0xD8, 0xE1, 0x62, 0x2B, 0x08,
0xAF, 0xBA, 0xD8, 0x4D, 0xBF, 0xC2, 0xA5, 0x5D};
const u8 CWiiSaveCrypted::s_md5_blanker[16] = {0x0E, 0x65, 0x37, 0x81, 0x99, 0xBE, 0x45, 0x17,
@ -102,7 +100,6 @@ void CWiiSaveCrypted::ExportAllSaves()
CWiiSaveCrypted::CWiiSaveCrypted(const std::string& filename, u64 title_id)
: m_encrypted_save_path(filename), m_title_id(title_id)
{
Common::ReadReplacements(replacements);
memcpy(m_sd_iv, "\x21\x67\x12\xE6\xAA\x1F\x68\x9F\x95\xC5\xA2\x23\x24\xDC\x6A\x98", 0x10);
if (!title_id) // Import
@ -340,12 +337,8 @@ void CWiiSaveCrypted::ImportWiiSaveFiles()
}
else
{
std::string filename((char*)file_hdr_tmp.name);
for (const Common::replace_t& replacement : replacements)
{
for (size_t j = 0; (j = filename.find(replacement.first, j)) != filename.npos; ++j)
filename.replace(j, 1, replacement.second);
}
std::string filename =
Common::EscapeFileName(reinterpret_cast<const char*>(file_hdr_tmp.name));
std::string file_path_full = m_wii_title_path + filename;
File::CreateFullPath(file_path_full);
@ -388,7 +381,6 @@ void CWiiSaveCrypted::ExportWiiSaveFiles()
for (u32 i = 0; i < m_files_list_size; i++)
{
FileHDR file_hdr_tmp;
std::string name;
memset(&file_hdr_tmp, 0, FILE_HDR_SZ);
u32 file_size = 0;
@ -407,15 +399,8 @@ void CWiiSaveCrypted::ExportWiiSaveFiles()
file_hdr_tmp.size = Common::swap32(file_size);
file_hdr_tmp.Permissions = 0x3c;
name = m_files_list[i].substr(m_wii_title_path.length() + 1);
for (const Common::replace_t& repl : replacements)
{
for (size_t j = 0; (j = name.find(repl.second, j)) != name.npos; ++j)
{
name.replace(j, repl.second.length(), 1, repl.first);
}
}
std::string name =
Common::UnescapeFileName(m_files_list[i].substr(m_wii_title_path.length() + 1));
if (name.length() > 0x44)
{