From 12c312b4db3c056f61421601b88b30df4c6e82b9 Mon Sep 17 00:00:00 2001 From: atom0s Date: Fri, 25 Mar 2022 20:09:21 -0700 Subject: [PATCH] API: Add new option to zero the DOS stub data when unpacking. Core: Add UI option to enable/disable the new zero DOS stub data option. Unpackers: Add support for new zero DOS stub data option. API: `DontRealignSections` and `ZeroDosStubData` are now default enabled as this is the general 'correct' way to handle most files. (Some files do require the section alignment to happen and some files may use the DOS stub for self-validation and such. Adjust accordingly when using Steamless.) --- Steamless.API/Model/SteamlessOptions.cs | 12 +++++++++++- Steamless.Unpacker.Variant10.x86/Main.cs | 5 +++++ Steamless.Unpacker.Variant20.x86/Main.cs | 4 ++++ Steamless.Unpacker.Variant21.x86/Main.cs | 4 ++++ Steamless.Unpacker.Variant30.x64/Main.cs | 4 ++++ Steamless.Unpacker.Variant30.x86/Main.cs | 5 +++++ Steamless.Unpacker.Variant31.x64/Main.cs | 4 ++++ Steamless.Unpacker.Variant31.x86/Main.cs | 5 +++++ Steamless/View/MainView.xaml | 2 ++ 9 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Steamless.API/Model/SteamlessOptions.cs b/Steamless.API/Model/SteamlessOptions.cs index a9494e3..6c98c56 100644 --- a/Steamless.API/Model/SteamlessOptions.cs +++ b/Steamless.API/Model/SteamlessOptions.cs @@ -37,7 +37,8 @@ namespace Steamless.API.Model this.DumpPayloadToDisk = false; this.DumpSteamDrmpToDisk = false; this.UseExperimentalFeatures = false; - this.DontRealignSections = false; + this.DontRealignSections = true; + this.ZeroDosStubData = true; } /// @@ -93,5 +94,14 @@ namespace Steamless.API.Model get => this.Get("DontRealignSections"); set => this.Set("DontRealignSections", value); } + + /// + /// Gets or sets if the DOS stub data should be zeroed. + /// + public bool ZeroDosStubData + { + get => this.Get("ZeroDosStubData"); + set => this.Set("ZeroDosStubData", value); + } } } \ No newline at end of file diff --git a/Steamless.Unpacker.Variant10.x86/Main.cs b/Steamless.Unpacker.Variant10.x86/Main.cs index 4874226..bbc84fe 100644 --- a/Steamless.Unpacker.Variant10.x86/Main.cs +++ b/Steamless.Unpacker.Variant10.x86/Main.cs @@ -34,6 +34,7 @@ namespace Steamless.Unpacker.Variant10.x86 using Classes; using System; using System.IO; + using System.Linq; using System.Reflection; [SteamlessApiVersion(1, 0)] @@ -248,6 +249,10 @@ namespace Steamless.Unpacker.Variant10.x86 try { + // Zero the DosStubData if desired.. + if (this.Options.ZeroDosStubData && this.File.DosStubSize > 0) + this.File.DosStubData = Enumerable.Repeat((byte)0, (int)this.File.DosStubSize).ToArray(); + // Rebuild the file sections.. this.File.RebuildSections(this.Options.DontRealignSections == false); diff --git a/Steamless.Unpacker.Variant20.x86/Main.cs b/Steamless.Unpacker.Variant20.x86/Main.cs index bf2d540..1abc507 100644 --- a/Steamless.Unpacker.Variant20.x86/Main.cs +++ b/Steamless.Unpacker.Variant20.x86/Main.cs @@ -309,6 +309,10 @@ namespace Steamless.Unpacker.Variant20.x86 try { + // Zero the DosStubData if desired.. + if (this.Options.ZeroDosStubData && this.File.DosStubSize > 0) + this.File.DosStubData = Enumerable.Repeat((byte)0, (int)this.File.DosStubSize).ToArray(); + // Open the unpacked file for writing.. var unpackedPath = this.File.FilePath + ".unpacked.exe"; fStream = new FileStream(unpackedPath, FileMode.Create, FileAccess.ReadWrite); diff --git a/Steamless.Unpacker.Variant21.x86/Main.cs b/Steamless.Unpacker.Variant21.x86/Main.cs index dc17a28..172568c 100644 --- a/Steamless.Unpacker.Variant21.x86/Main.cs +++ b/Steamless.Unpacker.Variant21.x86/Main.cs @@ -432,6 +432,10 @@ namespace Steamless.Unpacker.Variant21.x86 try { + // Zero the DosStubData if desired.. + if (this.Options.ZeroDosStubData && this.File.DosStubSize > 0) + this.File.DosStubData = Enumerable.Repeat((byte)0, (int)this.File.DosStubSize).ToArray(); + // Rebuild the file sections.. this.File.RebuildSections(this.Options.DontRealignSections == false); diff --git a/Steamless.Unpacker.Variant30.x64/Main.cs b/Steamless.Unpacker.Variant30.x64/Main.cs index 79fd7cd..6d96bd5 100644 --- a/Steamless.Unpacker.Variant30.x64/Main.cs +++ b/Steamless.Unpacker.Variant30.x64/Main.cs @@ -482,6 +482,10 @@ namespace Steamless.Unpacker.Variant30.x64 try { + // Zero the DosStubData if desired.. + if (this.Options.ZeroDosStubData && this.File.DosStubSize > 0) + this.File.DosStubData = Enumerable.Repeat((byte)0, (int)this.File.DosStubSize).ToArray(); + // Rebuild the file sections.. this.File.RebuildSections(this.Options.DontRealignSections == false); diff --git a/Steamless.Unpacker.Variant30.x86/Main.cs b/Steamless.Unpacker.Variant30.x86/Main.cs index 8355478..643184f 100644 --- a/Steamless.Unpacker.Variant30.x86/Main.cs +++ b/Steamless.Unpacker.Variant30.x86/Main.cs @@ -35,6 +35,7 @@ namespace Steamless.Unpacker.Variant30.x86 using Classes; using System; using System.IO; + using System.Linq; using System.Reflection; using System.Security.Cryptography; @@ -437,6 +438,10 @@ namespace Steamless.Unpacker.Variant30.x86 try { + // Zero the DosStubData if desired.. + if (this.Options.ZeroDosStubData && this.File.DosStubSize > 0) + this.File.DosStubData = Enumerable.Repeat((byte)0, (int)this.File.DosStubSize).ToArray(); + // Rebuild the file sections.. this.File.RebuildSections(this.Options.DontRealignSections == false); diff --git a/Steamless.Unpacker.Variant31.x64/Main.cs b/Steamless.Unpacker.Variant31.x64/Main.cs index 6b4151e..bd08f96 100644 --- a/Steamless.Unpacker.Variant31.x64/Main.cs +++ b/Steamless.Unpacker.Variant31.x64/Main.cs @@ -434,6 +434,10 @@ namespace Steamless.Unpacker.Variant31.x64 try { + // Zero the DosStubData if desired.. + if (this.Options.ZeroDosStubData && this.File.DosStubSize > 0) + this.File.DosStubData = Enumerable.Repeat((byte)0, (int)this.File.DosStubSize).ToArray(); + // Rebuild the file sections.. this.File.RebuildSections(this.Options.DontRealignSections == false); diff --git a/Steamless.Unpacker.Variant31.x86/Main.cs b/Steamless.Unpacker.Variant31.x86/Main.cs index 67148cd..9fbf23d 100644 --- a/Steamless.Unpacker.Variant31.x86/Main.cs +++ b/Steamless.Unpacker.Variant31.x86/Main.cs @@ -36,6 +36,7 @@ namespace Steamless.Unpacker.Variant31.x86 using System; using System.Collections.Generic; using System.IO; + using System.Linq; using System.Reflection; using System.Security.Cryptography; @@ -433,6 +434,10 @@ namespace Steamless.Unpacker.Variant31.x86 try { + // Zero the DosStubData if desired.. + if (this.Options.ZeroDosStubData && this.File.DosStubSize > 0) + this.File.DosStubData = Enumerable.Repeat((byte)0, (int)this.File.DosStubSize).ToArray(); + // Rebuild the file sections.. this.File.RebuildSections(this.Options.DontRealignSections == false); diff --git a/Steamless/View/MainView.xaml b/Steamless/View/MainView.xaml index d36a71f..efcb3c9 100644 --- a/Steamless/View/MainView.xaml +++ b/Steamless/View/MainView.xaml @@ -85,6 +85,7 @@ + @@ -92,6 +93,7 @@ +