private void ButtonPatch_Click(object sender, RoutedEventArgs e) { if (CheckRdpSession()) { DisableControls(); worker.RunWorkerAsync(argument: new object[] { true, Patcher.StringsToPatch(textBoxFind.Text, textBoxReplace.Text) }); } }
private void ButtonPatch_Click(object sender, RoutedEventArgs e) { // Stoppig: 3 * ServiceTimeout + Starting: 1 * ServiceTimeout if (CheckRdpSession($"The current remote desktop session will be disconnected and might remain unreachable for more than {4 * Patcher.ServiceTimeout} seconds. Continue?")) { DisableControls(); worker.RunWorkerAsync(argument: new object[] { true, Patcher.StringsToPatch(textBoxFind.Text, textBoxReplace.Text) }); } }
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(); }