SelectWechat.xaml.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Management;
  7. using System.Text;
  8. using System.Text.RegularExpressions;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Shapes;
  18. using WechatPCMsgBakTool.Helpers;
  19. using WechatPCMsgBakTool.Model;
  20. namespace WechatPCMsgBakTool
  21. {
  22. /// <summary>
  23. /// SelectWechat.xaml 的交互逻辑
  24. /// </summary>
  25. public partial class SelectWechat : Window
  26. {
  27. List<ProcessInfo> processInfos = new List<ProcessInfo>();
  28. public ProcessInfo? SelectProcess { get; set; } = null;
  29. public SelectWechat()
  30. {
  31. InitializeComponent();
  32. //GetWechatProcess();
  33. GetWechatProcessInfos();
  34. list_process.ItemsSource = processInfos;
  35. }
  36. private void GetWechatProcessInfos()
  37. {
  38. processInfos.Clear();
  39. Process[] processes = Process.GetProcessesByName("wechat");
  40. foreach(Process p in processes)
  41. {
  42. var h_list = ProcessHelper.GetHandles(p);
  43. foreach(var h in h_list)
  44. {
  45. if(h.ObjectType == 40)
  46. {
  47. string name = ProcessHelper.FindHandleName(h, p);
  48. if (name.Contains("\\MicroMsg.db") && name.Substring(name.Length - 3, 3) == ".db")
  49. {
  50. ProcessInfo info = new ProcessInfo();
  51. info.ProcessId = p.Id.ToString();
  52. info.ProcessName = p.ProcessName;
  53. info.DBPath = DevicePathMapper.FromDevicePath(name);
  54. processInfos.Add(info);
  55. }
  56. }
  57. }
  58. }
  59. }
  60. public void GetWechatProcess()
  61. {
  62. Process p = new Process();
  63. p.StartInfo.FileName = "tools/handle64.exe";
  64. p.StartInfo.Arguments = "-p wechat.exe";
  65. p.StartInfo.UseShellExecute = false;
  66. p.StartInfo.CreateNoWindow = true;
  67. p.StartInfo.RedirectStandardOutput = true;
  68. p.Start();
  69. string i = p.StandardOutput.ReadToEnd();
  70. if (i.Contains("SYSINTERNALS SOFTWARE LICENSE TERMS"))
  71. {
  72. MessageBox.Show("请先同意Handle64的使用协议,同意后关闭弹窗重新打开新增工作区即可");
  73. Process p1 = new Process();
  74. p1.StartInfo.FileName = "tools/handle64.exe";
  75. p1.StartInfo.Arguments = "-p wechat.exe";
  76. p1.Start();
  77. }
  78. string[] lines = i.Split(new string[] { "\r\n" }, StringSplitOptions.None);
  79. bool hitFind = false;
  80. ProcessInfo processInfo = new ProcessInfo();
  81. foreach (string line in lines)
  82. {
  83. if (line.Length < 6)
  84. continue;
  85. if (line.Substring(0, 6).ToLower() == "wechat")
  86. {
  87. hitFind = true;
  88. processInfo = new ProcessInfo();
  89. string[] lineInfo = line.Split(' ');
  90. processInfo.ProcessName = lineInfo[0];
  91. processInfo.ProcessId = lineInfo[2];
  92. }
  93. if (hitFind)
  94. {
  95. if (line.Substring(line.Length - 11, 11) == "MicroMsg.db")
  96. {
  97. Regex regex = new Regex("[a-zA-Z]:\\\\([a-zA-Z0-9() ]*\\\\)*\\w*.*\\w*");
  98. string path = regex.Match(line).Value;
  99. processInfo.DBPath = path;
  100. processInfos.Add(processInfo);
  101. hitFind = false;
  102. }
  103. }
  104. }
  105. list_process.ItemsSource = processInfos;
  106. }
  107. private void list_process_SelectionChanged(object sender, SelectionChangedEventArgs e)
  108. {
  109. SelectProcess = list_process.SelectedItem as ProcessInfo;
  110. }
  111. private void btn_close_Click(object sender, RoutedEventArgs e)
  112. {
  113. Close();
  114. }
  115. }
  116. }