diff --git a/src/xenia/kernel/util/shim_utils.h b/src/xenia/kernel/util/shim_utils.h index bf301a38b..53dc205fa 100644 --- a/src/xenia/kernel/util/shim_utils.h +++ b/src/xenia/kernel/util/shim_utils.h @@ -93,6 +93,12 @@ inline std::string_view TranslateAnsiString(const Memory* memory, ansi_string->length); } +inline std::string TranslateAnsiPath(const Memory* memory, + const X_ANSI_STRING* ansi_string) { + return string_util::trim( + std::string(TranslateAnsiString(memory, ansi_string))); +} + inline std::string_view TranslateAnsiStringAddress(const Memory* memory, uint32_t guest_address) { if (!guest_address) { diff --git a/src/xenia/kernel/xboxkrnl/xboxkrnl_io.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_io.cc index 376f357d4..4f11ca04b 100644 --- a/src/xenia/kernel/xboxkrnl/xboxkrnl_io.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_io.cc @@ -63,7 +63,7 @@ dword_result_t NtCreateFile_entry(lpdword_t handle_out, dword_t desired_access, vfs::Entry* root_entry = nullptr; // Compute path, possibly attrs relative. - auto target_path = util::TranslateAnsiString(kernel_memory(), object_name); + auto target_path = util::TranslateAnsiPath(kernel_memory(), object_name); // Enforce that the path is ASCII. if (!IsValidPath(target_path, false)) { @@ -462,7 +462,7 @@ dword_result_t NtQueryFullAttributesFile_entry( assert_always(); } - auto target_path = util::TranslateAnsiString(kernel_memory(), object_name); + auto target_path = util::TranslateAnsiPath(kernel_memory(), object_name); // Enforce that the path is ASCII. if (!IsValidPath(target_path, false)) { @@ -501,7 +501,7 @@ dword_result_t NtQueryDirectoryFile_entry( uint32_t info = 0; auto file = kernel_state()->object_table()->LookupObject(file_handle); - auto name = util::TranslateAnsiString(kernel_memory(), file_name); + auto name = util::TranslateAnsiPath(kernel_memory(), file_name); // Enforce that the path is ASCII. if (!IsValidPath(name, true)) { @@ -558,7 +558,7 @@ dword_result_t NtOpenSymbolicLinkObject_entry( auto object_name = kernel_memory()->TranslateVirtual(object_attrs->name_ptr); - auto target_path = util::TranslateAnsiString(kernel_memory(), object_name); + auto target_path = util::TranslateAnsiPath(kernel_memory(), object_name); // Enforce that the path is ASCII. if (!IsValidPath(target_path, false)) { diff --git a/src/xenia/kernel/xboxkrnl/xboxkrnl_io_info.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_io_info.cc index cca7391d5..69f86dfd7 100644 --- a/src/xenia/kernel/xboxkrnl/xboxkrnl_io_info.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_io_info.cc @@ -234,7 +234,7 @@ dword_result_t NtSetInformationFile_entry( auto info = info_ptr.as(); // Compute path, possibly attrs relative. std::filesystem::path target_path = - util::TranslateAnsiString(kernel_memory(), &info->ansi_string); + util::TranslateAnsiPath(kernel_memory(), &info->ansi_string); // Place IsValidPath in path from where it can be accessed everywhere if (!IsValidPath(target_path.string(), false)) { diff --git a/src/xenia/kernel/xboxkrnl/xboxkrnl_modules.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_modules.cc index 05dc07342..656089dad 100644 --- a/src/xenia/kernel/xboxkrnl/xboxkrnl_modules.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_modules.cc @@ -263,7 +263,7 @@ dword_result_t XexLoadImageHeaders_entry(pointer_t path, return X_STATUS_BUFFER_TOO_SMALL; } auto current_kernel = ctx->kernel_state; - auto target_path = util::TranslateAnsiString(current_kernel->memory(), path); + auto target_path = util::TranslateAnsiPath(current_kernel->memory(), path); vfs::File* vfs_file = nullptr; vfs::FileAction file_action; diff --git a/src/xenia/kernel/xboxkrnl/xboxkrnl_ob.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_ob.cc index 5677bad56..a5c9cd528 100644 --- a/src/xenia/kernel/xboxkrnl/xboxkrnl_ob.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_ob.cc @@ -350,9 +350,9 @@ DECLARE_XBOXKRNL_EXPORT1(ObReferenceObject, kNone, kImplemented); dword_result_t ObCreateSymbolicLink_entry(pointer_t path_ptr, pointer_t target_ptr) { auto path = xe::utf8::canonicalize_guest_path( - util::TranslateAnsiString(kernel_memory(), path_ptr)); + util::TranslateAnsiPath(kernel_memory(), path_ptr)); auto target = xe::utf8::canonicalize_guest_path( - util::TranslateAnsiString(kernel_memory(), target_ptr)); + util::TranslateAnsiPath(kernel_memory(), target_ptr)); if (xe::utf8::starts_with(path, "\\??\\")) { path = path.substr(4); // Strip the full qualifier @@ -367,7 +367,7 @@ dword_result_t ObCreateSymbolicLink_entry(pointer_t path_ptr, DECLARE_XBOXKRNL_EXPORT1(ObCreateSymbolicLink, kNone, kImplemented); dword_result_t ObDeleteSymbolicLink_entry(pointer_t path_ptr) { - auto path = util::TranslateAnsiString(kernel_memory(), path_ptr); + auto path = util::TranslateAnsiPath(kernel_memory(), path_ptr); if (!kernel_state()->file_system()->UnregisterSymbolicLink(path)) { return X_STATUS_UNSUCCESSFUL; }