fix: Revert null-padding - was corrupting adjacent data

The null-fill before overwrite was likely corrupting data after
the string, causing crashes. Reverted to develop behavior: only
overwrite the bytes we need to change.

Also re-enabled sentry patching.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
sanasol
2026-01-27 05:24:43 +01:00
parent 24a919588e
commit 778ed11f87

View File

@@ -141,8 +141,8 @@ class ClientPatcher {
} }
/** /**
* Replace bytes in buffer with null-padding for shorter replacements * Replace bytes in buffer - only overwrites the length of new bytes
* When new pattern is shorter than old, pads with 0x00 to prevent leftover bytes * Does NOT null-pad to avoid corrupting adjacent data
*/ */
replaceBytes(buffer, oldBytes, newBytes) { replaceBytes(buffer, oldBytes, newBytes) {
let count = 0; let count = 0;
@@ -156,10 +156,7 @@ class ClientPatcher {
const positions = this.findAllOccurrences(result, oldBytes); const positions = this.findAllOccurrences(result, oldBytes);
for (const pos of positions) { for (const pos of positions) {
// Zero-fill the old region first if new is shorter (prevents leftover bytes) // Only overwrite the length of the new bytes - don't null-fill!
if (newBytes.length < oldBytes.length) {
result.fill(0x00, pos, pos + oldBytes.length);
}
newBytes.copy(result, pos); newBytes.copy(result, pos);
count++; count++;
} }
@@ -214,11 +211,7 @@ class ClientPatcher {
const lastCharFirstByte = result[lastCharPos]; const lastCharFirstByte = result[lastCharPos];
if (lastCharFirstByte === oldLastCharByte) { if (lastCharFirstByte === oldLastCharByte) {
// Zero-fill first if new is shorter // Only overwrite, don't null-fill
if (newUtf16NoLast.length < oldUtf16NoLast.length) {
result.fill(0x00, pos, pos + oldUtf16NoLast.length);
}
newUtf16NoLast.copy(result, pos); newUtf16NoLast.copy(result, pos);
result[lastCharPos] = newLastCharByte; result[lastCharPos] = newLastCharByte;
count++; count++;
@@ -238,21 +231,20 @@ class ClientPatcher {
console.log(` Patching strategy: ${strategy.description}`); console.log(` Patching strategy: ${strategy.description}`);
// 1. Patch telemetry/sentry URL - DISABLED: May cause crash on glibc 2.41+ // 1. Patch telemetry/sentry URL
// The sentry string is near executable code and patching it may corrupt memory layout const oldSentry = 'https://ca900df42fcf57d4dd8401a86ddd7da2@sentry.hytale.com/2';
// const oldSentry = 'https://ca900df42fcf57d4dd8401a86ddd7da2@sentry.hytale.com/2'; const newSentry = `${protocol}t@${domain}/2`;
// const newSentry = `${protocol}t@${domain}/2`;
// const sentryResult = this.replaceBytes( const sentryResult = this.replaceBytes(
// result, result,
// this.stringToLengthPrefixed(oldSentry), this.stringToLengthPrefixed(oldSentry),
// this.stringToLengthPrefixed(newSentry) this.stringToLengthPrefixed(newSentry)
// ); );
// result = sentryResult.buffer; result = sentryResult.buffer;
// if (sentryResult.count > 0) { if (sentryResult.count > 0) {
// console.log(` Patched ${sentryResult.count} sentry URL(s)`); console.log(` Patched ${sentryResult.count} sentry URL(s)`);
// totalCount += sentryResult.count; totalCount += sentryResult.count;
// } }
console.log(` Skipping sentry patch (stability fix)`);
// 2. Patch main domain (hytale.com -> mainDomain) // 2. Patch main domain (hytale.com -> mainDomain)
const domainResult = this.replaceBytes( const domainResult = this.replaceBytes(