소스 검색

新增用户数和消息数统计
群聊导出支持用户名

Suxue 1 년 전
부모
커밋
ffbc855a0f
11개의 변경된 파일103개의 추가작업 그리고 12개의 파일을 삭제
  1. 5 4
      Helpers/DecryptionHelper.cs
  2. 1 1
      HtmlExport.cs
  3. 0 1
      Main.xaml.cs
  4. 1 1
      Main2.xaml.cs
  5. 5 0
      Model/WXModel.cs
  6. 1 0
      Pages/CreateWork.xaml.cs
  7. 16 2
      Pages/Workspace.xaml
  8. 23 1
      Pages/Workspace.xaml.cs
  9. 19 2
      ViewModel/WorkspaceViewModel.cs
  10. 26 0
      WXUserReader.cs
  11. 6 0
      WXWorkspace.cs

+ 5 - 4
Helpers/DecryptionHelper.cs

@@ -23,7 +23,7 @@ namespace WechatBakTool.Helpers
         const int DEFAULT_ITER = 64000;
         const int DEFAULT_PAGESIZE = 4096; //4048数据 + 16IV + 20 HMAC + 12
         const string SQLITE_HEADER = "SQLite format 3";
-        public static byte[]? GetWechatKey(string pid,bool mem_find_key,string account)
+        public static byte[]? GetWechatKey(string pid, bool mem_find_key, string account)
         {
             Process process = Process.GetProcessById(int.Parse(pid));
             ProcessModule? module = ProcessHelper.FindProcessModule(process.Id, "WeChatWin.dll");
@@ -37,7 +37,7 @@ namespace WechatBakTool.Helpers
                 return null;
             }
 
-            
+
 
             if (!mem_find_key)
             {
@@ -69,7 +69,7 @@ namespace WechatBakTool.Helpers
             else
             {
                 List<int> read = ProcessHelper.FindProcessMemory(process.Handle, module, account);
-                if(read.Count >= 2)
+                if (read.Count >= 2)
                 {
                     byte[] buffer = new byte[8];
                     int key_offset = read[1] - 64;
@@ -78,7 +78,7 @@ namespace WechatBakTool.Helpers
                         ulong addr = BitConverter.ToUInt64(buffer, 0);
 
                         byte[] key_bytes = new byte[32];
-                        if(ProcessHelper.ReadProcessMemory(process.Handle, (IntPtr)addr, key_bytes, key_bytes.Length, out _))
+                        if (ProcessHelper.ReadProcessMemory(process.Handle, (IntPtr)addr, key_bytes, key_bytes.Length, out _))
                         {
                             return key_bytes;
                         }
@@ -91,6 +91,7 @@ namespace WechatBakTool.Helpers
             }
             return null;
         }
+
         public static byte[] DecryptDB(byte[] db_file_bytes, byte[] password_bytes)
         {
             //数据库头16字节是盐值

+ 1 - 1
HtmlExport.cs

@@ -64,7 +64,7 @@ namespace WechatBakTool
 
             foreach (var msg in msgList)
             {
-                HtmlBody += string.Format("<div class=\"msg\"><p class=\"nickname\">{0} <span style=\"padding-left:10px;\">{1}</span></p>", msg.IsSender ? "我" : Session.NickName, TimeStampToDateTime(msg.CreateTime).ToString("yyyy-MM-dd HH:mm:ss"));
+                HtmlBody += string.Format("<div class=\"msg\"><p class=\"nickname\">{0} <span style=\"padding-left:10px;\">{1}</span></p>", msg.IsSender ? "我" : msg.NickName, TimeStampToDateTime(msg.CreateTime).ToString("yyyy-MM-dd HH:mm:ss"));
 
                 if (msg.Type == 1)
                     HtmlBody += string.Format("<p class=\"content\">{0}</p></div>", msg.StrContent);

+ 0 - 1
Main.xaml.cs

@@ -243,7 +243,6 @@ namespace WechatBakTool
                         }
                     }
                 }
-
             }
             
         }

+ 1 - 1
Main2.xaml.cs

@@ -74,7 +74,7 @@ namespace WechatBakTool
             UserBakConfig? config = list_workspace.SelectedItem as UserBakConfig;
             if(config == null)
             {
-                MessageBox.Show("该工作区可能有异常,请确认配置文件是否正确");
+                MainFrame.Navigate(new Uri("pack://application:,,,/Pages/Welcome.xaml?datatime=" + DateTime.Now.Ticks));
                 return;
             }
             if (!config.Decrypt)

+ 5 - 0
Model/WXModel.cs

@@ -33,6 +33,11 @@ namespace WechatBakTool.Model
         }
     }
 
+    public class WXCount
+    {
+        public int Count { get; set; }
+    }
+
     public class WXMsgGroup
     {
         [Column("StrTalker")]

+ 1 - 0
Pages/CreateWork.xaml.cs

@@ -111,6 +111,7 @@ namespace WechatBakTool.Pages
                         try
                         {
                             wXWorkspace.DecryptDB(ViewModel.SelectProcess.ProcessId, ViewModel.KeyType);
+
                             MessageBox.Show("创建工作区成功");
                             ((Main2)Window.GetWindow(this)).LoadWorkspace();
                         }

+ 16 - 2
Pages/Workspace.xaml

@@ -5,7 +5,7 @@
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
       xmlns:local="clr-namespace:WechatBakTool.Pages"
       mc:Ignorable="d" 
-      d:DesignHeight="450" d:DesignWidth="800"
+      d:DesignHeight="450" d:DesignWidth="720"
       Title="Workspace" Background="White">
     <Page.Resources>
         <Style x:Key="RepeatButtonTransparent" TargetType="{x:Type RepeatButton}">
@@ -127,8 +127,22 @@
             </ListView.Resources>
         </ListView>
         <Label Content="{Binding WXContact.NickName}" HorizontalAlignment="Left" Margin="258,21,0,0" VerticalAlignment="Top"/>
-        <ListView x:Name="list_msg" Margin="230,60,0,0" Background="Transparent" BorderThickness="0" ItemTemplate="{DynamicResource MsgText}">
+        <ListView x:Name="list_msg" Margin="230,60,0,60" Background="Transparent" BorderThickness="0,1,0,1" BorderBrush="#BB2775b6" ItemTemplate="{DynamicResource MsgText}">
             
         </ListView>
+        <Button Name="btn_export" Width="90" Height="30" Content="导出HTML" BorderBrush="Transparent" BorderThickness="0" Background="#2775b6" Foreground="White" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="20,15" Click="btn_export_Click" IsEnabled="{Binding SelectContact}">
+            <Button.Resources>
+                <Style TargetType="{x:Type Border}">
+                    <Setter Property="CornerRadius" Value="3"/>
+                </Style>
+            </Button.Resources>
+        </Button>
+        <Button x:Name="btn_open_workspace" Width="90" Height="30" Content="打开文件夹" BorderBrush="Transparent" BorderThickness="0" Background="#2775b6" Foreground="White" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,380,15" Click="btn_open_workspace_Click">
+            <Button.Resources>
+                <Style TargetType="{x:Type Border}">
+                    <Setter Property="CornerRadius" Value="3"/>
+                </Style>
+            </Button.Resources>
+        </Button>
     </Grid>
 </Page>

+ 23 - 1
Pages/Workspace.xaml.cs

@@ -16,7 +16,7 @@ using System.Windows.Input;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
-using System.Windows.Shapes;
+using WechatBakTool.Interface;
 using WechatBakTool.Model;
 using WechatBakTool.ViewModel;
 
@@ -83,5 +83,27 @@ namespace WechatBakTool.Pages
 
             Debug.WriteLine(ViewModel.SearchString);
         }
+
+        private void btn_export_Click(object sender, RoutedEventArgs e)
+        {
+            if(ViewModel.WXContact == null || UserReader == null)
+            {
+                MessageBox.Show("请选择联系人", "错误");
+                return;
+            }
+            IExport export = new HtmlExport();
+            export.InitTemplate(ViewModel.WXContact);
+            export.SetMsg(UserReader, ViewModel.WXContact);
+            export.SetEnd();
+            //string path = UserReader.GetSavePath(wXContact);
+            string path = Path.Combine(Main2.CurrentUserBakConfig!.UserWorkspacePath, ViewModel.WXContact.UserName + ".html");
+            export.Save(path);
+            MessageBox.Show("导出完成");
+        }
+
+        private void btn_open_workspace_Click(object sender, RoutedEventArgs e)
+        {
+            Process.Start("explorer.exe ", Main2.CurrentUserBakConfig!.UserWorkspacePath);
+        }
     }
 }

+ 19 - 2
ViewModel/WorkspaceViewModel.cs

@@ -11,9 +11,26 @@ namespace WechatBakTool.ViewModel
 {
     partial class WorkspaceViewModel : ObservableObject
     {
-        [ObservableProperty]
-        private WXContact? wXContact;
+        private WXContact? wXContact = null;
+        public WXContact? WXContact {
+            get { return wXContact; }
+            set {  
+                wXContact = value;
+                OnPropertyChanged("WXContact");
+                OnPropertyChanged("SelectContact");
+            }
+        }
 
+        public bool SelectContact
+        {
+            get
+            {
+                if (WXContact == null)
+                    return false;
+                else
+                    return true;
+            }
+        }
         [ObservableProperty]
         private ObservableCollection<WXContact>? contacts;
 

+ 26 - 0
WXUserReader.cs

@@ -84,6 +84,32 @@ namespace WechatBakTool
             }
             return null;
         }
+
+        public int[] GetWXCount()
+        {
+            SQLiteConnection con = DBInfo["MicroMsg"];
+            if (con == null)
+                return new int[] { 0, 0 };
+
+            string query = @"select count(*) as count from contact where type != 4";
+            int userCount = con.Query<WXCount>(query)[0].Count;
+
+            int msgCount = 0;
+            for (int i = 0; i <= 99; i++)
+            {
+                if (DBInfo.ContainsKey("MSG" + i.ToString()))
+                {
+                    con = DBInfo["MSG" + i.ToString()];
+                    if (con == null)
+                        return new int[] { userCount, 0 };
+
+                    query = "select count(*) as count from MSG";
+                    msgCount += con.Query<WXCount>(query)[0].Count;
+                }
+            }
+            return new int[] { userCount, msgCount };
+        }
+
         public ObservableCollection<WXContact> GetWXContacts(string? name = null,bool all = false)
         {
             SQLiteConnection con = DBInfo["MicroMsg"];

+ 6 - 0
WXWorkspace.cs

@@ -10,6 +10,7 @@ using System.Threading.Tasks;
 using System.Windows;
 using WechatBakTool.Helpers;
 using WechatBakTool.Model;
+using WechatBakTool.Pages;
 
 namespace WechatBakTool
 {
@@ -48,6 +49,11 @@ namespace WechatBakTool
 
                 WechatDBHelper.DecryUserData(key, source, to);
                 UserBakConfig.Decrypt = true;
+
+                WXUserReader reader = new WXUserReader(UserBakConfig);
+                int[] count = reader.GetWXCount();
+                UserBakConfig.Friends_Number = count[0].ToString();
+                UserBakConfig.Msg_Number = count[1].ToString();
                 SaveConfig(UserBakConfig);
             }
         }