1
0
Fork 0
mirror of https://github.com/atom0s/Steamless.git synced 2024-12-19 23:07:41 +01:00

API: PE32 - Fix SizeOfImage alignment.

API: PE64 - Fix SizeOfImage alignment.
Unpacker: v20.x86 - Fix SizeOfImage alignment.
Unpacker: v21.x86 - Fix SizeOfImage alignment.
Unpacker: v30.x64 - Fix incorrect TlsOepRva being stored and used.
Unpacker: v30.x64 - Fix incorrect TlsOepRva calculations when reading payload and SteamDRMP.dll.
Unpacker: v31.x64 - Fix incorrect TlsOepRva being stored and used.
Unpacker: v31.x64 - Fix incorrect TlsOepRva calculations when reading payload and SteamDRMP.dll.
This commit is contained in:
atom0s 2022-03-24 00:58:32 -07:00
parent 079a086129
commit 0ad40aeabd
No known key found for this signature in database
GPG key ID: 37D5FD3494D79AF8
8 changed files with 16 additions and 16 deletions

View file

@ -328,7 +328,7 @@ namespace Steamless.API.PE32
// Update the size of the image.. // Update the size of the image..
var ntHeaders = this.NtHeaders; var ntHeaders = this.NtHeaders;
ntHeaders.OptionalHeader.SizeOfImage = this.Sections.Last().VirtualAddress + this.Sections.Last().VirtualSize; ntHeaders.OptionalHeader.SizeOfImage = (uint)this.GetAlignment(this.Sections.Last().VirtualAddress + this.Sections.Last().VirtualSize, this.NtHeaders.OptionalHeader.SectionAlignment);
this.NtHeaders = ntHeaders; this.NtHeaders = ntHeaders;
} }

View file

@ -331,7 +331,7 @@ namespace Steamless.API.PE64
// Update the size of the image.. // Update the size of the image..
var ntHeaders = this.NtHeaders; var ntHeaders = this.NtHeaders;
ntHeaders.OptionalHeader.SizeOfImage = this.Sections.Last().VirtualAddress + this.Sections.Last().VirtualSize; ntHeaders.OptionalHeader.SizeOfImage = (uint)this.GetAlignment(this.Sections.Last().VirtualAddress + this.Sections.Last().VirtualSize, this.NtHeaders.OptionalHeader.SectionAlignment);
this.NtHeaders = ntHeaders; this.NtHeaders = ntHeaders;
} }

View file

@ -324,7 +324,7 @@ namespace Steamless.Unpacker.Variant20.x86
var ntHeaders = this.File.NtHeaders; var ntHeaders = this.File.NtHeaders;
var lastSection = this.File.Sections[this.File.Sections.Count - 1]; var lastSection = this.File.Sections[this.File.Sections.Count - 1];
ntHeaders.OptionalHeader.AddressOfEntryPoint = this.File.GetRvaFromVa(this.StubHeader.OEP); ntHeaders.OptionalHeader.AddressOfEntryPoint = this.File.GetRvaFromVa(this.StubHeader.OEP);
ntHeaders.OptionalHeader.SizeOfImage = lastSection.VirtualAddress + lastSection.VirtualSize; ntHeaders.OptionalHeader.SizeOfImage = this.File.GetAlignment(lastSection.VirtualAddress + lastSection.VirtualSize, this.File.NtHeaders.OptionalHeader.SectionAlignment);
this.File.NtHeaders = ntHeaders; this.File.NtHeaders = ntHeaders;
// Write the NT headers to the file.. // Write the NT headers to the file..

View file

@ -451,7 +451,7 @@ namespace Steamless.Unpacker.Variant21.x86
var lastSection = this.File.Sections[this.File.Sections.Count - 1]; var lastSection = this.File.Sections[this.File.Sections.Count - 1];
var originalEntry = BitConverter.ToUInt32(this.PayloadData.Skip(this.SteamDrmpOffsets[2]).Take(4).ToArray(), 0); var originalEntry = BitConverter.ToUInt32(this.PayloadData.Skip(this.SteamDrmpOffsets[2]).Take(4).ToArray(), 0);
ntHeaders.OptionalHeader.AddressOfEntryPoint = this.File.GetRvaFromVa(originalEntry); ntHeaders.OptionalHeader.AddressOfEntryPoint = this.File.GetRvaFromVa(originalEntry);
ntHeaders.OptionalHeader.SizeOfImage = lastSection.VirtualAddress + lastSection.VirtualSize; ntHeaders.OptionalHeader.SizeOfImage = this.File.GetAlignment(lastSection.VirtualAddress + lastSection.VirtualSize, this.File.NtHeaders.OptionalHeader.SectionAlignment);
this.File.NtHeaders = ntHeaders; this.File.NtHeaders = ntHeaders;
// Write the NT headers to the file.. // Write the NT headers to the file..

View file

@ -233,7 +233,7 @@ namespace Steamless.Unpacker.Variant30.x64
// Tls was valid for the real oep.. // Tls was valid for the real oep..
this.TlsAsOep = true; this.TlsAsOep = true;
this.TlsOepRva = fileOffset; this.TlsOepRva = this.File.GetRvaFromVa(this.File.TlsCallbacks[0]);
return true; return true;
} }
@ -246,7 +246,7 @@ namespace Steamless.Unpacker.Variant30.x64
private bool Step2() private bool Step2()
{ {
// Obtain the payload address and size.. // Obtain the payload address and size..
var payloadAddr = this.File.GetFileOffsetFromRva(this.TlsAsOep ? this.TlsOepRva : this.File.NtHeaders.OptionalHeader.AddressOfEntryPoint - this.StubHeader.BindSectionOffset); var payloadAddr = this.File.GetFileOffsetFromRva(this.TlsAsOep ? this.TlsOepRva - this.StubHeader.BindSectionOffset : this.File.NtHeaders.OptionalHeader.AddressOfEntryPoint - this.StubHeader.BindSectionOffset);
var payloadSize = (this.StubHeader.PayloadSize + 0x0F) & 0xFFFFFFF0; var payloadSize = (this.StubHeader.PayloadSize + 0x0F) & 0xFFFFFFF0;
// Do nothing if there is no payload.. // Do nothing if there is no payload..
@ -296,7 +296,7 @@ namespace Steamless.Unpacker.Variant30.x64
try try
{ {
// Obtain the SteamDRMP.dll file address and data.. // Obtain the SteamDRMP.dll file address and data..
var drmpAddr = this.File.GetFileOffsetFromRva(this.TlsAsOep ? this.TlsOepRva : this.File.NtHeaders.OptionalHeader.AddressOfEntryPoint - this.StubHeader.BindSectionOffset + this.StubHeader.DRMPDllOffset); var drmpAddr = this.File.GetFileOffsetFromRva(this.TlsAsOep ? this.TlsOepRva - this.StubHeader.BindSectionOffset + this.StubHeader.DRMPDllOffset : this.File.NtHeaders.OptionalHeader.AddressOfEntryPoint - this.StubHeader.BindSectionOffset + this.StubHeader.DRMPDllOffset);
var drmpData = new byte[this.StubHeader.DRMPDllSize]; var drmpData = new byte[this.StubHeader.DRMPDllSize];
Array.Copy(this.File.FileData, (long)drmpAddr, drmpData, 0, drmpData.Length); Array.Copy(this.File.FileData, (long)drmpAddr, drmpData, 0, drmpData.Length);

View file

@ -238,7 +238,7 @@ namespace Steamless.Unpacker.Variant30.x86
// Tls was valid for the real oep.. // Tls was valid for the real oep..
this.TlsAsOep = true; this.TlsAsOep = true;
this.TlsOepRva = fileOffset; this.TlsOepRva = this.File.GetRvaFromVa(this.File.TlsCallbacks[0]);
return true; return true;
} }
@ -251,7 +251,7 @@ namespace Steamless.Unpacker.Variant30.x86
private bool Step2() private bool Step2()
{ {
// Obtain the payload address and size.. // Obtain the payload address and size..
var payloadAddr = this.File.GetFileOffsetFromRva(this.TlsAsOep ? this.TlsOepRva : this.File.NtHeaders.OptionalHeader.AddressOfEntryPoint - this.StubHeader.BindSectionOffset); var payloadAddr = this.File.GetFileOffsetFromRva(this.TlsAsOep ? this.TlsOepRva - this.StubHeader.BindSectionOffset : this.File.NtHeaders.OptionalHeader.AddressOfEntryPoint - this.StubHeader.BindSectionOffset);
var payloadSize = (this.StubHeader.PayloadSize + 0x0F) & 0xFFFFFFF0; var payloadSize = (this.StubHeader.PayloadSize + 0x0F) & 0xFFFFFFF0;
// Do nothing if there is no payload.. // Do nothing if there is no payload..
@ -301,7 +301,7 @@ namespace Steamless.Unpacker.Variant30.x86
try try
{ {
// Obtain the SteamDRMP.dll file address and data.. // Obtain the SteamDRMP.dll file address and data..
var drmpAddr = this.File.GetFileOffsetFromRva(this.TlsAsOep ? this.TlsOepRva : this.File.NtHeaders.OptionalHeader.AddressOfEntryPoint - this.StubHeader.BindSectionOffset + this.StubHeader.DRMPDllOffset); var drmpAddr = this.File.GetFileOffsetFromRva(this.TlsAsOep ? this.TlsOepRva - this.StubHeader.BindSectionOffset + this.StubHeader.DRMPDllOffset : this.File.NtHeaders.OptionalHeader.AddressOfEntryPoint - this.StubHeader.BindSectionOffset + this.StubHeader.DRMPDllOffset);
var drmpData = new byte[this.StubHeader.DRMPDllSize]; var drmpData = new byte[this.StubHeader.DRMPDllSize];
Array.Copy(this.File.FileData, drmpAddr, drmpData, 0, drmpData.Length); Array.Copy(this.File.FileData, drmpAddr, drmpData, 0, drmpData.Length);

View file

@ -229,7 +229,7 @@ namespace Steamless.Unpacker.Variant31.x64
// Tls was valid for the real oep.. // Tls was valid for the real oep..
this.TlsAsOep = true; this.TlsAsOep = true;
this.TlsOepRva = fileOffset; this.TlsOepRva = this.File.GetRvaFromVa(this.File.TlsCallbacks[0]);
return true; return true;
} }
@ -242,7 +242,7 @@ namespace Steamless.Unpacker.Variant31.x64
private bool Step2() private bool Step2()
{ {
// Obtain the payload address and size.. // Obtain the payload address and size..
var payloadAddr = this.File.GetFileOffsetFromRva(this.TlsAsOep ? this.TlsOepRva : this.File.NtHeaders.OptionalHeader.AddressOfEntryPoint - this.StubHeader.BindSectionOffset); var payloadAddr = this.File.GetFileOffsetFromRva(this.TlsAsOep ? this.TlsOepRva - this.StubHeader.BindSectionOffset : this.File.NtHeaders.OptionalHeader.AddressOfEntryPoint - this.StubHeader.BindSectionOffset);
var payloadSize = (this.StubHeader.PayloadSize + 0x0F) & 0xFFFFFFF0; var payloadSize = (this.StubHeader.PayloadSize + 0x0F) & 0xFFFFFFF0;
// Do nothing if there is no payload.. // Do nothing if there is no payload..
@ -292,7 +292,7 @@ namespace Steamless.Unpacker.Variant31.x64
try try
{ {
// Obtain the SteamDRMP.dll file address and data.. // Obtain the SteamDRMP.dll file address and data..
var drmpAddr = this.File.GetFileOffsetFromRva(this.TlsAsOep ? this.TlsOepRva : this.File.NtHeaders.OptionalHeader.AddressOfEntryPoint - this.StubHeader.BindSectionOffset + this.StubHeader.DRMPDllOffset); var drmpAddr = this.File.GetFileOffsetFromRva(this.TlsAsOep ? this.TlsOepRva - this.StubHeader.BindSectionOffset + this.StubHeader.DRMPDllOffset : this.File.NtHeaders.OptionalHeader.AddressOfEntryPoint - this.StubHeader.BindSectionOffset + this.StubHeader.DRMPDllOffset);
var drmpData = new byte[this.StubHeader.DRMPDllSize]; var drmpData = new byte[this.StubHeader.DRMPDllSize];
Array.Copy(this.File.FileData, (long)drmpAddr, drmpData, 0, drmpData.Length); Array.Copy(this.File.FileData, (long)drmpAddr, drmpData, 0, drmpData.Length);

View file

@ -234,7 +234,7 @@ namespace Steamless.Unpacker.Variant31.x86
// Tls was valid for the real oep.. // Tls was valid for the real oep..
this.TlsAsOep = true; this.TlsAsOep = true;
this.TlsOepRva = fileOffset; this.TlsOepRva = this.File.GetRvaFromVa(this.File.TlsCallbacks[0]);
return true; return true;
} }
@ -247,7 +247,7 @@ namespace Steamless.Unpacker.Variant31.x86
private bool Step2() private bool Step2()
{ {
// Obtain the payload address and size.. // Obtain the payload address and size..
var payloadAddr = this.File.GetFileOffsetFromRva(this.TlsAsOep ? this.TlsOepRva : this.File.NtHeaders.OptionalHeader.AddressOfEntryPoint - this.StubHeader.BindSectionOffset); var payloadAddr = this.File.GetFileOffsetFromRva(this.TlsAsOep ? this.TlsOepRva - this.StubHeader.BindSectionOffset : this.File.NtHeaders.OptionalHeader.AddressOfEntryPoint - this.StubHeader.BindSectionOffset);
var payloadSize = (this.StubHeader.PayloadSize + 0x0F) & 0xFFFFFFF0; var payloadSize = (this.StubHeader.PayloadSize + 0x0F) & 0xFFFFFFF0;
// Do nothing if there is no payload.. // Do nothing if there is no payload..
@ -297,7 +297,7 @@ namespace Steamless.Unpacker.Variant31.x86
try try
{ {
// Obtain the SteamDRMP.dll file address and data.. // Obtain the SteamDRMP.dll file address and data..
var drmpAddr = this.File.GetFileOffsetFromRva(this.TlsAsOep ? this.TlsOepRva : this.File.NtHeaders.OptionalHeader.AddressOfEntryPoint - this.StubHeader.BindSectionOffset + this.StubHeader.DRMPDllOffset); var drmpAddr = this.File.GetFileOffsetFromRva(this.TlsAsOep ? this.TlsOepRva - this.StubHeader.BindSectionOffset + this.StubHeader.DRMPDllOffset : this.File.NtHeaders.OptionalHeader.AddressOfEntryPoint - this.StubHeader.BindSectionOffset + this.StubHeader.DRMPDllOffset);
var drmpData = new byte[this.StubHeader.DRMPDllSize]; var drmpData = new byte[this.StubHeader.DRMPDllSize];
Array.Copy(this.File.FileData, drmpAddr, drmpData, 0, drmpData.Length); Array.Copy(this.File.FileData, drmpAddr, drmpData, 0, drmpData.Length);