Пример #1
0
    def analyze_contact_oppo_bac(self):
        '''解析oppo系统自带案例'''
        try:
            vcf_dir = self.node.PathWithMountPoint
            f = open(vcf_dir, 'r')
            for line in f.readlines():
                if re.findall('BEGIN:VCARD', line):
                    self.oppo_dic = {}
                elif re.findall('END:VCARD', line):
                    self.oppo_dics.append(self.oppo_dic)
                #获取姓名
                elif re.findall("FN:", line) or re.findall("FN;", line):
                    self.vcf_helper("name", line)
                #获取电话号码
                elif re.findall("TEL:", line) or re.findall("TEL;", line):
                    self.vcf_helper("phone", line)
                #获取email
                elif re.findall("EMAIL:", line) or re.findall("EMAIL;", line):
                    self.vcf_helper("email", line)
                #获取地址
                elif re.findall("ADR:", line) or re.findall("ADR;", line):
                    self.vcf_helper("address", line)
                #获取备注
                elif re.findall("NOTE:", line) or re.findall("NOTE;", line):
                    self.vcf_helper("note", line)
                #获取公司
                elif re.findall("ORG:", line) or re.findall("ORG;", line):
                    self.vcf_helper("organization", line)
                #获取职务
                elif re.findall("TITLE:", line) or re.findall("TITLE;", line):
                    self.vcf_helper("occupation", line)

            for value in self.oppo_dics:
                try:
                    contacts = model_contact.Contact()
                    contacts.mail = self._verify_dict(value, "email")
                    contacts.company = self._verify_dict(value, "organization")
                    contacts.title = self._verify_dict(value, "occupation")
                    phone_number = self._verify_dict(value, "phone")
                    formatphone = self._verify_dict(value, "formatphone")
                    if formatphone is not None and formatphone is not '':
                        contacts.phone_number = formatphone
                    elif phone_number is not None:
                        contacts.phone_number = phone_number
                    else:
                        contacts.phone_number = ""
                    contacts.name = self._verify_dict(value, "name")
                    contacts.address = self._verify_dict(value, "address")
                    contacts.notes = self._verify_dict(value, "note")
                    contacts.source = self.node.AbsolutePath
                    self.db_insert_table_call_contacts(contacts)
                except:
                    traceback.print_exc()
            self.db_commit()
        except:
            traceback.print_exc()
Пример #2
0
    def _parse_contacts(self, node):
        contacts_files = node.Search(r'Contact_\d+.txt')
        for file_ in contacts_files:

            data = self._open_json(file_)
            if not data:
                continue

            post_success = data.get('result', None)
            if post_success != 'ok':
                continue

            contacts = data.get('data', {}).get('content', None)
            if not contacts:
                continue

            for contact_id, contact_info in contacts.items():
                try:
                    contact = model_contact.Contact()
                    contact.raw_contact_id = contact_id
                    contact.source = file_.AbsolutePath
                    detail = contact_info.get('content', {})
                    contact.name = detail.get('displayName', None)
                    contact.phone_number = ",".join(
                        [p['value'] for p in detail.get('phoneNumbers', [])])
                    contact.company = ",".join([
                        o.get('company', '')
                        for o in detail.get('organizations', [])
                    ])
                    contact.mail = ",".join(
                        [p['value'] for p in detail.get('emails', [])])
                    contact.notes = detail.get('note', None)
                    self.cm.db_insert_table_call_contacts(contact)
                except Exception as e:
                    print(e)

        self.cm.db_commit()
Пример #3
0
 def analyze_raw_contact_table(self):
     '''分析raw_contacts表获取联系次数与最近联系时间'''
     try:
         db = SQLiteParser.Database.FromNode(self.node, canceller)
         if db is None:
             return
         ts = SQLiteParser.TableSignature('raw_contacts')
         for rec in db.ReadTableRecords(ts, self.extractDeleted, True):
             contacts = model_contact.Contact()
             if canceller.IsCancellationRequested:
                 break
             id = self._db_record_get_int_value(rec, 'contact_id')
             times_contacted = self._db_record_get_int_value(
                 rec, 'times_contacted')
             last_time_contacted = self._db_record_get_int_value(
                 rec, 'last_time_contacted')
             if id not in self.raw_contact.keys():
                 self.raw_contact[id] = [
                     times_contacted, last_time_contacted
                 ]
     except Exception as e:
         print(e)
     except:
         traceback.print_exc()
Пример #4
0
 def parse_contact(self, file):
     f = open(file, 'r')
     lines = f.readlines()
     f.close()
     data = ''.join(lines).strip().replace('\n', '')
     try:
         data = json.loads(data)
         if "Rbeans" in data:
             contacts = data["Rbeans"]
             for contact in contacts:
                 c = model_contact.Contact()
                 contactId = contact["contactId"]
                 name_info = contact["name"]
                 first_name = name_info["firstName"]
                 last_name = name_info["lastName"]
                 middle_name = name_info["middleName"]
                 name = first_name + middle_name + last_name
                 c.raw_contact_id = contactId
                 c.name = name
                 c.source = self.file_node.AbsolutePath
                 self.db_insert_table_call_contacts(c)
             self.db_commit()
     except:
         pass
Пример #5
0
 def analyze_contact_huawei_bac(self):
     '''解析华为备份案例'''
     try:
         db = SQLiteParser.Database.FromNode(self.node, canceller)
         if db is None:
             return
         ts = SQLiteParser.TableSignature('data_tb')
         data_dic = {}  #{id:data}
         data = {
         }  #{"name":"xxx", "email":"xxx", "phone":"xxx", address:"xxx", organization:"xxx", occupation:"xxx", note:"xxx"}
         #使用字典嵌套保存整理后的数据
         #while (sr.Read()):
         for rec in db.ReadTableRecords(ts, self.extractDeleted, True):
             try:
                 if canceller.IsCancellationRequested:
                     break
                 id = self._db_record_get_int_value(rec, "raw_contact_id")
                 mimetype = self._db_record_get_string_value(
                     rec, "mimetype")
                 data1 = self._db_record_get_string_value(rec, "data1")
                 data2 = self._db_record_get_string_value(rec, "data2")
                 data3 = self._db_record_get_string_value(rec, "data3")
                 data4 = self._db_record_get_string_value(rec, "data4")
                 data5 = ""
                 if id not in data_dic.keys():
                     data = self._regularMatch(mimetype, data1, data2,
                                               data3, data4, data5)
                     if not data:
                         continue
                     data_dic[id] = data
                 else:
                     d = self._regularMatch(mimetype, data1, data2, data3,
                                            data4, data5)
                     if not d:
                         continue
                     if "phone" in d and "phone" in data_dic[id]:
                         if not re.findall(d["phone"],
                                           data_dic[id]["phone"]):
                             data_dic[id]["phone"] = data_dic[id][
                                 "phone"] + "," + d["phone"]
                     if "formatphone" in d and "formatphone" in data_dic[id]:
                         if not re.findall(
                                 d["formatphone"].replace("+", ""),
                                 data_dic[id]["formatphone"]):
                             data_dic[id]["formatphone"] = data_dic[id][
                                 "formatphone"] + "," + d["formatphone"]
                     elif "email" in d and "email" in data_dic[id]:
                         if not re.findall(d["email"],
                                           data_dic[id]["email"]):
                             data_dic[id]["email"] = data_dic[id][
                                 "email"] + "," + d["email"]
                     elif "address" in d and "address" in data_dic[id]:
                         if not re.findall(d["address"],
                                           data_dic[id]["address"]):
                             data_dic[id]["address"] = data_dic[id][
                                 "address"] + "," + d["address"]
                     else:
                         data_dic[id] = dict(data_dic[id].items() +
                                             d.items())
             except:
                 traceback.print_exc()
         #将嵌套字典中的数据保存至中间数据库
         for data in data_dic.items():
             try:
                 key = data[0]
                 value = data[1]
                 contacts = model_contact.Contact()
                 contacts.raw_contact_id = key
                 contacts.mail = self._verify_dict(value, "email")
                 contacts.company = self._verify_dict(value, "organization")
                 contacts.title = self._verify_dict(value, "occupation")
                 phone_number = self._verify_dict(value, "phone")
                 formatphone = self._verify_dict(value, "formatphone")
                 if formatphone is not None and formatphone is not '':
                     contacts.phone_number = formatphone
                 elif phone_number is not None:
                     contacts.phone_number = phone_number
                 else:
                     contacts.phone_number = ""
                 contacts.name = self._verify_dict(value, "name")
                 contacts.address = self._verify_dict(value, "address")
                 contacts.notes = self._verify_dict(value, "note")
                 contacts.source = self.node.AbsolutePath
                 self.db_insert_table_call_contacts(contacts)
             except:
                 pass
         self.db_commit()
     except:
         traceback.print_exc()
Пример #6
0
    def analyze_contact_logic_case1(self):
        '''逻辑提取案例'''
        try:
            db = SQLiteParser.Database.FromNode(self.node, canceller)
            if db is None:
                return
            ts = SQLiteParser.TableSignature('AddressBook')
            id = 0
            for rec in db.ReadTableRecords(ts, self.extractDeleted, True):
                contacts = model_contact.Contact()
                id += 1
                if canceller.IsCancellationRequested:
                    break
                contacts.raw_contact_id = id
                #邮箱
                homeEmail = self._db_record_get_string_value(rec, "homeEmails")
                jobEmail = self._db_record_get_string_value(rec, "jobEmails")
                customEmail = self._db_record_get_string_value(
                    rec, "customEmails")
                otherEmail = self._db_record_get_string_value(
                    rec, "otherEmails")
                emails = homeEmail + jobEmail + customEmail + otherEmail
                contacts.mail = emails.replace('\n', '').replace(
                    '][',
                    ',').replace('[',
                                 '').replace(']',
                                             '').replace('\"',
                                                         '').replace(' ', '')
                contacts.company = self._db_record_get_string_value(
                    rec, "organization")

                #电话号码
                phonenumber = self._db_record_get_string_value(
                    rec, "phoneNumbers")
                homenumber = self._db_record_get_string_value(
                    rec, "homeNumbers")
                jobnumber = self._db_record_get_string_value(rec, "jobNumbers")
                othernumber = self._db_record_get_string_value(
                    rec, "otherNumbers")
                customnumber = self._db_record_get_string_value(
                    rec, "customNumbers")
                numbers = phonenumber + homenumber + jobnumber + othernumber + customnumber
                pnumber = numbers.replace('\n', '').replace('][', ',').replace(
                    '[', '').replace(']', '').replace('\"',
                                                      '').replace(' ', '')
                pnumber = pnumber.split(',')
                pnumber = list(set(pnumber))
                contacts.phone_number = ','.join(pnumber)
                contacts.name = self._db_record_get_string_value(rec, "name")
                contacts.address = self._db_record_get_string_value(
                    rec, "homeStreets")
                contacts.notes = self._db_record_get_string_value(
                    rec, "remark")
                #pic_url = self.node.Parent.Parent.AbsolutePath + '/' + self._db_record_get_string_value(rec, "photoPath")
                #contacts.head_pic = pic_url
                contacts.source = self.node.AbsolutePath
                contacts.deleted = rec.IsDeleted
                self.db_insert_table_call_contacts(contacts)
            self.db_commit()
        except Exception as e:
            print(e)
Пример #7
0
    def analyze_contact_case1(self):
        '''从提取的删除数据库中获取数据,整理到中间数据库中'''
        try:
            db = SQLite.SQLiteConnection('Data Source = {}'.format(
                self.deleted_db))
            db.Open()
            db_cmd = SQLite.SQLiteCommand(db)
            if db is None:
                return
            db_cmd.CommandText = SQL_SEARCH_TABLE_DATA
            sr = db_cmd.ExecuteReader()
            data_dic = {}  #{id:data}
            data = {
            }  #{"name":"xxx", "email":"xxx", "phone":"xxx", address:"xxx", organization:"xxx", occupation:"xxx", note:"xxx"}
            #使用字典嵌套保存整理后的数据
            while (sr.Read()):
                try:
                    if canceller.IsCancellationRequested:
                        break
                    id = self._db_reader_get_int_value(sr, 0)
                    mimetype = self._db_reader_get_string_value(sr, 1)
                    data1 = self._db_reader_get_string_value(sr, 2)
                    data2 = self._db_reader_get_string_value(sr, 3)
                    data3 = self._db_reader_get_string_value(sr, 4)
                    data4 = self._db_reader_get_string_value(sr, 5)
                    data5 = self._db_reader_get_string_value(sr, 6)
                    deleted = self._db_reader_get_int_value(sr, 7)
                    if id not in data_dic.keys():
                        data = self._regularMatch(mimetype, data1, data2,
                                                  data3, data4, data5)
                        if not data:
                            continue
                        data = dict(data.items() + [("deleted", deleted)])
                        data_dic[id] = data
                    else:
                        d = self._regularMatch(mimetype, data1, data2, data3,
                                               data4, data5)
                        if not d:
                            continue
                        if "phone" in d and "phone" in data_dic[id]:

                            if not re.findall(d["phone"].replace("+", ""),
                                              data_dic[id]["phone"]):
                                data_dic[id]["phone"] = data_dic[id][
                                    "phone"] + "," + d["phone"]
                        elif "formatphone" in d and "formatphone" in data_dic[
                                id]:
                            if not re.findall(d["formatphone"],
                                              data_dic[id]["formatphone"]):
                                data_dic[id]["formatphone"] = data_dic[id][
                                    "formatphone"] + "," + d["formatphone"]
                        elif "email" in d and "email" in data_dic[id]:
                            if not re.findall(d["email"].replace("\\", ""),
                                              data_dic[id]["email"]):
                                data_dic[id]["email"] = data_dic[id][
                                    "email"] + "," + d["email"]
                        elif "address" in d and "address" in data_dic[id]:
                            if not re.findall(d["address"],
                                              data_dic[id]["address"]):
                                data_dic[id]["address"] = data_dic[id][
                                    "address"] + "," + d["address"]
                        else:
                            data_dic[id] = dict(data_dic[id].items() +
                                                d.items())
                except:
                    traceback.print_exc()
            sr.Close()
            db_cmd.Dispose()
            db.Close()
            #将嵌套字典中的数据保存至中间数据库
            for data in data_dic.items():
                try:
                    key = data[0]
                    value = data[1]
                    contacts = model_contact.Contact()
                    contacts.raw_contact_id = key
                    contacts.mail = self._verify_dict(value, "email")
                    contacts.company = self._verify_dict(value, "organization")
                    contacts.title = self._verify_dict(value, "occupation")
                    phone_number = self._verify_dict(value, "phone")
                    formatphone = self._verify_dict(value, "formatphone")
                    contacts.phone_number = phone_number
                    #if formatphone is not None and formatphone is not '':
                    #    contacts.phone_number = formatphone
                    #elif phone_number is not None:
                    #    contacts.phone_number = phone_number
                    #else:
                    #    contacts.phone_number = ""
                    contacts.name = self._verify_dict(value, "name")
                    contacts.address = self._verify_dict(value, "address")
                    contacts.notes = self._verify_dict(value, "note")
                    raw_contact = self._verify_dict(self.raw_contact, key)
                    if raw_contact is not None:
                        contacts.times_contacted = raw_contact[0]
                        contacts.last_time_contact = raw_contact[1]
                    contacts.source = self.contact_node.AbsolutePath
                    contacts.deleted = self._verify_dict(value, "deleted")
                    self.db_insert_table_call_contacts(contacts)
                except:
                    pass
            self.db_commit()
        except:
            traceback.print_exc()
Пример #8
0
 def parse_contact(self, file):
     f = open(file, 'r')
     lines = f.readlines()
     f.close()
     data = ''.join(lines).strip().replace('\n', '')
     try:
         data = json.loads(data)
         info = data['info'] if 'info' in data else ''
         if info is not '':
             vcards = info['vacrds'] if 'vacrds' in info else []
             for vcard in vcards:
                 try:
                     dataid = vcard['dataid'] if 'dataid' in vcard else 0
                     contact_info = vcard[
                         'vcard'] if 'vcard' in vcard else {}
                     if contact_info is {}:
                         return
                     n = contact_info['N'] if 'N' in contact_info else []
                     names = []
                     for i in n:
                         if 'VALUE' in i:
                             names.append(i['VALUE'])
                     n = contact_info[
                         'TEL'] if 'TEL' in contact_info else []
                     numbers = []
                     for i in n:
                         if 'VALUE' in i:
                             numbers.append(i['VALUE'])
                     n = contact_info[
                         'NOTE'] if 'NOTE' in contact_info else []
                     notes = []
                     for i in n:
                         if 'VALUE' in i:
                             notes.append(i['VALUE'])
                     n = contact_info[
                         'EMAIL'] if 'EMAIL' in contact_info else []
                     emails = []
                     for i in n:
                         if 'VALUE' in i:
                             emails.append(i['VALUE'])
                     n = contact_info[
                         'TITLE'] if 'TITLE' in contact_info else []
                     titles = []
                     for i in n:
                         if 'VALUE' in i:
                             titles.append(i['VALUE'])
                     n = contact_info[
                         'ORG'] if 'ORG' in contact_info else []
                     orgs = []
                     for i in n:
                         if 'VALUE' in i:
                             orgs.append(i['VALUE'])
                     contact = model_contact.Contact()
                     contact.raw_contact_id = dataid
                     contact.mail = ','.join(emails)
                     contact.company = ','.join(orgs)
                     contact.title = ','.join(titles)
                     contact.phone_number = ','.join(numbers)
                     contact.name = ','.join(names).replace(';', '')
                     contact.notes = ','.join(notes)
                     contact.source = self.file_node.AbsolutePath
                     self.db_insert_table_call_contacts(contact)
                 except:
                     pass
             self.db_commit()
     except:
         return