Advertisement
Guest User

Untitled

a guest
Sep 5th, 2016
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11.  
  12. namespace win10fix2
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         static bool ShouldDoBackups = true;
  17.         static bool ShouldShowPrompts = true;
  18.  
  19.         public Form1()
  20.         {
  21.             InitializeComponent();
  22.         }
  23.  
  24.         static void DirSearch(string sDir)
  25.         {
  26.             foreach (string f in Directory.GetFiles(sDir))
  27.             {
  28.                 if (Path.GetExtension(f) == ".exe")
  29.                 {
  30.                     if (ShouldShowPrompts)
  31.                     {
  32.                         DialogResult dr = MessageBox.Show("Fix this file?\n" + f, "", MessageBoxButtons.YesNo);
  33.                         if (dr == DialogResult.Yes)
  34.                         {
  35.                             BackupAndFixFile(f);
  36.                         }
  37.                     }
  38.                     else
  39.                     {
  40.                         BackupAndFixFile(f);
  41.                     }
  42.                 }
  43.             }
  44.             foreach (string d in Directory.GetDirectories(sDir))
  45.             {
  46.                 DirSearch(d);
  47.             }
  48.         }
  49.  
  50.         static void BackupAndFixFile(String fileName)
  51.         {
  52.             if (ShouldDoBackups)
  53.             {
  54.                 BackupFile(fileName);
  55.             }
  56.             FixFile(fileName);
  57.         }
  58.  
  59.         static void BackupFile(String fileName)
  60.         {
  61.             String newFileName = Path.GetFileNameWithoutExtension(fileName) + " backup before win10 fix" + Path.GetExtension(fileName);
  62.             newFileName = Path.Combine(Path.GetDirectoryName(fileName), newFileName);
  63.             try {
  64.                 File.Copy(fileName, newFileName);
  65.             }
  66.             catch
  67.             {
  68.  
  69.             }
  70.         }
  71.  
  72.         static void FixFile(String fileName)
  73.         {
  74.             try {
  75.                 using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite))
  76.                 {
  77.                     stream.Position = 0x116;
  78.                     stream.WriteByte(0xAE);
  79.                 }
  80.             }
  81.             catch
  82.             {
  83.  
  84.             }
  85.         }
  86.  
  87.         private void button1_Click(object sender, EventArgs e)
  88.         {
  89.             ShouldDoBackups = checkBox1.Checked;
  90.             ShouldShowPrompts = checkBox2.Checked;
  91.             DirSearch(Directory.GetCurrentDirectory());
  92.             this.Close();
  93.         }
  94.  
  95.         private void button2_Click(object sender, EventArgs e)
  96.         {
  97.             OpenFileDialog ofd = new OpenFileDialog();
  98.             ofd.Filter = "Executables (.txt)|*.exe|All Files (*.*)|*.*";
  99.             DialogResult dr = ofd.ShowDialog();
  100.             if (dr == DialogResult.OK)
  101.             {
  102.                 BackupAndFixFile(ofd.FileName);
  103.             }
  104.         }
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement