2
0

SelectWechat.xaml.cs 5.0 KB

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