def parse_sms(self, node): res = model_sms.VMSG(node).dict_from_vmsg() for record in res: sms = model_sms.SMS() # sms.sim_id = record.get('') # sms.smsc = record.get('') # sms._id = record.get('') sms.read_status = record.get('read_status') sms.type = record.get('box') # sms.subject = record.get('') sms.body = record.get('content') sms.source = self.vmsg_source _date = record.get('date') if isinstance(_date, (int, long)): sms.delivered_date = _date elif isinstance(_date, str): sms.delivered_date = self._convert_strtime_2_ts(_date) #sms.delivered_date = sms.send_time sms.is_sender = 1 if sms.type in (MSG_TYPE_SENT, MSG_TYPE_OUTBOX, MSG_TYPE_DRAFT) else 0 if sms.is_sender == 1: # 发 sms.sender_phonenumber = self.sim_phonenumber.get( sms.sim_id, None) if sms.sim_id else None sms.sender_name = self._get_contacts(sms.sender_phonenumber) sms.recv_phonenumber = record.get('tel') sms.recv_name = self._get_contacts(sms.recv_phonenumber) else: # 收 sms.sender_phonenumber = record.get('tel') sms.sender_name = self._get_contacts(sms.sender_phonenumber) sms.recv_phonenumber = self.sim_phonenumber.get( sms.sim_id, None) if sms.sim_id else None sms.recv_name = self._get_contacts(sms.recv_phonenumber) self.csm.db_insert_table_sms(sms) self.csm.db_commit()
def _parse_logs_sms(self, rec): sms = model_sms.SMS() sms._id = rec['_id'].Value sms.sim_id = rec['simnum'].Value if rec.ContainsKey('simnum') else None if rec.ContainsKey('is_read'): sms.read_status = rec['is_read'].Value sms.type = rec['type'].Value # MSG_TYPE sms.body = rec['m_content'].Value sms.send_time = rec['date'].Value sms.delivered_date = rec['date'].Value if sms.type in [ MSG_TYPE_INBOX, MSG_TYPE_SENT ] else None sms.is_sender = 1 if sms.type in (MSG_TYPE_SENT, MSG_TYPE_OUTBOX, MSG_TYPE_DRAFT) else 0 _number = rec['normalized_number'].Value if rec.ContainsKey( 'normalized_number') else rec['number'].Value if sms.is_sender == 1: # 发 sms.sender_phonenumber = self.sim_phonenumber.get( sms.sim_id, None) if sms.sim_id else None sms.sender_name = self._get_contacts(sms.sender_phonenumber) sms.recv_phonenumber = _number sms.recv_name = rec['name'].Value else: # 收 sms.sender_phonenumber = _number sms.sender_name = rec['name'].Value sms.recv_phonenumber = self.sim_phonenumber.get( sms.sim_id, None) if sms.sim_id else None sms.recv_name = self._get_contacts(sms.recv_phonenumber) sms.deleted = 1 if rec.IsDeleted else 0 sms.source = self.cur_db_source self.csm.db_insert_table_sms(sms)
def _parse_icing_sms(self, rec): sms = model_sms.SMS() # content://sms/7 # sms_id = rec['uri'].Value.replace('content://sms/', '') sms.sim_id = rec['_id'].Value if rec.ContainsKey('_id') else None sms.deleted = rec['deleted'].Value if rec.ContainsKey('deleted') else 0 sms.smsc = rec['service_center'].Value if rec.ContainsKey( 'service_center') else None sms._id = rec['_id'].Value # sms.read_status = rec['read'].Value sms.type = rec['type'].Value # MSG_TYPE sms.subject = rec['subject'].Value sms.body = rec['body'].Value sms.send_time = rec['date'].Value sms.delivered_date = rec['date'].Value if sms.type in [ MSG_TYPE_INBOX, MSG_TYPE_SENT ] else None sms.is_sender = 1 if sms.type in (MSG_TYPE_SENT, MSG_TYPE_OUTBOX, MSG_TYPE_DRAFT) else 0 if sms.is_sender == 1: # 发 sms.sender_phonenumber = self.sim_phonenumber.get( sms.sim_id, None) if sms.sim_id else None sms.sender_name = self._get_contacts(sms.sender_phonenumber) sms.recv_phonenumber = rec['address'].Value sms.recv_name = self._get_contacts(sms.recv_phonenumber) else: # 收 sms.sender_phonenumber = rec['address'].Value sms.sender_name = self._get_contacts(sms.sender_phonenumber) sms.recv_phonenumber = self.sim_phonenumber.get( sms.sim_id, None) if sms.sim_id else None sms.recv_name = self._get_contacts(sms.recv_phonenumber) sms.deleted = 1 if rec.IsDeleted or sms.deleted else 0 sms.source = self.cur_db_source self.csm.db_insert_table_sms(sms)
def parse_sms(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['vcards'] if 'vcards' in info else [] for vcard in vcards: try: information = vcard[ 'INFORMATION'] if 'INFORMATION' in vcard else '' sender = vcard['SENDER'] if 'SENDER' in vcard else '' sender_name = vcard[ 'SENDNAME'] if 'SENDNAME' in vcard else '' send_date = vcard[ 'SENDDATE'] if 'SENDDATE' in vcard else '' id = vcard['dataid'] if 'dataid' in vcard else 0 sms = model_sms.SMS() sms._id = id sms.sender_phonenumber = sender sms.sender_name = sender_name sms.body = information sms.send_time = self.time2timestamp(send_date) sms.source = self.file_node.AbsolutePath self.db_insert_table_sms(sms) except: pass self.db_commit() except: pass
def _parse_icing_mms(self, rec): ''' FieldName SQLType _id INTEGER msg_type TEXT uri TEXT type INTEGER thread_id INTEGER address TEXT date INTEGER subject TEXT body TEXT score INTEGER content_type TEXT media_uri TEXT read INTEGER ''' try: mms = model_sms.SMS() mms.is_mms = 1 mms._id = rec['_id'].Value mms.subject = AndroidMMSParser._decode_mms_subject( rec['subject'].Value) mms.read_status = rec['read'].Value # mms.body = rec['body'].Value mms.send_time = rec['date'].Value mms.delivered_date = rec['date'].Value if mms.type in [ MSG_TYPE_INBOX, MSG_TYPE_SENT ] else None mms.type = rec['type'].Value # MSG_TYPE mms.is_sender = 1 if mms.type in (MSG_TYPE_SENT, MSG_TYPE_OUTBOX) else 0 if mms.is_sender == 1: # 发 mms.sender_phonenumber = self.sim_phonenumber.get( mms.sim_id, None) if mms.sim_id else None mms.sender_name = self._get_contacts(mms.sender_phonenumber) mms.recv_phonenumber = rec['address'].Value mms.recv_name = self._get_contacts(mms.recv_phonenumber) else: # 收 mms.sender_phonenumber = rec['address'].Value mms.sender_name = self._get_contacts(mms.sender_phonenumber) mms.recv_phonenumber = self.sim_phonenumber.get( mms.sim_id, None) if mms.sim_id else None mms.recv_name = self._get_contacts(mms.recv_phonenumber) mms.deleted = 1 if rec.IsDeleted else 0 mms.source = self.cur_db_source self.csm_mms.db_insert_table_mms(mms) except: exc()
def _parse_sms(self, node): sms_files = node.Search(r'Sms_\d+.txt') for file_ in sms_files: data = self._open_file(file_) phone_calls = data.get('phonecall_view', {}).get('entries', []) sms = data.get('entries', []) for pc in phone_calls: try: record = model_callrecord.Records() record.source = file_.AbsolutePath record.duration = pc.get('duration', None) record.phone_number = pc.get('number', None) record.id = pc.get('id', None) record.date = TimeHelper.convert_timestamp( pc.get('date', None)) self.crm.db_insert_table_call_records(record) except Exception as e: print(e) for s in sms: try: s = s['entry'] message = model_sms.SMS() message.source = file_.AbsolutePath message.body = s.get('snippet', None) message.send_time = TimeHelper.convert_timestamp( s.get('localTime', None)) message.read_status = 1 if s['unread'] == 0 else 0 message.is_sender = 1 if s['folder'] == 1 else 0 message._id = s.get('id', None) recipients = s.get('recipients', None) message.sender_phonenumber, message.recv_phonenumber = (self.owner_phone, recipients) \ if message.is_sender else (recipients, self.owner_phone) self.sms.db_insert_table_sms(message) except Exception as e: print(e) self.crm.db_commit() self.sms.db_commit()
def parse_sms(self, table_name): """ sms/sms.db - SMS RecNo FieldName SQLType 1 phoneNumber TEXT 2 time TEXT 3 name TEXT 4 shortType INTEGER 5 isMms INTEGER 6 theme TEXT 7 shortRead INTEGER 8 body TEXT 9 path TEXT """ for rec in self._read_table(table_name): try: if (self._is_empty(rec, 'body', 'phoneNumber') or rec['isMms'].Value == 1): continue sms = model_sms.SMS() try: sms.sms_id = rec['phoneNumber'].Value + rec['time'].Value if (self._is_duplicate(pk_value=sms.sms_id) or self._include_garbled_str(rec['body'].Value)): continue except: exc() continue # sms.sender_phonenumber = rec['phoneNumber'].Value if rec['phoneNumber'].Value != 'insert-address-token' else None # sms.sender_name = self.contacts.get(sms.sender_phonenumber, None) if rec['shortType'].Value == 1: sms.type = MSG_TYPE_INBOX elif rec['shortType'].Value == 2: sms.type = MSG_TYPE_OUTBOX else: sms.type = MSG_TYPE_ALL sms.read_status = rec['shortRead'].Value sms.subject = rec['theme'].Value sms.body = rec['body'].Value.replace('\0', '') sms.send_time = self._convert_strtime_2_ts(rec['time'].Value) sms.delivered_date = sms.send_time sms.is_sender = 1 if sms.type == MSG_TYPE_OUTBOX else 0 if sms.is_sender == 1: # 发 sms.sender_phonenumber = self.sim_phonenumber.get( sms.sim_id, None) if sms.sim_id else None sms.sender_name = self._get_contacts( sms.sender_phonenumber) sms.recv_phonenumber = rec['phoneNumber'].Value if rec[ 'phoneNumber'].Value != 'insert-address-token' else None sms.recv_name = self._get_contacts(sms.recv_phonenumber) else: # 收 sms.sender_phonenumber = rec['phoneNumber'].Value if rec[ 'phoneNumber'].Value != 'insert-address-token' else None sms.sender_name = self._get_contacts( sms.sender_phonenumber) sms.recv_phonenumber = self.sim_phonenumber.get( sms.sim_id, None) if sms.sim_id else None sms.recv_name = self._get_contacts(sms.recv_phonenumber) sms.source = self.cur_db_source sms.deleted = 1 if rec.IsDeleted else 0 self.csm.db_insert_table_sms(sms) except: exc() self.csm.db_commit()
def parse_mms(self, table_name, addr_dict, mms_mid_text_dict): """ pdu - 彩信 FieldName SQLType _id INTEGER thread_id INTEGER date INTEGER date_sent INTEGER msg_box INTEGER # MSG_TYPE read INTEGER m_id TEXT sub TEXT sub_cs INTEGER # 主题所用字符集 ct_t TEXT # 彩信对应的Content-Type是application/vnd.wap.multipart.related ct_l TEXT # X-Mms-Content-Location exp INTEGER # 过期时间 m_cls TEXT # X-Mms-Message-Class,此条彩信的用途:auto,advertisement,personal,informational m_type INTEGER # X-Mms-Message-Type,由MMS协议定义的彩信类型,、、 128 if sent send-req:128 130 if to send again notification-ind:130 132 if resent retrieve-conf为132 v INTEGER m_size INTEGER pri INTEGER # X-Mms-Priority,此条彩信的优先级,normal 129,low 128,high 130 rr INTEGER rpt_a INTEGER resp_st INTEGER st INTEGER # 该彩信的下载状态,未启动-128,下载中-129,传输失败-130,保存失败-135 tr_id TEXT retr_st INTEGER retr_txt TEXT retr_txt_cs INTEGER read_status INTEGER ct_cls INTEGER resp_txt TEXT d_tm INTEGER d_rpt INTEGER locked INTEGER seen INTEGER sub_id INTEGER network_type INTEGER creator TEXT text_only INTEGER privacy_mode integer is_secret INTEGER """ for rec in self._read_table(table_name): try: mms = model_sms.SMS() if (rec.ContainsKey('_id') and self._is_duplicate(rec, '_id')): continue mms.is_mms = 1 mms._id = rec['_id'].Value mms.sender_phonenumber = addr_dict.get(mms._id, {}).get('from_address') mms.recv_phonenumber = addr_dict.get(mms._id, {}).get('to_address') mms.subject = self._decode_mms_subject(rec['sub'].Value) mms.read_status = rec['read'].Value mms.body = mms_mid_text_dict.get(mms._id) mms.delivered_date = rec['date'].Value mms.send_time = rec[ 'date_sent'].Value if 'date_sent' in rec.Keys else mms.delivered_date mms.type = rec['msg_box'].Value # MSG_TYPE mms.is_sender = 1 if mms.type in (MSG_TYPE_SENT, MSG_TYPE_OUTBOX) else 0 mms.deleted = 1 if rec.IsDeleted else 0 mms.source = self.cur_db_source self.csm.db_insert_table_mms(mms) except: exc() self.csm.db_commit()
def parse_sms(self, table_name): """ sms - 短信 _id INTEGER PRIMARY KEY, thread_id INTEGER, address TEXT, person INTEGER, 联系人(模块)列表里的序号,陌生人为null date INTEGER, 毫秒 date_sent INTEGER DEFAULT 0, read INTEGER DEFAULT 0, status INTEGER DEFAULT -1, -1 默认值, 0-complete , 64-pending , 128-failed type INTEGER, ALL=0;INBOX=1;SENT=2;DRAFT=3;OUTBOX=4;FAILED=5;QUEUED=6; subject TEXT, body TEXT, (xiaomi: service_center) seen INTEGER DEFAULT 0, timed INTEGER DEFAULT 0, deleted INTEGER DEFAULT 0, sync_state INTEGER DEFAULT 0, marker INTEGER DEFAULT 0, source TEXT, bind_id INTEGER DEFAULT 0, mx_status INTEGER DEFAULT 0, mx_id INTEGER, out_time INTEGER DEFAULT 0, account TEXT, sim_id INTEGER DEFAULT 0, block_type INTEGER DEFAULT 0, advanced_seen INTEGER DEFAULT 0, b2c_ttl INTEGER DEFAULT 0, b2c_numbers TEXT, fake_cell_type INTEGER DEFAULT 0, url_risky_type INTEGER DEFAULT 0, creator TEXT, favorite_date INTEGER DEFAULT 0 """ pk_name = '_id' if table_name == 'sms_tb': pk_name = 'group_id' for rec in self._read_table(table_name): try: if (self._is_empty(rec, 'type', 'body') or self._is_duplicate(rec, pk_name) or self._include_garbled_str(rec['body'].Value)): continue if (rec['address'].Value and not self._is_num(rec['address'].Value)): continue sms = model_sms.SMS() # 华为没有的字段 sms.sim_id = rec['sim_id'].Value if rec.ContainsKey( 'sim_id') else None sms.deleted = rec['deleted'].Value if rec.ContainsKey( 'deleted') else 0 sms.smsc = rec['service_center'].Value if rec.ContainsKey( 'service_center') else None sms._id = rec[pk_name].Value sms.read_status = rec['read'].Value sms.type = rec['type'].Value # MSG_TYPE sms.subject = rec['subject'].Value sms.body = rec['body'].Value sms.delivered_date = rec['date'].Value sms.send_time = rec[ 'date_sent'].Value if 'date_sent' in rec.Keys else sms.delivered_date sms.is_sender = 1 if sms.type in (MSG_TYPE_SENT, MSG_TYPE_OUTBOX, MSG_TYPE_DRAFT) else 0 if sms.is_sender == 1: # 发 sms.sender_phonenumber = self.sim_phonenumber.get( sms.sim_id, None) if sms.sim_id else None sms.sender_name = self._get_contacts( sms.sender_phonenumber) sms.recv_phonenumber = rec['address'].Value sms.recv_name = self._get_contacts(sms.recv_phonenumber) else: # 收 sms.sender_phonenumber = rec['address'].Value sms.sender_name = self._get_contacts( sms.sender_phonenumber) sms.recv_phonenumber = self.sim_phonenumber.get( sms.sim_id, None) if sms.sim_id else None sms.recv_name = self._get_contacts(sms.recv_phonenumber) sms.deleted = 1 if rec.IsDeleted or sms.deleted else 0 sms.source = self.cur_db_source self.csm.db_insert_table_sms(sms) except: exc() self.csm.db_commit()