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.
This commit is contained in:
ramhaidar 2024-07-28 11:35:27 +07:00
commit b5e095e691
8 changed files with 245 additions and 37 deletions

126
.gitignore vendored Normal file
View file

@ -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

View file

@ -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;
}
}

View file

@ -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);
}
}
}
}

View file

@ -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")]

View file

@ -1,10 +1,10 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 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.
// </auto-generated>
//------------------------------------------------------------------------------
@ -13,13 +13,13 @@ namespace Win_1337_Patch.Properties {
/// <summary>
/// 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.
/// </summary>
// 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 {
}
/// <summary>
/// Restituisce l'istanza di ResourceManager nella cache utilizzata da questa classe.
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[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 {
}
/// <summary>
/// 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.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {

View file

@ -1,10 +1,10 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 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.
// </auto-generated>
//------------------------------------------------------------------------------
@ -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())));

View file

@ -8,9 +8,10 @@
<OutputType>WinExe</OutputType>
<RootNamespace>Win_1337_Patch</RootNamespace>
<AssemblyName>Win_1337_Patch</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -21,6 +22,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -30,6 +32,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>vampire.ico</ApplicationIcon>

View file

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Win_1337_Patch.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Win_1337_Patch.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
</configSections>
<userSettings>
<Win_1337_Patch.Properties.Settings>
<setting name="urlexe" serializeAs="String">
<value />
<value/>
</setting>
<setting name="url1337" serializeAs="String">
<value />
<value/>
</setting>
<setting name="fixoffset" serializeAs="String">
<value>True</value>
@ -21,4 +21,4 @@
</setting>
</Win_1337_Patch.Properties.Settings>
</userSettings>
</configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>