private string FindName(SqliteContext context, string phonenumber) { if (null == context) { return(string.Empty); } string sqlStr = string.Format(@"SELECT b.data1 FROM data_tb a, data_tb b WHERE a.mimetype = 'vnd.android.cursor.item/phone_v2' AND a.data1 = '{0}' AND b.mimetype = 'vnd.android.cursor.item/name' AND a.raw_contact_id = b.raw_contact_id", phonenumber); var res = context.Find(new SQLiteString(sqlStr)); if (res.IsValid()) { return(DynamicConvert.ToSafeString(res.First().data1)); } return(string.Empty); }
/// <summary> /// 构造路线搜索记录节点 /// </summary> private void CreateAddlineSearchTreeNode(string dbFile, TreeNode addLineSearchNode) { try { IEnumerable <dynamic> datas = null; using (var context = new SqliteContext(dbFile)) { datas = context.Find(new SQLiteString("SELECT _data AS datastr,XLY_DataType FROM search_history_tab WHERE _history_type = 2 ORDER BY _lasted_used DESC")); } if (datas.IsInvalid()) { return; } foreach (var data in datas) { var search = ToTencentMapSearchRoute(data); if (null != search) { addLineSearchNode.Items.Add(search); } } } catch { } }
/// <summary> /// 解析数据 /// </summary> /// <param name="datasource"></param> public void BuildData(CallDataSource datasource) { if (!FileHelper.IsValid(MainDbPath)) { return; } using (var context = new SqliteContext(MainDbPath)) { var dataList = context.Find("SELECT duration,duration_type,type,number,name,date from calls ORDER BY _id"); foreach (var calllogdata in dataList) { Call callTemp = new Call(); callTemp.DataState = EnumDataState.Normal; callTemp.DurationSecond = DynamicConvert.ToSafeInt(calllogdata.duration); callTemp.Number = DynamicConvert.ToSafeString(calllogdata.number); callTemp.Name = DynamicConvert.ToSafeString(calllogdata.name); callTemp.StartDate = new DateTime(1970, 1, 1).AddSeconds(DynamicConvert.ToSafeLong(calllogdata.date) / 1000).AddHours(8); switch ((int)DynamicConvert.ToSafeInt(calllogdata.type)) { case 2: callTemp.Type = 0 == callTemp.DurationSecond ? EnumCallType.MissedCallOut : EnumCallType.CallOut; break; default: callTemp.Type = 0 == callTemp.DurationSecond ? EnumCallType.MissedCallIn : EnumCallType.CallIn; break; } datasource.Items.Add(callTemp); } } }
/// <summary> /// 解析数据 /// </summary> /// <param name="datasource"></param> public void BuildData(ContactDataSource datasource) { if (!FileHelper.IsValid(MainDbPath)) { return; } SqliteContext mainContext = null; try { var rMainDbFile = SqliteRecoveryHelper.DataRecovery(MainDbPath, @"chalib\com.android.providers.contacts\contacts2.db.charactor", "raw_contacts,contacts,phone_lookup,data,mimetypes,groups", true); mainContext = new SqliteContext(rMainDbFile); // raw_contacts表数据集合 var contactList = mainContext.Find(_SelectRawContactsSql); // phone_lookup表数据集合 var phoneLookupList = mainContext.Find("SELECT * FROM phone_lookup"); // dataView视图数据集合 var dataViewList = mainContext.Find(_SelectDataViewSql); // 群组列表 var groupList = mainContext.Find("SELECT * FROM groups"); // 联系人解析 var items = new List <Contact>(); if (contactList.IsValid()) { items = TryParseItems(contactList); TryParsePhoneLookup(items, phoneLookupList); TryParseDataView(items, dataViewList, groupList); } foreach (var item in items.Where(c => c.Number.IsValid())) { datasource.Items.Add(item); } } finally { mainContext?.Dispose(); mainContext = null; } }
/// <summary> /// 构建动态恢复的表 /// </summary> /// <param name="sourcedb"></param> /// <returns></returns> private string RecoveryTables(string sourcedb) { var sqliteObj = new SqliteContext(sourcedb); var listTables = sqliteObj.Find(new SQLiteString("select tbl_name from sqlite_master where type = 'table'")). Select(table => DynamicConvert.ToSafeString(table.tbl_name)).Cast <string>().Where(t => t.StartsWith("Chat_")).ToList(); listTables.Add("Friend"); listTables.Add("Friend_Ext"); return(string.Join(",", listTables)); }
/// <summary> /// 查询某个数据库表的创建sql语句,用于判断表中是否包含某个字段 /// </summary> /// <param name="context">数据库操作对象</param> /// <param name="tableName">数据表名</param> /// <returns>返回创建表的sql语句</returns> private string GetCreateTableSql(SqliteContext context, string tableName) { try { string selectSql = string.Format(@"select sql from sqlite_master where tbl_name='{0}' and type='table'", tableName); var data = context.Find(new SQLiteString(selectSql)); return(DynamicConvert.ToSafeString(data.FirstOrDefault().sql)); } catch { return(string.Empty); } }
private DateTime?GetLastContactDate(SqliteContext context, string id) { var data = context.Find(new SQLiteString(string.Format("SELECT last_time_contacted FROM raw_contacts_tb WHERE _id = '{0}'", id))).FirstOrDefault(); if (null != data) { string value = DynamicConvert.ToSafeString(data.last_time_contacted); if (value.IsValid() && "0" != value) { return(new DateTime(1970, 1, 1).AddSeconds(DynamicConvert.ToSafeLong(data.last_time_contacted) / 1000).AddHours(8)); } } return(null); }
/// <summary> /// 解析数据 /// </summary> /// <param name="datasource"></param> public void BuildData(CallDataSource datasource) { SqliteContext mainContext = null; SqliteContext callsContext = null; try { List <dynamic> list = new List <dynamic>(); if (FileHelper.IsValid(MainDbPath)) { var rMainDbFile = SqliteRecoveryHelper.DataRecovery(MainDbPath, @"chalib\com.android.providers.contacts\contacts2.db.charactor", "calls", true); mainContext = new SqliteContext(rMainDbFile); var ls = mainContext.Find("SELECT * FROM calls"); if (ls.IsValid()) { list.AddRange(ls); } } if (FileHelper.IsValid(CallsDbPath)) { var rMainDbFile = SqliteRecoveryHelper.DataRecovery(CallsDbPath, @"chalib\com.android.providers.contacts\contacts2.db.charactor", "calls", true); callsContext = new SqliteContext(rMainDbFile); var ls = callsContext.Find("SELECT * FROM calls"); if (ls.IsValid()) { list.AddRange(ls); } } var items = new List <Call>(); TryParseCall(items, list); foreach (var item in items) { datasource.Items.Add(item); } } finally { mainContext?.Dispose(); callsContext?.Dispose(); mainContext = null; callsContext = null; } }
/// <summary> /// 构造同行信息节点 /// </summary> private void CreateTongxing(string filesPath, TreeNode searchNode) { try { var dbs = Directory.GetFiles(filesPath, "*.msgstore").Where(f => System.Text.RegularExpressions.Regex.IsMatch(f, @"\d+_v4.msgstore")); if (dbs.IsInvalid()) { return; } foreach (var msgstore in dbs) { var newDbFile = SqliteRecoveryHelper.DataRecovery(msgstore, "", "message"); string userid = System.Text.RegularExpressions.Regex.Match(msgstore, @"(\d+)_v4.msgstore").Groups[1].Value; IEnumerable <dynamic> msgs = null; using (SqliteContext context = new SqliteContext(newDbFile)) { msgs = context.Find(new SQLiteString("SELECT sid,time,sender,content,XLY_DataType FROM message WHERE sender != '@TIM#SYSTEM' ORDER BY time")); } if (msgs.IsInvalid()) { continue; } TreeNode msgNode = new TreeNode() { Text = userid, Type = typeof(TencentMapTongxingMsg), Items = new DataItems <TencentMapTongxingMsg>(DbFilePath) }; foreach (var msg in msgs) { var res = ToTencentMapTongxingMsg(msg); if (null != res) { msgNode.Items.Add(res); } } searchNode.TreeNodes.Add(msgNode); } } catch { } }
/// <summary> /// 根据mmssms.db,获得sms表(短信)集合 /// </summary> /// <param name="context">数据库</param> /// <param name="createSmsSql">创建sms表sql语句,用于判断某个字段是否存在</param> /// <returns>返回sms表(短信)集合</returns> private IEnumerable <dynamic> GetSmssList(SqliteContext context, ref string createSmsSql) { string charatorPath = MatchCharatorPath(); createSmsSql = GetCreateTableSql(context, "sms"); string sqlStr = @"select ifnull(_id,0) as _id,address as number,date{0},read,type,body as content{1}{2}{3} from sms"; string part1 = ValidateTableFieldExist(createSmsSql, "date_sent INTEGER") ? ",date_sent" : string.Empty; string part2 = ValidateTableFieldExist(createSmsSql, "receive_date INTEGER") ? ",receive_date" : string.Empty; string part3 = ValidateTableFieldExist(createSmsSql, "deleted INTEGER") ? ",deleted" : string.Empty; string part4 = ValidateTableFieldExist(createSmsSql, "XLY_DataType INTEGER") ? ",XLY_DataType" : string.Empty; sqlStr = string.Format(sqlStr, part1, part2, part3, part4); return(context.Find(sqlStr)); }
/// <summary> /// 获取主用户 /// </summary> /// <param name="accountDb"></param> /// <param name="context"></param> /// <returns></returns> private TwitterAccount GetMasterAccount(string accountDb, SqliteContext context) { var accountid = FindAccountId(accountDb); var res = context.Find(new SQLiteString(String.Format("SELECT * FROM users WHERE user_id = '{0}'", accountid))); if (res.IsValid()) { return(TwitterAccount.DyConvert(res.First())); } else { return(new TwitterAccount() { UserId = accountid }); } }
/// <summary> /// 解析数据 /// </summary> /// <param name="datasource"></param> public void BuildData(CallDataSource datasource) { if (!FileHelper.IsValid(MainDbPath)) { return; } SqliteContext context = null; SqliteContext contactcontext = null; try { context = new SqliteContext(MainDbPath); if (FileHelper.IsValid(ContactDbPath)) { contactcontext = new SqliteContext(ContactDbPath); } var calllogList = context.Find(new SQLiteString("SELECT number,date,duration,type,ring_times FROM calls_tb")); foreach (var calllogdata in calllogList) { Call callTmp = new Call(); callTmp.Number = DynamicConvert.ToSafeString(calllogdata.number); callTmp.Name = FindName(contactcontext, callTmp.Number); callTmp.Type = ConvertToEnumCallType(DynamicConvert.ToSafeString(calllogdata.type), DynamicConvert.ToSafeString(calllogdata.duration)); callTmp.DataState = EnumDataState.Normal; callTmp.StartDate = new DateTime(1970, 1, 1).AddSeconds(DynamicConvert.ToSafeLong(calllogdata.date) / 1000).AddHours(8); callTmp.DurationSecond = DynamicConvert.ToSafeInt(calllogdata.duration); datasource.Items.Add(callTmp); } } catch { } finally { context?.Dispose(); contactcontext?.Dispose(); context = null; contactcontext = null; } }
private IEnumerable <dynamic> GetContactList() { if (!FileHelper.IsValid(ContactDbPath)) { return(new List <dynamic>()); } var nfile = SqliteRecoveryHelper.DataRecovery(ContactDbPath, @"chalib\com.android.providers.contacts\contacts2.db.charactor", "data,mimetypes", true); var context = new SqliteContext(nfile); string sqlStr = "select A.mimetype_id,A.raw_contact_id,A.data1,A.data4,substr(B.[mimetype],25,length(B.[mimetype])-24) as mimetype from data as A left outer join mimetypes as B on A.[mimetype_id] = B.[_id]"; var res = context.Find(new SQLiteString(sqlStr)); if (null != context) { context.Dispose(); } return(res); }
private IEnumerable <dynamic> _Find(string file, string sql) { try { if (!System.IO.File.Exists(file)) { Console.WriteLine(string.Format("文件不存在", file)); return(null); } using (SqliteContext context = new SqliteContext(file)) { var res = context.Find(sql); return(res); } } catch (Exception ex) { Console.WriteLine(string.Format("SQL查询失败", file, ex.Message)); throw; } }
private List <Call> GetFromLog() { SqliteContext context = null; try { var items = new List <Call>(); if (!FileHelper.IsValid(MainDbPath)) { return(items); } var newFile = SqliteRecoveryHelper.DataRecovery(MainDbPath, @"chalib\com.android.providers.telephony\logs.db.charactor", "logs", true); // 处理新文件 context = new SqliteContext(newFile); var calls = context.Find(new SQLiteString("select * from logs where logtype=100 or logtype=256")); if (calls.IsInvalid()) { return(items); } TryParseCall(items, calls); return(items); } catch { return(new List <Call>()); } finally { if (null != context) { context.Dispose(); } } }
/// <summary> /// 解析数据 /// </summary> /// <param name="dataSource"></param> public void BuildData(SmsDataSource dataSource) { if (!FileHelper.IsValid(MainDbPath)) { return; } SqliteContext mainContext = null; string attendDirPath = MediaDomainPath; try { var rMainDbFile = SqliteRecoveryHelper.DataRecovery(MainDbPath, @"chalib\IOS_Sms\sms.db.charactor", "message,handle,attachment,chat,chat_message_join,chat_handle_join,message_attachment_join", true); mainContext = new SqliteContext(rMainDbFile); var handleDynamicList = mainContext.FindByName("handle"); var chathandlejoinDynamicList = mainContext.Find(new SQLiteString("SELECT chat_id,handle_id FROM chat_handle_join WHERE chat_id NOTNULL")).ToList(); var chatmessagejoinDynamicList = mainContext.Find(new SQLiteString("SELECT chat_id,message_id FROM chat_message_join WHERE chat_id NOTNULL")); var messageAttachmentJoinDynamicList = mainContext.Find(new SQLiteString("SELECT message_id,attachment_id FROM message_attachment_join WHERE message_id NOTNULL")).ToList(); var attachmentDynamicList = mainContext.FindByName("attachment"); var dateStr = ""; mainContext.UsingSafeConnection(new SQLiteString("select * from message order by date desc"), r => { dynamic smsObj; while (r.Read()) { smsObj = r.ToDynamic(); var sms = new SMS(); //短信内容 sms.Content = DynamicConvert.ToSafeString(smsObj.text); sms.Content = FragmentHelper.RemoveNullityDataNew(sms.Content); // 验证内容是否为空 if (FragmentHelper.IsEmptyString(sms.Content)) { continue; } sms.DataState = DynamicConvert.ToEnumByValue(smsObj.XLY_DataType, EnumDataState.Normal); //发送时间和读取时间。 dateStr = DynamicConvert.ToSafeString(smsObj.date); if (dateStr.Length > 9) { dateStr = dateStr.Substring(0, 9); } sms.StartDate = DynamicConvert.ToSafeDateTime(dateStr, 2001); //sms.ReadTime = DynamicConvert.ToSafeDateTime(smsObj.date_read, 2001); int smsId = DynamicConvert.ToSafeInt(smsObj.ROWID); sms.Remark = string.Empty; int hanldeId = DynamicConvert.ToSafeInt(smsObj.handle_id); if (hanldeId == 0) { //群发消息 var someChatMsgObj = chatmessagejoinDynamicList.FirstOrDefault(cmj => DynamicConvert.ToSafeInt(cmj.message_id) == smsId && DynamicConvert.ToSafeInt(cmj.chat_id) != 0); if (someChatMsgObj != null) { var handleIdList = chathandlejoinDynamicList.FindAll(chj => DynamicConvert.ToSafeInt(chj.chat_id) == someChatMsgObj.chat_id); var numbersBuilder = new StringBuilder(); foreach (var oneHandle in handleIdList) { numbersBuilder.Append(GetPhoteNumber(DynamicConvert.ToSafeInt(oneHandle.handle_id), handleDynamicList)); numbersBuilder.Append(";"); } sms.Remark = LanguageHelper.GetString(Languagekeys.PluginSMS_QunSend) + "; "; sms.Number = numbersBuilder.ToString().TrimEnd(";"); } } else { sms.Number = GetPhoteNumber(hanldeId, handleDynamicList); } if (sms.Number.IsValid() && sms.DataState == EnumDataState.Fragment) { if (!FragmentHelper.IsValidFragment(sms.Number)) { continue; } } //发送或者接收 sms.SmsState = DynamicConvert.ToSafeInt(smsObj.is_from_me) == 1 ? EnumSMSState.SendSMS : EnumSMSState.ReceiveSMS; int isDelivered = DynamicConvert.ToSafeInt(smsObj.is_delivered); int isSent = DynamicConvert.ToSafeInt(smsObj.is_sent); if (sms.SmsState == EnumSMSState.ReceiveSMS) { sms.Remark += DynamicConvert.ToSafeInt(smsObj.is_read) == 1 ? string.Format("{0};", LanguageHelper.GetString(Languagekeys.PluginSMS_IsRead)) : string.Format("{0};", LanguageHelper.GetString(Languagekeys.PluginSMS_NotRead)); } else { if (isDelivered == 0 && isSent == 0) { sms.Remark += LanguageHelper.GetString(Languagekeys.PluginSMS_SendFail) + "; "; } } #region 附件解析 int cache_has_attachments = DynamicConvert.ToSafeInt(smsObj.cache_has_attachments); if (cache_has_attachments == 1) { var attachmentIdList = messageAttachmentJoinDynamicList.FindAll(maj => DynamicConvert.ToSafeInt(maj.message_id) != 0 && DynamicConvert.ToSafeInt(maj.message_id) == smsId); sms.Remark += LanguageHelper.GetString(Languagekeys.PluginSMS_Attachment) + "; "; foreach (var oneAttachIdObj in attachmentIdList) { int attId = DynamicConvert.ToSafeInt(oneAttachIdObj.attachment_id); var attachObj = attachmentDynamicList.FirstOrDefault(att => DynamicConvert.ToSafeInt(att.ROWID) == attId); if (attachObj != null) { string attPath = DynamicConvert.ToSafeString(attachObj.filename); attPath = attPath.Replace('/', '\\').TrimStart('~'); sms.Remark += FileHelper.ConnectPath(attendDirPath, attPath) + ";"; } } } #endregion sms.Remark = sms.Remark.TrimEnd(";"); if (sms.Remark.Contains(LanguageHelper.GetString(Languagekeys.PluginSMS_NotRead))) { sms.ReadState = EnumReadState.Unread; } else { sms.ReadState = EnumReadState.Read; } if (sms.Number.IsInvalid() && sms.Content.IsInvalid()) { continue; } if (sms.Number.IsInvalid()) { var address = DataParseHelper.NumberToStu(DynamicConvert.ToSafeString(smsObj.address)); sms.Number = DynamicConvert.ToSafeString(address); } dataSource.Items.Add(sms); } }); } finally { mainContext?.Dispose(); mainContext = null; } }
/// <summary> /// 构造搜索记录节点 /// </summary> /// <param name="context"></param> /// <param name="searchNode"></param> private void CreateSearchNode(SqliteContext context, TreeNode searchNode) { var list = context.Find(new SQLiteString("SELECT name,time,type FROM search_queries ORDER BY time DESC")); searchNode.Items.AddRange(list.Select(d => TwitterSearchEntry.DyConvert(d)).Cast <TwitterSearchEntry>()); }
/// <summary> /// 解析数据 /// </summary> /// <param name="datasource"></param> public void BuildData(ContactDataSource datasource) { if (!FileHelper.IsValid(MainDbPath)) { return; } SqliteContext mainContext = null; try { var dataList = mainContext.Find(new SQLiteString("SELECT raw_contact_id,data1,mimetype FROM data_tb WHERE data1 NOTNULL ORDER BY raw_contact_id,mimetype")); var rawidList = dataList.Select(d => DynamicConvert.ToSafeString(d.raw_contact_id)).Distinct(); foreach (string rawid in rawidList) { var nameData = dataList.FirstOrDefault(d => DynamicConvert.ToSafeString(d.raw_contact_id) == rawid && DynamicConvert.ToSafeString(d.mimetype) == "vnd.android.cursor.item/name"); var noteData = dataList.FirstOrDefault(d => DynamicConvert.ToSafeString(d.raw_contact_id) == rawid && DynamicConvert.ToSafeString(d.mimetype) == "vnd.android.cursor.item/note"); var emailData = dataList.FirstOrDefault(d => DynamicConvert.ToSafeString(d.raw_contact_id) == rawid && DynamicConvert.ToSafeString(d.mimetype) == "vnd.android.cursor.item/email_v2"); //var websiteData = dataList.FirstOrDefault(d => DynamicConvert.ToSafeString(d.raw_contact_id) == rawid && DynamicConvert.ToSafeString(d.mimetype) == "vnd.android.cursor.item/website"); var addressData = dataList.FirstOrDefault(d => DynamicConvert.ToSafeString(d.raw_contact_id) == rawid && DynamicConvert.ToSafeString(d.mimetype) == "vnd.android.cursor.item/postal-address_v2"); //string name = "", note = "", email = "", website = "", address = ""; string name = "", note = "", email = "", address = ""; if (null != nameData) { name = DynamicConvert.ToSafeString(nameData.data1); } if (null != noteData) { note = DynamicConvert.ToSafeString(noteData.data1); } if (null != emailData) { email = DynamicConvert.ToSafeString(emailData.data1); } //if (null != websiteData) //{ // website = DynamicConvert.ToSafeString(websiteData.data1); //} if (null != addressData) { address = DynamicConvert.ToSafeString(addressData.data1); } var phones = dataList.Where(d => DynamicConvert.ToSafeString(d.raw_contact_id) == rawid && DynamicConvert.ToSafeString(d.mimetype) == "vnd.android.cursor.item/phone_v2") .Select(d => DynamicConvert.ToSafeString(d.data1)); //var groups = dataList.Where(d => DynamicConvert.ToSafeString(d.raw_contact_id) == rawid && DynamicConvert.ToSafeString(d.mimetype) == "vnd.android.cursor.item/group_membership") // .Select(d => DynamicConvert.ToSafeString(d.data1)).Distinct(); //string groupinfo = GetGroupsInfo(context, groups); DateTime?lastContactDate = GetLastContactDate(mainContext, rawid); if (phones.IsInvalid()) { if (name.IsInvalid()) { continue; } Contact contactTemp = new Contact(); contactTemp.DataState = EnumDataState.Normal; contactTemp.Name = name; contactTemp.Remark = note; contactTemp.Email = email; //contactTemp.Website = website; contactTemp.PostalAddress = address; //contactTemp.GroupName = groupinfo; contactTemp.LastContactDate = lastContactDate; datasource.Items.Add(contactTemp); } else { foreach (var phonenumber in phones) { Contact contactTemp = new Contact(); contactTemp.DataState = EnumDataState.Normal; contactTemp.Number = DynamicConvert.ToSafeString(phonenumber); contactTemp.Name = name; contactTemp.Remark = note; contactTemp.Email = email; //contactTemp.Website = website; contactTemp.PostalAddress = address; //contactTemp.GroupName = groupinfo; contactTemp.LastContactDate = lastContactDate; datasource.Items.Add(contactTemp); } } } } finally { mainContext?.Dispose(); mainContext = null; } }
/// <summary> /// 构造查询列表记录节点 /// </summary> /// <param name="context"></param> /// <param name="viewNode"></param> private void CreateViewNode(SqliteContext context, TreeNode viewNode) { var list = context.Find(new SQLiteString("SELECT topics_ev_id,topics_ev_owner_id,topics_ev_query,topics_ev_title,topics_ev_subtitle FROM lists_view")); viewNode.Items.AddRange(list.Select(d => TwitterViewEntry.DyConvert(d)).Cast <TwitterViewEntry>()); }
private bool FindAppDataForHuawei(string app, string source, string dest) { try { string dbFile = string.Format("{0}.db", app); var fls = Directory.GetFiles(source, dbFile, SearchOption.AllDirectories); if (fls.IsInvalid()) { return(false); } if (_huaweiApp.Contains(app)) { var targetFilePath = new FileInfo(Path.Combine(dest, "data", app, dbFile)); if (!Directory.Exists(targetFilePath.DirectoryName)) { Directory.CreateDirectory(targetFilePath.DirectoryName); } File.Copy(fls.Single(), targetFilePath.FullName, true); return(true); } var context = new SqliteContext(fls.FirstOrDefault()); //获取文件列表 var file_info = context.Find(new SQLiteString("SELECT file_index,file_path FROM apk_file_info ORDER BY file_index")); foreach (var file in file_info) { try { string file_index = DynamicConvert.ToSafeString(file.file_index); string file_path = DynamicConvert.ToSafeString(file.file_path); if (file_index == "-1") {//-1是文件夹,不管 continue; } var targetFilePath = new FileInfo(Path.Combine(dest, "data", file_path.Substring(file_path.IndexOf(app)))); if (!Directory.Exists(targetFilePath.DirectoryName)) { Directory.CreateDirectory(targetFilePath.DirectoryName); } //恢复文件 using (Stream fs = new FileStream(targetFilePath.FullName, FileMode.Create)) { context.UsingSafeConnection(new SQLiteString(string.Format("SELECT file_data FROM apk_file_data WHERE file_index = '{0}' ORDER BY data_index", file_index)), dr => { while (dr.Read()) { var data = dr.ToDynamic(); var da = (byte[])data.file_data; fs.Write(da, 0, da.Length); } }); } } catch { } } return(true); } catch { return(false); } }
/// <summary> /// 构造瞬间记录节点 /// </summary> /// <param name="context"></param> /// <param name="momentNode"></param> private void CreateMomentNode(SqliteContext context, TreeNode momentNode) { var list = context.Find(new SQLiteString("SELECT _id as id,title,subcategory_string,subcategory_favicon_url,time_string,description,moment_url,capsule_content_version FROM moments")); momentNode.Items.AddRange(list.Select(d => TwitterMomentEntry.DyConvert(d)).Cast <TwitterMomentEntry>()); }
/// <summary> /// 构造收藏信息节点 /// </summary> private void CreateFavoriteSearch(string databasesPath, TreeNode searchNode) { try { string dbFile = Path.Combine(databasesPath, "favorite.db"); if (!File.Exists(dbFile)) { return; } dbFile = SqliteRecoveryHelper.DataRecovery(dbFile, "", "FavoritePOIEntity,FavoriteRouteEntity,FavoriteStreetEntity"); IEnumerable <dynamic> addrNodeDatas = null; IEnumerable <dynamic> routeNodeDatas = null; IEnumerable <dynamic> streetNodeDatas = null; TreeNode addrNode = new TreeNode() { Text = "收藏地点", Type = typeof(TencentMapFavoriteAddr), Items = new DataItems <TencentMapFavoriteAddr>(DbFilePath) }; TreeNode routeNode = new TreeNode() { Text = "收藏路线", Type = typeof(TencentMapFavoriteRoute), Items = new DataItems <TencentMapFavoriteRoute>(DbFilePath) }; TreeNode streetNode = new TreeNode() { Text = "收藏街景", Type = typeof(TencentMapFavoriteStreet), Items = new DataItems <TencentMapFavoriteStreet>(DbFilePath) }; searchNode.TreeNodes.Add(addrNode); searchNode.TreeNodes.Add(routeNode); searchNode.TreeNodes.Add(streetNode); //收藏地点 using (var context = new SqliteContext(dbFile)) { addrNodeDatas = context.Find(new SQLiteString("SELECT creatTime,name,obj,XLY_DataType FROM FavoritePOIEntity ORDER BY creatTime DESC")); } foreach (var data in addrNodeDatas) { var addr = ToTencentMapFavoriteAddr(data); if (null != addr) { addrNode.Items.Add(addr); } } //收藏路线 using (var context = new SqliteContext(dbFile)) { routeNodeDatas = context.Find(new SQLiteString("SELECT name,fromPoi,toPoi,time,routeType,XLY_DataType FROM FavoriteRouteEntity ORDER BY creatTime DESC")); } foreach (var data in routeNodeDatas) { var addr = ToTencentMapFavoriteRoute(data); if (null != addr) { routeNode.Items.Add(addr); } } //收藏街景 using (var context = new SqliteContext(dbFile)) { streetNodeDatas = context.Find(new SQLiteString("SELECT name,streetData,lastEditTime,XLY_DataType FROM FavoriteStreetEntity ORDER BY lastEditTime DESC")); } foreach (var data in streetNodeDatas) { var addr = ToTencentMapFavoriteStreet(data); if (null != addr) { streetNode.Items.Add(addr); } } } finally { } }
/// <summary> /// 获取所有用户 /// </summary> /// <param name="context"></param> /// <returns></returns> private List <TwitterAccount> GetAllTwitterAccount(SqliteContext context) { return(context.Find(new SQLiteString("SELECT * FROM users")).Select(d => TwitterAccount.DyConvert(d)).Cast <TwitterAccount>().ToList()); }
/// <summary> /// 解析数据 /// </summary> /// <param name="dataSource"></param> public void BuildData(MMSDataSource dataSource) { if (!FileHelper.IsValid(MainDbPath)) { return; } SqliteContext mainContext = null; string attendDirPath = MediaDomainPath; try { var rMainDbFile = SqliteRecoveryHelper.DataRecovery(MainDbPath, @"chalib\IOS_Sms\sms.db.charactor", "message,handle,attachment,chat,chat_message_join,chat_handle_join,message_attachment_join", true); mainContext = new SqliteContext(rMainDbFile); var messageSource = mainContext.Find(new SQLiteString("SELECT * FROM MESSAGE WHERE CACHE_HAS_ATTACHMENTS = 1 and ROWID not null")); var allContact = mainContext.FindByName("HANDLE"); foreach (var message in messageSource) { var sb = new StringBuilder( "select distinct atta.[filename],atta.[mime_type],atta.[created_date] from MESSAGE_ATTACHMENT_JOIN mes "); sb.Append("left join attachment atta on mes.attachment_id = atta.[ROWID] "); sb.AppendFormat("where mes.[message_id] = {0} and atta.filename not null", DynamicConvert.ToSafeString(message.ROWID)); var contact = allContact.First(cct => DynamicConvert.ToSafeInt(cct.ROWID) == DynamicConvert.ToSafeInt(message.handle_id)); var mms = new MMS(); mms.SenderName = DynamicConvert.ToSafeString(contact.uncanonicalized_id); mms.SendState = DynamicConvert.ToSafeInt(message.is_from_me) == 1 ? EnumSendState.Send : EnumSendState.Receive; mms.Date = DynamicConvert.ToSafeDateTime(message.date); mms.ReadDate = DynamicConvert.ToSafeDateTime(message.date_read); mms.Content = DynamicConvert.ToSafeString(message.text).TrimStart('?') + Environment.NewLine; // 获取当前消息的所有附件; var attaSource = mainContext.Find(new SQLiteString(sb.ToString())); foreach (var atta in attaSource) { if (FragmentHelper.IsValidFragment(atta)) { continue; } string attPath = DynamicConvert.ToSafeString(atta.filename).TrimStart('~').TrimStart('/').Replace("/", @"\"); mms.Content += string.Format("{0}{1}", Path.Combine(attendDirPath, attPath), Environment.NewLine); } mms.Content = FragmentHelper.RemoveNullityDataNew(mms.Content.Trim()); // 验证内容是否为空 if (FragmentHelper.IsEmptyString(mms.Content)) { continue; } dataSource.Items.Add(mms); } } finally { mainContext?.Dispose(); mainContext = null; } }
/// <summary> /// 获取所有推文 /// </summary> /// <param name="context"></param> /// <returns></returns> private List <TwitterStatuses> GetAllTwitterStatuses(SqliteContext context) { var items = context.Find(new SQLiteString("SELECT s.XLY_DataType,s.status_id,(SELECT username FROM users WHERE user_id = s.author_id) as username,(SELECT name FROM users WHERE user_id = s.author_id) as author_name,s.in_r_user_id,(SELECT name FROM users WHERE user_id = s.in_r_user_id) as in_r_user_name,s.in_r_status_id,s.content,s.created,s.source,s.favorited,s.retweeted,s.favorite_count,s.retweet_count FROM statuses s ORDER BY s.created")).Select(d => TwitterStatuses.DyConvert(d)).Cast <TwitterStatuses>().Where(i => i.StatusesId.IsValid() && i.StatusesId != "0").ToList(); return(DataTypeFilter(items, (ls, i) => ls.Any(ii => ii.StatusesId == i.StatusesId))); }
/// <summary> /// 解析数据 /// </summary> /// <param name="datasource"></param> public void BuildData(CallDataSource datasource) { if (!FileHelper.IsValid(MainDbPath)) { return; } SqliteContext mainContext = null; try { //主数据库对象 var mainDbPath = SqliteRecoveryHelper.DataRecovery(MainDbPath, "", "ZCALLRECORD", true); mainContext = new SqliteContext(mainDbPath); IEnumerable <dynamic> addressDynamicList = null; if (FileHelper.IsValid(AddrDbPath)) { var addressDbPath = SqliteRecoveryHelper.DataRecovery(AddrDbPath, @"chalib\IOS_Contact\AddressBook.sqlitedb.charactor", "ABMultiValue,ABPerson", true); SqliteContext addrContext = new SqliteContext(addressDbPath); addressDynamicList = addrContext.Find("select p.[value],p.[record_id],v.[Last],v.[ROWID] from ABMultiValue p left join ABPerson v on p.[record_id]=v.[ROWID] where p.[property]=3"); addrContext.Dispose(); addrContext = null; } mainContext.UsingSafeConnection("select XLY_DataType,ZDURATION,Z_OPT,ZDURATION,ZORIGINATED,cast(ZADDRESS as varchar) as number, cast(ZDATE as DATETIME) as phonetime from ZCALLRECORD", r => { Call call; dynamic callObj; while (r.Read()) { callObj = r.ToDynamic(); call = new Call(); call.Number = DataParseHelper.NumberToStu(DynamicConvert.ToSafeString(callObj.number)); // 号码过滤,验证号码长度 if (!DataParseHelper.ValidateNumber(call.Number)) { continue; } if (addressDynamicList.IsValid()) { var addressname = addressDynamicList.FirstOrDefault(o => DynamicConvert.ToSafeString(o.value).Replace("-", "").Equals(callObj.number)); if (addressname != null) { call.Name = FragmentHelper.RemoveNullityDataNew(DynamicConvert.ToSafeString(addressname.Last)); } } call.DataState = DynamicConvert.ToEnumByValue(callObj.XLY_DataType, EnumDataState.Normal); call.DurationSecond = DynamicConvert.ToSafeInt(callObj.ZDURATION); string time = DynamicConvert.ToSafeString(callObj.phonetime).Insert(0, "1"); double opertime = time.ToDouble() - 21692848; call.StartDate = DynamicConvert.ToSafeDateTime(opertime); call.Type = GetCallV10Status(DynamicConvert.ToSafeInt(callObj.ZORIGINATED), call.DurationSecond); datasource.Items.Add(call); } }); } finally { mainContext?.Dispose(); mainContext = null; } }
/// <summary> /// 解析数据 /// </summary> /// <param name="datasource"></param> public void BuildData(CallDataSource datasource) { if (!FileHelper.IsValid(MainDbPath)) { return; } using (var context = new SqliteContext(MainDbPath)) { using (var contactDb = new SqliteContext(ContactDbPath)) { var smsList = context.Find(new SQLiteString("SELECT address,date,body,type,read FROM sms_tb")); foreach (var smsData in smsList) { SMS smsTemp = new SMS(); smsTemp.Content = DynamicConvert.ToSafeString(smsData.body); smsTemp.Number = DynamicConvert.ToSafeString(smsData.address); smsTemp.Number = smsTemp.Number.TrimStart("+86"); smsTemp.ContactName = FindName(contactDb, smsTemp.Number); smsTemp.StartDate = new DateTime(1970, 1, 1).AddSeconds(DynamicConvert.ToSafeLong(smsData.date) / 1000).AddHours(8); string type = DynamicConvert.ToSafeString(smsData.type); switch (type) { case "1": smsTemp.SmsState = EnumSMSState.ReceiveSMS; string read = DynamicConvert.ToSafeString(smsData.read); switch (read) { case "1": smsTemp.ReadState = EnumReadState.Read; //smsTemp.SmsReadState = LanguageHelper.Get("LANGKEY_YiDu_01076"); break; case "0": smsTemp.ReadState = EnumReadState.Unread; //smsTemp.SmsReadState = LanguageHelper.Get("LANGKEY_WeiDu_01077"); break; } break; case "2": smsTemp.SmsState = EnumSMSState.SendSMS; break; case "3": smsTemp.SmsState = EnumSMSState.DraftSMS; break; case "5": smsTemp.SmsState = EnumSMSState.SendSMS; break; default: smsTemp.SmsState = EnumSMSState.None; break; } smsTemp.DataState = EnumDataState.Normal; datasource.Items.Add(smsTemp); } var smsListA = context.Find(new SQLiteString("SELECT send_msg_status,msg_content,msg_date,address FROM table_broadcastchat_tb")); foreach (var smsData in smsListA) { SMS smsTemp = new SMS(); smsTemp.Content = DynamicConvert.ToSafeString(smsData.msg_content); smsTemp.Number = DynamicConvert.ToSafeString(smsData.address); smsTemp.Number = smsTemp.Number.TrimStart("+86"); smsTemp.ContactName = FindName(contactDb, smsTemp.Number); smsTemp.StartDate = new DateTime(1970, 1, 1).AddSeconds(DynamicConvert.ToSafeLong(smsData.msg_date) / 1000).AddHours(8); string type = DynamicConvert.ToSafeString(smsData.send_msg_status); switch (type) { case "2": //群发 case "5": //群发 smsTemp.SmsState = EnumSMSState.SendSMS; break; case "3": //发送 smsTemp.SmsState = EnumSMSState.SendSMS; break; case "8": //草稿箱 smsTemp.SmsState = EnumSMSState.DraftSMS; break; default: smsTemp.SmsState = EnumSMSState.None; break; } smsTemp.DataState = EnumDataState.Normal; datasource.Items.Add(smsTemp); } } } }
private void BuildData(MMSDataSource ds, string databasesFilePath) { var nfile = SqliteRecoveryHelper.DataRecovery(databasesFilePath, "", "canonical_addresses,pdu,part"); using (var sqliteContext = new SqliteContext(nfile)) { MMS item = null; // 获取所有彩信信息; List <dynamic> itemsMMS = sqliteContext.FindByName("pdu").ToList(); List <dynamic> itemsAddr = sqliteContext.FindByName("canonical_addresses").ToList(); List <dynamic> itemsPart = sqliteContext.Find(new SQLiteString("select * from part where ct not in ('application/smil')")).ToList(); foreach (var o in itemsMMS) { try { item = new MMS(); item.DataState = DynamicConvert.ToEnumByValue <EnumDataState>(o.XLY_DataType, EnumDataState.Normal); item.SendState = DynamicConvert.ToSafeInt(o.msg_box) == 1 ? EnumSendState.Receive : EnumSendState.Send; item.Date = DynamicConvert.ToSafeDateTime(o.date); // 获取彩信的扩展; var resultAddr = itemsAddr.Find(addr => DynamicConvert.ToSafeInt(addr.xly_id) == DynamicConvert.ToSafeInt(o.thread_id)); if (resultAddr == null) { continue; } item.SenderName = DataParseHelper.NumberToStu(DynamicConvert.ToSafeString(resultAddr.address)); // 内容扩展 var resultPart = itemsPart.FindAll(part => DynamicConvert.ToSafeInt(part.mid) == DynamicConvert.ToSafeInt(o.xly_id)); // 这段方法虽然看起来不爽,但是别删!有个别手机数据结构不同!这里主要兼容; wangxi 2014-7-14 17:14:05 if (string.IsNullOrEmpty(item.SenderName) && resultPart.Count != 0) { var num = itemsAddr.Find(addr => DynamicConvert.ToSafeInt(resultPart.First().xly_id) == DynamicConvert.ToSafeInt(addr.xly_id)); item.SenderName = DynamicConvert.ToSafeString(num.address); item.SenderName = DataParseHelper.NumberToStu(item.SenderName); } if (resultPart.Count == 0) { item.Content = DynamicConvert.ToSafeString(o.ct_l); item.Type = EnumColumnType.URL; } else { if (resultPart.Count == 1) { if (DynamicConvert.ToSafeString(resultPart.First().xly_data) != "") { item.Content = DynamicConvert.ToSafeString(resultPart.First().xly_data).TrimStart('/').Replace("/", @"\"); } else { item.Content = DynamicConvert.ToSafeString(resultPart.First().text); } } if (resultPart.Count > 1) { // 获取所有附加消息; var allMsg = resultPart.FindAll(part => DynamicConvert.ToSafeString(part.ct).Equals("text/plain")); var allPart = resultPart.FindAll(part => DynamicConvert.ToSafeString(part.text) == string.Empty); string message = string.Empty; foreach (var mess in allMsg) { message += string.Format("{0}{1}", mess.text, Environment.NewLine); } string parts = string.Empty; foreach (var part in allPart) { if (!string.IsNullOrEmpty(DynamicConvert.ToSafeString(part.xly_data))) { string npath = DynamicConvert.ToSafeString(part.xly_data); parts += string.Format("{0}{1}", npath, Environment.NewLine); } } item.Content = parts + message; } } item.Content = item.Content.Trim(); ds.Items.Add(item); } catch { } } } }
/// <summary> /// 构造聊天节点 /// </summary> /// <param name="masterAccount"></param> /// <param name="allUsers"></param> /// <param name="context"></param> /// <param name="chatNode"></param> private void CreateConversationNode(TwitterAccount masterAccount, List <TwitterAccount> allUsers, SqliteContext context, TreeNode chatNode) { TreeNode privateChatNode = new TreeNode() { Type = typeof(TwitterConverstationEntry), Text = "私聊", Items = new DataItems <TwitterConverstationEntry>(DbFilePath) }; TreeNode groupChatNode = new TreeNode() { Type = typeof(TwitterGroupConverstation), Text = "群聊", Items = new DataItems <TwitterGroupConverstation>(DbFilePath) }; //1.获取私聊 var privateChatUsers = context.Find(new SQLiteString("SELECT conversation_id FROM conversations WHERE type = 0 ORDER BY _id")); foreach (var privateChat in privateChatUsers) { string conversation_id = DynamicConvert.ToSafeString(privateChat.conversation_id);//私聊id格式为 XXX-MMM //获取用户列表 var chatUsers = context.Find(new SQLiteString(string.Format("SELECT user_id FROM conversation_participants WHERE conversation_id = '{0}'", conversation_id))); //if (chatUsers.IsInvalid() || chatUsers.Count != 2) //{ // continue; //} TreeNode tempChatNode = new TreeNode() { Type = typeof(TwitterConverstationEntry), Items = new DataItems <TwitterConverstationEntry>(DbFilePath) }; //获取私聊对象信息 string otherUserId = chatUsers.Select(u => DynamicConvert.ToSafeString(u.user_id)).FirstOrDefault(id => id != masterAccount.UserId); var otherUser = allUsers.FirstOrDefault(u => u.UserId == otherUserId); if (null != otherUser) { tempChatNode.Text = string.Format("{0}({1})", otherUser.NickName, otherUser.UserName); } else { tempChatNode.Text = otherUserId; } //获取聊天内容 var entries = context.Find(new SQLiteString(string.Format("SELECT c.user_id,u.username,u.name,c.created,c.entry_type,c.data,c.request_id FROM conversation_entries c,users u WHERE c.conversation_id = '{0}' AND c.entry_type IN (0,1) AND c.user_id = u.user_id ORDER BY c.created", conversation_id))); foreach (var entry in entries) { tempChatNode.Items.Add(TwitterConverstationEntry.DyConvert(masterAccount, entry)); } privateChatNode.TreeNodes.Add(tempChatNode); } //2.获取群聊 var groupChats = context.Find(new SQLiteString("SELECT conversation_id,title FROM conversations WHERE type = 1 ORDER BY _id")); foreach (var groupChat in groupChats) { string conversation_id = DynamicConvert.ToSafeString(groupChat.conversation_id); //群聊id string conversation_name = DynamicConvert.ToSafeString(groupChat.title); //群聊名称 TwitterGroupConverstation group = new TwitterGroupConverstation(); group.ConversationId = conversation_id; group.GroupName = conversation_name; //获取用户列表 var chatUsers = context.Find(new SQLiteString(string.Format("SELECT u.username,u.name,c.join_time FROM conversation_participants c,users u WHERE c.conversation_id = '{0}' AND c.user_id = u.user_id", conversation_id))); group.GroupMembersCount = chatUsers.Count(); //构造群聊信息 StringBuilder sb = new StringBuilder(); foreach (var user in chatUsers) { var username = DynamicConvert.ToSafeString(user.username); var nickname = DynamicConvert.ToSafeString(user.name); sb.AppendLine(string.Format("{0} {1}", username, nickname)); } group.GroupMembers = sb.ToString(); //获取聊天内容 TreeNode tempGroupChatNode = new TreeNode() { Type = typeof(TwitterConverstationEntry), Items = new DataItems <TwitterConverstationEntry>(DbFilePath) }; tempGroupChatNode.Text = string.Format("{0}({1})", conversation_name, conversation_id); var entries = context.Find(new SQLiteString(string.Format("SELECT c.user_id,u.username,u.name,c.created,c.entry_type,c.data,c.request_id FROM conversation_entries c,users u WHERE c.conversation_id = '{0}' AND c.entry_type IN (0,1) AND c.user_id = u.user_id ORDER BY c.created", conversation_id))); foreach (var entry in entries) { tempGroupChatNode.Items.Add(TwitterConverstationEntry.DyConvert(masterAccount, entry)); } groupChatNode.Items.Add(group); groupChatNode.TreeNodes.Add(tempGroupChatNode); } chatNode.TreeNodes.Add(privateChatNode); chatNode.TreeNodes.Add(groupChatNode); }
/// <summary> /// 解析数据 /// </summary> /// <param name="datasource"></param> public void BuildData(ContactDataSource datasource) { if (!FileHelper.IsValid(MainDbPath)) { return; } SqliteContext mainContext = null; try { var rMainDbFile = SqliteRecoveryHelper.DataRecovery(MainDbPath, @"chalib\IOS_Contact\AddressBook.sqlitedb_V7.charactor", "ABPerson,ABMultiValue,ABGroupMembers,ABGroup", true); mainContext = new SqliteContext(rMainDbFile); string groupString = "select member_id,Name from ABGroupMembers m left join ABGroup g on m.group_id == g.ROWID"; var groups = mainContext.Find(groupString); mainContext.UsingSafeConnection("select p.*,v.record_id,v.property,v.label,v.[value] from ABPerson p,ABMultiValue v WHERE p.ROWID = v.record_id", r => { Contact contact; dynamic contactObj; while (r.Read()) { contactObj = r.ToDynamic(); contact = new Contact(); contact.DataState = DynamicConvert.ToEnumByValue(contactObj.XLY_DataType, EnumDataState.Normal); //正常的联系人,目前只处理电话号码的信息,如亲属关系,社交等暂不处理。 if (contact.DataState == EnumDataState.Normal) { int propertyId = DynamicConvert.ToSafeInt(contactObj.property); if (propertyId != 3) { continue; } } contact.Name = DynamicConvert.ToSafeString(contactObj.Last) + DynamicConvert.ToSafeString(contactObj.First); contact.Name = FragmentHelper.RemoveNullityDataNew(contact.Name); contact.Number = DataParseHelper.NumberToStu(DynamicConvert.ToSafeString(contactObj.value)); // 号码过滤,验证号码长度 if (!DataParseHelper.ValidateNumber(contact.Number)) { continue; } //创建时间(最后修改时间) contact.CreateDate = DynamicConvert.ToSafeDateTime(contactObj.ModificationDate, 2001); //联系人分组 int contactId = DynamicConvert.ToSafeInt(contactObj.ROWID); var groupObj = groups.FirstOrDefault(g => DynamicConvert.ToSafeInt(g.member_id) == contactId); if (groupObj != null) { contact.GroupName = DynamicConvert.ToSafeString(groupObj.Name); } //基础备注 contact.Remark = BuildRemark(contactObj).ToString().TrimStart(';'); datasource.Items.Add(contact); } }); } finally { mainContext?.Dispose(); mainContext = null; } }