Ejemplo n.º 1
0
        public MainWindow()
        {
            worker.WorkerReportsProgress = true;
            worker.DoWork             += worker_DoWork;
            worker.RunWorkerCompleted += worker_RunWorkerCompleted;
            worker.ProgressChanged    += worker_ProgressChanged;
            InitializeComponent();
            // Get Assemblyversion
            string version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

            // Remove last digit of Assemblyversion, except it is not equal to 0
            version = System.Text.RegularExpressions.Regex.Replace(version, @"(\d\.\d\.\d)(\.0$)", "$1");
            // Update the link text
            System.Windows.Documents.Run link = (System.Windows.Documents.Run)HyperlinkPatcherVersion.Inlines.FirstInline;
            link.Text = String.Format("Patcher version {0}", version);
            patcher   = new Patcher();
            if (patcher.AllowRdp)
            {
                radioButtonEnableRdp.IsChecked = true;
            }
            else
            {
                radioButtonDisableRdp.IsChecked = true;
            }
            if (patcher.EnableNla)
            {
                checkBoxNla.IsChecked = true;
            }
            else
            {
                checkBoxNla.IsChecked = false;
            }
            if (patcher.AllowMulti)
            {
                radioButtonEnableMulti.IsChecked = true;
            }
            else
            {
                radioButtonDisableMulti.IsChecked = true;
            }
            if (patcher.AllowBlank)
            {
                radioButtonEnableBlank.IsChecked = true;
            }
            else
            {
                radioButtonDisableBlank.IsChecked = true;
            }
            radioButtonAutoMode.IsChecked = true;
            CheckStatus(false);
            formInitialized = true;
        }
Ejemplo n.º 2
0
 public MainWindow()
 {
     worker.WorkerReportsProgress = true;
     worker.DoWork             += worker_DoWork;
     worker.RunWorkerCompleted += worker_RunWorkerCompleted;
     worker.ProgressChanged    += worker_ProgressChanged;
     InitializeComponent();
     patcher = new Patcher();
     if (patcher.AllowRdp)
     {
         radioButtonEnableRdp.IsChecked = true;
     }
     else
     {
         radioButtonDisableRdp.IsChecked = true;
     }
     if (patcher.EnableNla)
     {
         checkBoxNla.IsChecked = true;
     }
     else
     {
         checkBoxNla.IsChecked = false;
     }
     if (patcher.AllowMulti)
     {
         radioButtonEnableMulti.IsChecked = true;
     }
     else
     {
         radioButtonDisableMulti.IsChecked = true;
     }
     if (patcher.AllowBlank)
     {
         radioButtonEnableBlank.IsChecked = true;
     }
     else
     {
         radioButtonDisableBlank.IsChecked = true;
     }
     radioButtonAutoMode.IsChecked = true;
     CheckStatus(false);
     formInitialized = true;
 }
Ejemplo n.º 3
0
        private void CheckStatus(bool quickCheck)
        {
            if (!quickCheck)
            {
                textBoxMessages.Clear();
            }
            version = patcher.GetVersion();
            textBlockVersion.Text = "Version: " + version;
            if (radioButtonAutoMode.IsChecked == true)
            {
                if (!quickCheck)
                {
                    // Read patches from file

                    try
                    {
                        List <object> res = patcher.ReadPatchfile();
                        patches = (List <object>)res[0];
                        List <string> warnings = (List <string>)res[1];
                        foreach (string warning in warnings)
                        {
                            AddMessage("Warning: " + warning);
                        }
                        readfileSuccess = true;
                    }
                    catch (System.IO.FileNotFoundException)
                    {
                        readfileSuccess = false;
                        AddMessage(String.Format("Error: patchfile '{0}' not found, prepare '{0}' or enter patches manually", patcher.Patchfile));
                    }
                    catch (Exception exception)
                    {
                        readfileSuccess = false;
                        AddMessage(String.Format("Error: Reading patchfile '{0}' failed, fix '{0}' or enter patches manually ({1})", patcher.Patchfile, exception.Message.ToString()));
                    }
                }

                List <object> matchingPatch    = new List <object>();
                ulong         patchedMatches   = 0;
                ulong         unpatchedMatches = 0;
                foreach (List <Object> patch in patches)
                {
                    Patcher.Status patchStatus = patcher.CheckStatus((List <object>)patch[0]);
                    if (patchStatus != Unkown)
                    {
                        if (patchStatus == Patched)
                        {
                            patchedMatches++;
                            AddMessage(String.Format("Patch on line {0} in '{1}' indicates patched termsrv.dll", (ulong)patch[1], patcher.Patchfile));
                        }
                        else
                        {
                            // Remember the patch to use it for patching as long as it remains the only match
                            matchingPatch = patch;
                            unpatchedMatches++;
                            AddMessage(String.Format("Patch on line {0} in '{1}' indicates unpatched termsrv.dll", (ulong)patch[1], patcher.Patchfile));
                        }
                    }
                }
                textBoxFind.Text    = "";
                textBoxReplace.Text = "";
                if (readfileSuccess)
                {
                    // Do not complain here again for missing patches if patch file reading skipped or failed (failed reading already shows other warnings)

                    if (unpatchedMatches == 0 && patchedMatches == 0)
                    {
                        status = Unkown;
                        AddMessage(String.Format("Error: No matching patch for termsrv.dll found in patchfile '{0}', edit '{0}' or enter patches manually", patcher.Patchfile));
                    }
                    else if (unpatchedMatches == 1 && patchedMatches == 0)
                    {
                        // A single match for the unpatched status allows to patch termsrv.dll

                        status = Unpatched;
                        AddMessage(String.Format("Automatic patching enabled: Matching patch for termsrv.dll in patchfile '{0}' found on line {1}", patcher.Patchfile, (ulong)matchingPatch[1]));
                        foreach (List <object> subpatch in (List <object>)matchingPatch[0])
                        {
                            if (textBoxFind.Text != "")
                            {
                                textBoxFind.Text    += " | ";
                                textBoxReplace.Text += " | ";
                            }
                            textBoxFind.Text    += Patcher.IntArrToString((int[])subpatch[0]);
                            textBoxReplace.Text += Patcher.ByteArrToString((byte[])subpatch[1]);
                        }
                    }
                    else if (unpatchedMatches > 1 && patchedMatches == 0)
                    {
                        // More than one match for unpatched status

                        status = Unkown;
                        AddMessage(String.Format("Error: Multiple patches for termsrv.dll found in patchfile '{0}', edit '{0}' or enter patches manually", patcher.Patchfile));
                    }
                    else if (unpatchedMatches == 0 && patchedMatches > 0)
                    {
                        // One or more matches for the patched status is fine for the various Windows 10 termsrv.dll versions

                        status = Patched;
                    }
                    else if (unpatchedMatches > 0 && patchedMatches > 0)
                    {
                        status = Unkown;
                        AddMessage(String.Format("Error: Contradicting patches for termsrv.dll found in patchfile '{0}', edit '{0}' or enter patches manually", patcher.Patchfile));
                    }
                }
                else
                {
                    status = Unkown;
                }
            }
            else
            {
                try
                {
                    status = patcher.CheckStatus(Patcher.StringsToPatch(textBoxFind.Text, textBoxReplace.Text));
                    if (status == Unkown)
                    {
                        AddMessage("Error: No match in termsrv.dll found for manual patch patterns");
                    }
                    else
                    if (!quickCheck)
                    {
                        {
                            AddMessage("Manual patching enabled: Match in termsrv.dll found for manual patch patterns");
                        }
                    }
                }
                catch (Exception exception)
                {
                    status = Unkown;
                    AddMessage(String.Format("Error: {0}", exception.Message.ToString()));
                }
            }
            switch (status)
            {
            case Patched:
                textBlockStatus.Text = "Status: " + Patched;
                break;

            case Unpatched:
                textBlockStatus.Text = "Status: " + Unpatched;
                break;

            case Unkown:
                textBlockStatus.Text = "Status: " + Unkown;
                break;
            }
            if (patcher.BackupAvailable())
            {
                textBlockBackupStatus.Text = "Backup: Available";
                AddMessage($"Backup: {patcher.GetBackupPath()}");
            }
            else
            {
                textBlockBackupStatus.Text = "Backup: Not available";
            }
            SetControls();
        }