Пример #1
0
        /// <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;
            }
        }
Пример #2
0
        /// <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;
            }
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        /// <summary>
        /// 获取通讯录  包括好友和群聊
        /// </summary>
        private void LoadAllContacts()
        {
            LsAllFriends      = new List <WeChatFriendShow>();
            LsAllGroupFriends = new List <WeChatGroupShow>();

            #region 从MM.sqlite的Friend表获取好友信息

            var sql = @"SELECT
                            f.*, 
                            e.*
                        FROM
                            Friend f
                        LEFT JOIN Friend_Ext e ON f.UsrName = e.UsrName";
            MainContext.UsingSafeConnection(sql, r =>
            {
                dynamic data;
                WeChatFriendShow friendInfo;

                while (r.Read())
                {
                    data = r.ToDynamic();

                    if (DynamicConvert.ToSafeString(data.UsrName).Contains("@chatroom"))
                    {
                        LsAllGroupFriends.Add(CreateWeChatGroupShow(data));
                    }
                    else
                    {
                        friendInfo = new WeChatFriendShow();
                        CreateWeChatFriendShow(data, ref friendInfo);

                        LsAllFriends.Add(friendInfo);
                    }
                }
            });

            #endregion

            #region 从WCDB_Contact.sqlite的表Friend获取好友信息

            string WCDBPath = Path.Combine(MD5AccountPath, "DB", "WCDB_Contact.sqlite");
            if (FileHelper.IsValid(WCDBPath))
            {
                List <char> listC = new List <char>();
                for (int i = 0; i < 32; i++)
                {
                    listC.Add((char)i);
                }
                listC.Add((char)127);
                var arrC = listC.ToArray();//分割字符

                using (var WCDB = new SqliteContext(WCDBPath))
                {
                    WCDB.UsingSafeConnection("SELECT * FROM Friend WHERE imgStatus != 1", r =>
                    {//imgStatus为1的记录为系统功能
                        dynamic fd;
                        DynamicEx dy;
                        WeChatFriendShow friendInfo;

                        while (r.Read())
                        {
                            fd = r.ToDynamic();

                            dy = new DynamicEx();
                            dy.Set("UsrName", fd.userName);
                            dy.Set("type", fd.type);
                            dy.Set("certificationFlag", fd.certificationFlag);
                            dy.Set("imgStatus", fd.imgStatus);
                            dy.Set("XLY_DataType", "2");

                            byte[] dbContactRemark = fd.dbContactRemark;
                            if (dbContactRemark.IsValid())
                            {//获取昵称、备注、修改后微信号
                                GetdbContactRemark(dbContactRemark, ref dy);
                            }

                            byte[] dbContactProfile = fd.dbContactProfile;
                            if (dbContactProfile.IsValid())
                            {//获取位置和签名
                                GetdbContactProfile(dbContactProfile, ref dy);
                            }

                            byte[] dbContactChatRoom = fd.dbContactChatRoom;
                            if (dbContactChatRoom.IsValid())
                            {//获取群组成员列表
                                var dArr = System.Text.Encoding.UTF8.GetString(dbContactChatRoom).Split(arrC, StringSplitOptions.RemoveEmptyEntries).ToList();
                                if (dArr.IsValid())
                                {
                                    string ConChatRoomMem   = dArr.FirstOrDefault(d => d.Contains(";"));
                                    string ConChatRoomOwner = "";
                                    if (dArr.IndexOf(ConChatRoomMem) + 1 < dArr.Count)
                                    {//群组的创建者在群组成员后面
                                        ConChatRoomOwner = dArr[dArr.IndexOf(ConChatRoomMem) + 1];
                                    }

                                    if (0 == dArr.IndexOf(ConChatRoomMem))
                                    {//如果成员的索引是0,前面会多出一个随机的字符
                                        ConChatRoomMem = ConChatRoomMem.Substring(1);
                                    }

                                    dy.Set("ConChatRoomMem", ConChatRoomMem);
                                    dy.Set("ConChatRoomOwner", ConChatRoomOwner);
                                }
                            }

                            if (DynamicConvert.ToSafeString(fd.userName).Contains("@chatroom"))
                            {
                                LsAllGroupFriends.Add(CreateWeChatGroupShow(dy));
                            }
                            else
                            {
                                friendInfo = new WeChatFriendShow();
                                CreateWeChatFriendShow(dy, ref friendInfo);

                                LsAllFriends.Add(friendInfo);
                            }
                        }
                    });
                }
            }

            #endregion
        }
        /// <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;
            }
        }
Пример #6
0
        /// <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;
            }
        }