From 2380a4bd8a01ea5b9c719b32f222a2cf53df800b Mon Sep 17 00:00:00 2001 From: atom0s Date: Sat, 26 Mar 2022 02:25:36 -0700 Subject: [PATCH] Unpackers: (x86) - Ensure all unpacked files default to a checksum of 0. --- Steamless.Unpacker.Variant10.x86/Main.cs | 3 +-- Steamless.Unpacker.Variant20.x86/Main.cs | 1 + Steamless.Unpacker.Variant21.x86/Main.cs | 1 + Steamless.Unpacker.Variant30.x86/Main.cs | 3 ++- Steamless.Unpacker.Variant31.x86/Main.cs | 3 ++- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Steamless.Unpacker.Variant10.x86/Main.cs b/Steamless.Unpacker.Variant10.x86/Main.cs index f8a96bd..a96bc19 100644 --- a/Steamless.Unpacker.Variant10.x86/Main.cs +++ b/Steamless.Unpacker.Variant10.x86/Main.cs @@ -36,7 +36,6 @@ namespace Steamless.Unpacker.Variant10.x86 using System.IO; using System.Linq; using System.Reflection; - using System.Runtime.InteropServices; [SteamlessApiVersion(1, 0)] public class Main : SteamlessPlugin @@ -275,7 +274,7 @@ namespace Steamless.Unpacker.Variant10.x86 if (this.File.DosStubSize > 0) fStream.WriteBytes(this.File.DosStubData); - // Update the entry point and checksum of the file.. + // Update the NT headers.. var ntHeaders = this.File.NtHeaders; ntHeaders.OptionalHeader.AddressOfEntryPoint = this.OriginalEntryPoint; ntHeaders.OptionalHeader.CheckSum = 0; diff --git a/Steamless.Unpacker.Variant20.x86/Main.cs b/Steamless.Unpacker.Variant20.x86/Main.cs index 382c24e..35ae77e 100644 --- a/Steamless.Unpacker.Variant20.x86/Main.cs +++ b/Steamless.Unpacker.Variant20.x86/Main.cs @@ -335,6 +335,7 @@ namespace Steamless.Unpacker.Variant20.x86 var ntHeaders = this.File.NtHeaders; var lastSection = this.File.Sections[this.File.Sections.Count - 1]; ntHeaders.OptionalHeader.AddressOfEntryPoint = this.File.GetRvaFromVa(this.StubHeader.OEP); + ntHeaders.OptionalHeader.CheckSum = 0; ntHeaders.OptionalHeader.SizeOfImage = this.File.GetAlignment(lastSection.VirtualAddress + lastSection.VirtualSize, this.File.NtHeaders.OptionalHeader.SectionAlignment); this.File.NtHeaders = ntHeaders; diff --git a/Steamless.Unpacker.Variant21.x86/Main.cs b/Steamless.Unpacker.Variant21.x86/Main.cs index 4f5e58d..df4cedf 100644 --- a/Steamless.Unpacker.Variant21.x86/Main.cs +++ b/Steamless.Unpacker.Variant21.x86/Main.cs @@ -462,6 +462,7 @@ namespace Steamless.Unpacker.Variant21.x86 var lastSection = this.File.Sections[this.File.Sections.Count - 1]; var originalEntry = BitConverter.ToUInt32(this.PayloadData.Skip(this.SteamDrmpOffsets[2]).Take(4).ToArray(), 0); ntHeaders.OptionalHeader.AddressOfEntryPoint = this.File.GetRvaFromVa(originalEntry); + ntHeaders.OptionalHeader.CheckSum = 0; ntHeaders.OptionalHeader.SizeOfImage = this.File.GetAlignment(lastSection.VirtualAddress + lastSection.VirtualSize, this.File.NtHeaders.OptionalHeader.SectionAlignment); this.File.NtHeaders = ntHeaders; diff --git a/Steamless.Unpacker.Variant30.x86/Main.cs b/Steamless.Unpacker.Variant30.x86/Main.cs index c93e26d..e526e7e 100644 --- a/Steamless.Unpacker.Variant30.x86/Main.cs +++ b/Steamless.Unpacker.Variant30.x86/Main.cs @@ -463,9 +463,10 @@ namespace Steamless.Unpacker.Variant30.x86 if (this.File.DosStubSize > 0) fStream.WriteBytes(this.File.DosStubData); - // Update the entry point of the file.. + // Update the NT headers.. var ntHeaders = this.File.NtHeaders; ntHeaders.OptionalHeader.AddressOfEntryPoint = this.StubHeader.OriginalEntryPoint; + ntHeaders.OptionalHeader.CheckSum = 0; this.File.NtHeaders = ntHeaders; // Write the NT headers to the file.. diff --git a/Steamless.Unpacker.Variant31.x86/Main.cs b/Steamless.Unpacker.Variant31.x86/Main.cs index 980cc7f..2089850 100644 --- a/Steamless.Unpacker.Variant31.x86/Main.cs +++ b/Steamless.Unpacker.Variant31.x86/Main.cs @@ -459,9 +459,10 @@ namespace Steamless.Unpacker.Variant31.x86 if (this.File.DosStubSize > 0) fStream.WriteBytes(this.File.DosStubData); - // Update the entry point of the file.. + // Update the NT headers.. var ntHeaders = this.File.NtHeaders; ntHeaders.OptionalHeader.AddressOfEntryPoint = (uint)this.StubHeader.OriginalEntryPoint; + ntHeaders.OptionalHeader.CheckSum = 0; this.File.NtHeaders = ntHeaders; // Write the NT headers to the file..