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

API: (PE32) Adjusted 'Parse' method to exit early if the DOS stub is invalid. (Avoids attempting to read an invalid NT header block.)

API: (PE64) Adjusted 'Parse' method to exit early if the DOS stub is invalid. (Avoids attempting to read an invalid NT header block.)
This commit is contained in:
atom0s 2023-05-28 02:07:05 -07:00
parent 7f92aded2c
commit 4c3c6e757c
No known key found for this signature in database
GPG key ID: 37D5FD3494D79AF8
2 changed files with 12 additions and 8 deletions

View file

@ -85,12 +85,14 @@ namespace Steamless.API.PE32
if (this.FileData.Length < (Marshal.SizeOf(typeof(NativeApi32.ImageDosHeader32)) + Marshal.SizeOf(typeof(NativeApi32.ImageNtHeaders32)))) if (this.FileData.Length < (Marshal.SizeOf(typeof(NativeApi32.ImageDosHeader32)) + Marshal.SizeOf(typeof(NativeApi32.ImageNtHeaders32))))
return false; return false;
// Read the file headers.. // Read the file DOS header..
this.DosHeader = Pe32Helpers.GetStructure<NativeApi32.ImageDosHeader32>(this.FileData); this.DosHeader = Pe32Helpers.GetStructure<NativeApi32.ImageDosHeader32>(this.FileData);
this.NtHeaders = Pe32Helpers.GetStructure<NativeApi32.ImageNtHeaders32>(this.FileData, this.DosHeader.e_lfanew); if (!this.DosHeader.IsValid)
return false;
// Validate the headers.. // Read the file NT headers..
if (!this.DosHeader.IsValid || !this.NtHeaders.IsValid) this.NtHeaders = Pe32Helpers.GetStructure<NativeApi32.ImageNtHeaders32>(this.FileData, this.DosHeader.e_lfanew);
if (!this.NtHeaders.IsValid)
return false; return false;
// Read and store the dos header if it exists.. // Read and store the dos header if it exists..

View file

@ -85,12 +85,14 @@ namespace Steamless.API.PE64
if (this.FileData.Length < (Marshal.SizeOf(typeof(NativeApi64.ImageDosHeader64)) + Marshal.SizeOf(typeof(NativeApi64.ImageNtHeaders64)))) if (this.FileData.Length < (Marshal.SizeOf(typeof(NativeApi64.ImageDosHeader64)) + Marshal.SizeOf(typeof(NativeApi64.ImageNtHeaders64))))
return false; return false;
// Read the file headers.. // Read the file DOS header..
this.DosHeader = Pe64Helpers.GetStructure<NativeApi64.ImageDosHeader64>(this.FileData); this.DosHeader = Pe64Helpers.GetStructure<NativeApi64.ImageDosHeader64>(this.FileData);
this.NtHeaders = Pe64Helpers.GetStructure<NativeApi64.ImageNtHeaders64>(this.FileData, this.DosHeader.e_lfanew); if (!this.DosHeader.IsValid)
return false;
// Validate the headers.. // Read the file NT headers..
if (!this.DosHeader.IsValid || !this.NtHeaders.IsValid) this.NtHeaders = Pe64Helpers.GetStructure<NativeApi64.ImageNtHeaders64>(this.FileData, this.DosHeader.e_lfanew);
if (!this.NtHeaders.IsValid)
return false; return false;
// Read and store the dos header if it exists.. // Read and store the dos header if it exists..