Skip to content

Commit

Permalink
v0.9.7.1 Release!
Browse files Browse the repository at this point in the history
1.优化批量导出时的体验。现在起记录为空的用户将不会被导出。
2.修复批量导出的部分问题。
  • Loading branch information
SuxueCode committed Jan 10, 2024
1 parent affafe3 commit 76def41
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Export/ExportInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace WechatBakTool.Export
public interface IExport
{
void InitTemplate(WXContact session,string path);
void SetMsg(WXUserReader reader, WXContact session, WorkspaceViewModel viewModel);
bool SetMsg(WXUserReader reader, WXContact session, WorkspaceViewModel viewModel);
void SetEnd();
void Save(string path = "");
}
Expand Down
12 changes: 8 additions & 4 deletions Export/HtmlExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public void InitTemplate(WXSession session)

HtmlBody += string.Format("<div class=\"msg\"><p class=\"nickname\"><b>与 {0}({1}) 的聊天记录</b></p>", Session.NickName, Session.UserName);
HtmlBody += string.Format("<div class=\"msg\"><p class=\"nickname\"><b>导出时间:{0}</b></p><hr/>", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
File.WriteAllText(Path, HtmlBody);
}

public void InitTemplate(WXContact contact, string p)
Expand All @@ -51,7 +50,7 @@ public void SetEnd()
File.AppendAllText(Path, HtmlBody);
}

public void SetMsg(WXUserReader reader, WXContact contact,WorkspaceViewModel viewModel)
public bool SetMsg(WXUserReader reader, WXContact contact,WorkspaceViewModel viewModel)
{
if (Session == null)
throw new Exception("请初始化模版:Not Use InitTemplate");
Expand All @@ -60,11 +59,16 @@ public void SetMsg(WXUserReader reader, WXContact contact,WorkspaceViewModel vie
if (msgList == null)
throw new Exception("获取消息失败,请确认数据库读取正常");

if(msgList.Count == 0)
{
viewModel.ExportCount = "没有消息,忽略";
return false;
}
msgList.Sort((x, y) => x.CreateTime.CompareTo(y.CreateTime));

bool err = false;
int msgCount = 0;
HtmlBody = "";

StreamWriter streamWriter = new StreamWriter(Path, true);
foreach (var msg in msgList)
{
Expand Down Expand Up @@ -340,7 +344,7 @@ public void SetMsg(WXUserReader reader, WXContact contact,WorkspaceViewModel vie
}
streamWriter.Close();
streamWriter.Dispose();
return true;
}
private static DateTime TimeStampToDateTime(long timeStamp, bool inMilli = false)
{
Expand Down
3 changes: 2 additions & 1 deletion Export/TXTExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void IExport.SetEnd()

}

public void SetMsg(WXUserReader reader, WXContact session, WorkspaceViewModel viewModel)
public bool SetMsg(WXUserReader reader, WXContact session, WorkspaceViewModel viewModel)
{
if (Contact == null)
throw new Exception("请初始化模版:Not Use InitTemplate");
Expand Down Expand Up @@ -146,6 +146,7 @@ public void SetMsg(WXUserReader reader, WXContact session, WorkspaceViewModel vi
msgCount++;
viewModel.ExportCount = msgCount.ToString();
}
return true;
}

private static DateTime TimeStampToDateTime(long timeStamp, bool inMilli = false)
Expand Down
15 changes: 13 additions & 2 deletions Helpers/DecryptionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,18 @@ public class DecryptionHelper
}
return null;
}

public static string GetMD5(string text)
{
MD5 md5 = MD5.Create();
byte[] bs = Encoding.UTF8.GetBytes(text);
byte[] hs = md5.ComputeHash(bs);
StringBuilder sb = new StringBuilder();
foreach(byte b in hs)
{
sb.Append(b.ToString("x2"));
}
return sb.ToString();
}
public static void DecryptDB(string file, string to_file, byte[] password_bytes)
{
//数据库头16字节是盐值
Expand Down Expand Up @@ -227,7 +238,7 @@ public static void DecryptDB(string file, string to_file, byte[] password_bytes)
byte[] reserved_byte = new byte[reserved];
fileStream.Seek((page_no * DEFAULT_PAGESIZE) + DEFAULT_PAGESIZE - reserved, SeekOrigin.Begin);
fileStream.Read(reserved_byte, 0, Convert.ToInt32(reserved));
reserved_byte.CopyTo(decryped_page_bytes, Convert.ToInt32(DEFAULT_PAGESIZE - reserved));
reserved_byte.CopyTo(decryped_page_bytes, DEFAULT_PAGESIZE - reserved);

tofileStream.Write(decryped_page_bytes, 0, decryped_page_bytes.Length);

Expand Down
8 changes: 7 additions & 1 deletion Pages/CreateWork.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,13 @@ private void cb_manual_Checked(object sender, RoutedEventArgs e)
{
if (File.Exists("auth.txt"))
{

string auth = File.ReadAllText("auth.txt");
// 我已知晓手动模式可能潜在的法律及道德风险,我明白非法使用将要承担相关法律责任。
if (DecryptionHelper.GetMD5(auth) == "295f634af60d61dfa52a5f35849ac42b")
{
MessageBox.Show("已经创建空的配置文件,请完善该配置文件后,点击开始解密","提示");
MessageBox.Show("该功能现阶段暂未启用","错误");
}
}
else
{
Expand Down
42 changes: 35 additions & 7 deletions Pages/Manager.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
Expand All @@ -30,6 +31,8 @@ public partial class Manager : Page
{
private WorkspaceViewModel workspaceViewModel = new WorkspaceViewModel();
public WXUserReader? UserReader;
private List<WXContact>? ExpContacts;
private bool Suspend = false;
public Manager()
{
DataContext = workspaceViewModel;
Expand Down Expand Up @@ -61,15 +64,25 @@ private void btn_export_all_Click(object sender, RoutedEventArgs e)
});
if (UserReader != null)
{
List<WXContact>? contacts = UserReader.GetWXContacts().ToList();
foreach (var contact in contacts)
if (!Suspend)
ExpContacts = UserReader.GetWXContacts().ToList();
else
Suspend = false;

foreach (var contact in ExpContacts!)
{
if (Suspend)
{
workspaceViewModel.ExportCount = "已暂停";
return;
}

if (group && contact.UserName.Contains("@chatroom"))
{
workspaceViewModel.WXContact = contact;
ExportMsg(contact);
}
if (user)
if (user && !contact.UserName.Contains("@chatroom") && !contact.UserName.Contains("gh_"))
{
workspaceViewModel.WXContact = contact;
ExportMsg(contact);
Expand All @@ -83,12 +96,27 @@ private void btn_export_all_Click(object sender, RoutedEventArgs e)
private void ExportMsg(WXContact contact)
{
workspaceViewModel.ExportCount = "";
string path = Path.Combine(Main2.CurrentUserBakConfig!.UserWorkspacePath, contact.UserName + ".html");
// string path = Path.Combine(Main2.CurrentUserBakConfig!.UserWorkspacePath, contact.UserName + ".html");
string name = contact.NickName;
name = name.Replace(@"\", "");
name = Regex.Replace(name, "[ \\[ \\] \\^ \\-_*×――(^)$%~!/@#$…&%¥—+=<>《》|!!???::•`·、。,;,.;\"‘’“”-]", "");
string path = Path.Combine(
Main2.CurrentUserBakConfig!.UserWorkspacePath,
string.Format(
"{0}-{1}.html",
contact.UserName,
contact.Remark == "" ? name : contact.Remark
)
);

IExport export = new HtmlExport();
export.InitTemplate(contact, path);
export.SetMsg(UserReader!, contact, workspaceViewModel);
export.SetEnd();
export.Save(path);
if(export.SetMsg(UserReader!, contact, workspaceViewModel))
{
export.SetEnd();
export.Save(path);
}

}

private void btn_emoji_download_Click(object sender, RoutedEventArgs e)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
> [!NOTE]
> 反馈群:815054692<br/>
> 如果觉得不错,欢迎右上角点个star!这是对作者的鼓励,谢谢!<br/>
> 进群请先Star项目,然后问答消息留id<br/>
<br/>
### 免责声明
Expand Down Expand Up @@ -73,7 +74,7 @@ A:基本上都是因为刚迁移完,缓存没写入到数据库导致的,
### 参考/引用
项目在开发过程中参考了以下项目或资料,有引用相关代码,如有需要,推荐您可以去参考下相关资料:

1. C#使用OpenSSL解密微信数据库,这里注意一下64位适配问题,注意dll引用: [Mr0x01/WXDBDecrypt.NET](https://github.com/Mr0x01/WXDBDecrypt.NET)<br/>
1. C#使用OpenSSL解密微信数据库,这里注意一下64位适配问题,注意dll引用,另外解密的资源优化不是很好,可以参考一下我改写的,C#还需要注意一下超大文件的问题[Mr0x01/WXDBDecrypt.NET](https://github.com/Mr0x01/WXDBDecrypt.NET)<br/>
2. C#使用地址获取微信Key: [AdminTest0/SharpWxDump](https://github.com/AdminTest0/SharpWxDump)
3. 解密微信语音,我是直接调用解密,反正都要ffmpeg,多一个也是多,多两个也是多,懒得头铁实现: [kn007/silk-v3-decoder](https://github.com/kn007/silk-v3-decoder)
4. 解密微信图片 [吾爱破解chenhahacjl/微信 DAT 图片解密 (C#)](https://www.52pojie.cn/forum.php?mod=viewthread&tid=1507922)
Expand Down
6 changes: 3 additions & 3 deletions WechatBakTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<AssemblyVersion>0.9.7.0</AssemblyVersion>
<FileVersion>0.9.7.0</FileVersion>
<Version>0.9.7.0</Version>
<AssemblyVersion>0.9.7.1</AssemblyVersion>
<FileVersion>0.9.7.1</FileVersion>
<Version>0.9.7.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 76def41

Please sign in to comment.