//#region IDataItems测试相关类 //[Serializable] //public class Person : AbstractDataItem //{ // public Person(string name, int age) // { // Name = name; // Age = age; // } // [Display(DataType = DisplayDataType.TEXT)] // public string Name { get; set; } // [Display(DataType = DisplayDataType.INTEGER)] // public int Age { get; set; } // [Display(DataType = DisplayDataType.TEXT)] // public string Location { get; set; } // [Display(DataType = DisplayDataType.INTEGER)] // public int Age2 { get; set; } // [Display(DataType = DisplayDataType.INTEGER)] // public int Age3 { get; set; } // [Display(DataType = DisplayDataType.INTEGER)] // public int Age4 { get; set; } // [Display(DataType = DisplayDataType.INTEGER)] // public int Age5 { get; set; } // [Display(DataType = DisplayDataType.INTEGER)] // public int Age6 { get; set; } //} //[Serializable] //public class Dog : AbstractDataItem //{ // public Dog(string name, int age) // { // Name = name; // Age = age; // } // [Display(Key = "xxxx", DataType = DisplayDataType.TEXT)] // public string Name { get; set; } // [Display(DataType = DisplayDataType.INTEGER)] // public int Age { get; set; } //} //#endregion //public static void Test(string[] args) //{ // //TestDataItems(); // var dsA = Serializer.DeSerializeFromBinary<IDataSource>(@"D:\test\1.bin") as SimpleDataSource; // var diA = dsA.Items as DataItems<Person>; // //var dsB = DeSerializeFromBinary<IDataSource>(@"D:\test\2.bin") as TreeDataSource; // //var diB = dsB.TreeNodes[0].Items as DataItems<Person>; // foreach (Person s in diA) // { // } // //foreach (Person s in diB) // //{ // //} // //var res = diA.FirstOrDefault(s => s.Name == "新华公告111"); // //var ls = diA.Skip(100).Take(10).ToList(); // //var count = diA.Count(); //} //public static void TestDataItems() //{ // foreach (var ff in Directory.GetFiles(@"D:\test\")) // { // File.Delete(ff); // } // Stopwatch st = new Stopwatch(); // st.Start(); // int total = 200000; // var dbfilePath = @"D:\test\test1.db"; // var t1 = Task.Run(() => // { // SimpleDataSource ds = new SimpleDataSource(); // ds.Items = new DataItems<Person>(dbfilePath); // int count = total; // while (count > 0) // { // ds.Items.Add(new Person("新华公告", 11) { Location = "四川省成都市高新区天府大道9999号" }); // count--; // } // ds.Items.Add(new Person("新华公告111", 11) { Location = "四川省成都市高新区天府大道9999号" }); // ds.BuildParent(); // Serializer.SerializeToBinary(ds, @"D:\test\1.bin"); // Console.WriteLine("1 OK!"); // }); // var t2 = Task.Run(() => // { // TreeDataSource ds = new TreeDataSource(); // TreeNode node = new TreeNode() // { // Items = new DataItems<Person>(dbfilePath) // }; // ds.TreeNodes.Add(node); // int count = total; // while (count > 0) // { // node.Items.Add(new Person("花样区域", 11) { Location = "北京市海淀区人民广场888号" }); // count--; // } // ds.BuildParent(); // Serializer.SerializeToBinary(ds, @"D:\test\2.bin"); // Console.WriteLine("2 OK!"); // }); // var t3 = Task.Run(() => // { // TreeDataSource ds = new TreeDataSource(); // TreeNode node = new TreeNode() // { // Items = new DataItems<Dog>(dbfilePath) // }; // ds.TreeNodes.Add(node); // int count = total; // while (count > 0) // { // node.Items.Add(new Dog("cccccc", 33)); // count--; // } // ds.BuildParent(); // Serializer.SerializeToBinary(ds, @"D:\test\3.bin"); // Console.WriteLine("3 OK!"); // }); // Task.WaitAll(t1, t2, t3); // st.Stop(); // Console.WriteLine("ALL OK!"); // Console.WriteLine(st.ElapsedMilliseconds / 1000.0); //} #endregion #region 安卓微信数据库解密测试 public void WXDecryptedDllTest() { string sourceFile = @"I:\本地数据\微信数据没平航多1\com.tencent.mm\MicroMsg\b7d12bb40bcdfb5c682fb6cff1e69b34\EnMicroMsg.db"; IntPtr wxHandle = IntPtr.Zero; // 打开数据库文件,获得文件句柄 wxHandle = WXDeCryptedCoreDll.WXOpen(sourceFile); //WXDeCryptedCoreDll.WXDeCryptedDBToFile(wxHandle, @"I:\本地数据\微信数据没平航多1\com.tencent.mm\MicroMsg\b7d12bb40bcdfb5c682fb6cff1e69b34\test.db"); WXDeCryptedCoreDll.WXDeCryptedDBToFileBakdata(wxHandle, @"I:\本地数据\微信数据没平航多1\com.tencent.mm\MicroMsg\b7d12bb40bcdfb5c682fb6cff1e69b34\test.db", pHandel => { WxbakMsgdata data = (WxbakMsgdata)Marshal.PtrToStructure(pHandel, typeof(WxbakMsgdata)); var ss1 = GetUnMomString(data.wxid, data.wxidByteLen); var ss2 = GetUnMomString(data.pmsg, data.msgbytelen); return(0); }); WXDeCryptedCoreDll.CloseHanle(ref wxHandle); }
/// <summary> /// 解密安卓微信数据库,获取bak数据并保存到数据库 /// </summary> /// <param name="sqliteFile">要解密的数据库文件全路径</param> /// <param name="deleteDataDbFile">bak数据保存数据库文件全路径</param> /// <returns>解密后数据库文件全路径</returns> public static string DecryptAndroidWeChatSqliteGetDelete(string sqliteFile, ref string deleteDataDbFile) { IntPtr wxHandle = IntPtr.Zero; string resultFile = string.Empty; try { // 打开数据库文件,获得文件句柄 wxHandle = WXDeCryptedCoreDll.WXOpen(sqliteFile); if (IntPtr.Zero == wxHandle) { LoggerManagerSingle.Instance.Error("解密安卓微信数据库时打开数据库文件失败! 解密文件:" + sqliteFile); return(string.Empty); } // 解密后文件路径 var fi = new FileInfo(sqliteFile); resultFile = Path.Combine(fi.DirectoryName, string.Format("Decrypt_{0}", fi.Name)); //创建数据库存储数据 var saveDbPath = sqliteFile + ".data.db"; FileHelper.DeleteFileSafe(saveDbPath); var saveDb = new SqliteContext(saveDbPath); saveDb.ExecuteNonQuery("CREATE TABLE WxbakMsgdata (\"type\" TEXT,\"isSend\" TEXT, \"utctime\" TEXT, \"wxid\" TEXT,\"pmsg\" BLOB);"); saveDb.ExecuteNonQuery("CREATE INDEX wxidIndex ON WxbakMsgdata(wxid);"); saveDb.UsingSafeTransaction(c => { //数据库解密 var result = WXDeCryptedCoreDll.WXDeCryptedDBToFileBakdata(wxHandle, resultFile, pHandel => { WxbakMsgdata data = (WxbakMsgdata)Marshal.PtrToStructure(pHandel, typeof(WxbakMsgdata)); var sb = new StringBuilder(); sb.Append("INSERT INTO WxbakMsgdata VALUES ("); sb.AppendFormat("'{0}',", data.type); sb.AppendFormat("'{0}',", data.isSend); sb.AppendFormat("'{0}',", data.utctime); sb.AppendFormat("'{0}',", GetString(data.wxid, data.wxidByteLen)); sb.AppendFormat("@msgdata)"); c.CommandText = sb.ToString(); c.CommandType = CommandType.Text; c.Parameters.Clear(); c.Parameters.Add(new System.Data.SQLite.SQLiteParameter("msgdata", GetByteArr(data.pmsg, data.msgbytelen)) { DbType = DbType.Binary }); c.ExecuteNonQuery(); return(0); }); if (0 != result || !File.Exists(resultFile)) { LoggerManagerSingle.Instance.Error(string.Format("解密安卓微信数据库时打开数据库文件失败! 解密文件:{0} 错误码:{1}", sqliteFile, result)); } }); } catch (Exception ex) { LoggerManagerSingle.Instance.Error(ex, "解密安卓微信数据库时出现异常! 解密文件:" + sqliteFile); } finally { if (IntPtr.Zero != wxHandle) { WXDeCryptedCoreDll.CloseHanle(ref wxHandle); } } return(resultFile); }