Skip to content

Play your Steam library's Windows games on a jailbroken PS5.

C++

Harden redistributable installs against damaged packages

Leonardo Lobato470aa181ad3e
diff --git a/src/homebrew/runtime_host.cpp b/src/homebrew/runtime_host.cpp
index ca2a0da..5851181 100644
--- a/src/homebrew/runtime_host.cpp
+++ b/src/homebrew/runtime_host.cpp
@@ -514,10 +514,17 @@ std::string RuntimeHost::ApplySteamworks(Composition& c, const rt::RuntimeInstal
const auto redist = rt::InstallRedistributables(root.string(), *install_dir,
(HostPath(record.data_root) / "library/prefixes/game").string(),
config_.unix_time());
+ // Names and reasons come from the game's files: one line each, whatever they hold.
+ const auto field = [](std::string text) {
+ if (text.size() > 240) text.resize(240);
+ for (auto& value : text)
+ if (static_cast<unsigned char>(value) < 0x20 || value == 0x7f) value = '?';
+ return text;
+ };
for (const auto& outcome : redist.outcomes)
if (outcome.result != "already" && outcome.result != "covered")
- Log("redist app=" + std::to_string(record.app_id) + " script=" + outcome.script + " name=" + outcome.name +
- " result=" + outcome.result + " detail=" + outcome.detail +
+ Log("redist app=" + std::to_string(record.app_id) + " script=" + field(outcome.script) + " name=" +
+ field(outcome.name) + " result=" + outcome.result + " detail=" + field(outcome.detail) +
(outcome.files ? " files=" + std::to_string(outcome.files) : std::string()));
}
// Registry values the recipe carries (docs/community-recipes.md), written the way an install script's are.
diff --git a/src/runtime/artifact_hash.cpp b/src/runtime/artifact_hash.cpp
index 4e10572..a792a1d 100644
--- a/src/runtime/artifact_hash.cpp
+++ b/src/runtime/artifact_hash.cpp
@@ -9,6 +9,7 @@
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <vector>
namespace playden::runtime {
namespace {
@@ -76,7 +77,8 @@ std::optional<std::string> HashArtifactFile(const std::filesystem::path& path) {
!S_ISREG(before.st_mode) || before.st_size < 0) return std::nullopt;
Hash hash;
if (!hash.Start()) return std::nullopt;
- std::array<unsigned char, 64 * 1024> buffer{};
+ // On the heap: the console's worker threads have small stacks.
+ std::vector<unsigned char> buffer(64 * 1024);
std::uint64_t total = 0;
for (;;) {
const auto count = read(file.get(), buffer.data(), buffer.size());
diff --git a/src/runtime/msi_package.cpp b/src/runtime/msi_package.cpp
index 6954632..e7b7148 100644
--- a/src/runtime/msi_package.cpp
+++ b/src/runtime/msi_package.cpp
@@ -149,7 +149,9 @@ bool Compound::Open(std::string_view data, std::string* reason) {
difat = U32(data, static_cast<std::size_t>(at) + sector_size_ - 4);
}
fat_.clear();
+ std::set<std::uint32_t> fat_seen;
for (const auto sector : fat_list) {
+ if (!fat_seen.insert(sector).second) return fail("damaged package");
const std::uint64_t at = (static_cast<std::uint64_t>(sector) + 1) * sector_size_;
if (at + sector_size_ > data.size()) return fail("damaged package");
for (std::size_t index = 0; index < sector_size_ / 4; ++index)
@@ -159,7 +161,7 @@ bool Compound::Open(std::string_view data, std::string* reason) {
const auto whole_chain = [&](std::uint32_t start, std::string* out) {
out->clear();
for (std::uint32_t sector = start, steps = 0; sector != kEndOfChain; ++steps) {
- if (sector >= fat_.size() || steps > fat_.size()) return false;
+ if (sector >= fat_.size() || steps > total_sectors || out->size() + sector_size_ > data.size()) return false;
const std::uint64_t at = (static_cast<std::uint64_t>(sector) + 1) * sector_size_;
if (at + sector_size_ > data.size()) return false;
out->append(data.substr(static_cast<std::size_t>(at), sector_size_));
@@ -315,7 +317,7 @@ bool Database::ReadColumns(const std::string& stream, const std::vector<ColumnIn
table->columns.clear();
for (const auto* column : stored) table->columns.push_back(column->name);
table->rows.assign(count, std::vector<Cell>(stored.size()));
- std::size_t at = 0;
+ std::size_t at = 0, text_bytes = 0;
for (std::size_t column = 0; column < stored.size(); ++column) {
const bool binary = (stored[column]->type & ~kTypeNullable) == (kTypeString | kTypeValid);
const bool text = (stored[column]->type & kTypeString) && !binary;
@@ -327,6 +329,8 @@ bool Database::ReadColumns(const std::string& stream, const std::vector<ColumnIn
: U16(stream, at);
cell.null = id == 0;
cell.text = String(id);
+ // Cells copy pooled strings: a table repeating one long string must not multiply it without bound.
+ if ((text_bytes += cell.text.size()) > kMaxStreamBytes / 4) return false;
} else if (widths[column] == 2) {
const auto raw = U16(stream, at);
cell.null = raw == 0;
@@ -444,15 +448,22 @@ class ConditionParser {
}
bool Negation(bool* value) {
if (Keyword("NOT")) {
- if (!Negation(value)) return false;
+ if (++depth_ > kMaxDepth) return false;
+ const bool ok = Negation(value);
+ --depth_;
+ if (!ok) return false;
*value = !*value;
return true;
}
return Comparison(value);
}
+ // As Windows Installer: a bare property is true when it has a value ("0" included), a bare
+ // integer when it isn't 0; values compare as integers when both are, else an integer against
+ // text is false (only <> holds) and text compares as text.
struct Operand {
std::string text;
- bool integer = false;
+ bool integer = false; // the text is an integer
+ bool literal = false; // an integer written in the condition
long long number = 0;
};
static Operand Classify(std::string text, bool literal_string) {
@@ -484,6 +495,7 @@ class ConditionParser {
std::size_t end = at_ + 1;
while (end < text_.size() && std::isdigit(static_cast<unsigned char>(text_[end]))) ++end;
*operand = Classify(std::string(text_.substr(at_, end - at_)), false);
+ operand->literal = true;
at_ = end;
return !operand->text.empty() && operand->text != "-";
}
@@ -504,12 +516,15 @@ class ConditionParser {
*operand = Classify(state || found == properties_.end() ? std::string() : found->second, false);
return true;
}
- static bool Truth(const Operand& operand) { return operand.integer ? operand.number != 0 : !operand.text.empty(); }
+ static bool Truth(const Operand& operand) { return operand.literal ? operand.number != 0 : !operand.text.empty(); }
bool Comparison(bool* value) {
Space();
if (at_ < text_.size() && text_[at_] == '(') {
++at_;
- if (!Implication(value)) return false;
+ if (++depth_ > kMaxDepth) return false;
+ const bool ok = Implication(value);
+ --depth_;
+ if (!ok) return false;
Space();
if (at_ >= text_.size() || text_[at_] != ')') return false;
++at_;
@@ -541,6 +556,10 @@ class ConditionParser {
at_ = probe + op.size();
Operand right;
if (!Value(&right)) return false;
+ if ((left.literal && !right.integer) || (right.literal && !left.integer)) {
+ *value = op == "<>";
+ return true;
+ }
if (left.integer && right.integer) {
const auto a = left.number, b = right.number;
*value = op == "=" ? a == b : op == "<>" ? a != b : op == "<" ? a < b : op == ">" ? a > b
@@ -554,9 +573,11 @@ class ConditionParser {
: op == "<<" ? a.rfind(b, 0) == 0 : (a.size() >= b.size() && a.compare(a.size() - b.size(), b.size(), b) == 0);
return true;
}
+ static constexpr int kMaxDepth = 32; // the console's worker stacks are small
std::string_view text_;
const std::map<std::string, std::string>& properties_;
std::size_t at_ = 0;
+ int depth_ = 0;
};
// ---------------------------------------------------------------------------------------------
@@ -599,6 +620,24 @@ std::optional<std::string> StandardFolder(const std::string& name) {
return std::nullopt;
}
+// "C:\\a\\b\\" as a path below drive_c ("a/b"); nullopt for another drive or a ".." part.
+std::optional<std::string> DrivePath(const std::string& windows) {
+ if (windows.size() < 3 || (windows[0] != 'C' && windows[0] != 'c') || windows[1] != ':' || windows[2] != '\\' ||
+ !Ascii(windows))
+ return std::nullopt;
+ std::string out;
+ for (std::size_t at = 3; at < windows.size();) {
+ auto end = windows.find('\\', at);
+ if (end == std::string::npos) end = windows.size();
+ const auto part = windows.substr(at, end - at);
+ at = end + 1;
+ if (part.empty() || part == ".") continue;
+ if (part == ".." || part.find('/') != std::string::npos || part.find(':') != std::string::npos) return std::nullopt;
+ out += (out.empty() ? "" : "/") + part;
+ }
+ return out;
+}
+
bool PerUserFolder(const std::string& name) {
static const std::set<std::string> kFolders = {
"AppDataFolder", "LocalAppDataFolder", "PersonalFolder", "DesktopFolder", "ProgramMenuFolder",
@@ -619,6 +658,7 @@ class PlanBuilder {
const std::string& data, bool default_value);
const Database& database_;
std::map<std::string, std::string> properties_;
+ std::map<std::string, std::string> declared_; // the Property table as written
std::map<std::string, std::pair<std::string, std::string>> directory_rows_; // key → parent, name
std::map<std::string, std::optional<std::string>> directories_; // resolved, relative to drive_c
std::map<std::string, std::string> file_paths_; // File key → Windows path
@@ -630,6 +670,12 @@ std::optional<std::string> PlanBuilder::Directory(const std::string& key, int de
if (const auto found = directories_.find(key); found != directories_.end()) return found->second;
std::optional<std::string> result;
const auto row = directory_rows_.find(key);
+ // A directory the Property table sets ("INSTALLDIR" = "C:\\Vendor\\") is placed there.
+ if (const auto declared = declared_.find(key); declared != declared_.end())
+ if (const auto placed = DrivePath(declared->second)) {
+ directories_[key] = placed;
+ return placed;
+ }
if (const auto standard = StandardFolder(key)) {
result = standard;
} else if (PerUserFolder(key) || row == directory_rows_.end() || depth > 64) {
@@ -719,7 +765,7 @@ bool PlanBuilder::Build(MsiInstallPlan* plan, std::string* reason) {
{"UILevel", "2"}};
for (const auto& row : property.rows) {
const auto& name = At(property, row, "Property");
- if (!name.null) properties_[name.text] = At(property, row, "Value").text;
+ if (!name.null) properties_[name.text] = declared_[name.text] = At(property, row, "Value").text;
}
properties_["ALLUSERS"] = "1";
plan->product_code = properties_["ProductCode"];
@@ -791,9 +837,14 @@ bool PlanBuilder::Build(MsiInstallPlan* plan, std::string* reason) {
const auto attributes = At(file, row, "Attributes").number;
const auto disk = std::find_if(media_rows.begin(), media_rows.end(),
[&](const auto& media_row) { return media_row.first >= sequence; });
- if (!folder || name.empty() || name.find('/') != std::string::npos || name.find('\\') != std::string::npos ||
- disk == media_rows.end() || disk->second.empty() || (attributes & 0x2000)) {
- ++plan->skipped_files;
+ if (!folder) {
+ ++plan->skipped_files; // a per-user folder
+ continue;
+ }
+ if (name.empty() || name == "." || name == ".." || name.find('/') != std::string::npos ||
+ name.find('\\') != std::string::npos || !Ascii(name) || disk == media_rows.end() || disk->second.empty() ||
+ (attributes & 0x2000)) {
+ ++plan->unsupported_files; // uncompressed beside the package, or a name the bottle can't hold
continue;
}
const bool embedded = disk->second[0] == '#';
@@ -848,7 +899,10 @@ bool PlanBuilder::Build(MsiInstallPlan* plan, std::string* reason) {
} else {
data = WineString(Format(value, &multi));
}
- if (multi || !Ascii(key) || !Ascii(name) || !Ascii(data) || key.empty()) {
+ // Wine's registry text can't take these unescaped in a key or value name.
+ if (multi || !Ascii(key) || !Ascii(name) || !Ascii(data) || key.empty() || name.find('"') != std::string::npos ||
+ name.find('\\') != std::string::npos || key.find('[') != std::string::npos || key.find(']') != std::string::npos ||
+ key.find('"') != std::string::npos) {
++plan->skipped_registry;
continue;
}
@@ -983,6 +1037,12 @@ bool ExtractCabinet(std::string_view cabinet, const std::function<bool(const std
for (const auto& member : members)
if (member.folder == folder_index) wanted.push_back(&member);
std::sort(wanted.begin(), wanted.end(), [](const Member* a, const Member* b) { return a->offset < b->offset; });
+ for (std::size_t index = 0; index < wanted.size(); ++index) {
+ if (wanted[index]->size > kMaxStreamBytes) return fail("a cabinet member is too large");
+ if (index + 1 < wanted.size() &&
+ static_cast<std::uint64_t>(wanted[index]->offset) + wanted[index]->size > wanted[index + 1]->offset)
+ return fail("damaged cabinet: members overlap");
+ }
std::size_t next = 0;
std::string current; // the member being collected
std::uint64_t position = 0; // bytes of the folder produced so far
diff --git a/src/runtime/msi_package.h b/src/runtime/msi_package.h
index 252c4f5..a0f2d9c 100644
--- a/src/runtime/msi_package.h
+++ b/src/runtime/msi_package.h
@@ -44,13 +44,14 @@ struct MsiInstallPlan {
// Folders (Windows paths) the package adds to the machine-wide PATH.
std::vector<std::string> path_prepend;
std::vector<std::string> path_append;
- std::size_t skipped_files = 0; // under a folder this reader doesn't place, or uncompressed
+ std::size_t skipped_files = 0; // under a per-user folder, which this installer leaves alone
+ std::size_t unsupported_files = 0; // uncompressed beside the package, or a name the bottle can't hold
std::size_t skipped_registry = 0; // binary or multi-string values, HKEY_USERS
std::size_t custom_actions = 0; // not run
};
-// Reads a package. false with a reason for a file that is not a readable package; a package
-// whose files sit uncompressed beside it is read, with those files counted in skipped_files.
+// Reads a package. false with a reason for a file that is not a readable package; files it
+// can't install are counted (skipped_files, unsupported_files) for the caller to judge.
bool ReadMsiPackage(std::string_view package, MsiInstallPlan* plan, std::string* reason);
// One stream of the package by its decoded name ("media1.cab"); nullopt when missing.
diff --git a/src/runtime/redist_install.cpp b/src/runtime/redist_install.cpp
index 55d6025..6408ba7 100644
--- a/src/runtime/redist_install.cpp
+++ b/src/runtime/redist_install.cpp
@@ -126,7 +126,15 @@ bool InsideGame(const std::string& windows_path, const std::string& install_dir,
return false;
auto rest = windows_path.substr(base.size() + 1);
std::replace(rest.begin(), rest.end(), '\\', '/');
- if (rest.empty() || rest.find("..") != std::string::npos) return false;
+ // Strictly below the game folder: no root, empty, "." or ".." part, and no drive.
+ if (rest.empty() || rest.front() == '/' || rest.back() == '/' || rest.find(':') != std::string::npos) return false;
+ for (std::size_t at = 0; at <= rest.size();) {
+ auto end = rest.find('/', at);
+ if (end == std::string::npos) end = rest.size();
+ const auto part = rest.substr(at, end - at);
+ if (part.empty() || part == "." || part == "..") return false;
+ at = end + 1;
+ }
*relative = rest;
return true;
}
@@ -254,8 +262,13 @@ bool InstallPackage(const std::filesystem::path& package_path, const std::filesy
}
MsiInstallPlan plan;
if (!ReadMsiPackage(package, &plan, reason)) return false;
+ if (plan.unsupported_files) {
+ *reason = std::to_string(plan.unsupported_files) + " of the package's files are stored in a way Playden can't install";
+ return false;
+ }
std::map<std::string, std::vector<const MsiFile*>> wanted; // member → files
for (const auto& file : plan.files) wanted[file.member].push_back(&file);
+ std::set<const MsiFile*> delivered;
const auto drive = prefix / "drive_c";
for (std::size_t index = 0; index < plan.cabinets.size(); ++index) {
const auto& cabinet = plan.cabinets[index];
@@ -278,6 +291,10 @@ bool InstallPackage(const std::filesystem::path& package_path, const std::filesy
if (found == wanted.end()) return true;
for (const auto* file : found->second) {
if (file->cabinet != index) continue;
+ if (data.size() != file->size || !delivered.insert(file).second) {
+ failure = "the package's copy of C:\\" + file->target + " is not the size it lists";
+ return false;
+ }
const auto slash = file->target.rfind('/');
const auto folder = slash == std::string::npos ? std::string() : file->target.substr(0, slash);
const auto name = slash == std::string::npos ? file->target : file->target.substr(slash + 1);
@@ -295,6 +312,10 @@ bool InstallPackage(const std::filesystem::path& package_path, const std::filesy
return false;
}
}
+ if (delivered.size() != plan.files.size()) {
+ *reason = std::to_string(plan.files.size() - delivered.size()) + " of the package's files are missing from its cabinets";
+ return false;
+ }
auto machine = plan.machine;
if (!plan.path_prepend.empty() || !plan.path_append.empty()) {
const auto current = MachinePath(prefix);
diff --git a/tests/runtime_redist_test.cpp b/tests/runtime_redist_test.cpp
index 3fb20e6..fc71b68 100644
--- a/tests/runtime_redist_test.cpp
+++ b/tests/runtime_redist_test.cpp
@@ -294,16 +294,18 @@ std::string Package(const std::vector<TableSpec>& tables, const std::vector<std:
// 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.
-std::string SamplePackage() {
+enum class Variant { kNormal, kWrongSize, kUncompressed };
+
+std::string SamplePackage(Variant variant = Variant::kNormal) {
std::vector<TableSpec> tables;
tables.push_back({"Property", {{"Property", 's'}, {"Value", 's'}},
{{"ProductCode", "{11111111-2222-3333-4444-555555555555}"}, {"ProductName", "Sample Runtime"},
- {"ProductVersion", "1.2.3"}, {"P_VERSION", "7"}}});
+ {"ProductVersion", "1.2.3"}, {"P_VERSION", "7"}, {"D_FIXED", "C:\\Fixed\\Place\\"}}});
tables.push_back({"Directory", {{"Directory", 's'}, {"Directory_Parent", 's'}, {"DefaultDir", 's'}},
{{"TARGETDIR", "", "SourceDir"}, {"ProgramFilesFolder", "TARGETDIR", "."},
{"D_VENDOR", "ProgramFilesFolder", "vendor~1|Vendor Runtime"}, {"D_COMMON", "D_VENDOR", "Common"},
{"D_ENGINE", "D_VENDOR", "Engine"}, {"D_V1", "D_ENGINE", "v1~1|v1"},
- {"D_DESKTOP", "DesktopFolder", "Sample"}}});
+ {"D_DESKTOP", "DesktopFolder", "Sample"}, {"D_FIXED", "ProgramFilesFolder", "Wrong"}}});
tables.push_back({"Feature", {{"Feature", 's'}, {"Feature_Parent", 's'}, {"Level", 'i'}},
{{"F_Main", "", "1"}, {"F_64", "", "0"}, {"F_Off", "", "0"}, {"F_Child", "F_Off", "1"}}});
tables.push_back({"Condition", {{"Feature_", 's'}, {"Level", 'i'}, {"Condition", 's'}},
@@ -323,7 +325,8 @@ std::string SamplePackage() {
tables.push_back({"File",
{{"File", 's'}, {"Component_", 's'}, {"FileName", 's'}, {"FileSize", 'l'}, {"Version", 's'},
{"Language", 's'}, {"Attributes", 'i'}, {"Sequence", 'i'}},
- {{"first", "C_LOADER", "loader~1.dll|Loader.dll", "10", "", "", "512", "1"},
+ {{"first", "C_LOADER", "loader~1.dll|Loader.dll", variant == Variant::kWrongSize ? "9" : "10", "", "",
+ variant == Variant::kUncompressed ? "8192" : "512", "1"},
{"second", "C_ENGINE", "Core.dll", "10", "", "", "512", "2"},
{"empty", "C_ENGINE", "Empty.dat", "0", "", "", "512", "3"},
{"off", "C_OFF", "Off.dll", "10", "", "", "512", "4"},
@@ -340,7 +343,9 @@ std::string SamplePackage() {
{"r5", "2", "SOFTWARE\\Vendor", "Blob", "#x0102", "C_REG"},
{"r6", "2", "SOFTWARE\\Vendor\\Engines", "1.0", "#5", "C_ENGINE"},
{"r7", "1", "Software\\Vendor", "User", "[#first]", "C_REG"},
- {"r8", "2", "SOFTWARE\\Vendor", "Hidden", "x", "C_OFF"}}});
+ {"r8", "2", "SOFTWARE\\Vendor", "Hidden", "x", "C_OFF"},
+ {"r9", "2", "SOFTWARE\\Vendor", "Fixed", "[D_FIXED]", "C_REG"},
+ {"r10", "2", "SOFTWARE\\Vendor", "Bad\"Name", "x", "C_REG"}}});
tables.push_back({"Environment", {{"Environment", 's'}, {"Name", 's'}, {"Value", 's'}, {"Component_", 's'}},
{{"e1", "=-*PATH", "[D_COMMON];[~]", "C_ENV"}, {"e2", "=-*OTHER", "x", "C_ENV"}}});
tables.push_back({"CustomAction", {{"Action", 's'}, {"Type", 'i'}, {"Source", 's'}, {"Target", 's'}},
@@ -378,6 +383,18 @@ void TestConditions() {
CHECK(EvaluateMsiCondition("&Feature = 3", properties) == false);
CHECK(!EvaluateMsiCondition("VersionNT >", properties).has_value());
CHECK(!EvaluateMsiCondition("(VersionNT", properties).has_value());
+ // A property set to "0" is set; an integer against missing text compares false (but <>).
+ CHECK(EvaluateMsiCondition("Zero", {{"Zero", "0"}}) == true);
+ CHECK(EvaluateMsiCondition("0", properties) == false);
+ CHECK(EvaluateMsiCondition("Missing < 1", properties) == false);
+ CHECK(EvaluateMsiCondition("Missing <> 1", properties) == true);
+ CHECK(EvaluateMsiCondition("Name = 1", properties) == false);
+ // Deep nesting is refused rather than recursing without bound.
+ std::string deep;
+ for (int index = 0; index < 1000; ++index) deep += "NOT ";
+ CHECK(!EvaluateMsiCondition(deep + "VersionNT", properties).has_value());
+ CHECK(!EvaluateMsiCondition(std::string(1000, '(') + "VersionNT" + std::string(1000, ')'), properties).has_value());
+ CHECK(EvaluateMsiCondition("((NOT (VersionNT = 0)))", properties) == true);
}
void TestCabinet() {
@@ -400,6 +417,12 @@ void TestCabinet() {
CHECK(reason == "LZX cabinets are not supported");
CHECK(!ExtractCabinet(TwoBlockCabinet(), [](const std::string&, std::string_view) { return false; }, &reason));
CHECK(!ExtractCabinet("MSCF", [](const std::string&, std::string_view) { return true; }, &reason));
+ // Members that overlap are refused: "second" moved to offset 5.
+ auto overlapping = TwoBlockCabinet();
+ const auto second = overlapping.find("second") - 16 + 4;
+ overlapping[second] = 5;
+ CHECK(!ExtractCabinet(overlapping, [](const std::string&, std::string_view) { return true; }, &reason));
+ CHECK(reason == "damaged cabinet: members overlap");
}
void TestPlan() {
@@ -429,7 +452,11 @@ void TestPlan() {
CHECK(!FindValue(plan.machine, "Software\\Wow6432Node\\Vendor", "Blob"));
const auto* user = FindValue(plan.user, "Software\\Vendor", "User");
CHECK(user && user->data == "\"C:\\\\Program Files (x86)\\\\Vendor Runtime\\\\Common\\\\Loader.dll\"");
- CHECK(plan.skipped_registry == 2); // the binary value and the OTHER variable
+ // A directory the Property table sets keeps that place.
+ const auto* fixed = FindValue(plan.machine, "Software\\Wow6432Node\\Vendor", "Fixed");
+ CHECK(fixed && fixed->data == "\"C:\\\\Fixed\\\\Place\\\\\"");
+ CHECK(plan.unsupported_files == 0);
+ CHECK(plan.skipped_registry == 3); // the binary value, the quoted name and the OTHER variable
CHECK((plan.path_prepend == std::vector<std::string>{"C:\\Program Files (x86)\\Vendor Runtime\\Common\\"}));
CHECK(plan.path_append.empty());
}
@@ -473,6 +500,10 @@ void TestScripts() {
"\"Path\" \"%INSTALLDIR%\" } } } } \"kvsignatures\" { \"InstallScript\" \"00\" }",
"Z:\\games\\1", &values, &reason));
CHECK(values.machine.size() == 2);
+ RedistEntry rooted{"X", "msiexec", "/i Z:\\data\\games\\696180\\\\tmp\\x.msi", ""};
+ CHECK(ClassifyRedist(rooted, "Z:\\data\\games\\696180", &package) == RedistAction::kNotRun);
+ RedistEntry dotted{"X", "msiexec", "/i Z:\\data\\games\\696180\\.\\x.msi", ""};
+ CHECK(ClassifyRedist(dotted, "Z:\\data\\games\\696180", &package) == RedistAction::kNotRun);
RedistEntry direct{"X", "Z:\\data\\games\\696180\\redist\\x.msi", "", ""};
CHECK(ClassifyRedist(direct, "Z:\\data\\games\\696180", &package) == RedistAction::kMsi && package == "redist/x.msi");
}
@@ -528,6 +559,14 @@ void TestInstall() {
const auto again = InstallRedistributables(game.string(), "Z:\\games\\42", prefix.string(), 1700000200);
CHECK(again.outcomes.size() == 2 && again.outcomes[0].result == "already");
CHECK(ReadText(prefix / "system.reg") == system);
+ // A package whose cabinet doesn't match its file list, or that keeps files beside it, fails and isn't recorded.
+ for (const auto variant : {Variant::kWrongSize, Variant::kUncompressed}) {
+ std::filesystem::remove(prefix / ".playden-redist");
+ WriteText(game / "_CommonRedist/Sample/1.0/sample.msi", SamplePackage(variant));
+ const auto refused = InstallRedistributables(game.string(), "Z:\\games\\42", prefix.string(), 1700000250);
+ CHECK(refused.outcomes.size() == 2 && refused.outcomes[0].result == "failed");
+ CHECK(!std::filesystem::exists(prefix / ".playden-redist"));
+ }
// A damaged package fails alone.
std::filesystem::remove(prefix / ".playden-redist");
WriteText(game / "_CommonRedist/Sample/1.0/sample.msi", "broken");
@@ -559,9 +598,12 @@ void TestPhysxPackage() {
CHECK(cabinet);
// PLAYDEN_TEST_PHYSX_FILES may name a folder with the members another tool extracted.
const char* reference = std::getenv("PLAYDEN_TEST_PHYSX_FILES");
+ std::map<std::string, std::uint32_t> listed;
+ for (const auto& file : plan.files) listed[file.member] = file.size;
std::size_t count = 0, loader = 0, compared = 0;
CHECK(ExtractCabinet(*cabinet, [&](const std::string& name, std::string_view data) {
++count;
+ CHECK(!listed.count(name) || listed[name] == data.size()); // the installer checks this
if (name == "FILE_COMMON_PhysXLoader_dll") loader = data.size();
if (reference && *reference) {
CHECK(ReadText(std::filesystem::path(reference) / name) == data);