From 9993e574a0a980cd537c022faf3118fe8fd23537 Mon Sep 17 00:00:00 2001 From: Deterous <138427222+Deterous@users.noreply.github.com> Date: Thu, 2 Apr 2026 15:24:08 +0900 Subject: [PATCH] Fix Xbox Executable TLS offset (#76) * Fix XBE TLS address * Break early * Fix relative address --- .../XboxExecutable.cs | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/SabreTools.Serialization.Readers/XboxExecutable.cs b/SabreTools.Serialization.Readers/XboxExecutable.cs index ffda8926..8111d3dc 100644 --- a/SabreTools.Serialization.Readers/XboxExecutable.cs +++ b/SabreTools.Serialization.Readers/XboxExecutable.cs @@ -73,8 +73,26 @@ namespace SabreTools.Serialization.Readers #region TLS - // Get the TLS address - long tlsOffset = initialOffset + (header.TLSAddress - header.BaseAddress); + // Get the relative TLS address + long tlsOffset = initialOffset + header.TLSAddress; + + // Get the absolute TLS address + for (int i = 0; i < header.NumberOfSections; i++) + { + var sectionStart = xbe.SectionHeaders[i].VirtualAddress; + var sectionEnd = xbe.SectionHeaders[i].VirtualAddress + xbe.SectionHeaders[i].VirtualSize; + if (tlsOffset >= sectionStart && tlsOffset < sectionEnd) + { + // TLS offset is relative to .rdata section start + tlsOffset = xbe.SectionHeaders[i].RawAddress + (tlsOffset - sectionStart); + break; + } + + // Fallback if relative address not in any section + if (i == (header.NumberOfSections - 1)) + tlsOffset -= header.BaseAddress; + } + if (tlsOffset >= initialOffset && tlsOffset < data.Length) { // Seek to the TLS