def parse_account(self, dbPath): '''解析账户数据''' db = SQLite.SQLiteConnection( 'Data Source = {}; ReadOnly = True'.format(dbPath)) db.Open() db_cmd = SQLite.SQLiteCommand(db) try: if db is None: return db_cmd.CommandText = """select * from cfurl_cache_receiver_data where receiver_data like '%nickname%'""" sr = db_cmd.ExecuteReader() try: account = model_im.Account() while (sr.Read()): account = model_im.Account() account.source = self.node.AbsolutePath account_data = json.loads( json.dumps( self._db_reader_get_string_value(sr, 2).replace( '\\', '').replace('\"', "'").replace('"', ''))) account_dic = json.loads(account_data.replace("'", '"')) account.account_id = account_dic['nickname'] account.username = account_dic['nickname'] account.nickname = account_dic['nickname'] account.photo = account_dic['headimgurl'] account.gender = 1 if account_dic['sex'] == 1 else 0 account.country = account_dic['country'] account.province = account_dic['province'] account.deleted = 0 self.db_insert_table_account(account) if account.account_id is None: account.account_id = '未知用户' account.username = '******' self.db_insert_table_account(account) except: traceback.print_exc() self.account_id = account.account_id self.account_name = account.username self.db_commit() db_cmd.Dispose() db.Close() except Exception as e: print(e)
def __generate_transfer(self): connection = unity_c37r.create_connection(self.cache_db) cmd = sql.SQLiteCommand(connection) cmd.CommandText = ''' select * from tb_transfer ''' fts = NDFileTransfer() reader = cmd.ExecuteReader() while reader.Read(): t = NDBCPTRANSFER() t.set_value_with_idx( t.account_id, unity_c37r.c_sharp_get_string(reader, fts.account)) t.set_value_with_idx( t.file_name, unity_c37r.c_sharp_get_string(reader, fts.file_name)) t.set_value_with_idx( t.file_size, unity_c37r.c_sharp_get_long(reader, fts.file_size)) t.set_value_with_idx( t.hash, unity_c37r.c_sharp_get_string(reader, fts.hash_code)) t.set_value_with_idx( t.server_path, unity_c37r.c_sharp_get_string(reader, fts.server_path)) t.set_value_with_idx( t.file_path, unity_c37r.c_sharp_get_string(reader, fts.local_path)) t.set_value_with_idx( t.url, unity_c37r.c_sharp_get_string(reader, fts.url)) t.set_value_with_idx( t.torrent, unity_c37r.c_sharp_get_string(reader, fts.torrent_name)) t.set_value_with_idx( t.status, unity_c37r.c_sharp_get_long(reader, fts.status)) t.set_value_with_idx( t.action_type, unity_c37r.c_sharp_get_long(reader, fts.is_download)) t.set_value_with_idx( t.begin_time, unity_c37r.c_sharp_get_long(reader, fts.begin_time)) t.set_value_with_idx( t.end_time, unity_c37r.c_sharp_get_long(reader, fts.end_time)) t.set_value_with_idx( t.cached_size, unity_c37r.c_sharp_get_long(reader, fts.cached_size)) t.set_value_with_idx( t.delete_status, unity_c37r.c_sharp_get_long(reader, fts.deleted)) t.set_value_with_idx(t.collect_id, self.cid) t.set_value_with_idx(t.app_type, self.app_type) self.db_insert_transfer(t) self.db_commit() reader.Close() cmd.Dispose() connection.Close()
def analyze_attach(self): '''保存附件数据到中间数据库''' self.db = SQLite.SQLiteConnection('Data Source = {}'.format( self.recoverDB)) self.db.Open() self.db_cmd = SQLite.SQLiteCommand(self.db) try: if self.db is None: return self.db_cmd.CommandText = SQL_ASSOCIATE_TABLE_ATTACH sr = self.db_cmd.ExecuteReader() while sr.Read(): try: if canceller.IsCancellationRequested: break attachment = Attachment() attachment.attachment_id = self._db_reader_get_int_value( sr, 0) attachment.owner_account_id = self._db_reader_get_int_value( sr, 1) attachment.mail_id = self._db_reader_get_int_value(sr, 2) attachname = self._db_reader_get_string_value(sr, 3) attachment.attachment_name = attachname if attachname is not '': attachNodes = self.attachnode.Search(attachname + '$') for attachNode in attachNodes: attachment.attachment_save_dir = attachNode.AbsolutePath break attachment.attachment_size = self._db_reader_get_int_value( sr, 4) attachment.attachment_download_date = self._db_reader_get_int_value( sr, 5) attachment.source = self.node.AbsolutePath attachment.deleted = self._db_reader_get_int_value(sr, 6) self.mm.db_insert_table_attachment(attachment) except: traceback.print_exc() self.mm.db_commit() self.db_cmd.Dispose() self.db.Close() except Exception as e: print(e)
def _generate_basestation_info(self): '''生成基站信息bcp''' try: db = SQLite.SQLiteConnection('Data Source = {}'.format(self.cache_db)) db.Open() db_cmd = SQLite.SQLiteCommand(db) if db is None: return db_cmd.CommandText = '''select distinct * from WA_MFORENSICS_080400''' sr = db_cmd.ExecuteReader() while (sr.Read()): try: if canceller.IsCancellationRequested: break base = BasestationInfo() base.COLLECT_TARGET_ID = self.collect_target_id base.MCC = self._db_reader_get_int_value(sr, 1) base.MNC = self._db_reader_get_int_value(sr, 2) base.ECGI = self._db_reader_get_string_value(sr, 3) base.LAC = self._db_reader_get_string_value(sr, 4) base.CellID = self._db_reader_get_string_value(sr, 5) base.SID = self._db_reader_get_string_value(sr, 6) base.NID = self._db_reader_get_string_value(sr, 7) base.BASE_STATION_ID = self._db_reader_get_string_value(sr, 8) base.CITY_CODE = self._db_reader_get_string_value(sr, 9) base.COMPANY_ADDRESS = self._db_reader_get_string_value(sr, 10) base.LONGITUDE = self._db_reader_get_string_value(sr, 11) base.LATITUDE = self._db_reader_get_string_value(sr, 12) base.ABOVE_SEALEVEL = self._db_reader_get_string_value(sr, 13) base.START_TIME = str(sr[14]) if sr[14] is not None else None base.END_TIME = self._db_reader_get_string_value(sr, 15) base.DELETE_STATUS = self._db_reader_get_string_value(sr, 16) base.DELETE_TIME = self._db_reader_get_int_value(sr, 17) self.db_insert_table_basestation_information(base) except: pass self.db_commit() sr.Close() db_cmd.Dispose() db.Close() except: pass
def parse_chatroom_member(self, dbPath): '''解析群组成员数据''' db = SQLite.SQLiteConnection( 'Data Source = {}; ReadOnly = True'.format(dbPath)) db.Open() db_cmd = SQLite.SQLiteCommand(db) try: if self.db is None: return db_cmd.CommandText = '''select a.discussionid, a.memberid, b.birthday, b.gender, b.name, b.signature, a.deleted from bb_discussion_member_info as a left join bb_user_info as b on a.memberid = b.userid''' sr = db_cmd.ExecuteReader() while (sr.Read()): try: chatroom_member = model_im.ChatroomMember() if canceller.IsCancellationRequested: break chatroom_member.account_id = self.account_id chatroom_member.chatroom_id = self._db_reader_get_int_value( sr, 0) chatroom_member.deleted = self._db_reader_get_int_value( sr, 6) chatroom_member.display_name = self._db_reader_get_string_value( sr, 4) chatroom_member.member_id = self._db_reader_get_int_value( sr, 1) chatroom_member.source = self.node.AbsolutePath chatroom_member.birthday = self._db_reader_get_int_value( sr, 2) chatroom_member.gender = self._db_reader_get_int_value( sr, 3) chatroom_member.signature = self._db_reader_get_string_value( sr, 5) self.db_insert_table_chatroom_member(chatroom_member) except: traceback.print_exc() sr.Close() self.db_commit() db_cmd.Dispose() db.Close() except Exception as e: print(e)
def read_deleted_records(self): '''获取删除数据保存至删除数据库''' self.create_deleted_db() self.db = SQLite.SQLiteConnection('Data Source = {}'.format(self.recoverDB)) self.db.Open() self.db_cmd = SQLite.SQLiteCommand(self.db) self.db_trans.Commit() self.db_trans = self.db.BeginTransaction() self.read_deleted_table_participant() self.read_deleted_table_contact() self.read_deleted_table_contact_number() self.read_deleted_table_conversation() self.read_deleted_table_message() self.read_deleted_table_call() self.db_trans.Commit() self.db_cmd.Dispose() self.db.Close()
def create_connection_tentatively(db_node, read_only=True): cmd = 'DataSource = {}; ReadOnly = {}' cmd = cmd.format(db_node.PathWithMountPoint, 'True' if read_only else 'False') try: conn = None dcmd = None reader = None conn = sql.SQLiteConnection(cmd) conn.Open() dcmd = sql.SQLiteCommand(conn) dcmd.CommandText = ''' select * from sqlite_master limit 1 offset 0 ''' reader = dcmd.ExecuteReader() reader.Read() reader.Close() dcmd.Dispose() return conn except: traceback.print_exc() if reader is not None: reader.Close() if dcmd is not None: dcmd.Dispose() if conn is not None: conn.Close() data = db_node.Data sz = db_node.Size cache = ds.OpenCachePath('C37R') if not os.path.exists(cache): os.mkdir(cache) cache_db = cache + '/' + md5(db_node.PathWithMountPoint) f = open(cache_db, 'wb+') f.write(data.read(sz)) f.close() cmd = 'DataSource = {}; ReadOnly = {}'.format( cache_db, 'True' if read_only else 'False') conn = sql.SQLiteConnection(cmd) conn.Open() return conn
def parse_friend(self, dbPath): '''解析好友(联系人)数据''' db = SQLite.SQLiteConnection( 'Data Source = {}; ReadOnly = True'.format(dbPath)) db.Open() db_cmd = SQLite.SQLiteCommand(db) try: if db is None: return db_cmd.CommandText = '''select a.userid, a.birthday, a.customized_id, a.gender, a.name, a.signature, b.id, a.deleted from bb_user_info as a left join bb_buddy_id_info as b on a.userid = b.userid''' sr = db_cmd.ExecuteReader() while (sr.Read()): try: friend = model_im.Friend() if canceller.IsCancellationRequested: break friend.account_id = self.account_id friend.deleted = self._db_reader_get_int_value(sr, 7) friend.friend_id = self._db_reader_get_int_value(sr, 0) friend.birthday = self._db_reader_get_int_value(sr, 1) friend.nickname = self._db_reader_get_string_value(sr, 4) friend.fullname = self._db_reader_get_string_value(sr, 4) friend.source = self.node.AbsolutePath friend.gender = 1 if self._db_reader_get_int_value( sr, 3) == 0 else 0 friend.signature = self._db_reader_get_string_value(sr, 5) friend.type = model_im.FRIEND_TYPE_FRIEND if not IsDBNull( sr[6]) else model_im.FRIEND_TYPE_NONE self.db_insert_table_friend(friend) except: traceback.print_exc() sr.Close() self.db_commit() db_cmd.Dispose() db.Close() except Exception as e: print(e)
def read_deleted_table_mailinfo(self): self.db = SQLite.SQLiteConnection('Data Source = {}'.format( self.recoverDB)) self.db.Open() self.db_cmd = SQLite.SQLiteCommand(self.db) try: node = self.node if node is None: return db = SQLiteParser.Database.FromNode(node, canceller) if db is None: return ts = SQLiteParser.TableSignature('FM_MailInfo') for rec in db.ReadTableDeletedRecords(ts, False): if canceller.IsCancellationRequested: break if IsDBNull(rec['mailId'].Value) or rec['mailId'].Value == 0: continue param = () param = param + (rec['mailId'].Value, ) param = param + (rec['accountId'].Value, ) param = param + (rec['folderId'].Value, ) param = param + (rec['fromEmail'].Value, ) param = param + (rec['fromNick'].Value, ) param = param + (rec['tos'].Value, ) param = param + (rec['ccs'].Value, ) param = param + (rec['bcc'].Value, ) param = param + (rec['receivedUtc'].Value, ) param = param + (rec['subject'].Value, ) param = param + (rec['abstract'].Value, ) param = param + (rec['isRead'].Value, ) param = param + (rec['isRecalled'].Value, ) param = param + (rec['ip'].Value, ) param = param + (rec['size'].Value, ) self.db_insert_table(SQL_INSERT_TABLE_RECOVER_MAILINFO, param) self.db_cmd.Dispose() self.db.Close() except Exception as e: print(e)
def get_account_list(self): conn = SQLite.SQLiteConnection("Data Source = {0}; ReadOnly = True".format(self.decrypt_db_path)) try: account_list = [] conn.Open() cmd = SQLite.SQLiteCommand(conn) cmd.CommandText = ''' select tbl_name from sqlite_master where tbl_name like '%POI_SNAPSHOT%' and type ='table' ''' reader = cmd.ExecuteReader() while reader.Read(): try: a_id = reader.GetString(0) if not reader.IsDBNull(0) else "" # if len(a_id) != len("POI_SNAPSHOT"): account_list.append(a_id[len("POI_SNAPSHOT"):]) except Exception as e: TraceService.Trace(TraceLevel.Error,"{0}".format(e)) reader.Close() conn.Close() return account_list except: pass
def analyze_attachment(self, mailPath, deleteFlag): '''保存附件数据到中间数据库''' self.db = SQLite.SQLiteConnection( 'Data Source = {}; ReadOnly = True'.format(mailPath)) self.db.Open() self.db_cmd = SQLite.SQLiteCommand(self.db) attachment_node = self.node.Parent.GetByPath('/attachmentCacheFolder') try: if self.db is None: return self.db_cmd.CommandText = SQL_ASSOCIATE_TABLE_ATTACH sr = self.db_cmd.ExecuteReader() while sr.Read(): attachment = Attachment() if canceller.IsCancellationRequested: break attachment.attachment_id = sr[0] attachment.owner_account_id = sr[1] attachment.mail_id = sr[2] attachment.attachment_name = sr[3] if not IsDBNull(sr[0]) and not IsDBNull(sr[3]): md5_attachname = hashlib.md5() attach_name = str(sr[0]) + sr[3] md5_attachname.update(attach_name.encode(encoding='utf-8')) local_name = md5_attachname.hexdigest() fileNodes = attachment_node.Search(local_name) for node in fileNodes: attachment.attachment_save_dir = node.AbsolutePath break attachment.attachment_size = sr[4] attachment.attachment_download_date = sr[5] attachment.source = self.node.AbsolutePath self.mm.db_insert_table_attachment(attachment) attachment.deleted = deleteFlag self.mm.db_commit() self.db_cmd.Dispose() self.db.Close() except Exception as e: print(e)
def parse_feed(self, dbPath): '''解析动态数据''' db = SQLite.SQLiteConnection( 'Data Source = {}; ReadOnly = True'.format(dbPath)) db.Open() db_cmd = SQLite.SQLiteCommand(db) fs = self.node.FileSystem try: if self.db is None: return db_cmd.CommandText = '''select address, userid, sendTime, nickname, icon, myuid, likecount, datetime, reviewcount, gender, dynamicid, sendPhotos, content, deleted from DBTableName_MySendDynamic''' sr = db_cmd.ExecuteReader() while (sr.Read()): try: feed = model_im.Feed() if canceller.IsCancellationRequested: break feed.account_id = self.account_id feed.sender_id = self._db_reader_get_int_value(sr, 1) feed.send_time = self._get_timestamp( self._db_reader_get_int_value(sr, 2)) feed.deleted = self._db_reader_get_int_value(sr, 13) feed.likecount = self._db_reader_get_int_value(sr, 6) feed.content = self._db_reader_get_string_value(sr, 12) feed.commentcount = self._db_reader_get_int_value(sr, 8) if not IsDBNull(sr[11]): mediapathes = Encoding.UTF8.GetString(sr[11]) feed.image_path = mediapathes self.db_insert_table_feed(feed) except: traceback.print_exc() sr.Close() self.db_commit() db_cmd.Dispose() db.Close() except Exception as e: print(e)
def parse_account(self, node, dbPath, deleteFlag): '''解析账户数据(viber_messages)''' db = SQLite.SQLiteConnection('Data Source = {}; ReadOnly = True'.format(dbPath)) db.Open() db_cmd = SQLite.SQLiteCommand(db) try: if db is None: return db_cmd.CommandText = '''select _id, display_name, number from participants_info where _id = 1''' sr = db_cmd.ExecuteReader() try: if not sr.HasRows: account = model_im.Account() account.account_id = '未知用户' account.username = '******' account.source = self.node.AbsolutePath account.deleted = 0 self.account_id = account.account_id self.account_name = account.username self.db_insert_table_account(account) while(sr.Read()): account = model_im.Account() account.account_id = self._db_reader_get_int_value(sr, 0) if not IsDBNull(sr[0]) else '未知用户' account.telephone = self._db_reader_get_string_value(sr, 2) account.username = self._db_reader_get_string_value(sr, 1) if not IsDBNull(sr[1]) else '未知用户' account.source = node.AbsolutePath account.deleted = deleteFlag self.account_id = account.account_id self.account_name = account.username self.db_insert_table_account(account) except: traceback.print_exc() self.local_number = account.telephone self.db_commit() db_cmd.Dispose() db.Close() except Exception as e: print(e)
def db_check(self, app_v): if not os.path.exists(self.cache) or not os.path.exists(self.cache + '.im'): self.need_parse = True return conns = unity_c37r.create_connection(self.cache) cmd = sql.SQLiteCommand(conns) try: eb_checked = False eb_app_checked = False cmd.CommandText = ''' select version_value from tb_version where version_key = '{}' '''.format(EB_VERSION_KEY) reader = None reader = cmd.ExecuteReader() if reader.Read(): res = unity_c37r.c_sharp_get_long(reader, 0) if res == EB_VERSION_VALUE: eb_checked = True cmd.Dispose() cmd.CommandText = ''' select version_value from tb_version where version_key = '{}' '''.format(EB_APP_VERSION_KEY) reader = cmd.ExecuteReader() if reader.Read(): res = unity_c37r.c_sharp_get_long(reader, 0) if res == app_v: eb_app_checked = True cmd.Dispose() reader.Close() conns.Close() conns = None reader = None if not ( eb_checked and eb_app_checked): self.need_parse = True n_parse = self.im.need_parse(self.cache + '.im', EB_VERSION_VALUE) if n_parse: self.need_parse = True return self.need_parse = False except Exception as e: traceback.print_exc() if reader is not None: reader.Close() if conns is not None: cmd.Dispose() conns.Close() self.log.m_err('check db failed, please try again!') self.log.m_err(e.message) self.need_parse = True return
def generate(self): try: self.mail.db_create(self.cache_path) self.db = SQLite.SQLiteConnection('Data Source = {}'.format( self.cache_db)) self.db.Open() self._generate_account() self._generate_contact() self._generate_mail() self._generate_attachment() self.db.Close() self.mail.db_close() except Exception as e: print(e)
def __init__(self, bcp_path, mount_path, cache_db, bcp_db, collect_target_id, contact_account_type): self.bcp_path = bcp_path self.db = bcp_db self.mnt = mount_path self.cache_db = cache_db self.cid = collect_target_id self.app_type = contact_account_type if os.path.exists(self.db): os.remove(self.db) self.conn = unity_c37r.create_connection(self.db, False) self.cmd = sql.SQLiteCommand(self.conn) self.transaciton = None self.create_tables()
def read_deleted_records(self): '''获取删除数据保存至删除数据库''' self.create_deleted_db() self.rdb = SQLite.SQLiteConnection('Data Source = {}'.format( self.recoverDB)) self.rdb.Open() self.rdb_cmd = SQLite.SQLiteCommand(self.rdb) fs = self.node.FileSystem nodes = fs.Search('/cn.zoega.iAround/Cache.db$') for node in nodes: self.fnode = node break self.read_deleted_table_account() self.read_deleted_table_user() self.read_deleted_table_groupmsg() self.read_deleted_table_p2pmsg() self.read_deleted_table_feed() self.rdb_cmd.Dispose() self.rdb.Close()
def generate_bcp_account(self): conn = unity_c37r.create_connection(self.cache_db + '.IM') cmds = sql.SQLiteCommand(conn) cmds.CommandText = ''' select * from account ''' reader = cmds.ExecuteReader() while reader.Read(): a = AccountInfo() #a.colltection_target_id = self.colltection_target_id a.set_value_with_idx(a.colltection_target_id, self.colltection_target_id) a.set_value_with_idx(a.app_code, self.app_code) a.set_value_with_idx(a.account_id, unity_c37r.c_sharp_get_string(reader, 0)) a.set_value_with_idx(a.nick, unity_c37r.c_sharp_get_string(reader, 1)) a.set_value_with_idx(a.account, unity_c37r.c_sharp_get_string(reader, 2)) a.set_value_with_idx(a.password, unity_c37r.c_sharp_get_string(reader, 3)) pic = unity_c37r.c_sharp_get_string(reader, 4) pic = os.path.join(self.mnt, pic) if os.path.exists(pic): #a.set_value_with_idx(os.path.join(self.app_code, )) ppath,pname = os.path.split(pic) a.set_value_with_idx(a.photo, self.app_code + '/' + pname) pass # copy file... a.set_value_with_idx(a.telephone, unity_c37r.c_sharp_get_string(reader, 5)) gender = unity_c37r.c_sharp_get_long(reader, 6) rg = '0' if gender == 0: rg = '0' elif gender == 1: rg = '1' elif gender == 2: rg = '2' elif gender == 9: rg = '9' a.set_value_with_idx(a.sex_code, rg) a.set_value_with_idx(a.age, unity_c37r.c_sharp_get_long(reader, 7)) #a.set_value_with_idx(a.country_code, unity_c37r.c_sharp_get_string(reader, 8)) # NOT SUPPORT RIGHT NOW!!!! a.set_value_with_idx(a.city, unity_c37r.c_sharp_get_string(reader, 9)) #a.set_value_with_idx(a.signature, unity_c37r.c_sharp_get_string(reader, )) a.set_value_with_idx(a.address, unity_c37r.c_sharp_get_string(reader, 12)) a.set_value_with_idx(a.birth, unity_c37r.c_sharp_get_string(reader, 13)) a.set_value_with_idx(a.signature, unity_c37r.c_sharp_get_string(reader, 14)) d = unity_c37r.c_sharp_get_string(reader, 15) a.set_value_with_idx(a.signature, d) # not support delete time unity_c37r.execute_query(self.cmd, TBL_BCP_INSERT_ACCOUNT, a.get_values()) self.db_commit() reader.Close() cmds.Dispose() conn.Close()
def analyze_contact(self): '''保存联系人数据到中间数据库''' self.db = SQLite.SQLiteConnection('Data Source = {}'.format( self.recoverDB)) self.db.Open() self.db_cmd = SQLite.SQLiteCommand(self.db) try: if self.db is None: return self.db_cmd.CommandText = SQL_ASSOCIATE_TABLE_CONTACT sr = self.db_cmd.ExecuteReader() id = 0 while sr.Read(): try: if canceller.IsCancellationRequested: break contact = Contact() id += 1 contact.contact_id = id contact.owner_account_id = self._db_reader_get_int_value( sr, 0) contact.contact_user = self._db_reader_get_string_value( sr, 1) contact.contact_email = self._db_reader_get_string_value( sr, 1) contact.contact_alias = self._db_reader_get_string_value( sr, 2) contact.source = self.node.AbsolutePath contact.deleted = self._db_reader_get_int_value(sr, 3) self.mm.db_insert_table_contact(contact) except: traceback.print_exc() self.mm.db_commit() self.db_cmd.Dispose() self.db.Close() except Exception as e: print(e)
def create_deleted_db(self): '''创建删除数据库''' if os.path.exists(self.recoverDB): os.remove(self.recoverDB) db = SQLite.SQLiteConnection('Data Source = {}'.format(self.recoverDB)) db.Open() db_cmd = SQLite.SQLiteCommand(db) if db_cmd is not None: db_cmd.CommandText = '''create table if not exists bb_account_info (user_id INTEGER, account_name TEXT, deleted INTEGER)''' db_cmd.ExecuteNonQuery() db_cmd.CommandText = '''create table if not exists bb_user_info (userid INTEGER, name TEXT, gender INTEGER, birthday INTEGER, signature TEXT, customized_id TEXT, deleted INTEGER)''' db_cmd.ExecuteNonQuery() db_cmd.CommandText = '''create table if not exists bb_buddy_id_info (id INTEGER, userid INTEGER, deleted INTEGER)''' db_cmd.ExecuteNonQuery() db_cmd.CommandText = '''create table if not exists bb_discussion_info (discussionid INTEGER, title TEXT, memberver INTEGER, deleted INTEGER)''' db_cmd.ExecuteNonQuery() db_cmd.CommandText = '''create table if not exists bb_discussion_member_info (discussionid INTEGER, memberid INTEGER, deleted INTEGER)''' db_cmd.ExecuteNonQuery() db_cmd.CommandText = '''create table if not exists bb_chat_msg_info (msgid INTEGER, content BLOB, fromId INTEGER, metatag TEXT, timestamp INTEGER, userid INTEGER, deleted INTEGER)''' db_cmd.ExecuteNonQuery() db_cmd.CommandText = '''create table if not exists bb_dl_item_info (item_id INTEGER, mediaBytesInfo BLOB, timeStamp INTEGER, user_id INTEGER, deleted INTEGER)''' db_cmd.ExecuteNonQuery() db_cmd.CommandText = '''create table if not exists bb_dl_comment_info (item_id INTEGER, action TEXT, comment TEXT, timestamp INTEGER, user_id INTEGER, commend_id INTEGER, deleted INTEGER)''' db_cmd.ExecuteNonQuery() db_cmd.CommandText = '''create table if not exists bb_discussion_chat_msg_info (content BLOB, msgid INTEGER, userId INTEGER, metatag TEXT, timestamp INTEGER, discussionid INTEGER, deleted INTEGER)''' db_cmd.ExecuteNonQuery() db_cmd.Dispose() db.Close()
def parse_friend(self, dbPath): '''解析好友(联系人)数据''' db = SQLite.SQLiteConnection( 'Data Source = {}; ReadOnly = True'.format(dbPath)) db.Open() db_cmd = SQLite.SQLiteCommand(db) try: if db is None: return db_cmd.CommandText = '''select otheruid, icon, relation, nickname, myuid, gender, sign, deleted from DBTableName_UserRelation''' sr = db_cmd.ExecuteReader() while (sr.Read()): try: friend = model_im.Friend() if canceller.IsCancellationRequested: break friend.account_id = self.account_id friend.deleted = self._db_reader_get_int_value(sr, 7) friend.friend_id = self._db_reader_get_int_value(sr, 0) friend.fullname = self._db_reader_get_string_value(sr, 3) friend.nickname = self._db_reader_get_string_value(sr, 3) friend.photo = self._db_reader_get_string_value(sr, 1) friend.gender = self._db_reader_get_int_value(sr, 5) friend.source = self.node.AbsolutePath friend.signature = self._db_reader_get_string_value(sr, 6) relation = self._db_reader_get_int_value(sr, 2) friend.type = model_im.FRIEND_TYPE_FRIEND if relation == 1 else model_im.FRIEND_TYPE_FOLLOW if relation == 3 else model_im.FRIEND_TYPE_FANS if relation == 2 else model_im.FRIEND_TYPE_NONE self.db_insert_table_friend(friend) except: traceback.print_exc() sr.Close() self.db_commit() db_cmd.Dispose() db.Close() except Exception as e: print(e)
def create_rdb(self): '''创建恢复数据库''' if os.path.exists(self.recoverDB): os.remove(self.recoverDB) db = SQLite.SQLiteConnection('Data Source = {}'.format(self.recoverDB)) db.Open() db_cmd = SQLite.SQLiteCommand(db) if db_cmd is not None: db_cmd.CommandText = SQL_CREATE_TABLE_RECOVER_ACCOUNT db_cmd.ExecuteNonQuery() db_cmd.CommandText = SQL_CREATE_TABLE_RECOVER_MAILINFO db_cmd.ExecuteNonQuery() db_cmd.CommandText = SQL_CREATE_TABLE_RECOVER_TOS db_cmd.ExecuteNonQuery() db_cmd.CommandText = SQL_CREATE_TABLE_RECOVER_CONTENT db_cmd.ExecuteNonQuery() db_cmd.CommandText = SQL_CREATE_TABLE_RECOVER_FOLDER db_cmd.ExecuteNonQuery() db_cmd.CommandText = SQL_CREATE_TABLE_RECOVER_CONTACT db_cmd.ExecuteNonQuery() db_cmd.CommandText = SQL_CREATE_TABLE_RECOVER_ATTACH db_cmd.ExecuteNonQuery() db_cmd.Dispose() db.Close()
def __init__(self, db_name, app_version=1): self.db_name = db_name self.need_parse = True self.conn = None self.cmd = None self.im = None if os.path.exists(self.db_name): self.need_parse = NetDisk.checkout(db_name, app_version) if self.need_parse: self.conn = unity_c37r.create_connection(db_name, False) self.cmd = sql.SQLiteCommand(self.conn) self.im = model_im.IM() self.im.db_create(db_name + '.IM') self.events = None self.create_tables()
def generate(self): self.im.db_create(self.bcp_db) self.db = SQLite.SQLiteConnection('Data Source = {}'.format(self.cache_db)) self.db.Open() self._generate_account() self._generate_friend() self._generate_group() self._generate_group_member() self._generate_message() self._generate_feed() self._generate_search() if self.db is not None: self.db.Close() self.db = None self.im.db_close()
def __generate_account(self): connection = unity_c37r.create_connection(self.cache_db + ".IM", True) command = sql.SQLiteCommand(connection) command.CommandText = ''' select * from account ''' reader = command.ExecuteReader() while reader.Read(): a = NDBCPACCOUNT() a.set_value_with_idx(a.account_id, unity_c37r.c_sharp_get_string(reader, 0)) a.set_value_with_idx(a.account, a.get_value_with_idx(a.account_id)) a.set_value_with_idx(a.nick, unity_c37r.c_sharp_get_string(reader, 1)) a.set_value_with_idx(a.password, unity_c37r.c_sharp_get_string(reader, 3)) photo = unity_c37r.c_sharp_get_string(reader, 4) photo = os.path.join(self.mnt, photo) if os.path.exists(photo): pass # ===>copy file fix that else: a.set_value_with_idx(a.photo, photo) a.set_value_with_idx(a.telephone, unity_c37r.c_sharp_get_string(reader, 5)) a.set_value_with_idx(a.email, unity_c37r.c_sharp_get_string(reader, 6)) gender = unity_c37r.c_sharp_get_long(reader, 7) gender = '0%d' % gender a.set_value_with_idx(a.gender, gender) a.set_value_with_idx(a.age, unity_c37r.c_sharp_get_long(reader, 8)) a.set_value_with_idx(a.city, unity_c37r.c_sharp_get_string(reader, 11)) a.set_value_with_idx(a.address, unity_c37r.c_sharp_get_string(reader, 12)) a.set_value_with_idx(a.birthday, unity_c37r.c_sharp_get_string(reader, 13)) a.set_value_with_idx(a.signature, unity_c37r.c_sharp_get_string(reader, 14)) a.set_value_with_idx(a.delete_status, unity_c37r.c_sharp_get_string(reader, 15)) a.set_value_with_idx(a.collect_id, self.cid) a.set_value_with_idx(a.app_type, self.app_type) self.db_insert_account(a) self.db_commit() reader.Close() command.Dispose() connection.Close()
def _generate_demo(self): try: self.db_cmd = SQLite.SQLiteCommand(self.db) if self.db_cmd is None: return self.db_cmd.CommandText = '''select distinct * from xxx''' sr = self.db_cmd.ExecuteReader() while (sr.Read()): if canceller.IsCancellationRequested: break xxx = XXX() xxx.COLLECT_TARGET_ID = self.collect_target_id self.mail.db_insert_table_xxx(xxx) self.mail.db_commit() self.db_cmd.Dispose() except Exception as e: print(e)
def __handle_location(self, aid, f_k): f_sql_node = self.root_node.GetByPath( 'Documents/{}/account/{}_Attachment.sqlite'.format(aid, aid)) if f_sql_node is None: return None #db = sqlite3.connect(f_sql_node.PathWithMountPoint) db = unity_c37r.create_connection(f_sql_node.PathWithMountPoint) cmd = sql.SQLiteCommand(db) cmd.CommandText = ''' select ZEXTENSION from ZATTACHMENTOBJECT where ZATT_ID = '{}' '''.format(f_k) reader = cmd.ExecuteReader() res = '' if reader.Read(): res = unity_c37r.c_sharp_get_string(reader, 0) cmd.Dispose() db.Close() return res
def _generate_mail(self): try: self.db_cmd = SQLite.SQLiteCommand(self.db) if self.db_cmd is None: return self.db_cmd.CommandText = '''select distinct b.account_user, a.mail_id, a.mail_from, a.mail_to, a.mail_cc, a.mail_bcc, a.mail_sent_date, a.mail_subject, a.mail_content, a.mail_read_status, a.deleted, a.mail_group, a.mail_group, a.deleted from mail as a left join account as b on a.owner_account_id = b.account_id''' sr = self.db_cmd.ExecuteReader() while (sr.Read()): if canceller.IsCancellationRequested: break mail = Mail() mail.COLLECT_TARGET_ID = self.collect_target_id mail.MAIL_TOOL_TYPE = self.mail_tool_type mail.ACCOUNT = sr[0] mail.SEQUENCE_NAME = sr[1] mail.FROM = sr[2] mail.TO = sr[3] mail.CC = sr[4] mail.BCC = sr[5] mail.MAIL_SEND_TIME = self._get_timestamp(sr[6]) mail.MAIL_SUBJECT = sr[7] mail.MAINFILE = sr[8] mail.MAIL_VIEW_STATUS = MAIL_VIEW_UNREAD if sr[ 9] == 0 else MAIL_VIEW_READ if sr[ 9] == 1 else MAIL_VIEW_OTHER mail.DELETE_STATUS = self._convert_delete_status(sr[10]) if sr[11] is '收件箱': mail.MAIL_SAVE_FOLDER = MAIL_SAVE_RECIEVE elif sr[11] is '发件箱': mail.MAIL_SAVE_FOLDER = MAIL_SAVE_POST elif sr[11] is '草稿箱': mail.MAIL_SAVE_FOLDER = MAIL_SAVE_DRAFT elif sr[11] is '垃圾箱': mail.MAIL_SAVE_FOLDER = MAIL_SAVE_TRASH else: mail.MAIL_SAVE_FOLDER = MAIL_SAVE_OTHER mail.FRIEND_GROUP = sr[12] mail.DELETE_STATUS = sr[13] self.mail.db_insert_table_mail(mail) self.mail.db_commit() except Exception as e: print(e)
def __find_file(self, aid, f_k): f_sql_node = self.root_node.GetByPath( 'Documents/{}/account/{}_ks3Resource.sqlite'.format(aid, aid)) if f_sql_node is None: return '' db = unity_c37r.create_connection(f_sql_node.PathWithMountPoint) cmd = sql.SQLiteCommand(db) cmd.CommandText = ''' select localPath from MLKS3ResourceObject where objectKey = '{}' '''.format(f_k) reader = cmd.ExecuteReader() res = '' if reader.Read(): res = os.path.join( self.root_node.AbsolutePath, 'Documents/{}/{}'.format( aid, unity_c37r.c_sharp_get_string(reader, 0))) cmd.Dispose() db.Close() return res
def generate(self): self.basic.db_create(self.cache_path) self.db = SQLite.SQLiteConnection('Data Source = {}'.format( self.cache_db)) self.db.Open() self._generate_basic_info() self._generate_terminal_info() self._generate_mobile_info() self._generate_os_info() self._generate_sim_info() self._generate_contact_info() self._generate_contact_detail() self._generate_call_record() self._generate_sms_info() self._generate_mms_info() self._generate_calendar_info() self._generate_sync_account() self._generate_alarm_clock() self._generate_operate_record() self.db.Close() self.basic.db_close()