CreateWork.xaml.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. }
  94. }
  95. }