Play your Steam library's Windows games on a jailbroken PS5.
C++
Install the package a redistributable's setup program carries
Leonardo Lobato1d3a40adfca3
diff --git a/src/runtime/redist_install.cpp b/src/runtime/redist_install.cppindex 559ca9b..347695d 100644--- a/src/runtime/redist_install.cpp+++ b/src/runtime/redist_install.cpp@@ -9,6 +9,7 @@#include <algorithm>#include <cerrno>#include <chrono>+#include <cstring>#include <fcntl.h>#include <filesystem>#include <functional>@@ -37,14 +38,32 @@ std::string Lower(std::string_view text) {return out;}-bool ReadFile(const std::filesystem::path& path, std::size_t maximum, std::string* text) {+bool ReadFile(const std::filesystem::path& path, std::size_t maximum, std::string* text, off_t offset = 0) {text->clear();const int file = ::open(path.c_str(), O_RDONLY | O_NOFOLLOW | O_CLOEXEC);if (file < 0) return false;+ if (offset && ::lseek(file, offset, SEEK_SET) != offset) {+ ::close(file);+ return false;+ }+ // The whole file at once: growing the string a piece at a time briefly holds two copies.+ struct stat info {};+ std::size_t expected = 0;+ if (::fstat(file, &info) == 0 && info.st_size > offset) {+ if (static_cast<std::uint64_t>(info.st_size - offset) > maximum) { // too large: refused before any allocation+ ::close(file);+ return false;+ }+ expected = static_cast<std::size_t>(info.st_size - offset);+ text->reserve(expected + 1);+ }bool ok = true;// Large packages: read straight into the string, not through a stack buffer (small worker stacks).- for (std::size_t chunk = 1u << 20;;) {+ for (;;) {const auto size = text->size();+ // Within the reserved size (one byte more, to see the end), so the string never grows past it.+ std::size_t chunk = 1u << 20;+ if (expected && size <= expected) chunk = std::min(chunk, expected + 1 - size);text->resize(size + chunk);const auto count = ::read(file, &(*text)[size], chunk);if (count < 0 && errno == EINTR) {@@ -290,20 +309,24 @@ bool InstallPlan(std::string_view package, const CabinetSource& beside, const stif (!used.count(index)) continue;const auto& cabinet = plan.cabinets[index];std::string bytes;+ std::optional<std::string_view> view; // an embedded cabinet in place, without a copy, when it can beif (cabinet.embedded) {- auto stream = ReadMsiStream(package, cabinet.name);- if (!stream) {- *reason = "the package's cabinet " + cabinet.name + " is missing";- return false;+ view = ViewMsiStream(package, cabinet.name);+ if (!view) {+ auto stream = ReadMsiStream(package, cabinet.name);+ if (!stream) {+ *reason = "the package's cabinet " + cabinet.name + " is missing";+ return false;+ }+ bytes = std::move(*stream);}- bytes = std::move(*stream);} else if (cabinet.name.find('/') != std::string::npos || cabinet.name.find('\\') != std::string::npos ||!beside(cabinet.name, &bytes)) {*reason = "the cabinet " + cabinet.name + " beside the package could not be read";return false;}std::string failure;- const bool ok = ExtractCabinet(bytes, [&](const std::string& member, std::string_view data) {+ const bool ok = ExtractCabinet(view ? *view : std::string_view(bytes), [&](const std::string& member, std::string_view data) {const auto found = wanted.find(member);if (found == wanted.end()) return true;for (const auto* file : found->second) {@@ -339,10 +362,16 @@ bool InstallPlan(std::string_view package, const CabinetSource& beside, const stconst auto extended = ExtendPath(current, plan.path_prepend, plan.path_append);if (extended != current) machine.push_back({kEnvironmentKey, "PATH", "str(2):" + WineString(extended)});}- // Steam marks the entry as run under its HasRunKey (a DWORD named after the entry).+ // Steam marks the entry as run under its HasRunKey (a DWORD named after the entry), unless the+ // package writes that value itself (PhysX's "PhysX Version" under AGEIA Technologies).const auto run_key = Lower(entry.has_run_key);- if (run_key.rfind("hkey_local_machine\\software\\", 0) == 0 && run_key.rfind("hkey_local_machine\\software\\wow6432node\\", 0) != 0)- machine.push_back({"Software\\Wow6432Node\\" + entry.has_run_key.substr(28), entry.name, "dword:00000001"});+ if (run_key.rfind("hkey_local_machine\\software\\", 0) == 0 && run_key.rfind("hkey_local_machine\\software\\wow6432node\\", 0) != 0) {+ RegistryValue marker{"Software\\Wow6432Node\\" + entry.has_run_key.substr(28), entry.name, "dword:00000001"};+ const bool written = std::any_of(machine.begin(), machine.end(), [&](const RegistryValue& value) {+ return !value.default_value && Lower(value.key) == Lower(marker.key) && Lower(value.name) == Lower(marker.name);+ });+ if (!written) machine.push_back(std::move(marker));+ }for (const auto& [hive, values] : {std::pair<const char*, const std::vector<RegistryValue>*>{"system.reg", &machine},std::pair<const char*, const std::vector<RegistryValue>*>{"user.reg", &plan.user}}) {if (!values->empty() && !ApplyBottleRegistryValues(*values, prefix.string(), unix_time, hive, reason)) return false;@@ -350,7 +379,17 @@ bool InstallPlan(std::string_view package, const CabinetSource& beside, const streturn true;}-// Installs a package from the game folder, its external cabinets beside it.+// Installs a package read from the game folder (on its own, or inside the setup program at+// package_path), its external cabinets beside that file.+bool InstallPackageBytes(std::string_view package, const std::filesystem::path& package_path,+ const std::filesystem::path& prefix, const RedistEntry& entry, std::int64_t unix_time,+ std::size_t* files, std::string* reason) {+ const auto beside = [&](const std::string& name, std::string* bytes) {+ return ReadFile(package_path.parent_path() / name, kMaxPackageBytes, bytes);+ };+ return InstallPlan(package, beside, prefix, entry, unix_time, {}, files, reason);+}+bool InstallPackage(const std::filesystem::path& package_path, const std::filesystem::path& prefix,const RedistEntry& entry, std::int64_t unix_time, std::size_t* files, std::string* reason) {std::string package;@@ -358,14 +397,83 @@ bool InstallPackage(const std::filesystem::path& package_path, const std::filesy*reason = "the package could not be read";return false;}- const auto beside = [&](const std::string& name, std::string* bytes) {- return ReadFile(package_path.parent_path() / name, kMaxPackageBytes, bytes);- };- return InstallPlan(package, beside, prefix, entry, unix_time, {}, files, reason);+ return InstallPackageBytes(package, package_path, prefix, entry, unix_time, files, reason);+}++// A package that reads as one and has files.+bool PackageWithFiles(std::string_view package) {+ MsiInstallPlan plan;+ std::string reason;+ return ReadMsiPackage(package, &plan, &reason) && !plan.files.empty();+}++constexpr char kCompoundSignature[] = "\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1";+constexpr std::size_t kMaxCandidates = 16;+// A package a setup program carries, at most (PhysX 9.09's is 33 MiB): it is read whole, and the console's heap is+// small.+constexpr std::size_t kMaxEmbeddedBytes = 96u * 1024u * 1024u;++// Whether the compound file header at offset looks like one a package has (the sector sizes Compound reads), so+// a signature that only happens to be in the program isn't read to the end.+bool CompoundHeaderAt(int file, off_t offset) {+ unsigned char header[0x22];+ if (::pread(file, header, sizeof(header), offset) != static_cast<ssize_t>(sizeof(header))) return false;+ const unsigned shift = header[0x1e] | header[0x1f] << 8, mini = header[0x20] | header[0x21] << 8;+ return std::memcmp(header, kCompoundSignature, 8) == 0 && (shift == 9 || shift == 12) && mini == 6;+}++// FindEmbeddedMsi on a file, read a piece at a time: only the package, from its offset to the+// file's end, is kept, in *package (the console's heap is small and a setup program can be large).+bool FindEmbeddedMsiFile(const std::filesystem::path& path, std::string* package) {+ const int file = ::open(path.c_str(), O_RDONLY | O_NOFOLLOW | O_CLOEXEC);+ if (file < 0) return false;+ const std::string_view signature(kCompoundSignature, 8);+ std::vector<char> chunk(1u << 20);+ std::string carry; // the previous piece's last bytes, for a signature across two pieces+ off_t carry_at = 0; // where carry starts in the file+ std::size_t candidates = 0;+ bool found = false;+ for (off_t read_at = 0; !found && candidates < kMaxCandidates && read_at < static_cast<off_t>(kMaxPackageBytes);) {+ const auto count = ::read(file, chunk.data(), chunk.size());+ if (count < 0 && errno == EINTR) continue;+ if (count <= 0) break;+ std::string window = carry;+ window.append(chunk.data(), static_cast<std::size_t>(count));+ const off_t window_at = carry_at;+ for (auto at = window.find(signature); at != std::string::npos && !found && candidates < kMaxCandidates;+ at = window.find(signature, at + 1)) {+ const off_t offset = window_at + static_cast<off_t>(at);+ if (offset == 0) continue; // the program itself+ ++candidates;+ if (CompoundHeaderAt(file, offset) && ReadFile(path, kMaxEmbeddedBytes, package, offset) &&+ PackageWithFiles(*package))+ found = true;+ }+ read_at += count;+ const auto keep = std::min<std::size_t>(window.size(), signature.size() - 1);+ carry = window.substr(window.size() - keep);+ carry_at = window_at + static_cast<off_t>(window.size() - keep);+ }+ ::close(file);+ if (!found) package->clear();+ return found;}} // namespace+std::optional<std::size_t> FindEmbeddedMsi(std::string_view program) {+ // Compound files the program carries; a setup program can hold other ones (its own resources),+ // so each is read as a package until one has files. A few are enough for a setup program.+ const std::string_view signature(kCompoundSignature, 8);+ std::size_t candidates = 0;+ for (auto at = program.find(signature, 1); at != std::string_view::npos && candidates < kMaxCandidates;+ at = program.find(signature, at + 1)) {+ ++candidates;+ if (PackageWithFiles(program.substr(at))) return at;+ }+ return std::nullopt;+}+RedistAction ClassifyRedist(const RedistEntry& entry, const std::string& install_dir, std::string* package) {const auto program = FileName(entry.process);if (program == "msiexec" || program == "msiexec.exe") {@@ -614,7 +722,13 @@ RedistInstallResult InstallRedistributables(const std::string& game_root, const}const std::filesystem::path prefix(prefix_dir);auto installed = InstalledPackages(prefix);- std::set<std::string> seen; // a package two scripts run is installed once+ // A package two scripts run is installed once. One that failed isn't tried again from the same folder (its+ // external cabinets are looked for there), and a setup program is looked into once.+ std::map<std::string, std::string> failed; // hash and folder -> why+ std::set<std::string> without_package; // setup programs' hashes+ const auto failure_key = [](const std::string& hash, const std::filesystem::path& path) {+ return hash + '\n' + path.parent_path().string();+ };for (const auto& script : scripts) {std::string text, reason;std::vector<RedistEntry> entries;@@ -627,6 +741,47 @@ RedistInstallResult InstallRedistributables(const std::string& game_root, constoutcome.name = entry.name;std::string package;const auto action = ClassifyRedist(entry, install_dir, &package);+ if (action == RedistAction::kNotRun && InsideGame(entry.process, install_dir, &package) && package.size() > 4 &&+ Lower(package).compare(package.size() - 4, 4, ".exe") == 0) {+ // A setup program the console can't start may carry its package as is (PhysX's). One+ // installed before is known by the program's hash, without reading its package again.+ const auto path = std::filesystem::path(game_root) / package;+ const auto hash = HashArtifactFile(path);+ std::string embedded;+ const bool already = hash && installed.count(*hash);+ const auto earlier = hash ? failed.find(failure_key(*hash, path)) : failed.end();+ bool carries = false;+ if (hash && !already && earlier == failed.end() && !without_package.count(*hash)) {+ carries = FindEmbeddedMsiFile(path, &embedded);+ if (!carries) without_package.insert(*hash);+ }+ if (already || earlier != failed.end() || carries) {+ outcome.detail = package + " (its package)";+ if (already) {+ outcome.result = "already";+ } else if (earlier != failed.end()) {+ outcome.result = "failed";+ outcome.detail = package + ": " + earlier->second;+ } else {+ std::string failure;+ if (!InstallPackageBytes(embedded, path, prefix, entry, unix_time, &outcome.files, &failure)) {+ outcome.result = "failed";+ } else if (!RecordPackage(prefix, *hash, package)) {+ outcome.result = "failed";+ failure = "installed, but could not be recorded";+ } else {+ outcome.result = "installed";+ installed[*hash] = package;+ }+ if (outcome.result == "failed") {+ outcome.detail = package + ": " + failure;+ failed[failure_key(*hash, path)] = failure;+ }+ }+ result.outcomes.push_back(std::move(outcome));+ continue;+ }+ }if (action != RedistAction::kMsi) {outcome.result = action == RedistAction::kCovered ? "covered" : "not-run";outcome.detail = FileName(entry.process);@@ -642,22 +797,28 @@ RedistInstallResult InstallRedistributables(const std::string& game_root, constresult.outcomes.push_back(std::move(outcome));continue;}- if (installed.count(*hash) || !seen.insert(*hash).second) {+ if (installed.count(*hash)) {outcome.result = "already";result.outcomes.push_back(std::move(outcome));continue;}std::string failure;- if (!InstallPackage(path, prefix, entry, unix_time, &outcome.files, &failure)) {+ if (const auto earlier = failed.find(failure_key(*hash, path)); earlier != failed.end()) {+ outcome.result = "failed";+ failure = earlier->second;+ } else if (!InstallPackage(path, prefix, entry, unix_time, &outcome.files, &failure)) {outcome.result = "failed";- outcome.detail = package + ": " + failure;} else if (!RecordPackage(prefix, *hash, package)) {outcome.result = "failed";- outcome.detail = package + ": installed, but could not be recorded";+ failure = "installed, but could not be recorded";} else {outcome.result = "installed";installed[*hash] = package;}+ if (outcome.result == "failed") {+ outcome.detail = package + ": " + failure;+ failed[failure_key(*hash, path)] = failure;+ }result.outcomes.push_back(std::move(outcome));}}diff --git a/src/runtime/redist_install.h b/src/runtime/redist_install.hindex e1fb21d..00a7ac9 100644--- a/src/runtime/redist_install.h+++ b/src/runtime/redist_install.h@@ -22,6 +22,12 @@ enum class RedistAction { kMsi, kCovered, kNotRun };// folder ('/' separators), found from `msiexec /i <package>` or a process that is the package.RedistAction ClassifyRedist(const RedistEntry& entry, const std::string& install_dir, std::string* package);+// A Windows Installer package a setup program carries as is, uncompressed (WISE and other+// self-extracting installers, NVIDIA's PhysX System Software among them): the offset of the first+// compound file in the program that reads as a package with files, or nullopt. Compressed payloads+// are not looked into.+std::optional<std::size_t> FindEmbeddedMsi(std::string_view program);+struct RedistOutcome {std::string script; // the install script, relative to the game folderstd::string name;@@ -36,9 +42,10 @@ struct RedistInstallResult {// Finds install scripts at the top of game_root and in its redistributable folders// (_CommonRedist, Redist, Support, __Installer…, up to four folders deep), and installs their-// Windows Installer packages into the stopped bottle at prefix_dir. A package installed before-// (the same SHA-256, listed in <prefix>/.playden-redist) is not installed again. A package that-// fails is reported and left out; the others still install.+// Windows Installer packages into the stopped bottle at prefix_dir, including a package a setup+// program in the game folder carries (FindEmbeddedMsi). A package installed before (the same+// SHA-256, listed in <prefix>/.playden-redist; a setup program's own) is not installed again. A+// package that fails is reported and left out; the others still install.RedistInstallResult InstallRedistributables(const std::string& game_root, const std::string& install_dir,const std::string& prefix_dir, std::int64_t unix_time);diff --git a/tests/runtime_redist_test.cpp b/tests/runtime_redist_test.cppindex 1e67450..b8e029d 100644--- a/tests/runtime_redist_test.cpp+++ b/tests/runtime_redist_test.cpp@@ -15,6 +15,7 @@#include <iterator>#include <map>#include <string>+#include <sys/resource.h>#include <unistd.h>#include <vector>@@ -33,8 +34,9 @@ namespace {// A package like NVIDIA's legacy PhysX one: a 32-bit loader in Vendor\Common (added to PATH),// an engine in Vendor\Engine\v1 found through a registry value, a 64-bit feature turned on by-// VersionNT64, a feature left off, and files in the two-block cabinet above.-enum class Variant { kNormal, kWrongSize, kUncompressed };+// VersionNT64, a feature left off, and files in the two-block cabinet above (beside the package for+// kExternalCabinet, as data.cab).+enum class Variant { kNormal, kWrongSize, kUncompressed, kExternalCabinet };std::string SamplePackage(Variant variant = Variant::kNormal) {std::vector<TableSpec> tables;@@ -72,7 +74,7 @@ std::string SamplePackage(Variant variant = Variant::kNormal) {{"off", "C_OFF", "Off.dll", "10", "", "", "512", "4"},{"link", "C_SHORTCUT", "Link.txt", "0", "", "", "512", "5"}}});tables.push_back({"Media", {{"DiskId", 'i'}, {"LastSequence", 'i'}, {"DiskPrompt", 's'}, {"Cabinet", 's'}},- {{"1", "5", "", "#data.cab"}}});+ {{"1", "5", "", variant == Variant::kExternalCabinet ? "data.cab" : "#data.cab"}}});tables.push_back({"Registry",{{"Registry", 's'}, {"Root", 'i'}, {"Key", 's'}, {"Name", 's'}, {"Value", 's'}, {"Component_", 's'}},{{"r1", "2", "SOFTWARE\\Vendor", "Core Path", "[D_ENGINE]", "C_REG"},@@ -90,6 +92,7 @@ std::string SamplePackage(Variant variant = Variant::kNormal) {{{"e1", "=-*PATH", "[D_COMMON];[~]", "C_ENV"}, {"e2", "=-*OTHER", "x", "C_ENV"}}});tables.push_back({"CustomAction", {{"Action", 's'}, {"Type", 'i'}, {"Source", 's'}, {"Target", 's'}},{{"CA1", "1", "Binary1", "Run"}}});+ if (variant == Variant::kExternalCabinet) return Package(tables, {});return Package(tables, {{"data.cab", TwoBlockCabinet()}});}@@ -416,6 +419,128 @@ std::filesystem::path MakeBottle(const std::filesystem::path& prefix) {return prefix;}+// A setup program that carries its package as is, as NVIDIA's PhysX System Software does (a WISE+// installer): the package is found past another compound file and installed from the program.+void TestEmbeddedPackage() {+ const std::string head = "MZ" + std::string(300, '\x90');+ const auto other = CompoundFile({{"resource", "not a package"}});+ const auto program = head + other + SamplePackage() + std::string(1000, '\x7f');+ CHECK(FindEmbeddedMsi(program) == head.size() + other.size());+ CHECK(!FindEmbeddedMsi(head + other + std::string(1000, '\x7f')));+ CHECK(!FindEmbeddedMsi(""));++ char pattern[] = "/tmp/playden-redist-XXXXXX";+ CHECK(::mkdtemp(pattern));+ const auto base = std::filesystem::canonical(pattern);+ const auto game = base / "game";+ const auto prefix = MakeBottle(base / "prefix");+ WriteText(game / "installscript.vdf",+ "\"InstallScript\" { \"Run Process\" { \"Version\" { "+ "\"HasRunKey\" \"HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\Vendor\" "+ "\"Process 1\" \"%INSTALLDIR%\\\\redist\\\\PhysX_SystemSoftware.exe\" \"Command 1\" \"/quiet\" } "+ "\"Other\" { \"Process 1\" \"%INSTALLDIR%\\\\redist\\\\other_setup.exe\" } } }");+ WriteText(game / "redist/PhysX_SystemSoftware.exe", program);+ WriteText(game / "redist/other_setup.exe", head + other);+ const auto result = InstallRedistributables(game.string(), "Z:\\games\\35140", prefix.string(), 1700000100);+ CHECK(result.outcomes.size() == 2);+ // The entry's HasRunKey value is one the package writes itself ("Version" under Vendor): the package's is kept.+ CHECK(result.outcomes[0].name == "Version" && result.outcomes[0].result == "installed" && result.outcomes[0].files == 3);+ CHECK(result.outcomes[0].detail == "redist/PhysX_SystemSoftware.exe (its package)");+ CHECK(result.outcomes[1].name == "Other" && result.outcomes[1].result == "not-run" &&+ result.outcomes[1].detail == "other_setup.exe");+ CHECK(ReadText(prefix / "drive_c/Program Files (x86)/Vendor Runtime/Common/Loader.dll") == "0123456789");+ CHECK(ReadText(prefix / "system.reg").find("\"Core Path\"=") != std::string::npos);+ CHECK(ReadText(prefix / "system.reg").find("\"Version\"=dword:00000007") != std::string::npos);+ CHECK(ReadText(prefix / ".playden-redist").find(" redist/PhysX_SystemSoftware.exe\n") != std::string::npos);+ // Installed once, under the program's own hash.+ const auto again = InstallRedistributables(game.string(), "Z:\\games\\35140", prefix.string(), 1700000200);+ CHECK(again.outcomes.size() == 2 && again.outcomes[0].result == "already");+ // The program is read a piece of 1 MiB at a time: a package whose signature straddles two pieces is found.+ std::filesystem::remove(prefix / ".playden-redist");+ const auto straddling = "MZ" + std::string((1u << 20) - 5, '\x90') + SamplePackage();+ CHECK(FindEmbeddedMsi(straddling) == (1u << 20) - 3);+ WriteText(game / "redist/PhysX_SystemSoftware.exe", straddling);+ const auto large = InstallRedistributables(game.string(), "Z:\\games\\35140", prefix.string(), 1700000300);+ CHECK(large.outcomes.size() == 2 && large.outcomes[0].result == "installed" && large.outcomes[0].files == 3);+ // The same program in two folders, its cabinet beside only the second: the first fails (again for a second entry,+ // without another try) and the second still installs.+ std::filesystem::remove(prefix / ".playden-redist");+ const auto external = head + SamplePackage(Variant::kExternalCabinet);+ WriteText(game / "installscript.vdf",+ "\"InstallScript\" { \"Run Process\" { "+ "\"A\" { \"Process 1\" \"%INSTALLDIR%\\\\a\\\\setup.exe\" } "+ "\"A again\" { \"Process 1\" \"%INSTALLDIR%\\\\a\\\\setup.exe\" } "+ "\"B\" { \"Process 1\" \"%INSTALLDIR%\\\\b\\\\setup.exe\" } } }");+ WriteText(game / "a/setup.exe", external);+ WriteText(game / "b/setup.exe", external);+ WriteText(game / "b/data.cab", TwoBlockCabinet());+ const auto split = InstallRedistributables(game.string(), "Z:\\games\\35140", prefix.string(), 1700000400);+ CHECK(split.outcomes.size() == 3);+ CHECK(split.outcomes[0].result == "failed" && split.outcomes[1].result == "failed");+ CHECK(split.outcomes[0].detail == split.outcomes[1].detail && split.outcomes[0].detail.rfind("a/setup.exe: ", 0) == 0);+ CHECK(split.outcomes[2].result == "installed" && split.outcomes[2].files == 3);+ std::filesystem::remove_all(base);+}++// NVIDIA's PhysX System Software 9.09.0814 setup program (Batman: Arkham Asylum's), when PLAYDEN_TEST_PHYSX_SETUP names a copy.+void TestPhysxSetupProgram() {+ const char* path = std::getenv("PLAYDEN_TEST_PHYSX_SETUP");+ if (!path || !*path) return;+ char pattern[] = "/tmp/playden-redist-XXXXXX";+ CHECK(::mkdtemp(pattern));+ const auto base = std::filesystem::canonical(pattern);+ const auto prefix = MakeBottle(base / "prefix");+ const auto game = base / "game";+ WriteText(game / "installscript.vdf",+ "\"InstallScript\" { \"Run Process\" { \"PhysX Version\" { "+ "\"HasRunKey\" \"HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\AGEIA Technologies\" "+ "\"Process 1\" \"%INSTALLDIR%\\\\redist\\\\PhysX_9.08.14_9.09.0814_SystemSoftware.exe\" \"Command 1\" \"/quiet\" "+ "\"MinimumHasRunValue\" \"9090814\" } } }");+ std::filesystem::create_directories(game / "redist");+ std::filesystem::copy_file(path, game / "redist/PhysX_9.08.14_9.09.0814_SystemSoftware.exe");+ // Installed first, before this test reads anything itself, so the peak it adds can be seen.+ struct rusage before {}, after {};+ ::getrusage(RUSAGE_SELF, &before);+ const auto result = InstallRedistributables(game.string(), "Z:\\games\\35140", prefix.string(), 1700000100);+ ::getrusage(RUSAGE_SELF, &after);+ CHECK(result.outcomes.size() == 1);+ std::fprintf(stderr, "PhysX setup program: %s %s, %zu files, peak memory %ld MB before, %ld MB after\n",+ result.outcomes[0].result.c_str(), result.outcomes[0].detail.c_str(), result.outcomes[0].files,+ static_cast<long>(before.ru_maxrss / (1024 * 1024)), static_cast<long>(after.ru_maxrss / (1024 * 1024)));+ CHECK(result.outcomes[0].result == "installed");+ CHECK(std::filesystem::exists(prefix / "drive_c/windows/syswow64/PhysXLoader.dll"));+ CHECK(std::filesystem::exists(prefix / "drive_c/Program Files (x86)/AGEIA Technologies/v2.8.1/PhysXCore.dll"));+ std::filesystem::remove_all(base);++ const auto program = ReadText(path);+ const auto at = FindEmbeddedMsi(program);+ CHECK(at);+ MsiInstallPlan plan;+ std::string reason;+ CHECK(ReadMsiPackage(std::string_view(program).substr(*at), &plan, &reason));+ const auto has = [&](const std::string& target) {+ return std::any_of(plan.files.begin(), plan.files.end(), [&](const MsiFile& file) { return file.target == target; });+ };+ // 9.09.0814 puts its loader in the system folder and the engines under AGEIA Technologies.+ CHECK(plan.product_name == "NVIDIA PhysX" && plan.product_version == "9.09.0814");+ CHECK(has("windows/syswow64/PhysXLoader.dll"));+ CHECK(has("Program Files (x86)/AGEIA Technologies/v2.8.1/PhysXCore.dll"));+ CHECK(!plan.unsupported_files && result.outcomes[0].files == plan.files.size());+ // Its cabinet is LZX. PLAYDEN_TEST_PHYSX_SETUP_FILES may name a folder with the members another tool extracted.+ if (const char* reference = std::getenv("PLAYDEN_TEST_PHYSX_SETUP_FILES"); reference && *reference) {+ const auto cabinet = ReadMsiStream(std::string_view(program).substr(*at), plan.cabinets.at(0).name);+ CHECK(cabinet);+ std::size_t compared = 0;+ CHECK(ExtractCabinet(*cabinet, [&](const std::string& name, std::string_view data) {+ CHECK(ReadText(std::filesystem::path(reference) / name) == data);+ ++compared;+ return true;+ }, &reason));+ std::fprintf(stderr, "PhysX setup program: %zu members match the reference\n", compared);+ CHECK(compared > 0);+ }+}+VcRedist SyntheticRedist(bool x64, const std::string& bundle) {const std::string arch = x64 ? "x64" : "x86";return {arch, "https://download.example/pr/" + *HashArtifactBytes(bundle) + "/VC_redist." + arch + ".exe",@@ -660,7 +785,9 @@ int main() {TestBurnBundle();TestScripts();TestInstall();+ TestEmbeddedPackage();TestPhysxPackage();+ TestPhysxSetupProgram();TestMfcFilter();TestMfcInstall();TestMfcScanRecord();