2
0

CreateWork.xaml.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. using WechatBakTool.Helpers;
  18. using WechatBakTool.Model;
  19. using WechatBakTool.ViewModel;
  20. namespace WechatBakTool.Pages
  21. {
  22. /// <summary>
  23. /// CreateWork.xaml 的交互逻辑
  24. /// </summary>
  25. public partial class CreateWork : Page
  26. {
  27. private CreateWorkViewModel ViewModel = new CreateWorkViewModel();
  28. public CreateWork()
  29. {
  30. DataContext = ViewModel;
  31. InitializeComponent();
  32. GetWechatProcessInfos();
  33. }
  34. private void GetWechatProcessInfos()
  35. {
  36. ViewModel.ProcessInfos.Clear();
  37. Process[] processes = Process.GetProcessesByName("wechat");
  38. foreach (Process p in processes)
  39. {
  40. var lHandles = NativeAPIHelper.GetHandleInfoForPID((uint)p.Id);
  41. foreach (var h in lHandles)
  42. {
  43. string name = NativeAPIHelper.FindHandleName(h, p);
  44. if (name != "")
  45. {
  46. // 预留handle log
  47. if (File.Exists("handle.log"))
  48. {
  49. File.AppendAllText("handle.log", string.Format("{0}|{1}|{2}|{3}\n", p.Id, h.ObjectTypeIndex, h.HandleValue, name));
  50. }
  51. if (name.Contains("\\MicroMsg.db") && name.Substring(name.Length - 3, 3) == ".db")
  52. {
  53. ProcessInfo info = new ProcessInfo();
  54. info.ProcessId = p.Id.ToString();
  55. info.ProcessName = p.ProcessName;
  56. info.DBPath = DevicePathMapper.FromDevicePath(name);
  57. ViewModel.ProcessInfos.Add(info);
  58. }
  59. }
  60. }
  61. }
  62. }
  63. private void list_process_SelectionChanged(object sender, SelectionChangedEventArgs e)
  64. {
  65. if (ViewModel.SelectProcess != null)
  66. {
  67. string[] name_raw = ViewModel.SelectProcess.DBPath.Split("\\");
  68. ViewModel.UserName = name_raw[name_raw.Length - 3];
  69. FileInfo fileInfo = new FileInfo(ViewModel.SelectProcess.DBPath);
  70. DirectoryInfo msgParent = fileInfo.Directory!.Parent!;
  71. DirectoryInfo[] accounts = msgParent.GetDirectories();
  72. DirectoryInfo? newUserName = null;
  73. foreach ( DirectoryInfo account in accounts )
  74. {
  75. if(account.Name.Contains("account_")) {
  76. if(newUserName == null)
  77. newUserName = account;
  78. else
  79. {
  80. if (newUserName.LastWriteTime < account.LastWriteTime)
  81. newUserName = account;
  82. }
  83. }
  84. }
  85. if(newUserName != null)
  86. {
  87. ViewModel.UserName = newUserName.Name.Split("_")[1];
  88. }
  89. }
  90. }
  91. private void btn_create_worksapce_Click(object sender, RoutedEventArgs e)
  92. {
  93. if(ViewModel.KeyType != -1)
  94. {
  95. if (ViewModel.SelectProcess != null)
  96. {
  97. string path = ViewModel.SelectProcess.DBPath.Replace("\\Msg\\MicroMsg.db", "");
  98. try
  99. {
  100. //创建工作区
  101. WXWorkspace wXWorkspace = new WXWorkspace(path, ViewModel.UserName);
  102. //DB移动
  103. wXWorkspace.MoveDB();
  104. //开始解密数据库
  105. try
  106. {
  107. wXWorkspace.DecryptDB(ViewModel.SelectProcess.ProcessId, ViewModel.KeyType);
  108. MessageBox.Show("创建工作区成功");
  109. ((Main2)Window.GetWindow(this)).LoadWorkspace();
  110. }
  111. catch (Exception ex)
  112. {
  113. MessageBox.Show(ex.Message);
  114. }
  115. }
  116. catch (Exception)
  117. {
  118. MessageBox.Show("创建工作区失败,请检查路径是否正确");
  119. }
  120. }
  121. }
  122. else
  123. {
  124. MessageBox.Show("请选择Key获取方式", "错误");
  125. }
  126. }
  127. }
  128. }