Skip to content

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

C++

Keep Steam account IDs out of the license logs

Leonardo Lobato93a71992bdb2
diff --git a/src/steam/backend/cm_client.cpp b/src/steam/backend/cm_client.cpp
index 2db25ac..e62b821 100644
--- a/src/steam/backend/cm_client.cpp
+++ b/src/steam/backend/cm_client.cpp
@@ -134,7 +134,8 @@ bool ShouldDumpLicenses(std::uint64_t hash) {
}
// The family summary of one license-list load and, when the list changed, a line per license that isn't
-// plainly the account's own.
+// plainly the account's own. Account IDs stay out of the log: an owner is "self", "0" (none) or "family-<n>",
+// numbered by ascending ID, which is enough to tell owners apart.
void LogLicenses(const std::function<void(const std::string&)>& log, const std::vector<cm::License>& licenses,
const std::map<std::uint32_t, const cm::License*>& chosen, std::uint32_t account_id) {
std::size_t own = 0, borrowed = 0, dropped = 0;
@@ -149,6 +150,13 @@ void LogLicenses(const std::function<void(const std::string&)>& log, const std::
}
const auto hash = LicenseListHash(licenses, account_id);
const bool dump = ShouldDumpLicenses(hash);
+ std::map<std::uint32_t, std::string> owner_labels;
+ for (const auto& [owner, count] : owners)
+ owner_labels.emplace(owner, "family-" + std::to_string(owner_labels.size() + 1));
+ const auto owner_label = [&](std::uint32_t owner) -> std::string {
+ if (owner == 0) return "0";
+ return owner == account_id ? "self" : owner_labels.at(owner);
+ };
std::string owner_text, flag_text;
std::size_t listed = 0;
for (const auto& [owner, count] : owners) {
@@ -156,7 +164,7 @@ void LogLicenses(const std::function<void(const std::string&)>& log, const std::
owner_text += ",+" + std::to_string(owners.size() - 16);
break;
}
- owner_text += (owner_text.empty() ? "" : ",") + std::to_string(owner) + ":" + std::to_string(count);
+ owner_text += (owner_text.empty() ? "" : ",") + owner_labels.at(owner) + ":" + std::to_string(count);
}
for (int bit = 0; bit < 32; ++bit)
if (bits[bit])
@@ -186,7 +194,7 @@ void LogLicenses(const std::function<void(const std::string&)>& log, const std::
verdict = std::string("result=kept reason=") + (OwnLicense(license, account_id) ? "own" : "borrowed");
}
log("family step=license package=" + std::to_string(license.package_id) +
- " owner=" + std::to_string(license.owner_id) + " flags=" + HexFlags(license.flags) +
+ " owner=" + owner_label(license.owner_id) + " flags=" + HexFlags(license.flags) +
" type=" + std::to_string(license.license_type) + " created=" + std::to_string(license.time_created) +
" token=" + (license.access_token ? "y" : "n") + " " + verdict);
};
diff --git a/src/web/logs_source.cpp b/src/web/logs_source.cpp
index d6bddc9..2e0ec35 100644
--- a/src/web/logs_source.cpp
+++ b/src/web/logs_source.cpp
@@ -228,6 +228,56 @@ void AddAccountNames(std::string_view text, std::set<std::string>* names) {
}
}
+// owner=<id> and owners=<id>:<count>,... as in tools/collect_logs.py. owner=0 is no account, and owners=<n>
+// without a colon is a count.
+std::string RedactOwnerIds(std::string_view text) {
+ constexpr std::string_view kOwner = "owner=", kOwners = "owners=", kStem = "owner";
+ const auto digits_end = [&](std::size_t at) {
+ while (at < text.size() && Digit(text[at])) ++at;
+ return at;
+ };
+ std::string out;
+ out.reserve(text.size());
+ std::size_t copied = 0;
+ const auto replace = [&](std::size_t start, std::size_t end) {
+ out.append(text.substr(copied, start - copied));
+ out += "<steam-id>";
+ copied = end;
+ };
+ for (std::size_t at = text.find(kStem); at != std::string_view::npos; at = text.find(kStem, at)) {
+ const bool boundary = at == 0 || !WordChar(text[at - 1]);
+ const auto rest = text.substr(at);
+ if (boundary && rest.substr(0, kOwner.size()) == kOwner) {
+ const auto start = at + kOwner.size();
+ const auto end = digits_end(start);
+ if (end > start && text.substr(start, end - start) != "0" && (end == text.size() || !WordChar(text[end]))) {
+ replace(start, end);
+ at = end;
+ continue;
+ }
+ } else if (boundary && rest.substr(0, kOwners.size()) == kOwners) {
+ auto item = at + kOwners.size();
+ const auto first = digits_end(item);
+ if (first > item && first + 1 < text.size() && text[first] == ':' && Digit(text[first + 1])) {
+ for (;;) {
+ const auto id_end = digits_end(item);
+ if (id_end == item) break;
+ replace(item, id_end);
+ item = id_end;
+ if (item < text.size() && text[item] == ':') item = digits_end(item + 1);
+ if (item == text.size() || text[item] != ',') break;
+ ++item;
+ }
+ at = item;
+ continue;
+ }
+ }
+ at += kStem.size();
+ }
+ out.append(text.substr(copied));
+ return out;
+}
+
std::string Redact(std::string_view text, const std::set<std::string>& found, const Redaction& account) {
std::string out;
out.reserve(text.size());
@@ -245,6 +295,7 @@ std::string Redact(std::string_view text, const std::set<std::string>& found, co
}
out.push_back(text[i++]);
}
+ out = RedactOwnerIds(out);
if (account.steam_id != 0) ReplaceAll(out, std::to_string(account.steam_id), "<steam-id>");
std::vector<std::string> names(found.begin(), found.end());
if (!account.account_name.empty()) names.push_back(account.account_name);
diff --git a/src/web/logs_source.h b/src/web/logs_source.h
index 2105280..3a4d586 100644
--- a/src/web/logs_source.h
+++ b/src/web/logs_source.h
@@ -63,7 +63,8 @@ std::string WithoutStoreSuffix(const std::string& name);
std::string TitleNameFromParam(std::string_view json);
// Steam account names a log shows in Wine's L"SteamUser" L"<name>" and L"SteamAppUser" L"<name>".
void AddAccountNames(std::string_view text, std::set<std::string>* names);
-// SteamIDs (7656119 and ten more digits) become <steam-id>, the signed-in account's ID too; every
+// SteamIDs (7656119 and ten more digits) become <steam-id>, the signed-in account's ID too, and so do the
+// 32-bit account IDs older versions wrote as owner=<id> and owners=<id>:<count>,...; every
// name (the signed-in one and the found ones, longest first, ignoring ASCII case) becomes <steam-user>.
std::string Redact(std::string_view text, const std::set<std::string>& names, const Redaction& account);
// The last console_firmware= value in the texts, in order; empty if none.
diff --git a/tests/cm_client_test.cpp b/tests/cm_client_test.cpp
index c864066..1c7affb 100644
--- a/tests/cm_client_test.cpp
+++ b/tests/cm_client_test.cpp
@@ -480,21 +480,32 @@ void BorrowedLicensesAreShared() {
assert(result.package_apps.at(600) == (std::vector<std::uint32_t>{20, 40}));
const auto lines = log.Take();
- assert(HasLine(lines, "owner=cm family step=licenses total=5 own=1 borrowed=1 dropped=3 owners=8888:1,9999:2 "
+ assert(HasLine(lines, "owner=cm family step=licenses total=5 own=1 borrowed=1 dropped=3 owners=family-1:1,family-2:2 "
"flags=0x8:1,0x2000:1,0x4000:3 changed=y"));
- assert(HasLine(lines, "owner=cm family step=license package=600 owner=9999 flags=0x4000 type=0 created=1550000000 "
+ assert(HasLine(lines, "owner=cm family step=license package=600 owner=family-2 flags=0x4000 type=0 created=1550000000 "
"token=y result=kept reason=borrowed"));
- assert(HasLine(lines, "owner=cm family step=license package=700 owner=9999 flags=0x4008 type=0 created=1500000000 "
+ assert(HasLine(lines, "owner=cm family step=license package=700 owner=family-2 flags=0x4008 type=0 created=1500000000 "
"token=y result=dropped reason=flags:0x8"));
- assert(HasLine(lines, "owner=cm family step=license package=800 owner=8888 flags=0x4000 type=0 created=1500000000 "
+ assert(HasLine(lines, "owner=cm family step=license package=800 owner=family-1 flags=0x4000 type=0 created=1500000000 "
"token=y result=dropped reason=minutes"));
- assert(HasLine(lines, "owner=cm family step=license package=900 owner=4242 flags=0x2000 type=0 created=1450000000 "
+ assert(HasLine(lines, "owner=cm family step=license package=900 owner=self flags=0x2000 type=0 created=1450000000 "
"token=n result=dropped reason=flags:0x2000"));
assert(CountPrefix(lines, "owner=cm family step=license ") == 4); // package 100 is plainly the account's own
assert(HasLine(lines, "owner=cm family step=pics borrowed_packages=1 received=1 missing_token=0 unparsable=0 "
"absent=0 apps=2 depots=2 shared_apps=1"));
}
+// A license with no owner has no account to hide, and the log says so.
+void LicenseWithoutOwnerIsLogged() {
+ LogCapture log;
+ auto script = LicenseScript({{100, 1600000000, 0x80, 0, 7001}}, {{100, {{10}, {101}}}});
+ auto client = MakeClient(script);
+ std::atomic<bool> cancel{false};
+ assert(client.FetchAcquisitionDates(Session(), cancel).ok());
+ assert(HasLine(log.Take(), "owner=cm family step=license package=100 owner=0 flags=0x80 type=0 created=1600000000 "
+ "token=y result=kept reason=own"));
+}
+
// The same package through the account's own license and a borrowed one: the own license's token and date
// count, and its apps are not shared, whichever comes first in the list.
void OwnLicenseWinsOverBorrowedInEitherOrder() {
@@ -513,7 +524,7 @@ void OwnLicenseWinsOverBorrowedInEitherOrder() {
assert(result.owned_apps == (std::set<std::uint32_t>{10}) && result.shared_apps.empty());
assert(result.acquired_at.at(10) == 1600000000u);
const auto lines = log.Take();
- assert(HasLine(lines, "owner=cm family step=license package=100 owner=9999 flags=0x4000 type=0 created=" +
+ assert(HasLine(lines, "owner=cm family step=license package=100 owner=family-1 flags=0x4000 type=0 created=" +
std::to_string(borrowed.created) + " token=y result=superseded reason=own"));
assert(HasLine(lines, "owner=cm family step=pics borrowed_packages=0 received=0 missing_token=0 unparsable=0 "
"absent=0 apps=0 depots=0 shared_apps=0"));
@@ -592,7 +603,7 @@ void FamilyLicenseLinesAreCappedAndOnlyOnChange() {
}
lines = log.Take();
assert(CountPrefix(lines, "owner=cm family step=license package=") == 300);
- assert(HasLine(lines, "owner=cm family step=license package=5400 owner=9999 flags=0x4000 type=0 created=1500000000 "
+ assert(HasLine(lines, "owner=cm family step=license package=5400 owner=family-1 flags=0x4000 type=0 created=1500000000 "
"token=y result=kept reason=borrowed"));
assert(HasLine(lines, "owner=cm family step=license truncated=6"));
}
@@ -1337,6 +1348,7 @@ int main(int argc, char** argv) {
PackageZeroCounts();
ResetCmBackoff();
BorrowedLicensesAreShared();
+ LicenseWithoutOwnerIsLogged();
ResetCmBackoff();
OwnLicenseWinsOverBorrowedInEitherOrder();
ResetCmBackoff();
diff --git a/tests/test_collect_logs.py b/tests/test_collect_logs.py
index 9d69d0c..699510e 100644
--- a/tests/test_collect_logs.py
+++ b/tests/test_collect_logs.py
@@ -68,6 +68,23 @@ class CollectLogsTests(unittest.TestCase):
self.assertIn('<steam-user>', redacted)
self.assertIn('<steam-id>', redacted)
+ def test_redacts_owner_account_ids(self):
+ # The same cases as web_logs_source_test.cpp.
+ for text, expected in (
+ ('family step=license package=600 owner=157084330 flags=0x4000',
+ 'family step=license package=600 owner=<steam-id> flags=0x4000'),
+ ('family step=licenses owners=1043647817:1,1541563032:22,+3 flags=none',
+ 'family step=licenses owners=<steam-id>:1,<steam-id>:22,+3 flags=none'),
+ ('owners=1043647817:1,1541563032', 'owners=<steam-id>:1,<steam-id>'),
+ ('family webapi app=730 owners=76561198000000002,76561198000000003 exclude_reason=0',
+ 'family webapi app=730 owners=<steam-id>,<steam-id> exclude_reason=0'),
+ ):
+ self.assertEqual(collect_logs.redact(text, set()), expected)
+ for kept in ('owner=cm step=x', 'owner=shared x', 'owner=0 flags=0x1', 'owner=family-1 flags=0x1',
+ 'owner=self flags=0x1', 'family webapi shared_apps=3 owners=2 unlicensed=1',
+ 'owners=none flags=none', 'owners=family-1:1,family-2:2', 'co_owner=123', 'owner=123x'):
+ self.assertEqual(collect_logs.redact(kept, set()), kept)
+
def test_finds_the_account_name_in_any_log(self):
stopped_early = '== session-1.log\nPW_REPORT/1 profile=playden-steam-220\nopen C:/users/Alice failed\n'
names = collect_logs.account_names([stopped_early, title_log(40800)])
diff --git a/tests/web_logs_source_test.cpp b/tests/web_logs_source_test.cpp
index 55584f9..83cec7e 100644
--- a/tests/web_logs_source_test.cpp
+++ b/tests/web_logs_source_test.cpp
@@ -74,6 +74,18 @@ int main() {
CHECK(Redact("\xe2\x80\x9c" "76561198000000001\xe2\x80\x9d", {}, {}) == "\xe2\x80\x9c<steam-id>\xe2\x80\x9d");
// The signed-in account, exactly, even where no Wine line names it; the longest name first.
CHECK(Redact("steam user Bob 123 bobby", {"Bobby"}, {"bob", 123}) == "steam user <steam-user> <steam-id> <steam-user>");
+ // Account IDs from older logs, the same cases as test_collect_logs.py.
+ CHECK(Redact("family step=license package=600 owner=157084330 flags=0x4000", {}, {}) ==
+ "family step=license package=600 owner=<steam-id> flags=0x4000");
+ CHECK(Redact("family step=licenses owners=1043647817:1,1541563032:22,+3 flags=none", {}, {}) ==
+ "family step=licenses owners=<steam-id>:1,<steam-id>:22,+3 flags=none");
+ CHECK(Redact("owners=1043647817:1,1541563032", {}, {}) == "owners=<steam-id>:1,<steam-id>");
+ CHECK(Redact("family webapi app=730 owners=76561198000000002,76561198000000003 exclude_reason=0", {}, {}) ==
+ "family webapi app=730 owners=<steam-id>,<steam-id> exclude_reason=0");
+ for (const char* kept : {"owner=cm step=x", "owner=shared x", "owner=0 flags=0x1", "owner=family-1 flags=0x1",
+ "owner=self flags=0x1", "family webapi shared_apps=3 owners=2 unlicensed=1",
+ "owners=none flags=none", "owners=family-1:1,family-2:2", "co_owner=123", "owner=123x"})
+ CHECK(Redact(kept, {}, {}) == kept);
// A game that stopped before Wine named the user is still covered by another log's name.
names.clear();
const std::string stopped = "== session-1.log\nPW_REPORT/1 profile=playden-steam-220\nopen C:/users/Alice failed\n";
diff --git a/tools/collect_logs.py b/tools/collect_logs.py
index 17befb1..a7916cf 100644
--- a/tools/collect_logs.py
+++ b/tools/collect_logs.py
@@ -40,6 +40,10 @@ PROFILE = re.compile(r"profile=playden-steam-(\d+)")
REPORT_TIME = re.compile(r"^PW_REPORT/1 .*?\btime=(\d+)", re.MULTILINE)
ACCOUNT = re.compile(r'L"Steam(?:App)?User" L"([^"]+)"')
STEAM_ID = re.compile(r"\b7656119\d{10}\b")
+# 32-bit account IDs from older versions. owner=0 is no account, and owners=<n> without a colon is a count.
+OWNER_ID = re.compile(r"\bowner=(?!0\b)[0-9]+\b")
+OWNER_IDS = re.compile(r"\bowners=[0-9]+:[0-9]+(?:,[0-9]+(?::[0-9]+)?)*")
+OWNER_LIST_ID = re.compile(r"(?<=[=,])[0-9]+")
FIRMWARE = re.compile(r"console_firmware=(\S+)")
SKIP_SUFFIXES = (".ppm",)
@@ -167,6 +171,8 @@ def account_names(texts):
def redact(text, names):
text = STEAM_ID.sub("<steam-id>", text)
+ text = OWNER_ID.sub("owner=<steam-id>", text)
+ text = OWNER_IDS.sub(lambda match: OWNER_LIST_ID.sub("<steam-id>", match.group(0)), text)
for name in sorted(names, key=len, reverse=True):
text = re.sub(re.escape(name), "<steam-user>", text, flags=re.IGNORECASE)
return text