Jelajahi Sumber

新增部分消息类型容错
新增已删除联系人记录导出

Suxue 1 tahun lalu
induk
melakukan
3dfb81b990

+ 25 - 19
Export/HtmlExport.cs

@@ -12,6 +12,7 @@ using Newtonsoft.Json;
 using WechatBakTool.ViewModel;
 using System.Security.Policy;
 using System.Windows;
+using System.Xml.Linq;
 
 namespace WechatBakTool.Export
 {
@@ -157,31 +158,38 @@ namespace WechatBakTool.Export
                                         }
 
                                         HtmlBody += string.Format("<p class=\"content\">{0}</p>", title);
-                                        findNode = xmlObj.DocumentElement.SelectNodes("/msg/appmsg/recorditem");
-                                        if (findNode != null)
+                                        try
                                         {
-                                            if (findNode.Count > 0)
+                                            findNode = xmlObj.DocumentElement.SelectNodes("/msg/appmsg/recorditem");
+                                            if (findNode != null)
                                             {
-                                                XmlDocument itemObj = new XmlDocument();
-                                                itemObj.LoadXml(findNode[0]!.InnerText);
-                                                XmlNodeList? itemNode = itemObj.DocumentElement.SelectNodes("/recordinfo/datalist/dataitem");
-                                                if (itemNode.Count > 0)
+                                                if (findNode.Count > 0)
                                                 {
-                                                    foreach (XmlNode node in itemNode)
+                                                    XmlDocument itemObj = new XmlDocument();
+                                                    itemObj.LoadXml(findNode[0]!.InnerText);
+                                                    XmlNodeList? itemNode = itemObj.DocumentElement.SelectNodes("/recordinfo/datalist/dataitem");
+                                                    if (itemNode.Count > 0)
                                                     {
-                                                        string nodeMsg;
-                                                        string name = node["sourcename"].InnerText;
-                                                        if (node.Attributes["datatype"].InnerText == "1")
-                                                            nodeMsg = node["datadesc1"].InnerText;
-                                                        else if (node.Attributes["datatype"].InnerText == "2")
-                                                            nodeMsg = "不支持的消息";
-                                                        else
-                                                            nodeMsg = node["datatitle"].InnerText;
-                                                        HtmlBody += string.Format("<p class=\"content\">{0}:{1}</p>", name, nodeMsg);
+                                                        foreach (XmlNode node in itemNode)
+                                                        {
+                                                            string nodeMsg;
+                                                            string name = node["sourcename"].InnerText;
+                                                            if (node.Attributes["datatype"].InnerText == "1")
+                                                                nodeMsg = node["datadesc1"].InnerText;
+                                                            else if (node.Attributes["datatype"].InnerText == "2")
+                                                                nodeMsg = "不支持的消息";
+                                                            else
+                                                                nodeMsg = node["datatitle"].InnerText;
+                                                            HtmlBody += string.Format("<p class=\"content\">{0}:{1}</p>", name, nodeMsg);
+                                                        }
                                                     }
                                                 }
                                             }
                                         }
+                                        catch
+                                        {
+                                            HtmlBody += string.Format("<p class=\"content\">{0}</p>", "解析异常");
+                                        }
                                     }
                                 }
                             }
@@ -234,8 +242,6 @@ namespace WechatBakTool.Export
                                                 HtmlBody += string.Format("<p class=\"content\">未知的引用消息</p>");
                                             }
                                         }
-                                            
-                                        
                                     }
                                 }
                             }

+ 1 - 0
Model/WXModel.cs

@@ -165,6 +165,7 @@ namespace WechatBakTool.Model
         public string LastMsg { get; set; } = "";
         public int FileCount { get; set; } = 1;
         public string AvatarString { get; set; } = "";
+        public bool Hidden { get; set; } = false;
     }
     [Table("Contact")]
     public class WXContact

+ 1 - 1
Pages/CreateWork.xaml

@@ -39,7 +39,7 @@
         </Button>
         <Label Margin="210,350,0,0" Content="其他选项:" FontWeight="Bold" HorizontalAlignment="Left" VerticalAlignment="Top"/>
         <CheckBox Margin="215,380,0,0" Content="打包资源文件夹(功能规划中)" IsEnabled="False" HorizontalAlignment="Left" VerticalAlignment="Top" />
-        <CheckBox Margin="215,405,0,0" Content="手动模式(功能规划中)" IsEnabled="False" HorizontalAlignment="Left" VerticalAlignment="Top" />
+        <CheckBox Name="cb_manual" Checked="cb_manual_Checked"  Margin="215,405,0,0" Content="手动模式" Visibility="Visible" HorizontalAlignment="Left" VerticalAlignment="Top" />
         <Label Name="lab_status" Content="{Binding LabelStatus}" HorizontalAlignment="Left" Margin="30,450,0,0" VerticalAlignment="Top"/>
     </Grid>
 </Page>

+ 21 - 0
Pages/CreateWork.xaml.cs

@@ -97,6 +97,7 @@ namespace WechatBakTool.Pages
         private void btn_create_worksapce_Click(object sender, RoutedEventArgs e)
         {
             ViewModel.IsEnable = false;
+
             Task.Run(() => {
                 if (ViewModel.KeyType != -1)
                 {
@@ -147,5 +148,25 @@ namespace WechatBakTool.Pages
                 ViewModel.IsEnable = true;
             });
         }
+
+        private void cb_manual_Checked(object sender, RoutedEventArgs e)
+        {
+            MessageBox.Show("该功能仅限用于网络安全研究用途使用,红队同学请在合规授权下进行相关操作","重要提醒!!!!!!!!!");
+            if (MessageBox.Show("我确认获取到合规授权,仅用于网络安全用途使用", "信息确认", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
+            {
+                if (File.Exists("auth.txt"))
+                {
+
+                }
+                else
+                {
+                    MessageBox.Show("未完成声明文件,请先确认声明", "错误");
+                }
+            }
+            else
+            {
+                cb_manual.IsChecked = false;
+            }
+        }
     }
 }

+ 1 - 1
Pages/Workspace.xaml

@@ -225,7 +225,7 @@
                 </Style>
             </Button.Resources>
         </Button>
-        <Button x:Name="btn_pre_emoji" Width="80" Height="30" Style="{StaticResource  ButtonStyle}" Content="表情预下载" BorderBrush="Transparent" BorderThickness="0" Background="#2775b6" Foreground="White" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,405,292,0" IsEnabled="{Binding SelectContact}" Click="btn_pre_emoji_Click" >
+        <Button x:Name="btn_pre_emoji" Width="80" Height="30" Style="{StaticResource  ButtonStyle}" Content="表情预下载" BorderBrush="Transparent" BorderThickness="0" Background="#2775b6" Foreground="White" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,292,15" IsEnabled="{Binding SelectContact}" Click="btn_pre_emoji_Click" >
             <Button.Resources>
                 <Style TargetType="{x:Type Border}">
                     <Setter Property="CornerRadius" Value="3"/>

+ 20 - 4
Pages/Workspace.xaml.cs

@@ -92,6 +92,21 @@ namespace WechatBakTool.Pages
                 findName = "";
 
             ViewModel.Contacts = UserReader.GetWXContacts(findName);
+            // 保底回落搜索已删除人员
+            if(ViewModel.Contacts.Count == 0)
+            {
+                var i = UserReader.GetWXMsgs(txt_find_user.Text);
+                if (i != null)
+                {
+                    var g = i.GroupBy(x => x.StrTalker);
+                    ViewModel.Contacts = new System.Collections.ObjectModel.ObservableCollection<WXContact>();
+                    foreach (var x in g)
+                    {
+                        string name = x.Key;
+                        ViewModel.Contacts.Add(new WXContact() { UserName = name, NickName = name });
+                    }
+                }
+            }
         }
 
         private void txt_find_user_GotFocus(object sender, RoutedEventArgs e)
@@ -265,14 +280,14 @@ namespace WechatBakTool.Pages
 
         private void btn_pre_emoji_Click(object sender, RoutedEventArgs e)
         {
-            /*
             if(UserReader != null && ViewModel.WXContact != null)
             {
                 Task.Run(() => {
                     UserReader.PreDownloadEmoji(ViewModel.WXContact.UserName);
                     MessageBox.Show("用户所有表情预下载完毕");
                 });
-            }*/
+            }
+            /*
             if (UserReader != null && ViewModel.WXContact != null)
             {
                 Task.Run(() =>
@@ -292,7 +307,7 @@ namespace WechatBakTool.Pages
                     {
                         m.BytesExtra = null;
                         tmp.Add(m);
-                        if (all % 20000 == 0)
+                        if (all % 10000 == 0)
                         {
                             File.WriteAllText(ViewModel.WXContact.UserName + "-" + i.ToString() + ".json", string.Format("showMsg({0})", JsonConvert.SerializeObject(tmp)));
                             tmp.Clear();
@@ -309,7 +324,6 @@ namespace WechatBakTool.Pages
                         html.LastMsg = ViewModel.WXContact.LastMsg;
                         if (ViewModel.WXContact.Avatar != null)
                         {
-
                             using (var ms = new MemoryStream())
                             {
                                 ViewModel.WXContact.Avatar.StreamSource.CopyTo(ms);
@@ -321,11 +335,13 @@ namespace WechatBakTool.Pages
                         html.FileCount = i;
                         users.Add(html);
                     }
+
                     File.WriteAllText(ViewModel.WXContact.UserName + "-" + i.ToString() + ".json", string.Format("showMsg({0})", JsonConvert.SerializeObject(tmp)));
                     File.WriteAllText("WXContact.json", string.Format("getUser({0})", JsonConvert.SerializeObject(users)));
                     MessageBox.Show("json已导出");
                 });
             }
+            */
         }
     }
 }

+ 4 - 0
WXUserReader.cs

@@ -371,6 +371,10 @@ namespace WechatBakTool
                             w.StrTalker = contact.UserName;
                         }
                     }
+                    else
+                    {
+                        w.NickName = uid;
+                    }
 
                     // 群聊处理
                     if (uid.Contains("@chatroom"))

+ 14 - 4
WXWorkspace.cs

@@ -18,7 +18,7 @@ namespace WechatBakTool
     {
         private UserBakConfig UserBakConfig = new UserBakConfig();
         public WXWorkspace(string path,string account = "") {
-            string checkResult = Init(path, account);
+            string checkResult = Init(path, false, account);
             if (checkResult != "")
                 new Exception(checkResult);
         }
@@ -28,7 +28,7 @@ namespace WechatBakTool
             UserBakConfig = userBakConfig;
         }
 
-        public void DecryptDB(string pid,int type,CreateWorkViewModel viewModel)
+        public void DecryptDB(string pid,int type,CreateWorkViewModel viewModel,string pwd = "")
         {
             if (UserBakConfig == null)
             {
@@ -39,7 +39,17 @@ namespace WechatBakTool
             {
                 byte[]? key = null;
                 viewModel.LabelStatus = "正在获取秘钥,需要1 - 10秒左右";
-                key = DecryptionHelper.GetWechatKey(pid, type, UserBakConfig.Account);
+                if(pwd == "")
+                    key = DecryptionHelper.GetWechatKey(pid, type, UserBakConfig.Account);
+                else
+                {
+                    key = new byte[pwd.Length / 2];
+                    for(int i = 0;i<pwd.Length / 2; i++)
+                    {
+                        key[i] = Convert.ToByte(pwd.Substring(i * 2, 2), 16);
+                    }
+                }
+
                 if (key == null)
                 {
                     throw new Exception("获取到的密钥为空,获取失败");
@@ -104,7 +114,7 @@ namespace WechatBakTool
                 }
             }
         }
-        private string Init(string path,string account = "")
+        private string Init(string path,bool manual,string account = "")
         {
             string curPath = AppDomain.CurrentDomain.BaseDirectory;
             string md5 = GetMd5Hash(path);