/// <summary> /// 解析一组联系人详细信息 /// </summary> /// <param name="groupDataViewList">联系人详情信息分组列表(同一raw_contact_id)</param> /// <param name="contactList">联系人对象列表</param> /// <param name="groupList">群组列表</param> private void TryParseSingleGroupDataView(List <dynamic> groupDataViewList, List <Contact> contactList, IEnumerable <dynamic> groupList) { // 查找当前分组中,保存电话号码数据行列表 //List<dynamic> phoneDataViewList = groupDataViewList.Where(c => c.mimetype.Contains("phone")).ToList(); List <dynamic> phoneDataViewList = groupDataViewList; string number = ""; foreach (var phoneDataView in phoneDataViewList) { number = DataParseHelper.NumberToStu(phoneDataView.data1); // 号码过滤 if (!DataParseHelper.ValidateNumber(number)) { continue; } Contact contact = contactList.FirstOrDefault(s => s.Id == phoneDataView.raw_contact_id); if (contact == null) { contact = new Contact(); contact.Id = DynamicConvert.ToSafeInt(phoneDataView.raw_contact_id); contact.Number = number; contact.DataState = DynamicConvert.ToEnumByValue <EnumDataState>(phoneDataView.XLY_DataType, EnumDataState.Normal); contactList.Add(contact); } TryParseSingleDataView(contact, groupDataViewList, groupList); } }
private string GetPhoteNumber(int handleId, IEnumerable <dynamic> handleDynamicList) { var handleObj = handleDynamicList.FirstOrDefault(h => DynamicConvert.ToSafeInt(h.ROWID) == handleId); if (handleObj != null) { return(DataParseHelper.NumberToStu(handleObj.id)); } return(string.Empty); }
/// <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, @"chalib\IOS_Call\call_history.db.charactor", "call", true); mainContext = new SqliteContext(mainDbPath); mainContext.UsingSafeConnection("SELECT * FROM call", r => { Call call; dynamic callObj; while (r.Read()) { callObj = r.ToDynamic(); call = new Call(); call.DataState = DynamicConvert.ToEnumByValue(callObj.XLY_DataType, EnumDataState.Normal); call.Number = DataParseHelper.NumberToStu(DynamicConvert.ToSafeString(callObj.address)); // 号码过滤,验证号码长度 if (!DataParseHelper.ValidateNumber(call.Number)) { continue; } call.DurationSecond = DynamicConvert.ToSafeInt(callObj.duration); call.StartDate = DynamicConvert.ToSafeDateTime(callObj.date); call.Type = GetCallStatus(DynamicConvert.ToSafeInt(callObj.flags), call.DurationSecond); datasource.Items.Add(call); } }); } finally { mainContext?.Dispose(); mainContext = null; } }
/// <summary> /// 解析联系人列表(raw_contacts表) /// </summary> /// <param name="contactList">raw_contacts表数据列表</param> /// <returns>返回解析后联系人集合</returns> private List <Contact> TryParseItems(IEnumerable <dynamic> contactList) { var items = new List <Contact>(); Contact item; foreach (var sourceitem in contactList) { try { item = new Contact(); item.Name = DynamicConvert.ToSafeString(sourceitem.display_name); if (item.Name.IsInvalid()) { continue; } int id = DynamicConvert.ToSafeInt(sourceitem.xly_id); if (id < 1) { id = DynamicConvert.ToSafeInt(sourceitem.raw_contact_id); } item.Id = id; item.LastContactDate = DynamicConvert.ToSafeDateTime(sourceitem.last_time_contacted); var times = DynamicConvert.ToSafeInt(sourceitem.times_contacted); item.Number = DataParseHelper.NumberToStu(DynamicConvert.ToSafeString(sourceitem.raw_phone_number)); var d = DynamicConvert.ToSafeInt(sourceitem.deleted); var d2 = DynamicConvert.ToEnumByValue <EnumDataState>(sourceitem.XLY_DataType, EnumDataState.Normal); item.DataState = EnumDataState.Normal; if (d == 1 || d2 == EnumDataState.Deleted || d2 == EnumDataState.Fragment) { item.DataState = EnumDataState.Deleted; } if (times > 0) { item.Remark = string.Format("{0}:{1} ", LanguageHelper.GetString(Languagekeys.PluginContacts_Times), times); } items.Add(item); } catch { } } return(items); }
private void TryParseCall(List <Call> items, IEnumerable <dynamic> calls) { foreach (var v in calls) { var item = new Call(); item.DataState = DynamicConvert.ToEnumByValue <EnumDataState>(v.XLY_DataType, EnumDataState.Normal); item.Number = DataParseHelper.NumberToStu(v.number); // 号码过滤,验证号码长度 if (!DataParseHelper.ValidateNumber(v.number)) { continue; } item.DurationSecond = DynamicConvert.ToSafeInt(v.duration); int type = DynamicConvert.ToSafeInt(v.type); switch (type) { case 1: case 3: item.Type = type.ToEnumByValue <EnumCallType>(); break; case 2: item.Type = item.DurationSecond > 0 ? EnumCallType.CallOut : EnumCallType.MissedCallOut; break; case 10: //新建联系人事件 continue; default: item.Type = EnumCallType.None; break; } if (item.DataState == EnumDataState.Normal) { item.Name = DynamicConvert.ToSafeString(v.name); } if ("1" == DynamicConvert.ToSafeString(v.mark_deleted) || "1" == DynamicConvert.ToSafeString(v.deleted)) {//红米 item.DataState = EnumDataState.Deleted; } item.StartDate = DynamicConvert.ToSafeDateTime(v.date); items.Add(item); } }
/// <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> /// 根据phone_lookup表,解析联系人号码 /// </summary> /// <param name="items">联系人列表</param> /// <param name="phoneLookupList">phone_lookup表集合</param> private void TryParsePhoneLookup(List <Contact> items, IEnumerable <dynamic> phoneLookupList) { if (items.IsInvalid() || phoneLookupList.IsInvalid()) { return; } foreach (var p in phoneLookupList) { try { string number = DynamicConvert.ToSafeString(p.normalized_number); number = DataParseHelper.NumberToStu(number); // 号码过滤 if (!DataParseHelper.ValidateNumber(number)) { continue; } //已存在,则跳过 //这儿不能过滤,存在两个联系人同一号码的情况 //if (items.Any(s => s.Number == number)) //{ // continue; //} var c = items.Find(s => s.Id == p.raw_contact_id); if (c == null) { var ncc = new Contact(); ncc.Id = DynamicConvert.ToSafeInt(p.raw_contact_id); ncc.Number = number; ncc.DataState = DynamicConvert.ToEnumByValue <EnumDataState>(p.XLY_DataType, EnumDataState.Normal); items.Add(ncc); continue; } if (c.Number.IsInvalid()) { c.Number = number; continue; } if (c.Number == number) { continue; } //new var nc = new Contact(); nc.Id = c.Id; nc.Name = c.Name; nc.LastContactDate = c.LastContactDate; nc.Remark = c.Remark; var dataState = DynamicConvert.ToEnumByValue <EnumDataState>(p.XLY_DataType, EnumDataState.Normal); if (dataState == EnumDataState.Deleted || dataState == EnumDataState.Fragment) { nc.DataState = EnumDataState.Deleted; } else { nc.DataState = c.DataState; } nc.Number = number; items.Add(nc); } catch { } } }
/// <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; } }
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="datasource"></param> public void BuildData(SmsDataSource datasource) { if (!FileHelper.IsValid(MainDbPath)) { return; } SqliteContext mainContext = null; try { string charatorPath = MatchCharatorPath(); var rMainDbFile = SqliteRecoveryHelper.DataRecovery(MainDbPath, charatorPath, "sms", true); mainContext = new SqliteContext(rMainDbFile); string createSmsSql = string.Empty; var smssList = GetSmssList(mainContext, ref createSmsSql); if (smssList.IsInvalid()) { return; } var contactList = GetContactList(); SMS item; foreach (var sms in smssList) { try { item = new SMS(); item.Content = DynamicConvert.ToSafeString(sms.content); item.Content = FragmentHelper.RemoveNullityDataNew(item.Content); // 验证内容是否为空 if (FragmentHelper.IsEmptyString(item.Content)) { continue; } item.SmsState = DynamicConvert.ToEnumByValue <EnumSMSState>(sms.type, EnumSMSState.None); item.Number = DynamicConvert.ToSafeString(sms.number); item.Number = DataParseHelper.NumberToStu(item.Number); item.ContactName = DynamicConvert.ToSafeString(sms.name); if (item.ContactName.IsInvalid()) { // 关联获取联系人名称 item.ContactName = GetContactName(item.Number, contactList); } item.DataState = DynamicConvert.ToEnumByValue <EnumDataState>(sms.XLY_DataType, EnumDataState.Normal); if (DynamicConvert.ToSafeString(sms.deleted) == "1") { item.DataState = EnumDataState.Deleted; } item.StartDate = DynamicConvert.ToSafeDateTime(sms.date); item.ReadState = DynamicConvert.ToSafeInt(sms.read) == 0 ? EnumReadState.Unread : EnumReadState.Read; datasource.Items.Add(item); } catch { } } } finally { mainContext?.Dispose(); mainContext = null; } }
/// <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; } }