From 71ce22e35822941bb71c6e60e0d9d59af850054a Mon Sep 17 00:00:00 2001 From: ShinobiSheep Date: Tue, 27 Nov 2018 13:54:07 +0100 Subject: [PATCH 1/4] Request admin priviledges by default --- Win_1337_Patch/app.manifest | 76 +++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Win_1337_Patch/app.manifest diff --git a/Win_1337_Patch/app.manifest b/Win_1337_Patch/app.manifest new file mode 100644 index 0000000..5910f3c --- /dev/null +++ b/Win_1337_Patch/app.manifest @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 4a51cff5dc958c8ac8a1bce2a17d65a2217697a5 Mon Sep 17 00:00:00 2001 From: ShinobiSheep Date: Tue, 27 Nov 2018 13:55:41 +0100 Subject: [PATCH 2/4] Various small changes --- Win_1337_Patch/1337.Designer.cs | 21 +++------------ Win_1337_Patch/1337.cs | 31 ++++++++++------------- Win_1337_Patch/Properties/AssemblyInfo.cs | 4 +-- Win_1337_Patch/Win_1337_Patch.csproj | 4 +++ 4 files changed, 23 insertions(+), 37 deletions(-) diff --git a/Win_1337_Patch/1337.Designer.cs b/Win_1337_Patch/1337.Designer.cs index 5963524..df15762 100644 --- a/Win_1337_Patch/1337.Designer.cs +++ b/Win_1337_Patch/1337.Designer.cs @@ -37,7 +37,6 @@ this.btnSelect1337 = new System.Windows.Forms.Button(); this.linkdfox = new System.Windows.Forms.LinkLabel(); this.Patch = new System.Windows.Forms.Button(); - this.cfixoff = new System.Windows.Forms.Button(); this.controlloBackup = new System.Windows.Forms.CheckBox(); this.cfileoffsett = new System.Windows.Forms.CheckBox(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); @@ -65,7 +64,7 @@ this.t1337.Size = new System.Drawing.Size(309, 20); this.t1337.TabIndex = 16; this.t1337.TabStop = false; - this.t1337.Text = "Select .1337 File..."; + this.t1337.Text = "Select 1337 File..."; this.t1337.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; this.t1337.DragDrop += new System.Windows.Forms.DragEventHandler(this.t1337_DragDrop); this.t1337.DragEnter += new System.Windows.Forms.DragEventHandler(this.t1337_DragEnter); @@ -115,7 +114,7 @@ this.linkdfox.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.linkdfox.ForeColor = System.Drawing.Color.BlueViolet; this.linkdfox.LinkColor = System.Drawing.Color.Indigo; - this.linkdfox.Location = new System.Drawing.Point(255, 62); + this.linkdfox.Location = new System.Drawing.Point(226, 62); this.linkdfox.Name = "linkdfox"; this.linkdfox.Size = new System.Drawing.Size(77, 13); this.linkdfox.TabIndex = 73; @@ -135,18 +134,6 @@ this.Patch.UseVisualStyleBackColor = true; this.Patch.Click += new System.EventHandler(this.Patch_Click); // - // cfixoff - // - this.cfixoff.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.cfixoff.ForeColor = System.Drawing.Color.Crimson; - this.cfixoff.Location = new System.Drawing.Point(156, 57); - this.cfixoff.Name = "cfixoff"; - this.cfixoff.Size = new System.Drawing.Size(88, 23); - this.cfixoff.TabIndex = 75; - this.cfixoff.Text = "Exit"; - this.cfixoff.UseVisualStyleBackColor = true; - this.cfixoff.Click += new System.EventHandler(this.Esci_Click); - // // controlloBackup // this.controlloBackup.AutoSize = true; @@ -186,7 +173,6 @@ this.ClientSize = new System.Drawing.Size(432, 83); this.Controls.Add(this.cfileoffsett); this.Controls.Add(this.controlloBackup); - this.Controls.Add(this.cfixoff); this.Controls.Add(this.Patch); this.Controls.Add(this.linkdfox); this.Controls.Add(this.btnSelect1337); @@ -200,7 +186,7 @@ this.MinimumSize = new System.Drawing.Size(448, 122); this.Name = "Form1"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "Win 1337 Apply Patch File v1.8..."; + this.Text = "Win 1337 Apply Patch File"; this.Load += new System.EventHandler(this.DFoX_Load); this.ResumeLayout(false); this.PerformLayout(); @@ -215,7 +201,6 @@ private System.Windows.Forms.Button btnSelect1337; private System.Windows.Forms.LinkLabel linkdfox; private System.Windows.Forms.Button Patch; - private System.Windows.Forms.Button cfixoff; private System.Windows.Forms.CheckBox controlloBackup; private System.Windows.Forms.CheckBox cfileoffsett; private System.Windows.Forms.ToolTip toolTip1; diff --git a/Win_1337_Patch/1337.cs b/Win_1337_Patch/1337.cs index a9be69a..5c14d26 100644 --- a/Win_1337_Patch/1337.cs +++ b/Win_1337_Patch/1337.cs @@ -17,6 +17,10 @@ namespace Win_1337_Patch public Form1() { InitializeComponent(); + var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; + string ver = "v" + version.Major + "." + version.Minor; + this.Text = "Win 1337 Apply Patch File " + ver; + linkdfox.Text = ver + " By DeltaFoX"; } private void set() { @@ -35,6 +39,7 @@ namespace Win_1337_Patch apriDialogoFile1.Filter = "File " + ext + "|" + nf; apriDialogoFile1.FilterIndex = 0; apriDialogoFile1.Title = "Select the file \"" + nf + "\" File..."; + if (apriDialogoFile1.ShowDialog() == DialogResult.OK) { exe = apriDialogoFile1.FileName; @@ -45,8 +50,8 @@ namespace Win_1337_Patch } else { - t1337.Text = "Select .1337 File..."; - texe.Text = "Name of Exe/Dll to Patch..."; + t1337.Text = "Select a .1337 File..."; + texe.Text = "Select the Exe/Dll to Patch..."; f1337 = String.Empty; exe = String.Empty; } @@ -72,7 +77,7 @@ namespace Win_1337_Patch OpenFileDialog apriDialogoFile1 = new OpenFileDialog(); apriDialogoFile1.Filter = "File 1337|*.*"; apriDialogoFile1.FilterIndex = 0; - apriDialogoFile1.Title = "Select the file 1337 File..."; + apriDialogoFile1.Title = "Select the .1337 File..."; apriDialogoFile1.InitialDirectory = url1337 != "" ? url1337 : Directory.GetCurrentDirectory() + "\\"; apriDialogoFile1.RestoreDirectory = true; if (apriDialogoFile1.ShowDialog() == DialogResult.OK) @@ -97,34 +102,26 @@ namespace Win_1337_Patch { if (!s.StartsWith(">")) { - MessageBox.Show("File 1337 is not valid...", "Info...", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("The .1337 File is not valid...", "Info...", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } return true; } - private void Esci_Click(object sender, EventArgs e) - { - Application.Exit(); - } private void Patch_Click(object sender, EventArgs e) { if (f1337 == String.Empty) { - MessageBox.Show("Select a 1337 File...", "Info...", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Select a .1337 File...", "Info...", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { DFoX_Patch(); } - catch (UnauthorizedAccessException) - { - MessageBox.Show("Sorry !!!\nYou Run the Program as Administrator...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - } catch { - MessageBox.Show("Problems on Patch...", "Info...", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Problem occured when Patching...", "Info...", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } @@ -140,7 +137,7 @@ namespace Win_1337_Patch return; if (lines[0].Substring(1).ToLower().Trim() != Path.GetFileName(exe).ToLower().Trim()) { - MessageBox.Show("File 1337 is not valid for selected exe/dll...\n\n(\"" + lines[0].Substring(1).ToLower() + "\" but you have selected \"" + Path.GetFileName(exe).ToLower() + "\")", "Info...", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("The .1337 File is not valid for selected exe/dll...\n\n(\"" + lines[0].Substring(1).ToLower() + "\" but you have selected \"" + Path.GetFileName(exe).ToLower() + "\")", "Info...", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } byte[] bexe = File.ReadAllBytes(exe); @@ -211,7 +208,7 @@ namespace Win_1337_Patch exe = urlexe; } else - texe.Text = "Name of Exe/Dll to Patch..."; + texe.Text = "Select the Exe/Dll to Patch..."; if (url1337 != "" && urlexe != "") { t1337.Text = Ellipsis.Compact(url1337, t1337, EllipsisFormat.Path); @@ -219,7 +216,7 @@ namespace Win_1337_Patch f1337 = url1337; } else - t1337.Text = "Select .1337 File..."; + t1337.Text = "Select a .1337 File..."; } private void cfileoffsett_CheckedChanged(object sender, EventArgs e) diff --git a/Win_1337_Patch/Properties/AssemblyInfo.cs b/Win_1337_Patch/Properties/AssemblyInfo.cs index c89e728..4221447 100644 --- a/Win_1337_Patch/Properties/AssemblyInfo.cs +++ b/Win_1337_Patch/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build // usando l'asterisco '*' come illustrato di seguito: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.8.0.0")] -[assembly: AssemblyFileVersion("1.8.0.0")] +[assembly: AssemblyVersion("1.9.0.0")] +[assembly: AssemblyFileVersion("1.9.0.0")] diff --git a/Win_1337_Patch/Win_1337_Patch.csproj b/Win_1337_Patch/Win_1337_Patch.csproj index be928de..1ab5e23 100644 --- a/Win_1337_Patch/Win_1337_Patch.csproj +++ b/Win_1337_Patch/Win_1337_Patch.csproj @@ -34,6 +34,9 @@ vampire.ico + + app.manifest + @@ -71,6 +74,7 @@ True + SettingsSingleFileGenerator Settings.Designer.cs From b5e095e691b203adc285cab8b64e47b229ada832 Mon Sep 17 00:00:00 2001 From: ramhaidar <49301219+ramhaidar@users.noreply.github.com> Date: Sun, 28 Jul 2024 11:35:27 +0700 Subject: [PATCH 3/4] Added Method to Change DLL Ownership and Minor UI Changes - **1337.Designer.cs**: - Added a new checkbox for changing ownership (`cchangeOwnership`). - Adjusted the size and layout of various UI components (`t1337`, `texe`, `btnSelect1337`). - **1337.cs**: - Added "cchangeOwnership_CheckedChanged" and "UnlockDLL" functions to change DLL ownership as instructed by [@VorlonCD](https://github.com/VorlonCD) described in [this issue](https://github.com/keylase/nvidia-patch/issues/795#issuecomment-2225573296). - Win_1337_Patch.csproj**: - Updated project reference and target framework to ensure compatibility. - Includes new resources and dependencies required for additional features. - app.config**: - Fixed XML formatting issues and improved structure. - Added support for the .NET Framework 4.8 runtime. --- .gitignore | 126 ++++++++++++++++++ Win_1337_Patch/1337.Designer.cs | 39 ++++-- Win_1337_Patch/1337.cs | 60 +++++++++ Win_1337_Patch/Properties/AssemblyInfo.cs | 4 +- .../Properties/Resources.Designer.cs | 26 ++-- .../Properties/Settings.Designer.cs | 10 +- Win_1337_Patch/Win_1337_Patch.csproj | 5 +- Win_1337_Patch/app.config | 12 +- 8 files changed, 245 insertions(+), 37 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5d26588 --- /dev/null +++ b/.gitignore @@ -0,0 +1,126 @@ +# Ignore Visual Studio temporary files, build results, and +# build logs directory. + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific folders +.vs/ +.vscode/ +.idea/ +.vscode-test/ + +# Mono Auto Generated Files +mono_crash.* + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini +$RECYCLE.BIN/ + +# VS Code directories +.vscode/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# DotNet Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# NuGet +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config + +# Include only NuGet's .gitignore +!/.nuget/ +!/.nuget/NuGet.Config +!/.nuget/NuGet.exe + +# If using the new MSBuild .csproj format, uncomment this to ignore .NET Core / NuGet cache +#!**/[Dd]ebug/ +#!**/[Rr]elease/ + +# Include only DLLs in the bin directory +bin/**/*.dll + +# Include only the package directory itself +!**/[Pp]ackages/ + +# Ignore temp files +**/bin +**/obj +**/TempPE + +# Rider specific files +.idea/ +*.sln.iml + +# .NET Core directories +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopCache.xml + +# Files generated by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Recycle Bin used by Visual Studio +*.cachefile + +# Exclude folder containing source code +src/ +!src/**/*.cs diff --git a/Win_1337_Patch/1337.Designer.cs b/Win_1337_Patch/1337.Designer.cs index df15762..1cbe49f 100644 --- a/Win_1337_Patch/1337.Designer.cs +++ b/Win_1337_Patch/1337.Designer.cs @@ -40,6 +40,7 @@ this.controlloBackup = new System.Windows.Forms.CheckBox(); this.cfileoffsett = new System.Windows.Forms.CheckBox(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); + this.cchangeOwnership = new System.Windows.Forms.CheckBox(); this.SuspendLayout(); // // label7 @@ -61,7 +62,7 @@ this.t1337.Location = new System.Drawing.Point(90, 5); this.t1337.Name = "t1337"; this.t1337.ReadOnly = true; - this.t1337.Size = new System.Drawing.Size(309, 20); + this.t1337.Size = new System.Drawing.Size(343, 20); this.t1337.TabIndex = 16; this.t1337.TabStop = false; this.t1337.Text = "Select 1337 File..."; @@ -88,7 +89,7 @@ this.texe.Location = new System.Drawing.Point(90, 31); this.texe.Name = "texe"; this.texe.ReadOnly = true; - this.texe.Size = new System.Drawing.Size(336, 20); + this.texe.Size = new System.Drawing.Size(370, 20); this.texe.TabIndex = 14; this.texe.TabStop = false; this.texe.Text = "Name of Exe/Dll to Patch..."; @@ -99,7 +100,7 @@ this.btnSelect1337.CausesValidation = false; this.btnSelect1337.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F); this.btnSelect1337.ForeColor = System.Drawing.Color.DarkRed; - this.btnSelect1337.Location = new System.Drawing.Point(402, 3); + this.btnSelect1337.Location = new System.Drawing.Point(436, 2); this.btnSelect1337.Margin = new System.Windows.Forms.Padding(0); this.btnSelect1337.Name = "btnSelect1337"; this.btnSelect1337.Size = new System.Drawing.Size(24, 23); @@ -114,7 +115,7 @@ this.linkdfox.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.linkdfox.ForeColor = System.Drawing.Color.BlueViolet; this.linkdfox.LinkColor = System.Drawing.Color.Indigo; - this.linkdfox.Location = new System.Drawing.Point(226, 62); + this.linkdfox.Location = new System.Drawing.Point(256, 61); this.linkdfox.Name = "linkdfox"; this.linkdfox.Size = new System.Drawing.Size(77, 13); this.linkdfox.TabIndex = 73; @@ -126,7 +127,7 @@ // this.Patch.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Patch.ForeColor = System.Drawing.Color.DarkBlue; - this.Patch.Location = new System.Drawing.Point(338, 57); + this.Patch.Location = new System.Drawing.Point(372, 56); this.Patch.Name = "Patch"; this.Patch.Size = new System.Drawing.Size(88, 23); this.Patch.TabIndex = 74; @@ -142,7 +143,7 @@ this.controlloBackup.Cursor = System.Windows.Forms.Cursors.Hand; this.controlloBackup.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.controlloBackup.ForeColor = System.Drawing.Color.Teal; - this.controlloBackup.Location = new System.Drawing.Point(3, 61); + this.controlloBackup.Location = new System.Drawing.Point(8, 60); this.controlloBackup.Name = "controlloBackup"; this.controlloBackup.Size = new System.Drawing.Size(69, 17); this.controlloBackup.TabIndex = 76; @@ -158,7 +159,7 @@ this.cfileoffsett.Cursor = System.Windows.Forms.Cursors.Hand; this.cfileoffsett.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.cfileoffsett.ForeColor = System.Drawing.Color.Teal; - this.cfileoffsett.Location = new System.Drawing.Point(74, 61); + this.cfileoffsett.Location = new System.Drawing.Point(79, 60); this.cfileoffsett.Name = "cfileoffsett"; this.cfileoffsett.Size = new System.Drawing.Size(80, 17); this.cfileoffsett.TabIndex = 77; @@ -166,11 +167,27 @@ this.cfileoffsett.UseVisualStyleBackColor = true; this.cfileoffsett.CheckedChanged += new System.EventHandler(this.cfileoffsett_CheckedChanged); // + // cchangeOwnership + // + this.cchangeOwnership.AutoSize = true; + this.cchangeOwnership.Checked = true; + this.cchangeOwnership.CheckState = System.Windows.Forms.CheckState.Checked; + this.cchangeOwnership.Cursor = System.Windows.Forms.Cursors.Hand; + this.cchangeOwnership.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold); + this.cchangeOwnership.ForeColor = System.Drawing.Color.Teal; + this.cchangeOwnership.Location = new System.Drawing.Point(165, 60); + this.cchangeOwnership.Name = "cchangeOwnership"; + this.cchangeOwnership.Size = new System.Drawing.Size(93, 17); + this.cchangeOwnership.TabIndex = 78; + this.cchangeOwnership.Text = "Unlock DLL"; + this.cchangeOwnership.UseVisualStyleBackColor = true; + this.cchangeOwnership.CheckedChanged += new System.EventHandler(this.cchangeOwnership_CheckedChanged); + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(432, 83); + this.ClientSize = new System.Drawing.Size(472, 83); this.Controls.Add(this.cfileoffsett); this.Controls.Add(this.controlloBackup); this.Controls.Add(this.Patch); @@ -180,10 +197,11 @@ this.Controls.Add(this.t1337); this.Controls.Add(this.label6); this.Controls.Add(this.texe); + this.Controls.Add(this.cchangeOwnership); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; - this.MaximumSize = new System.Drawing.Size(448, 122); - this.MinimumSize = new System.Drawing.Size(448, 122); + this.MaximumSize = new System.Drawing.Size(488, 122); + this.MinimumSize = new System.Drawing.Size(488, 122); this.Name = "Form1"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Win 1337 Apply Patch File"; @@ -204,6 +222,7 @@ private System.Windows.Forms.CheckBox controlloBackup; private System.Windows.Forms.CheckBox cfileoffsett; private System.Windows.Forms.ToolTip toolTip1; + private System.Windows.Forms.CheckBox cchangeOwnership; } } diff --git a/Win_1337_Patch/1337.cs b/Win_1337_Patch/1337.cs index 5c14d26..289be29 100644 --- a/Win_1337_Patch/1337.cs +++ b/Win_1337_Patch/1337.cs @@ -3,6 +3,8 @@ using System; using System.Diagnostics; using System.IO; using System.Windows.Forms; +using System.Security.AccessControl; +using System.Security.Principal; namespace Win_1337_Patch { @@ -284,5 +286,63 @@ namespace Win_1337_Patch { btnSelect1337.PerformClick(); } + + private void cchangeOwnership_CheckedChanged(object sender, EventArgs e) + { + if (cchangeOwnership.Checked) + { + try + { + if (!string.IsNullOrEmpty(exe)) + { + UnlockDLL(exe); + MessageBox.Show($"Ownership of {exe} changed to Administrators and full control granted.", "Ownership Changed", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Please select a DLL/EXE file first.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + cchangeOwnership.Checked = false; + } + } + catch (Exception ex) + { + MessageBox.Show($"An error occurred: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + cchangeOwnership.Checked = false; + } + } + } + + private void UnlockDLL(string filePath) + { + if (!File.Exists(filePath)) + { + MessageBox.Show("The specified file does not exist.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + try + { + FileSecurity fileSecurity = File.GetAccessControl(filePath); + IdentityReference administrators = new NTAccount("Administrators"); + + fileSecurity.SetOwner(administrators); + + File.SetAccessControl(filePath, fileSecurity); + + FileSystemAccessRule accessRule = new FileSystemAccessRule(administrators, + FileSystemRights.FullControl, + AccessControlType.Allow); + + fileSecurity.AddAccessRule(accessRule); + + File.SetAccessControl(filePath, fileSecurity); + + MessageBox.Show($"Owner changed to 'Administrators' and full control permissions granted to 'Administrators' for file: {filePath}", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + MessageBox.Show($"An error occurred while changing ownership: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } } } diff --git a/Win_1337_Patch/Properties/AssemblyInfo.cs b/Win_1337_Patch/Properties/AssemblyInfo.cs index 4221447..a4f19ff 100644 --- a/Win_1337_Patch/Properties/AssemblyInfo.cs +++ b/Win_1337_Patch/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build // usando l'asterisco '*' come illustrato di seguito: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.9.0.0")] -[assembly: AssemblyFileVersion("1.9.0.0")] +[assembly: AssemblyVersion("2.0.0.0")] +[assembly: AssemblyFileVersion("2.0.0.0")] diff --git a/Win_1337_Patch/Properties/Resources.Designer.cs b/Win_1337_Patch/Properties/Resources.Designer.cs index 157385d..11ac648 100644 --- a/Win_1337_Patch/Properties/Resources.Designer.cs +++ b/Win_1337_Patch/Properties/Resources.Designer.cs @@ -1,10 +1,10 @@ //------------------------------------------------------------------------------ // -// Il codice è stato generato da uno strumento. -// Versione runtime:4.0.30319.42000 +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 // -// Le modifiche apportate a questo file possono provocare un comportamento non corretto e andranno perse se -// il codice viene rigenerato. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. // //------------------------------------------------------------------------------ @@ -13,13 +13,13 @@ namespace Win_1337_Patch.Properties { /// - /// Classe di risorse fortemente tipizzata per la ricerca di stringhe localizzate e così via. + /// A strongly-typed resource class, for looking up localized strings, etc. /// - // Questa classe è stata generata automaticamente dalla classe StronglyTypedResourceBuilder. - // tramite uno strumento quale ResGen o Visual Studio. - // Per aggiungere o rimuovere un membro, modificare il file con estensione ResX ed eseguire nuovamente ResGen - // con l'opzione /str oppure ricompilare il progetto VS. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { @@ -33,7 +33,7 @@ namespace Win_1337_Patch.Properties { } /// - /// Restituisce l'istanza di ResourceManager nella cache utilizzata da questa classe. + /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Resources.ResourceManager ResourceManager { @@ -47,8 +47,8 @@ namespace Win_1337_Patch.Properties { } /// - /// Esegue l'override della proprietà CurrentUICulture del thread corrente per tutte le - /// ricerche di risorse eseguite utilizzando questa classe di risorse fortemente tipizzata. + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Globalization.CultureInfo Culture { diff --git a/Win_1337_Patch/Properties/Settings.Designer.cs b/Win_1337_Patch/Properties/Settings.Designer.cs index 5bd05e4..65b8fd8 100644 --- a/Win_1337_Patch/Properties/Settings.Designer.cs +++ b/Win_1337_Patch/Properties/Settings.Designer.cs @@ -1,10 +1,10 @@ //------------------------------------------------------------------------------ // -// Il codice è stato generato da uno strumento. -// Versione runtime:4.0.30319.42000 +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 // -// Le modifiche apportate a questo file possono provocare un comportamento non corretto e andranno perse se -// il codice viene rigenerato. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. // //------------------------------------------------------------------------------ @@ -12,7 +12,7 @@ namespace Win_1337_Patch.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.8.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.10.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/Win_1337_Patch/Win_1337_Patch.csproj b/Win_1337_Patch/Win_1337_Patch.csproj index 1ab5e23..03b0204 100644 --- a/Win_1337_Patch/Win_1337_Patch.csproj +++ b/Win_1337_Patch/Win_1337_Patch.csproj @@ -8,9 +8,10 @@ WinExe Win_1337_Patch Win_1337_Patch - v4.0 + v4.8 512 true + AnyCPU @@ -21,6 +22,7 @@ DEBUG;TRACE prompt 4 + false AnyCPU @@ -30,6 +32,7 @@ TRACE prompt 4 + false vampire.ico diff --git a/Win_1337_Patch/app.config b/Win_1337_Patch/app.config index d5c3fae..fb31ed4 100644 --- a/Win_1337_Patch/app.config +++ b/Win_1337_Patch/app.config @@ -1,17 +1,17 @@ - + - -
+ +
- + - + True @@ -21,4 +21,4 @@ - \ No newline at end of file + From 11d01e8693f2255ba58abc47c61aa5f7f7de4fe9 Mon Sep 17 00:00:00 2001 From: ramhaidar <49301219+ramhaidar@users.noreply.github.com> Date: Sun, 25 Aug 2024 09:30:38 +0700 Subject: [PATCH 4/4] Comprehensive Code Refactor and Configuration Update - Error Handling: Standardized across methods, added descriptive error messages. - File Selection: Simplified `OpenFileDialog`, improved backup naming, added user-friendly prompts. - Ownership Management: Added ownership change feature with success messages. - UX: Added tooltips, enhanced drag-and-drop feedback. - Code Cleanup: Removed redundant code, modernized constructs, consistent formatting. - Config: Streamlined `app.config`, ensured .NET 4.8 target. - Checksum Refactor: Switched to 64-bit pointers, optimized resource management. - Version Update: Incremented assembly and file versions to 2.1.0.0. - Settings: Added `changeOwnership` setting with default `True`, scoped per user. --- Win_1337_Patch/1337.cs | 320 +++++++++++------- Win_1337_Patch/Properties/AssemblyInfo.cs | 4 +- .../Properties/Settings.Designer.cs | 12 + Win_1337_Patch/Properties/Settings.settings | 3 + Win_1337_Patch/app.config | 7 +- Win_1337_Patch/mCheckSum.cs | 37 +- 6 files changed, 250 insertions(+), 133 deletions(-) diff --git a/Win_1337_Patch/1337.cs b/Win_1337_Patch/1337.cs index 289be29..e84405e 100644 --- a/Win_1337_Patch/1337.cs +++ b/Win_1337_Patch/1337.cs @@ -24,40 +24,53 @@ namespace Win_1337_Patch this.Text = "Win 1337 Apply Patch File " + ver; linkdfox.Text = ver + " By DeltaFoX"; } + private void set() { - t1337.Text = Ellipsis.Compact(f1337, t1337, EllipsisFormat.Path); - toolTip1.SetToolTip(t1337, f1337); - Properties.Settings.Default["url1337"] = f1337; - Properties.Settings.Default.Save(); - string[] lines = File.ReadAllLines(f1337); - if (!check_Symbol(lines[0])) - return; - string unf = lines[0].Substring(1).ToLower().Trim(); - string nf = Path.GetFileName(unf); - string ext = Path.GetExtension(unf); - OpenFileDialog apriDialogoFile1 = new OpenFileDialog(); - apriDialogoFile1.FileName = nf; - apriDialogoFile1.Filter = "File " + ext + "|" + nf; - apriDialogoFile1.FilterIndex = 0; - apriDialogoFile1.Title = "Select the file \"" + nf + "\" File..."; - - if (apriDialogoFile1.ShowDialog() == DialogResult.OK) + try { - exe = apriDialogoFile1.FileName; - texe.Text = Ellipsis.Compact(Path.GetFileName(exe), texe, EllipsisFormat.Path); - toolTip1.SetToolTip(texe, exe); - Properties.Settings.Default["urlexe"] = exe; + t1337.Text = Ellipsis.Compact(f1337, t1337, EllipsisFormat.Path); + toolTip1.SetToolTip(t1337, f1337); + Properties.Settings.Default["url1337"] = f1337; Properties.Settings.Default.Save(); + + string[] lines = File.ReadAllLines(f1337); + if (!check_Symbol(lines[0])) + return; + + string unf = lines[0].Substring(1).ToLower().Trim(); + string nf = Path.GetFileName(unf); + string ext = Path.GetExtension(unf); + OpenFileDialog apriDialogoFile1 = new OpenFileDialog + { + FileName = nf, + Filter = "File " + ext + "|" + nf, + FilterIndex = 0, + Title = "Select the file \"" + nf + "\" File..." + }; + + if (apriDialogoFile1.ShowDialog() == DialogResult.OK) + { + exe = apriDialogoFile1.FileName; + texe.Text = Ellipsis.Compact(Path.GetFileName(exe), texe, EllipsisFormat.Path); + toolTip1.SetToolTip(texe, exe); + Properties.Settings.Default["urlexe"] = exe; + Properties.Settings.Default.Save(); + } + else + { + t1337.Text = "Select a .1337 File..."; + texe.Text = "Select the Exe/Dll to Patch..."; + f1337 = String.Empty; + exe = String.Empty; + } } - else + catch (Exception ex) { - t1337.Text = "Select a .1337 File..."; - texe.Text = "Select the Exe/Dll to Patch..."; - f1337 = String.Empty; - exe = String.Empty; + MessageBox.Show($"An error occurred while setting up the file: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + private void t1337_DragDrop(object sender, DragEventArgs e) { try @@ -65,39 +78,47 @@ namespace Win_1337_Patch f1337 = ((string[])e.Data.GetData(DataFormats.FileDrop, false))[0]; set(); } - catch + catch (Exception ex) { - //Nothing; + MessageBox.Show($"An error occurred while processing drag and drop: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } - return; } + private void btnSelect1337_Click(object sender, EventArgs e) { try { string url1337 = Properties.Settings.Default["url1337"].ToString(); - OpenFileDialog apriDialogoFile1 = new OpenFileDialog(); - apriDialogoFile1.Filter = "File 1337|*.*"; - apriDialogoFile1.FilterIndex = 0; - apriDialogoFile1.Title = "Select the .1337 File..."; - apriDialogoFile1.InitialDirectory = url1337 != "" ? url1337 : Directory.GetCurrentDirectory() + "\\"; - apriDialogoFile1.RestoreDirectory = true; + OpenFileDialog apriDialogoFile1 = new OpenFileDialog + { + Filter = "File 1337|*.*", + FilterIndex = 0, + Title = "Select the .1337 File...", + InitialDirectory = url1337 != "" ? url1337 : Directory.GetCurrentDirectory() + "\\", + RestoreDirectory = true + }; if (apriDialogoFile1.ShowDialog() == DialogResult.OK) { f1337 = apriDialogoFile1.FileName; set(); } } - catch + catch (Exception ex) { - //Nothing; + MessageBox.Show($"An error occurred while selecting the .1337 file: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } - return; } private void t1337_DragEnter(object sender, DragEventArgs e) { - e.Effect = DragDropEffects.All; + try + { + e.Effect = DragDropEffects.All; + } + catch (Exception ex) + { + MessageBox.Show($"An error occurred during DragEnter: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } private bool check_Symbol(string s) @@ -121,12 +142,12 @@ namespace Win_1337_Patch { DFoX_Patch(); } - catch + catch (Exception ex) { - MessageBox.Show("Problem occured when Patching...", "Info...", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; + MessageBox.Show($"A problem occurred when patching: {ex.Message}", "Info...", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + private void DFoX_Patch() { if (!File.Exists(exe) || !File.Exists(f1337)) @@ -134,6 +155,20 @@ namespace Win_1337_Patch MessageBox.Show("Files are no Longer Present...", "Info...", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + + if (cchangeOwnership.Checked) + { + try + { + UnlockDLL(exe); + } + catch (Exception ex) + { + MessageBox.Show($"An error occurred while changing ownership: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + string[] lines = File.ReadAllLines(f1337); if (!check_Symbol(lines[0])) return; @@ -167,9 +202,12 @@ namespace Win_1337_Patch { if (controlloBackup.Checked == true) { - if (File.Exists(exe + ".BAK")) - File.Delete(exe + ".BAK"); - File.Copy(exe, exe + ".BAK"); + string dateSuffix = DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss-tt"); + string backupFileName = $"{exe}.{dateSuffix}.BAK"; + + if (File.Exists(backupFileName)) + File.Delete(backupFileName); + File.Copy(exe, backupFileName); } if (File.Exists(exe)) File.Delete(exe); @@ -177,8 +215,8 @@ namespace Win_1337_Patch SistemaPeCks(exe); MessageBox.Show("File " + Path.GetFileName(exe) + " Patched...", "Info...", MessageBoxButtons.OK, MessageBoxIcon.Information); } - return; } + private void SistemaPeCks(string file) { try @@ -186,57 +224,109 @@ namespace Win_1337_Patch using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.ReadWrite)) { ImageRemoveCertificate(fs.SafeFileHandle.DangerousGetHandle(), 0); - fs.Close(); } - mCheckSum PE = new mCheckSum(); - PE.FixCheckSum(file); + + checked + { + mCheckSum PE = new mCheckSum(); + PE.FixCheckSum(file); + } } - catch + catch (OverflowException ex) { - //Nothing + MessageBox.Show($"Overflow error occurred while processing PE checksum: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + catch (Exception ex) + { + MessageBox.Show($"An error occurred while processing PE checksum: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } - return; } + private void DFoX_Load(object sender, EventArgs e) { - string urlexe = Properties.Settings.Default["urlexe"].ToString().Trim(); - string url1337 = Properties.Settings.Default["url1337"].ToString().Trim(); - cfileoffsett.Checked = (bool)Properties.Settings.Default["fixoffset"]; - controlloBackup.Checked = (bool)Properties.Settings.Default["backup"]; - if (urlexe != "") + try { - texe.Text = Ellipsis.Compact(Path.GetFileName(urlexe), texe, EllipsisFormat.Path); - toolTip1.SetToolTip(texe, urlexe); - exe = urlexe; + string urlexe = Properties.Settings.Default["urlexe"].ToString().Trim(); + string url1337 = Properties.Settings.Default["url1337"].ToString().Trim(); + cfileoffsett.Checked = (bool)Properties.Settings.Default["fixoffset"]; + controlloBackup.Checked = (bool)Properties.Settings.Default["backup"]; + cchangeOwnership.Checked = (bool)Properties.Settings.Default["changeOwnership"]; + + if (urlexe != "") + { + texe.Text = Ellipsis.Compact(Path.GetFileName(urlexe), texe, EllipsisFormat.Path); + toolTip1.SetToolTip(texe, urlexe); + exe = urlexe; + } + else + texe.Text = "Select the Exe/Dll to Patch..."; + + if (url1337 != "" && urlexe != "") + { + t1337.Text = Ellipsis.Compact(url1337, t1337, EllipsisFormat.Path); + toolTip1.SetToolTip(t1337, url1337); + f1337 = url1337; + } + else + t1337.Text = "Select a .1337 File..."; } - else - texe.Text = "Select the Exe/Dll to Patch..."; - if (url1337 != "" && urlexe != "") + catch (Exception ex) { - t1337.Text = Ellipsis.Compact(url1337, t1337, EllipsisFormat.Path); - toolTip1.SetToolTip(t1337, url1337); - f1337 = url1337; + MessageBox.Show($"An error occurred during form load: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } - else - t1337.Text = "Select a .1337 File..."; } private void cfileoffsett_CheckedChanged(object sender, EventArgs e) { - Properties.Settings.Default["fixoffset"] = cfileoffsett.Checked; - Properties.Settings.Default.Save(); + try + { + Properties.Settings.Default["fixoffset"] = cfileoffsett.Checked; + Properties.Settings.Default.Save(); + } + catch (Exception ex) + { + MessageBox.Show($"An error occurred while saving fix offset setting: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } private void controlloBackup_CheckedChanged(object sender, EventArgs e) { - Properties.Settings.Default["backup"] = controlloBackup.Checked; - Properties.Settings.Default.Save(); + try + { + Properties.Settings.Default["backup"] = controlloBackup.Checked; + Properties.Settings.Default.Save(); + } + catch (Exception ex) + { + MessageBox.Show($"An error occurred while saving backup setting: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void cchangeOwnership_CheckedChanged(object sender, EventArgs e) + { + try + { + Properties.Settings.Default["changeOwnership"] = cchangeOwnership.Checked; + Properties.Settings.Default.Save(); + } + catch (Exception ex) + { + MessageBox.Show($"An error occurred while saving change ownership setting: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } private void linkdfox_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { - _apriUrl(@"https://github.com/Deltafox79/Win_1337_Apply_Patch"); + try + { + _apriUrl(@"https://github.com/Deltafox79/Win_1337_Apply_Patch"); + } + catch (Exception ex) + { + MessageBox.Show($"An error occurred while opening the URL: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } + private void _apriUrl(string url) { try @@ -244,16 +334,21 @@ namespace Win_1337_Patch string browserPath = ottieniLaPathBrowser(); if (browserPath == string.Empty) browserPath = "iexplore"; - Process process = new Process(); - process.StartInfo = new ProcessStartInfo(browserPath); - process.StartInfo.Arguments = url; + Process process = new Process + { + StartInfo = new ProcessStartInfo(browserPath) + { + Arguments = url + } + }; process.Start(); } - catch + catch (Exception ex) { - //Nothing + MessageBox.Show($"An error occurred while opening the browser: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + private static string ottieniLaPathBrowser() { string name = String.Empty; @@ -268,11 +363,10 @@ namespace Win_1337_Patch if (!name.EndsWith("exe")) name = name.Substring(0, name.LastIndexOf(".exe") + 4); - } - catch + catch (Exception ex) { - return String.Empty; + MessageBox.Show($"An error occurred while retrieving browser path: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { @@ -284,31 +378,13 @@ namespace Win_1337_Patch private void t1337_DoubleClick(object sender, EventArgs e) { - btnSelect1337.PerformClick(); - } - - private void cchangeOwnership_CheckedChanged(object sender, EventArgs e) - { - if (cchangeOwnership.Checked) + try { - try - { - if (!string.IsNullOrEmpty(exe)) - { - UnlockDLL(exe); - MessageBox.Show($"Ownership of {exe} changed to Administrators and full control granted.", "Ownership Changed", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - else - { - MessageBox.Show("Please select a DLL/EXE file first.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - cchangeOwnership.Checked = false; - } - } - catch (Exception ex) - { - MessageBox.Show($"An error occurred: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - cchangeOwnership.Checked = false; - } + btnSelect1337.PerformClick(); + } + catch (Exception ex) + { + MessageBox.Show($"An error occurred during double click: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -322,22 +398,32 @@ namespace Win_1337_Patch try { - FileSecurity fileSecurity = File.GetAccessControl(filePath); - IdentityReference administrators = new NTAccount("Administrators"); + ProcessStartInfo psi = new ProcessStartInfo("cmd.exe") + { + UseShellExecute = false, + RedirectStandardInput = true, + RedirectStandardOutput = true, + CreateNoWindow = true + }; - fileSecurity.SetOwner(administrators); + using (Process process = new Process()) + { + process.StartInfo = psi; + process.Start(); - File.SetAccessControl(filePath, fileSecurity); + using (StreamWriter sw = process.StandardInput) + { + if (sw.BaseStream.CanWrite) + { + sw.WriteLine($"takeown /F \"{filePath}\""); + sw.WriteLine($"icacls \"{filePath}\" /grant Administrators:F"); + } + } - FileSystemAccessRule accessRule = new FileSystemAccessRule(administrators, - FileSystemRights.FullControl, - AccessControlType.Allow); + process.WaitForExit(); + } - fileSecurity.AddAccessRule(accessRule); - - File.SetAccessControl(filePath, fileSecurity); - - MessageBox.Show($"Owner changed to 'Administrators' and full control permissions granted to 'Administrators' for file: {filePath}", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); + MessageBox.Show($"Ownership and permissions of {filePath} have been successfully changed.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { diff --git a/Win_1337_Patch/Properties/AssemblyInfo.cs b/Win_1337_Patch/Properties/AssemblyInfo.cs index a4f19ff..316d6a0 100644 --- a/Win_1337_Patch/Properties/AssemblyInfo.cs +++ b/Win_1337_Patch/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build // usando l'asterisco '*' come illustrato di seguito: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.0.0")] -[assembly: AssemblyFileVersion("2.0.0.0")] +[assembly: AssemblyVersion("2.1.0.0")] +[assembly: AssemblyFileVersion("2.1.0.0")] diff --git a/Win_1337_Patch/Properties/Settings.Designer.cs b/Win_1337_Patch/Properties/Settings.Designer.cs index 65b8fd8..a3b03e2 100644 --- a/Win_1337_Patch/Properties/Settings.Designer.cs +++ b/Win_1337_Patch/Properties/Settings.Designer.cs @@ -70,5 +70,17 @@ namespace Win_1337_Patch.Properties { this["backup"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool changeOwnership { + get { + return ((bool)(this["changeOwnership"])); + } + set { + this["changeOwnership"] = value; + } + } } } diff --git a/Win_1337_Patch/Properties/Settings.settings b/Win_1337_Patch/Properties/Settings.settings index 5645b6b..e1b8d1f 100644 --- a/Win_1337_Patch/Properties/Settings.settings +++ b/Win_1337_Patch/Properties/Settings.settings @@ -14,5 +14,8 @@ True + + True + \ No newline at end of file diff --git a/Win_1337_Patch/app.config b/Win_1337_Patch/app.config index fb31ed4..9ac6901 100644 --- a/Win_1337_Patch/app.config +++ b/Win_1337_Patch/app.config @@ -8,10 +8,10 @@ - + - + True @@ -19,6 +19,9 @@ True + + True + diff --git a/Win_1337_Patch/mCheckSum.cs b/Win_1337_Patch/mCheckSum.cs index 316b37d..962b532 100644 --- a/Win_1337_Patch/mCheckSum.cs +++ b/Win_1337_Patch/mCheckSum.cs @@ -28,7 +28,7 @@ namespace Win_1337_Patch IMAGE_DOS_HEADER DHD = new IMAGE_DOS_HEADER(); IMAGE_NT_HEADERS NHD = new IMAGE_NT_HEADERS(); - int iPointer = 0; + long iPointer = 0; uint uOriginal = 0; uint uRecalculated = 0; uint uRet = 0; @@ -36,16 +36,23 @@ namespace Win_1337_Patch try { - BinaryReader bReader = new BinaryReader(new FileStream(sFilePath, FileMode.Open, FileAccess.Read)); - fBytes = bReader.ReadBytes((int)bReader.BaseStream.Length); - bReader.Close(); + using (BinaryReader bReader = new BinaryReader(new FileStream(sFilePath, FileMode.Open, FileAccess.Read))) + { + fBytes = bReader.ReadBytes((int)bReader.BaseStream.Length); + } + } + catch + { + return false; } - catch { } if (fBytes.Length <= 0) { return false; } GCHandle gHandle = GCHandle.Alloc(fBytes, GCHandleType.Pinned); - iPointer = gHandle.AddrOfPinnedObject().ToInt32(); + checked + { + iPointer = gHandle.AddrOfPinnedObject().ToInt64(); + } DHD = (IMAGE_DOS_HEADER)Marshal.PtrToStructure(new IntPtr(iPointer), typeof(IMAGE_DOS_HEADER)); NHD = (IMAGE_NT_HEADERS)Marshal.PtrToStructure(new IntPtr(iPointer + DHD.e_lfanew), typeof(IMAGE_NT_HEADERS)); gHandle.Free(); @@ -74,17 +81,23 @@ namespace Win_1337_Patch NHD.OptionalHeader.CheckSum = uRecalculated; byte[] bNHD = getBytes_(NHD); - if (fBytes.Length - (DHD.e_lfanew + bNHD.Length) <= 0) { Array.Resize(ref fBytes, (int)(fBytes.Length + bNHD.Length)); } + if (fBytes.Length - (DHD.e_lfanew + bNHD.Length) <= 0) + { + Array.Resize(ref fBytes, (int)(fBytes.Length + bNHD.Length)); + } Array.Copy(bNHD, 0, fBytes, DHD.e_lfanew, bNHD.Length); try { - BinaryWriter bWriter = new BinaryWriter(new FileStream(sFilePath, FileMode.Open)); - bWriter.Write(fBytes); - bWriter.Flush(); - bWriter.Close(); + using (BinaryWriter bWriter = new BinaryWriter(new FileStream(sFilePath, FileMode.Open))) + { + bWriter.Write(fBytes); + } + } + catch + { + return false; } - catch { return false; } return true; }