Beispiel #1
0
    def parse_logs(self, table_name):
        '''
            FieldName	SQLType
            _id
            number	              TEXT
            address	              TEXT
            date	              INTEGER
            duration	          INTEGER
            type	              INTEGER
            new
            simnum	              INTEGER
            name	              TEXT
            name_reversed	      TEXT
            numbertype	          INTEGER
            numberlabel	          TEXT
            messageid	          TEXT
            threadid	          TEXT
            logtype	              INTEGER
            frequent	          INTEGER
            contactid	          INTEGER
            raw_contact_id	      INTEGER
            m_subject	          TEXT
            m_content	          TEXT
            sns_tid	              TEXT
            sns_pkey	          TEXT
            account_name	      TEXT
            account_id	          TEXT
            sns_receiver_coun     TEXT
            sp_type	              TEXT
            cnap_name	          TEXT
            cdnip_number	      TEXT
            service_type	      INTEGER
            sdn_alpha_id	      TEXT
            real_phone_number     TEXT
            call_out_duration     INTEGER
            reject_flag	          INTEGER
        '''
        _sms_list = []
        for rec in self._read_table(table_name):
            try:
                pk_name = '_id'
                if (self._is_empty(rec, 'number', 'date')
                        or self._is_duplicate(rec, pk_name)
                        or self._include_garbled_str(rec['m_content'].Value)):
                    continue

                # logtype 200 是彩信, 300 是短信, 100 是通话记录
                if rec['logtype'].Value == 300:
                    self._parse_logs_sms(rec)
                elif rec['logtype'].Value == 200:
                    self._parse_logs_mms(rec)
            except:
                exc()
        self.csm.db_commit()
        self.csm_mms.db_commit()
Beispiel #2
0
    def parse_Account(self, user_plist_node, group_plist_node):
        ''' 解析两个 .plist

            \Library\Preferences\jp.naver.line.plist
            keys:
                SimCardInfo              # base64
                mid                      # account_id   u423af962f1456db6cba8465cf82bb91b
                migrationDate           
                name                     # nickname     王明
                uid                      # username     chrisnaruto
                statusMessage            # signatue
                tel                      # telephone
            Library\Preferences\group.com.linecorp.line.plist
            keys:
                LineAccountType             
                LineProfilePicturePath   # photo        startwith('/')
                LineProfilePictureStatus # photo
                mid                      # account_id   u423af962f1456db6cba8465cf82bb91b
        '''
        user_plist_res = self._read_plist(user_plist_node, 'mid', 'name',
                                          'uid', 'statusMessage', 'tel')
        group_plist_res = self._read_plist(group_plist_node,
                                           'LineProfilePicturePath')
        account = model_im.Account()
        if user_plist_res:
            account.account_id = self.cur_account_id = user_plist_res['mid']
            account.nickname = user_plist_res.get('name')
            account.username = user_plist_res.get('uid')
            account.signature = user_plist_res.get('statusMessage')
            account.telephone = user_plist_res.get('tel')
            pic_url = group_plist_res.get('LineProfilePicturePath')
            if pic_url and pic_url.startswith('/'):
                account.photo = self._search_profile_img(pic_url)
            account.source = self.user_plist_node.AbsolutePath
        else:
            try:
                account_node = self.root.GetByPath(
                    'Library/Application Support/PrivateStore/')
                account_id = account_node.Children[0].AbsolutePath.split(
                    '_')[1]
                if account_id.startswith('u'):
                    account.account_id = account_id
                    account.nickname = DEFAULT_USERNAME
                    account.username = DEFAULT_USERNAME
            except:
                pass
        if not account.account_id:
            return account
        try:
            account.insert_db(self.csm)
        except:
            exc()
        self.csm.db_commit()
        return account
Beispiel #3
0
    def parse_bookmark(self, table_name):
        ''' 'databases/browser2.db - bookmarks

            CREATE TABLE bookmarks (
                _id             INTEGER PRIMARY KEY,
                title           TEXT,url TEXT DEFAULT NULL,
                visits          INTEGER,date LONG,
                created         LONG,
                description     TEXT,
                bookmark        INTEGER,
                favicon         BLOB DEFAULT NULL,
                thumbnail       BLOB DEFAULT NULL,
                touch_icon      BLOB DEFAULT NULL,
                user_entered    INTEGER,
                folder          INTEGER DEFAULT 99
            );
        '''
        for rec in self._read_table(table_name):
            try:
                if (self._is_empty(rec, 'url', 'title')
                        or self._is_duplicate(rec, '_id')):
                    continue
                if 'folder' in rec.Keys and rec['folder'].Value == 1:
                    continue

                if not self._max_id:
                    self._max_id = rec.Count

                _time = 0
                if 'created' in rec.Keys:
                    _time = rec['created'].Value
                elif 'create_time' in rec.Keys:
                    _time = rec['create_time'].Value
                elif 'date' in rec.Keys:
                    _time = rec['date'].Value

                if rec['bookmark'].Value == 1:
                    bookmark = model_browser.Bookmark()
                    bookmark.id = rec['_id'].Value
                    bookmark.owneruser = self.cur_account_name
                    bookmark.title = rec['title'].Value
                    bookmark.time = _time
                    bookmark.url = rec['url'].Value
                    bookmark.source = self.cur_db_source
                    bookmark.deleted = 1 if rec.IsDeleted else 0
                    self.csm.db_insert_table_bookmarks(bookmark)

                elif rec['bookmark'].Value == 0:
                    self._parse_browser_record(rec)

                self._insert_search_from_browser_record(rec, _time)
            except:
                exc()
        self.csm.db_commit()
    def parse_DownloadFile(self, db_path, table_name):
        """ databases/flyflowdownload.db - bddownloadtable

            下载目录: /storage/emulated/0/baidu/flyflow/downloads/
            RecNo	FieldName	SQLType 
            1	manual	            INTEGER
            2	quiet	            INTEGER
            3	attribute	        TEXT
            4	completetime	    LONG
            5	createdtime	        LONG
            6	style	            TEXT
            7	filename	        TEXT
            8	key	                TEXT
            9	priority	        INTEGER
            10	progressmap	        TEXT
            11	referer	            TEXT
            12	savepath	        TEXT
            13	status	            INTEGER
            14	total	            LONG
            15	current	            LONG
            16	type	            TEXT
            17	url	                TEXT
        """
        # tp 'table_name:', self.root.AbsolutePath
        if not self._read_db(db_path):
            return
        for rec in self._read_table(table_name):
            if self._is_empty(rec, 'filename',
                              'url') or not self._is_url(rec, 'url'):
                continue
            if self._is_duplicate(rec, 'createdtime'):
                continue
            # tp('filename', rec['filename'].Value)
            downloads = model_browser.DownloadFile()
            downloads.url = rec['url'].Value
            downloads.filename = rec['filename'].Value
            downloads.filefolderpath = self._convert_2_nodepath(
                rec['savepath'].Value, downloads.filename)
            downloads.totalsize = rec['total'].Value
            downloads.createdate = rec['createdtime'].Value
            downloads.donedate = rec['completetime'].Value
            costtime = downloads.donedate - downloads.createdate
            downloads.costtime = costtime if costtime > 0 else None  # 毫秒
            # downloads.owneruser      = rec['name'].Value
            downloads.source = self.cur_db_source
            downloads.deleted = 1 if rec.IsDeleted else 0
            try:
                self.csm.db_insert_table_downloadfiles(downloads)
            except:
                exc()
        try:
            self.csm.db_commit()
        except:
            exc()
Beispiel #5
0
 def _get_contacts(self, sender_phonenumber):
     try:
         if isinstance(sender_phonenumber,
                       str) and len(sender_phonenumber) == 11:
             for i in ('+86', '86'):
                 name = self.contacts.get(i + sender_phonenumber, None)
                 if name:
                     return name
         return self.contacts.get(sender_phonenumber, None)
     except:
         exc()
         return None
Beispiel #6
0
 def _convert_form_data_type(self, _type):
     try:
         _type = _type.lower()
         if 'checkcode' in _type:
             return model_browser.FROMDATA_TYPE_CHECKCODE
         elif 'account' in _type:
             return model_browser.FROMDATA_TYPE_ACCOUNT
         else:
             return model_browser.FROMDATA_TYPE_KEYWORD
     except:
         exc()
         return 0
Beispiel #7
0
    def parse_DownloadFile(self, URLS, table_name):
        ''' Default/History - downloads

            FieldName	            SQLType
            id	                        INTEGER
            guid	                    VARCHAR
            current_path	            LONGVARCHAR
            target_path	                LONGVARCHAR
            start_time	                INTEGER
            received_bytes	            INTEGER
            total_bytes	                INTEGER
            state	                    INTEGER
            danger_type	                INTEGER
            interrupt_reason	        INTEGER
            hash	                    BLOB
            end_time	                INTEGER
            opened	                    INTEGER
            last_access_time	        INTEGER
            transient	                INTEGER
            referrer	                VARCHAR
            site_url	                VARCHAR
            tab_url	                    VARCHAR
            tab_referrer_url	        VARCHAR
            http_method	                VARCHAR
            by_ext_id	                VARCHAR
            by_ext_name	                VARCHAR
            etag	                    VARCHAR
            last_modified	                VARCHAR
            mime_type	VARCHAR	            255
            original_mime_type	VARCHAR	    255
        '''
        for rec in self._read_table(table_name):
            try:
                if (self._is_empty(rec, 'target_path') or 
                    self._is_duplicate(rec, 'id')):
                    continue
                downloads = model_browser.DownloadFile()
                downloads.id             = rec['id'].Value
                downloads.url            = URLS.get(downloads.id, None)
                downloads.filefolderpath = self._convert_nodepath(rec['target_path'].Value)
                downloads.filename       = rec['target_path'].Value.split('/')[-1]
                downloads.totalsize      = rec['total_bytes'].Value
                downloads.createdate     = self._convert_webkit_ts(rec['start_time'].Value)
                downloads.donedate       = self._convert_webkit_ts(rec['end_time'].Value)
                # costtime                 = downloads.donedate - downloads.createdate
                # downloads.costtime       = costtime if costtime > 0 else None  
                downloads.owneruser      = self.cur_account_name
                downloads.source         = self.cur_db_source
                downloads.deleted        = 1 if rec.IsDeleted else 0
                self.csm.db_insert_table_downloadfiles(downloads)
            except:
                exc()
        self.csm.db_commit()
Beispiel #8
0
 def _12306_read_json(self, json_node):
     try:
         _json_data = self._read_json(json_node=json_node)
         if (not _json_data or not _json_data.get('status')
                 or _json_data.get('httpstatus') != 200):
             return False
         else:
             self.cur_json_dict = _json_data.get('data', {})
             return True
     except:
         exc()
         return False
Beispiel #9
0
    def parse_Bookmark(self, db_path, table_name):
        ''' 书签 databases/d_searchbox.db - favor

            RecNo	FieldName	
            1	_id	            INTEGER
            2	ukey	            TEXT
            3	serverid	            TEXT
            4	tplid	            TEXT
            5	status	            TEXT
            6	title	            TEXT
            7	desc	            TEXT
            8	img	            TEXT
            9	url	            TEXT
            10	cmd	            TEXT
            11	opentype	            TEXT
            12	feature	            TEXT
            13	datatype	            TEXT
            14	parent	            TEXT
            15	visible	            TEXT
            16	enable	            TEXT
            17	createtime	            TEXT
            18	modifytime	            TEXT
            19	visittime	            TEXT
            20	visits	            INTEGER
            21	extra1	            TEXT
            22	extra2	            TEXT
        '''
        if not self._read_db(db_path):
            return
        for rec in self._read_table(table_name):
            if canceller.IsCancellationRequested:
                return
            if rec['datatype'].Value == '2' or not self._is_url(rec, 'url'):
                continue  # datatype==2 是文件夹
            if self._is_duplicate(rec, '_id'):
                continue
            bookmark = model_browser.Bookmark()
            bookmark.id = rec['_id'].Value
            # bookmark.account_id = rec['account_uid'].Value
            bookmark.time = rec['createtime'].Value
            bookmark.title = rec['title'].Value
            bookmark.url = rec['url'].Value
            bookmark.source = self.cur_db_source
            bookmark.deleted = 1 if rec.IsDeleted else 0
            try:
                self.csm.db_insert_table_bookmarks(bookmark)
            except:
                exc()
        try:
            self.csm.db_commit()
        except:
            exc()
Beispiel #10
0
 def parse(self):
     try:
         if DEBUG or self.mm.need_parse(self.cache_db, VERSION_APP_VALUE):
             self.mm.db_create(self.cache_db) 
             self.parse_model()
             if not canceller.IsCancellationRequested:
                 self.mm.db_insert_table_version(model_mail.VERSION_KEY_DB, model_mail.VERSION_VALUE_DB)
                 self.mm.db_insert_table_version(model_mail.VERSION_KEY_APP, VERSION_APP_VALUE)
             self.mm.db_commit()
             self.mm.db_close()
         tmp_dir = ds.OpenCachePath('tmp')
         save_cache_path(bcp_mail.MAIL_TOOL_TYPE_PHONE, self.cache_db, tmp_dir)
     except:
         exc()
Beispiel #11
0
    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()
Beispiel #12
0
    def parse_contact(self, table_name):
        """ mmail - Contact_<account_id> 

            RecNo	FieldName	SQLTypd
            1	id	UNSIGNED BIG      d INT
            2	etag	        TEXT
            3	serverHref	        TEXT
            4	name	        TEXT
            5	isDeleted	        INTEGER
            6	title	        TEXT
            7	org	            TEXT
            8	birthday	        TEXT
            9	NameComponent	    TEXT
            10	ADRComponent	    TEXT
            11	tels	        TEXT
            12	isGroup	        INTEGER
            13	members	        TEXT
            14	cid	            TEXT
            15	changeState	        INTEGER
            16	uid	            TEXT
            17	rev	            TEXT
            18	version	        TEXT
            19	email	        TEXT
            20	extraInfo	        TEXT
            21	displayTag	        TEXT
            22	note	        TEXT
            23	isFromPhone	        INTEGER
            24	groups	        TEXT
            25	isMarked	        INTEGER
        """
        table_name = table_name + str(self.cur_account_id)
        for rec in self._read_table(table_name):
            if canceller.IsCancellationRequested:
                return
            if self._is_empty(rec, 'id', 'email',
                              'name') or self._is_duplicate(rec, 'id'):
                continue
            contact = model_mail.Contact()
            contact.contact_id = rec['id'].Value
            contact.owner_account_id = self.cur_account_id
            contact.contact_user = self._parse_contacts(rec['email'].Value)
            contact.contact_email = self._parse_contacts(rec['email'].Value)
            contact.contact_alias = self._parse_contacts(rec['name'].Value)
            contact.deleted = 1 if rec.IsDeleted else rec['isDeleted'].Value
            contact.source = self.cur_db_source
            try:
                self.csm.db_insert_table_contact(contact)
            except:
                exc()
        self.csm.db_commit()
Beispiel #13
0
    def _get_wifi_signal_models(self):
        if not self._db_has_table('wifi_signal'):
            return []
        models = []

        sql = '''select * from wifi_signal'''
        '''
        0       id,           
        1       ssid, 
        2       bssid,        
        3       first_time,         
        4       last_time,         
        5       source,       
        6       deleted,      
        7       repeated        
        '''
        try:
            cmd = self.db.CreateCommand()
            cmd.CommandText = sql
            r = cmd.ExecuteReader()
            while r.Read():
                deleted = 0
                try:
                    id = self._db_reader_get_int_value(r, 0)        
                    ssid = self._db_reader_get_string_value(r, 1)  
                    bssid = self._db_reader_get_string_value(r, 2)     
                    first_time = self._get_timestamp(self._db_reader_get_int_value(r, 3))
                    last_time = self._get_timestamp(self._db_reader_get_int_value(r, 4) )
                    source = self._db_reader_get_string_value(r, 5)    
                    deleted = self._db_reader_get_int_value(r, 6)   

                    wireless = WirelessConnection()
                    wireless.SSId.Value = ssid
                    wireless.BSSId.Value = bssid
                    if last_time:                    
                        wireless.TimeStamp.Value = last_time
                    wireless.WirelessType.Value = WirelessType.Wifi
                    if source:
                        wireless.SourceFile = source
                    if deleted:
                        wireless.Deleted = self._convert_deleted_status(deleted)
                    models.append(wireless)
                except:
                    exc()
            r.Close()
            return models                    
        except:
            exc()
            return models
Beispiel #14
0
    def parse_contact(self, db_path, table_name):
        """
        华为没有此 db
            /Contact.db

            RecNo	FieldName	SQLType	Size
            1	_id	        integer
            2	name	        text
            3	email	        text
            4	blacklist	        integer
            5	writelist	        integer
            6	weight	            REAL	 
            7	nickname	        text
            8	pinyin	        text
            9	fristpinyin	        text
            10	isenable	        integer
            11	myemail	        text
            12	lasttime	        text
            13	timeStamp	        integer
            14	selected	        text
            15	color	        integer
            16	unread2top	        integer
            17	pop	            integer
            18	dirty	        integer
            19	lastTimestamp	integer
        """
        try:
            if not self._read_db(db_path):
                return
            for rec in self._read_table(table_name):
                if self._is_empty(rec, 'name', 'email') or self._is_duplicate(
                        rec, '_id'):
                    continue
                contact = model_mail.Contact()
                contact.contact_id = rec['_id'].Value
                contact.owner_account_id = self._get_account_id(
                    rec['myemail'].Value)
                contact.contact_alias = rec['name'].Value
                contact.contact_email = rec['email'].Value
                contact.contact_last_modify = rec['timeStamp'].Value
                contact.source = self.cur_db_source
                contact.deleted = 1 if rec.IsDeleted else 0
                try:
                    self.csm.db_insert_table_contact(contact)
                except:
                    exc()
            self.csm.db_commit()
        except:
            pass
Beispiel #15
0
 def _parse_contacts(name_email):
     """ 联系人表中 格式转换 """
     if not name_email or IsDBNull(name_email):
         return
     try:
         res = None
         ne = eval(name_email)
         if isinstance(ne, list):
             res = ne[0]['value']
         elif isinstance(ne, dict):
             res = ne['value']
         return res
     except:
         exc()
         return None
Beispiel #16
0
    def db_create(self, db_path):
        if os.path.exists(db_path):
            try:
                os.remove(db_path)
            except:
                print('db_path:', db_path)
                exc()

        self.db = SQLite.SQLiteConnection('Data Source = {}'.format(db_path))
        self.db.Open()
        self.db_cmd = SQLite.SQLiteCommand(self.db)
        self.db_trans = self.db.BeginTransaction()

        self.db_create_table()
        self.db_commit()
Beispiel #17
0
    def get_location(self, location, content, time):
        try:
            object = json.loads(content)
            location.latitude = object['location'].split(',')[0]
            location.longitude = object['location'].split(',')[1]
            location.address = object['description']
            location.type = model_im.LOCATION_TYPE_GOOGLE
            location.timestamp = time

            self.csm.db_insert_table_location(location)
            self.csm.db_commit()
            return location.location_id
        except:
            exc()
            return
Beispiel #18
0
    def parse_Browserecord_SearchHistory(self, URLID_KEYWORD, table_name):
        ''' Default/History - urls

            FieldName	    SQLType     	        	
            id	            INTEGER
            url	            LONGVARCHAR
            title	            LONGVARCHAR
            visit_count	        INTEGER
            typed_count	        INTEGER
            last_visit_time	    INTEGER
            hidden	            INTEGER
        '''
        for rec in self._read_table(table_name):
            try:
                if (self._is_empty(rec, 'url', 'last_visit_time') or
                    self._is_duplicate(rec, 'id') or
                    not self._is_url(rec, 'url')):
                    continue
                browser_record = model_browser.Browserecord()
                browser_record.id          = rec['id'].Value
                browser_record.name        = rec['title'].Value
                browser_record.url         = rec['url'].Value
                browser_record.datetime    = self._convert_webkit_ts(rec['last_visit_time'].Value)
                browser_record.visit_count = rec['visit_count'].Value if rec['visit_count'].Value > 0 else 1
                browser_record.owneruser   = self.cur_account_name
                browser_record.source      = self.cur_db_source
                browser_record.deleted     = 1 if rec.IsDeleted else rec['hidden'].Value
                self.csm.db_insert_table_browserecords(browser_record)

                # 补充 keyword_search_terms 表中漏掉的搜索关键字
                if not URLID_KEYWORD.has_key(rec['id'].Value):
                    _search_item = self._search_item_from_browser_record(rec['title'].Value)
                else:
                    _search_item = ''

                if URLID_KEYWORD.has_key(rec['id'].Value) or _search_item:
                    search_history = model_browser.SearchHistory()
                    search_history.name = _search_item if _search_item else URLID_KEYWORD.get(rec['id'].Value, None)
                    search_history.id        = rec['id'].Value
                    search_history.url       = rec['url'].Value
                    search_history.datetime  = browser_record.datetime
                    search_history.owneruser = self.cur_account_name
                    search_history.source    = self.cur_db_source
                    search_history.deleted   = browser_record.deleted              
                    self.csm.db_insert_table_searchhistory(search_history)
            except:
                exc()
        self.csm.db_commit()
Beispiel #19
0
    def parse_Cookie(self, db_paths, table_name):
        ''' Android: app_webview/Cookies 
        
        Args:
            db_paths (list<str>): list of db_path
            table_name (str):

        Table Columns:
             FieldName	        SQL Type 	     	
        1    creation_utc	    INTEGER
        2    host_key	        TEXT
        3    name	            TEXT
        4    value	            TEXT
        5    path	            TEXT
        6    expires_utc	    INTEGER
        7    is_secure	        INTEGER     # or secure
        8    is_httponly	    INTEGER     # or httponly
        9    last_access_utc	INTEGER
        10   has_expires	    INTEGER
        11   is_persistent	    INTEGER     # or persistent
        12   priority	        INTEGER
        13   encrypted_value	BLOB
        14   firstpartyonly	    INTEGER
        '''
        for db_path in db_paths:
            if not self._read_db(db_path):
                continue
            for rec in self._read_table(table_name):
                try:
                    if (self._is_empty(rec, 'creation_utc')
                            or self._is_duplicate(rec, 'creation_utc')):
                        continue
                    cookie = Cookie()
                    cookie.id = rec['creation_utc'].Value
                    cookie.host_key = rec['host_key'].Value
                    cookie.name = rec['name'].Value
                    cookie.value = rec['value'].Value
                    cookie.createdate = rec['creation_utc'].Value
                    cookie.expiredate = rec['expires_utc'].Value
                    cookie.lastaccessdate = rec['last_access_utc'].Value
                    cookie.hasexipred = rec['has_expires'].Value
                    # cookie.owneruser      = self.cur_account_name
                    cookie.source = self.cur_db_source
                    cookie.deleted = 1 if rec.IsDeleted else 0
                    self.csm.db_insert_table_cookies(cookie)
                except:
                    exc()
            self.csm.db_commit()
Beispiel #20
0
    def parse_attachment(self, table_name):
        """ mmail - Part_<account_id> 

        RecNo	FieldName	
        1	id	UNSIGNED BIG            INT
        2	messageId	UNSIGNED BIG            INT
        3	localPath	            TEXT
        4	name	            TEXT
        5	filename	            TEXT
        6	serverId	            TEXT
        7	type	            INTEGER
        8	contentType	            TEXT
        9	size	UNSIGNED BIG            INT
        10	previewURL	            TEXT
        11	contentId	            TEXT
        12	flag	            INTEGER
        13	isDownloaded	            INTEGER
        14	downloadTime	IUNSIGNED BIG           INT
        15	charset	            TEXT
        16	encoding	            TEXT
        """
        table_name = 'Part_' + str(self.cur_account_id)
        for rec in self._read_table(table_name):
            if canceller.IsCancellationRequested:
                return
            if self._is_empty(rec, 'filename',
                              'messageId') or self._is_duplicate(rec, 'id'):
                continue
            attach = model_mail.Attachment()
            attach.attachment_id = rec['id'].Value
            attach.owner_account_id = self.cur_account_id
            attach.mail_id = rec['messageId'].Value
            attach.attachment_name = rec['filename'].Value
            attach.attachment_save_dir = self._convert_nodepath(
                rec['localPath'].Value)
            attach.attachment_download_date = rec['downloadTime'].Value
            attach.attachment_size = rec['size'].Value
            attach.mail_id = rec['messageId'].Value
            attach.source = self.cur_db_source
            attach.deleted = 1 if rec.IsDeleted else 0
            try:
                self.csm.db_insert_table_attachment(attach)
            except:
                exc()
        try:
            self.csm.db_commit()
        except:
            exc()
 def _convert_2_nodepath(self, raw_path, file_name):
     try:
         # huawei: /data/user/0/com.baidu.searchbox/files/template/profile.zip
         paths = [
             '/data/com.baidu.searchbox/files/template/',
             '/storage/emulated/0/baidu/flyflow/downloads/',
             'data/media/0/baidu/'
         ]
         fs = self.root.FileSystem
         # 新版本
         file_nodes = list(fs.Search(raw_path))
         if file_nodes:
             file_node = file_nodes[0]
             if file_node.Type == NodeType.File:
                 return file_node.AbsolutePath
         # 老版本
         if not file_name:
             raw_path_list = raw_path.split(r'/')
             file_name = raw_path_list[-1]
         for path in paths:
             # tp(self.root.FileSystem.AbsolutePath)
             # tp(os.path.join(path, file_name))
             #path_node = self.root.FileSystem.GetByPath(os.path.join(path, file_name))
             path_node = self.root.FileSystem.GetByPath('data.tar')
             # tp(self.root.FileSystem.Children)
             if path_node:
                 if path_node.Type == NodeType.File:
                     return path_node.AbsolutePath
         _path = None
         if len(file_name) > 0:
             try:
                 invalid_file_name = re.search(r'[\\/:*?"<>|\r\n]+',
                                               file_name)
                 if invalid_file_name:
                     return file_name
                 node = fs.Search(r'baidu.*?/{}$'.format(file_name))
                 for i in node:
                     _path = i.AbsolutePath
             except:
                 pass
         if _path:
             return _path
         return _path if _path else file_name
     except:
         tp('android_baidubrowser.py _conver_2_nodeapth error, file_name:',
            file_name)
         exc()
         return file_name
Beispiel #22
0
    def _read_db(self, db_root, db_path):
        ''' 读取手机数据库

        :type db_path: str
        :rtype: bool                              
        '''
        try:
            db_node = db_root.GetByPath(db_path)
            self.cur_db = SQLiteParser.Database.FromNode(db_node, canceller)
            if self.cur_db is None:
                return False
            self.cur_db_source = db_node.AbsolutePath
            return True
        except:
            exc()
            return False
Beispiel #23
0
    def sms_models_from_db(self):
        try:        
            models = []
            sql = ''' SELECT * FROM sms '''

            self.cursor.execute(sql)
            row = self.cursor.fetchone()
            while row is not None:
                sms = ModelsV2.Base.SMS()
                self._smsmms_base(sms, row)
                models.append(sms)
                row = self.cursor.fetchone() 
            return models     
        except:
            exc()
            return []       
Beispiel #24
0
 def _search_item_from_browser_record(self, browser_title):
     '''SEARCH_ENGINES = 
         r'((?P<keyword1>.*?)( - Google 搜尋| - Google Search|- Google 搜索\
         | - 百度| - 搜狗搜索|_360搜索| - 国内版 Bing)$)|(^网页搜索_(?P<keyword2>.*))|'
     '''
     try:
         if browser_title and not IsDBNull(browser_title):
             match_res = re.match(SEARCH_ENGINES, browser_title)
             if match_res and (match_res.group('keyword1') or match_res.group('keyword2')):
                 keyword1 = match_res.group('keyword1')
                 keyword2 = match_res.group('keyword2')
                 keyword = keyword1 if keyword1 else keyword2
                 return keyword
     except:
         exc()
         return ''
Beispiel #25
0
 def _convert_bir(birthday_str):
     '''
     
     Args:
         birthday_str (str): 19920426
     Returns:
         ts (int): timestamp(secoond)
     '''
     try:
         if not birthday_str or len(birthday_str) != 8:
             return None
         struct_time = time.strptime(birthday_str, "%Y%m%d")
         ts = time.mktime(struct_time)
         return ts
     except:
         exc()
Beispiel #26
0
    def db_create(self, db_path):
        if os.path.exists(db_path):
            try:
                os.remove(db_path)
            except:
                exc()
                return False

        self.db = SQLite.SQLiteConnection('Data Source = {}'.format(db_path))
        if self.db is not None:
            self.db.Open()
            self.db_cmd = SQLite.SQLiteCommand(self.db)
            self.db_trans = self.db.BeginTransaction()

            self.db_create_table()
            self.db_commit()
Beispiel #27
0
    def parse_part(self, table_name):
        ''' part 

            FieldName	SQLType    
            _id	            INTEGER 
            mid	            INTEGER 
            seq	            INTEGER 
            ct	            TEXT    
            name	        TEXT    
            chset	        INTEGER     # UTF-8为106
            cd	            TEXT        # CONTENT_DISPOSITION
            fn	            TEXT    
            cid	            TEXT    
            cl	            TEXT        # 华为 autobackup 为文件名
            ct	            TEXT        # 华为 autobackup 独有为文件类型
            ctt_s	        INTEGER 
            ctt_t	        TEXT        # CONTENT_TYPE 
            _data	        TEXT    
            text	        TEXT        # 如果是彩信始末,为彩信的SMIL内容;如果是文本附件,为附件内容;如果是视频、音频附件,此参数为空
        '''
        mms_mid_text_dict = {}
        for rec in self._read_table(table_name):
            try:
                if (rec.ContainsKey('_id') and self._is_duplicate(rec, '_id')
                        or self._is_empty(rec, 'ct')):
                    continue
                part = model_sms.MMSPart()
                if rec.ContainsKey('_id'):
                    part._id = rec['_id'].Value
                part.mms_id = rec['mid'].Value
                # part.sim_id
                part.part_filename = rec['cl'].Value if rec.ContainsKey(
                    'cl') else rec['name'].Value
                part.part_local_path = self._convert_nodepath(
                    rec['_data'].Value)
                # part.part_text =
                # part.part_charset
                if '/' in rec['ct'].Value:
                    part.part_contenttype = rec['ct'].Value.split('/')[0]

                if rec['text'].Value and part.part_contenttype == 'text':
                    mms_mid_text_dict[part.mms_id] = rec['text'].Value
                self.csm.db_insert_table_mms_part(part)
            except:
                exc()
        self.csm.db_commit()
        return mms_mid_text_dict
Beispiel #28
0
    def _get_callrecord_models(self):
        if not self._db_has_table('callrecord'):
            return []
        models = []

        sql = '''select * from callrecord'''
        '''
        0    _id, 
        1    phone_number, 
        2    date, 
        3    call_type, 
        4    source, 
        5    deleted, 
        6    repeated        
        '''
        try:
            cmd = self.db.CreateCommand()
            cmd.CommandText = sql
            r = cmd.ExecuteReader()
            while r.Read():
                deleted = 0
                try:
                    phone_number = self._db_reader_get_string_value(r, 1)
                    date = self._get_timestamp(self._db_reader_get_int_value(r, 2))
                    call_type = self._db_reader_get_int_value (r, 3)
                    source = self._db_reader_get_string_value(r, 4)
                    deleted = self._db_reader_get_int_value(r, 5, None)

                    c = CallBlocking()
                    if date:
                        c.BlockTime = date
                    if call_type in CALLBLOCK_TYPE_CONVERTER:                                      
                        c.Type = CALLBLOCK_TYPE_CONVERTER[call_type]
                    c.PhoneNumber = phone_number
                    if source:
                        c.SourceFile = source
                    if deleted:
                        c.Deleted = self._convert_deleted_status(deleted)                    
                    models.append(c)
                except:
                    exc()
            r.Close()
            return models                    
        except:
            exc()
            return models
Beispiel #29
0
    def parse_Chatroom(self, table_name, CHATROOM_MEMBER_COUNT):
        ''' TIMConversationCoreInfoORM 

            FieldName	                    SQLType                   	
            belongingConversationIdentifier	    TEXT
            infoVersion	                        INTEGER
            name	                        TEXT
            desc	                        TEXT
            icon	                        TEXT
            notice	                        TEXT
            ext	                            TEXT
        '''
        CHATROOM_ID_NAME = {}
        for rec in self._read_table(table_name):
            try:
                if (rec['belongingConversationIdentifier'].Value
                        not in CHATROOM_MEMBER_COUNT or self._is_empty(
                            rec, 'belongingConversationIdentifier', 'name')
                        or self._is_duplicate(
                            rec, 'belongingConversationIdentifier')):
                    continue
                chatroom = model_im.Chatroom()
                chatroom.account_id = self.cur_account_id
                chatroom.chatroom_id = rec[
                    'belongingConversationIdentifier'].Value
                chatroom.name = rec['name'].Value
                chatroom.photo = rec['icon'].Value
                try:
                    chatroom.creator_id = json.loads(
                        rec['ext'].Value).get('a:s_name_operator')
                except:
                    pass
                chatroom.member_count = CHATROOM_MEMBER_COUNT.get(
                    chatroom.chatroom_id, None)
                chatroom.create_time = rec['infoVersion'].Value
                chatroom.deleted = 1 if rec.IsDeleted else 0
                chatroom.source = self.cur_db_source
                try:
                    CHATROOM_ID_NAME[chatroom.chatroom_id] = chatroom.name
                except:
                    exc()
                chatroom.insert_db(self.csm)
            except:
                exc()
        self.csm.db_commit()
        return CHATROOM_ID_NAME
    def parse_Bookmark(self, db_path, table_name):
        """ dbbrowser.db - bookmark

            RecNo  FieldName
            1	   account_uid	        TEXT
            2	   create_time	        INTEGER
            3	   date	            INTEGER
            4	   edit_cmd	        TEXT
            5	   edit_time	    INTEGER
            6	   _id	            INTEGER
            7	   parent	        INTEGER
            8	   parent_uuid	        TEXT
            9	   platform	        TEXT
            10	   position	        INTEGER
            11	   reserve	        TEXT
            12	   sync_time	    INTEGER
            13	   sync_uuid	    TEXT
            14	   title	        TEXT
            15	   type	        INTEGER
            16	   url	        TEXT
            17	   visits	        INTEGER
        """
        if not self._read_db(db_path):
            return
        for rec in self._read_table(table_name):
            if self._is_empty(rec, 'url',
                              'title') or not self._is_url(rec, 'url'):
                continue
            if self._is_duplicate(rec, '_id'):
                continue
            bookmark = model_browser.Bookmark()
            bookmark.id = rec['_id'].Value
            # bookmark.owneruser = rec['account_uid'].Value
            bookmark.time = rec['create_time'].Value
            bookmark.title = rec['title'].Value
            bookmark.url = rec['url'].Value
            bookmark.source = self.cur_db_source
            bookmark.deleted = 1 if rec.IsDeleted else 0
            try:
                self.csm.db_insert_table_bookmarks(bookmark)
            except:
                exc()
        try:
            self.csm.db_commit()
        except:
            exc()