Fix Xbox Executable TLS offset (#76)

* Fix XBE TLS address

* Break early

* Fix relative address
This commit is contained in:
Deterous
2026-04-02 15:24:08 +09:00
committed by GitHub
parent 81c47b297d
commit 9993e574a0

View File

@@ -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