mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-21 16:12:47 -05:00
A guest path is resolved by appending its components to the host root or to a mount alias directory through std::filesystem::path. On Windows a component such as "C:" that came first in the appended part was parsed as a root name, so operator/ replaced the host directory instead of appending: "/savedata0/C:/Windows/win.ini" and "/app0/../C:/Windows/win.ini" resolved to "C:\Windows\win.ini", and "/C:/x" lost the component and resolved to "<root>\x". A colon is an ordinary character in a FreeBSD file name, so those names belong under the mount. Guest paths are now split into component names and joined to the host directory as text. Explicit native drive paths are still passed through. On NTFS a name containing ":" still opens an alternate data stream; the libc debt list now records it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
2.7 KiB
C++
52 lines
2.7 KiB
C++
#include "prx/libc/include/General.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <chrono>
|
|
#include <cstdlib>
|
|
#include <fstream>
|
|
#include <string>
|
|
|
|
static void Require(bool value) { if (!value) std::abort(); }
|
|
|
|
static std::string Under(const std::filesystem::path& directory, const std::string& names) {
|
|
auto text = directory.string();
|
|
for (std::size_t start = 0; start <= names.size();) {
|
|
const auto end = std::min(names.find('/', start), names.size());
|
|
text += static_cast<char>(std::filesystem::path::preferred_separator);
|
|
text += names.substr(start, end - start);
|
|
start = end + 1;
|
|
}
|
|
return text;
|
|
}
|
|
|
|
int main() {
|
|
const auto host = std::filesystem::canonical(std::filesystem::current_path());
|
|
const auto name = "AnyPS5-Drive-" + std::to_string(std::chrono::steady_clock::now().time_since_epoch().count());
|
|
const auto directory = host / name;
|
|
const auto mounted = directory / "Mounted";
|
|
Require(std::filesystem::create_directories(mounted / "Nested"));
|
|
{ std::ofstream file(directory / "Secret.txt"); file << 'x'; }
|
|
auto drive = host.root_name().string();
|
|
if (drive.empty()) drive = "C:";
|
|
std::string outside;
|
|
for (const auto& part : directory.relative_path()) outside += "/" + part.string();
|
|
AddPathAlias_nid_no_patch("/drive-mount", mounted.string().c_str());
|
|
|
|
Require(ResolvePath_nid_no_patch(("/drive-mount/" + drive + outside + "/Secret.txt").c_str()).string() ==
|
|
Under(mounted, drive + outside + "/Secret.txt"));
|
|
Require(ResolvePath_nid_no_patch(("/drive-mount/" + drive + "Nested").c_str()).string() == Under(mounted, drive + "Nested"));
|
|
Require(ResolvePath_nid_no_patch(("/drive-mount/" + drive).c_str()).string() == Under(mounted, drive));
|
|
Require(ResolvePath_nid_no_patch(("/drive-mount/Nested/" + drive + "/x").c_str()).string() == Under(mounted, "Nested/" + drive + "/x"));
|
|
Require(ResolvePath_nid_no_patch(("/" + name + "/../" + drive + outside + "/Secret.txt").c_str()).string() ==
|
|
Under(host, drive + outside + "/Secret.txt"));
|
|
Require(ResolvePath_nid_no_patch(("/" + drive + "/" + name + "/Secret.txt").c_str()).string() ==
|
|
Under(host, drive + "/" + name + "/Secret.txt"));
|
|
Require(ResolvePath_nid_no_patch(("/" + drive).c_str()).string() == Under(host, drive));
|
|
Require(ResolvePath_nid_no_patch(("/" + name + "/" + drive + "/x").c_str()).string() == Under(directory, drive + "/x"));
|
|
Require(ResolvePath_nid_no_patch(("/" + name + "/Secret.txt").c_str()) == directory / "Secret.txt");
|
|
Require(ResolvePath_nid_no_patch("/drive-mount/Nested").string() == Under(mounted, "Nested"));
|
|
|
|
RemovePathAlias_nid_no_patch("/drive-mount");
|
|
std::filesystem::remove_all(directory);
|
|
}
|