mirror of
https://github.com/Deltafox79/Win_1337_Apply_Patch
synced 2025-08-19 21:04:02 -07:00
Merge pull request #10 from ramhaidar/v2.1
Comprehensive Code Refactor and Configuration Update
This commit is contained in:
commit
962a773ece
6 changed files with 250 additions and 133 deletions
|
@ -24,40 +24,53 @@ namespace Win_1337_Patch
|
||||||
this.Text = "Win 1337 Apply Patch File " + ver;
|
this.Text = "Win 1337 Apply Patch File " + ver;
|
||||||
linkdfox.Text = ver + " By DeltaFoX";
|
linkdfox.Text = ver + " By DeltaFoX";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void set()
|
private void set()
|
||||||
{
|
{
|
||||||
t1337.Text = Ellipsis.Compact(f1337, t1337, EllipsisFormat.Path);
|
try
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
exe = apriDialogoFile1.FileName;
|
t1337.Text = Ellipsis.Compact(f1337, t1337, EllipsisFormat.Path);
|
||||||
texe.Text = Ellipsis.Compact(Path.GetFileName(exe), texe, EllipsisFormat.Path);
|
toolTip1.SetToolTip(t1337, f1337);
|
||||||
toolTip1.SetToolTip(texe, exe);
|
Properties.Settings.Default["url1337"] = f1337;
|
||||||
Properties.Settings.Default["urlexe"] = exe;
|
|
||||||
Properties.Settings.Default.Save();
|
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...";
|
MessageBox.Show($"An error occurred while setting up the file: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
texe.Text = "Select the Exe/Dll to Patch...";
|
|
||||||
f1337 = String.Empty;
|
|
||||||
exe = String.Empty;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void t1337_DragDrop(object sender, DragEventArgs e)
|
private void t1337_DragDrop(object sender, DragEventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -65,39 +78,47 @@ namespace Win_1337_Patch
|
||||||
f1337 = ((string[])e.Data.GetData(DataFormats.FileDrop, false))[0];
|
f1337 = ((string[])e.Data.GetData(DataFormats.FileDrop, false))[0];
|
||||||
set();
|
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)
|
private void btnSelect1337_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string url1337 = Properties.Settings.Default["url1337"].ToString();
|
string url1337 = Properties.Settings.Default["url1337"].ToString();
|
||||||
OpenFileDialog apriDialogoFile1 = new OpenFileDialog();
|
OpenFileDialog apriDialogoFile1 = new OpenFileDialog
|
||||||
apriDialogoFile1.Filter = "File 1337|*.*";
|
{
|
||||||
apriDialogoFile1.FilterIndex = 0;
|
Filter = "File 1337|*.*",
|
||||||
apriDialogoFile1.Title = "Select the .1337 File...";
|
FilterIndex = 0,
|
||||||
apriDialogoFile1.InitialDirectory = url1337 != "" ? url1337 : Directory.GetCurrentDirectory() + "\\";
|
Title = "Select the .1337 File...",
|
||||||
apriDialogoFile1.RestoreDirectory = true;
|
InitialDirectory = url1337 != "" ? url1337 : Directory.GetCurrentDirectory() + "\\",
|
||||||
|
RestoreDirectory = true
|
||||||
|
};
|
||||||
if (apriDialogoFile1.ShowDialog() == DialogResult.OK)
|
if (apriDialogoFile1.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
f1337 = apriDialogoFile1.FileName;
|
f1337 = apriDialogoFile1.FileName;
|
||||||
set();
|
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)
|
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)
|
private bool check_Symbol(string s)
|
||||||
|
@ -121,12 +142,12 @@ namespace Win_1337_Patch
|
||||||
{
|
{
|
||||||
DFoX_Patch();
|
DFoX_Patch();
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Problem occured when Patching...", "Info...", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show($"A problem occurred when patching: {ex.Message}", "Info...", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DFoX_Patch()
|
private void DFoX_Patch()
|
||||||
{
|
{
|
||||||
if (!File.Exists(exe) || !File.Exists(f1337))
|
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);
|
MessageBox.Show("Files are no Longer Present...", "Info...", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return;
|
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);
|
string[] lines = File.ReadAllLines(f1337);
|
||||||
if (!check_Symbol(lines[0]))
|
if (!check_Symbol(lines[0]))
|
||||||
return;
|
return;
|
||||||
|
@ -167,9 +202,12 @@ namespace Win_1337_Patch
|
||||||
{
|
{
|
||||||
if (controlloBackup.Checked == true)
|
if (controlloBackup.Checked == true)
|
||||||
{
|
{
|
||||||
if (File.Exists(exe + ".BAK"))
|
string dateSuffix = DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss-tt");
|
||||||
File.Delete(exe + ".BAK");
|
string backupFileName = $"{exe}.{dateSuffix}.BAK";
|
||||||
File.Copy(exe, exe + ".BAK");
|
|
||||||
|
if (File.Exists(backupFileName))
|
||||||
|
File.Delete(backupFileName);
|
||||||
|
File.Copy(exe, backupFileName);
|
||||||
}
|
}
|
||||||
if (File.Exists(exe))
|
if (File.Exists(exe))
|
||||||
File.Delete(exe);
|
File.Delete(exe);
|
||||||
|
@ -177,8 +215,8 @@ namespace Win_1337_Patch
|
||||||
SistemaPeCks(exe);
|
SistemaPeCks(exe);
|
||||||
MessageBox.Show("File " + Path.GetFileName(exe) + " Patched...", "Info...", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBox.Show("File " + Path.GetFileName(exe) + " Patched...", "Info...", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SistemaPeCks(string file)
|
private void SistemaPeCks(string file)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -186,57 +224,109 @@ namespace Win_1337_Patch
|
||||||
using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.ReadWrite))
|
using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.ReadWrite))
|
||||||
{
|
{
|
||||||
ImageRemoveCertificate(fs.SafeFileHandle.DangerousGetHandle(), 0);
|
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)
|
private void DFoX_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
string urlexe = Properties.Settings.Default["urlexe"].ToString().Trim();
|
try
|
||||||
string url1337 = Properties.Settings.Default["url1337"].ToString().Trim();
|
|
||||||
cfileoffsett.Checked = (bool)Properties.Settings.Default["fixoffset"];
|
|
||||||
controlloBackup.Checked = (bool)Properties.Settings.Default["backup"];
|
|
||||||
if (urlexe != "")
|
|
||||||
{
|
{
|
||||||
texe.Text = Ellipsis.Compact(Path.GetFileName(urlexe), texe, EllipsisFormat.Path);
|
string urlexe = Properties.Settings.Default["urlexe"].ToString().Trim();
|
||||||
toolTip1.SetToolTip(texe, urlexe);
|
string url1337 = Properties.Settings.Default["url1337"].ToString().Trim();
|
||||||
exe = urlexe;
|
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
|
catch (Exception ex)
|
||||||
texe.Text = "Select the Exe/Dll to Patch...";
|
|
||||||
if (url1337 != "" && urlexe != "")
|
|
||||||
{
|
{
|
||||||
t1337.Text = Ellipsis.Compact(url1337, t1337, EllipsisFormat.Path);
|
MessageBox.Show($"An error occurred during form load: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
toolTip1.SetToolTip(t1337, url1337);
|
|
||||||
f1337 = url1337;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
t1337.Text = "Select a .1337 File...";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cfileoffsett_CheckedChanged(object sender, EventArgs e)
|
private void cfileoffsett_CheckedChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Properties.Settings.Default["fixoffset"] = cfileoffsett.Checked;
|
try
|
||||||
Properties.Settings.Default.Save();
|
{
|
||||||
|
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)
|
private void controlloBackup_CheckedChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Properties.Settings.Default["backup"] = controlloBackup.Checked;
|
try
|
||||||
Properties.Settings.Default.Save();
|
{
|
||||||
|
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)
|
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)
|
private void _apriUrl(string url)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -244,16 +334,21 @@ namespace Win_1337_Patch
|
||||||
string browserPath = ottieniLaPathBrowser();
|
string browserPath = ottieniLaPathBrowser();
|
||||||
if (browserPath == string.Empty)
|
if (browserPath == string.Empty)
|
||||||
browserPath = "iexplore";
|
browserPath = "iexplore";
|
||||||
Process process = new Process();
|
Process process = new Process
|
||||||
process.StartInfo = new ProcessStartInfo(browserPath);
|
{
|
||||||
process.StartInfo.Arguments = url;
|
StartInfo = new ProcessStartInfo(browserPath)
|
||||||
|
{
|
||||||
|
Arguments = url
|
||||||
|
}
|
||||||
|
};
|
||||||
process.Start();
|
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()
|
private static string ottieniLaPathBrowser()
|
||||||
{
|
{
|
||||||
string name = String.Empty;
|
string name = String.Empty;
|
||||||
|
@ -268,11 +363,10 @@ namespace Win_1337_Patch
|
||||||
|
|
||||||
if (!name.EndsWith("exe"))
|
if (!name.EndsWith("exe"))
|
||||||
name = name.Substring(0, name.LastIndexOf(".exe") + 4);
|
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
|
finally
|
||||||
{
|
{
|
||||||
|
@ -284,31 +378,13 @@ namespace Win_1337_Patch
|
||||||
|
|
||||||
private void t1337_DoubleClick(object sender, EventArgs e)
|
private void t1337_DoubleClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
btnSelect1337.PerformClick();
|
try
|
||||||
}
|
|
||||||
|
|
||||||
private void cchangeOwnership_CheckedChanged(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (cchangeOwnership.Checked)
|
|
||||||
{
|
{
|
||||||
try
|
btnSelect1337.PerformClick();
|
||||||
{
|
}
|
||||||
if (!string.IsNullOrEmpty(exe))
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
UnlockDLL(exe);
|
MessageBox.Show($"An error occurred during double click: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,22 +398,32 @@ namespace Win_1337_Patch
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
FileSecurity fileSecurity = File.GetAccessControl(filePath);
|
ProcessStartInfo psi = new ProcessStartInfo("cmd.exe")
|
||||||
IdentityReference administrators = new NTAccount("Administrators");
|
{
|
||||||
|
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,
|
process.WaitForExit();
|
||||||
FileSystemRights.FullControl,
|
}
|
||||||
AccessControlType.Allow);
|
|
||||||
|
|
||||||
fileSecurity.AddAccessRule(accessRule);
|
MessageBox.Show($"Ownership and permissions of {filePath} have been successfully changed.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
|
||||||
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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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
|
// È 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:
|
// usando l'asterisco '*' come illustrato di seguito:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("2.0.0.0")]
|
[assembly: AssemblyVersion("2.1.0.0")]
|
||||||
[assembly: AssemblyFileVersion("2.0.0.0")]
|
[assembly: AssemblyFileVersion("2.1.0.0")]
|
||||||
|
|
12
Win_1337_Patch/Properties/Settings.Designer.cs
generated
12
Win_1337_Patch/Properties/Settings.Designer.cs
generated
|
@ -70,5 +70,17 @@ namespace Win_1337_Patch.Properties {
|
||||||
this["backup"] = value;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,5 +14,8 @@
|
||||||
<Setting Name="backup" Type="System.Boolean" Scope="User">
|
<Setting Name="backup" Type="System.Boolean" Scope="User">
|
||||||
<Value Profile="(Default)">True</Value>
|
<Value Profile="(Default)">True</Value>
|
||||||
</Setting>
|
</Setting>
|
||||||
|
<Setting Name="changeOwnership" Type="System.Boolean" Scope="User">
|
||||||
|
<Value Profile="(Default)">True</Value>
|
||||||
|
</Setting>
|
||||||
</Settings>
|
</Settings>
|
||||||
</SettingsFile>
|
</SettingsFile>
|
|
@ -8,10 +8,10 @@
|
||||||
<userSettings>
|
<userSettings>
|
||||||
<Win_1337_Patch.Properties.Settings>
|
<Win_1337_Patch.Properties.Settings>
|
||||||
<setting name="urlexe" serializeAs="String">
|
<setting name="urlexe" serializeAs="String">
|
||||||
<value/>
|
<value />
|
||||||
</setting>
|
</setting>
|
||||||
<setting name="url1337" serializeAs="String">
|
<setting name="url1337" serializeAs="String">
|
||||||
<value/>
|
<value />
|
||||||
</setting>
|
</setting>
|
||||||
<setting name="fixoffset" serializeAs="String">
|
<setting name="fixoffset" serializeAs="String">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
|
@ -19,6 +19,9 @@
|
||||||
<setting name="backup" serializeAs="String">
|
<setting name="backup" serializeAs="String">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</setting>
|
</setting>
|
||||||
|
<setting name="changeOwnership" serializeAs="String">
|
||||||
|
<value>True</value>
|
||||||
|
</setting>
|
||||||
</Win_1337_Patch.Properties.Settings>
|
</Win_1337_Patch.Properties.Settings>
|
||||||
</userSettings>
|
</userSettings>
|
||||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>
|
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace Win_1337_Patch
|
||||||
IMAGE_DOS_HEADER DHD = new IMAGE_DOS_HEADER();
|
IMAGE_DOS_HEADER DHD = new IMAGE_DOS_HEADER();
|
||||||
IMAGE_NT_HEADERS NHD = new IMAGE_NT_HEADERS();
|
IMAGE_NT_HEADERS NHD = new IMAGE_NT_HEADERS();
|
||||||
|
|
||||||
int iPointer = 0;
|
long iPointer = 0;
|
||||||
uint uOriginal = 0;
|
uint uOriginal = 0;
|
||||||
uint uRecalculated = 0;
|
uint uRecalculated = 0;
|
||||||
uint uRet = 0;
|
uint uRet = 0;
|
||||||
|
@ -36,16 +36,23 @@ namespace Win_1337_Patch
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
BinaryReader bReader = new BinaryReader(new FileStream(sFilePath, FileMode.Open, FileAccess.Read));
|
using (BinaryReader bReader = new BinaryReader(new FileStream(sFilePath, FileMode.Open, FileAccess.Read)))
|
||||||
fBytes = bReader.ReadBytes((int)bReader.BaseStream.Length);
|
{
|
||||||
bReader.Close();
|
fBytes = bReader.ReadBytes((int)bReader.BaseStream.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
catch { }
|
|
||||||
|
|
||||||
if (fBytes.Length <= 0) { return false; }
|
if (fBytes.Length <= 0) { return false; }
|
||||||
|
|
||||||
GCHandle gHandle = GCHandle.Alloc(fBytes, GCHandleType.Pinned);
|
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));
|
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));
|
NHD = (IMAGE_NT_HEADERS)Marshal.PtrToStructure(new IntPtr(iPointer + DHD.e_lfanew), typeof(IMAGE_NT_HEADERS));
|
||||||
gHandle.Free();
|
gHandle.Free();
|
||||||
|
@ -74,17 +81,23 @@ namespace Win_1337_Patch
|
||||||
NHD.OptionalHeader.CheckSum = uRecalculated;
|
NHD.OptionalHeader.CheckSum = uRecalculated;
|
||||||
|
|
||||||
byte[] bNHD = getBytes_(NHD);
|
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);
|
Array.Copy(bNHD, 0, fBytes, DHD.e_lfanew, bNHD.Length);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
BinaryWriter bWriter = new BinaryWriter(new FileStream(sFilePath, FileMode.Open));
|
using (BinaryWriter bWriter = new BinaryWriter(new FileStream(sFilePath, FileMode.Open)))
|
||||||
bWriter.Write(fBytes);
|
{
|
||||||
bWriter.Flush();
|
bWriter.Write(fBytes);
|
||||||
bWriter.Close();
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
catch { return false; }
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue