mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-04-05 22:01:33 +00:00
Fix Xbox Executable TLS offset (#76)
* Fix XBE TLS address * Break early * Fix relative address
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user