一个字节的错误七十二小时的徒劳…………
需要的友友请联系
支持塞班第三版手机使用,附上你的msg.info文件。
#Encoding:UTF-8 #FileName:InsertMobileQQ2008MsgIntoMobileQQ2009.py #Date:2009_10_19 #假如有错误,请联系我:[email protected] from time import mktime from appuifw import query,note from os import makedirs def de16(s): return s.decode("UTF-16") def de8(s): return s.decode("UTF-8") def buildtime(s): s=de16(s) x="%x" %long(mktime((int("20"+s[:2]),int(s[3:5]),int(s[6:8]),int(s[9:11]),int(s[12:14]),int(s[15:17]),5,290,-1))) t=chr(eval("0x"+x[0:2]))+chr(eval("0x"+x[2:4]))+chr(eval("0x"+x[4:6]))+chr(eval("0x"+x[6:8])) del x return t def insert(fin,fout): f=file(fin) try : T=file(fout,"a") except : makedirs(fout[:-8]) T=file(fout,"a") ni,re=getName(f) f.seek(0) mark2008=f.read(2) mark="/xa8" blank="/x00"*6 while 1: c=f.read(8) if not c : del c break del c time=f.read(34) f.read(2) name=f.read(32).replace("/x00/x00","") if (ni and re)==name : flag="/x80" else : flag="/x00" data="" i=-2 while 1 : c=f.read(2) i+=2 if not c : T.write(mark+chr(i)+buildtime(time)+blank+flag+data+mark+chr(i)) print de16(name),de16(time) print de16(data) del c break elif mark2008!=c : data+=c elif mark2008==c : T.write(mark+chr(i)+buildtime(time)+blank+flag+data+mark+chr(i)) print de16(name),de16(time) print de16(data) del c,name,data,time,i,flag break T.close() f.close() del f,T,ni,re,mark2008,mark,blank def getName(f): f.read(46) re=f.read(32).replace("/x00/x00","") return query(de16(re)+de8(" 是你的昵称吗?"),"query"),re def begin(): path=manager().AskUser("c:/data/",ext=[".db"]) temp=path.split("//") o=str(temp[3]) t=str(temp[-1][:-6]) del temp if (-1==path.find("QQ")) : note(de8("选择错误/n⊙﹏⊙"),"error") else : pathto="c:/system/data/tencent/QQ/"+o+"/"+t+"/msg.info" insert(path,pathto) del t,path,pathto,o if query(de8("继续导入与其他好友的聊天记录?"),"query") : begin() else : print "-"*30 class manager: #copy the powlite_fm __module__ = __name__ def __s2d(s, x): res = '' x = x.lower() for i in range(len(x)): ind = s.alphabet.find(x[i]) if (ind == -1): res += '1' else: res += s.numaplhabet[ind] return res def ru(s, x): return x.decode('utf-8') def ur(s, x): return x.encode('utf-8') def __init__(s): import appuifw import os import e32 (s.appuifw, s.os, s.e32,) = (appuifw, os, e32) s.lock = s.e32.Ao_lock() s.curdir = None s.marknum = 0 s.selectfile = [] s.txt = '' s.alphabet = s.ru('abcdefghijklmnopqrstuvwxyz/xd0/xb0/xd0/xb1/xd0/xb2/xd0/xb3/xd0/xb4/xd0/xb5/xd1/x91/xd0/xb6/xd0/xb7/xd0/xb8/xd0/xb9/xd0/xba/xd0/xbb/xd0/xbc/xd0/xbd/xd0/xbe/xd0/xbf/xd1/x80/xd1/x81/xd1/x82/xd1/x83/xd1/x84/xd1/x85/xd1/x86/xd1/x87/xd1/x88/xd1/x89/xd1/x8c/xd1/x8b/xd1/x8a/xd1/x8d/xd1/x8e/xd1/x8f1234567890 ') s.numaplhabet = u'2223334445556667777888999922223333344445555666677778888999912345678900' def AskUser(s, path = None, find = 'file', ext = [], soundmod = False, markmod = False): s.soundmod = soundmod s.markmod = markmod if s.soundmod: import audio import keycapture (s.audio, s.keycapture,) = (audio, keycapture) s.capturer = s.keycapture.KeyCapturer(s.keycap) s.capturer.forwarding = 0 s.capturer.keys = s.keycapture.all_keys s.workitem = s.ru('/xe8/xaf/xb7/xe7/xa8/x8d/xe5/x80/x99...') s.backitem = u'<<<' if ((path == None) and ((s.curdir != None) and (s.curdir != u'root'))): path = s.os.path.split(s.curdir)[0] if (path[-1] != '//'): path += '//' s.oldscreen = s.appuifw.app.screen s.oldbody = s.appuifw.app.body s.oldexitkeyhandler = s.appuifw.app.exit_key_handler s.oldmenu = s.appuifw.app.menu s.oldtitle = s.appuifw.app.title try: s.oldfocus = s.appuifw.app.body.focus s.appuifw.app.body.focus = False except: pass if (find == 'dir'): s.appuifw.app.title = s.title = s.ru('/xe9/x80/x89/xe6/x8b/xa9/xe7/x9b/xae/xe5/xbd/x95') else: s.appuifw.app.title = s.title = s.ru('/xe9/x80/x89/xe6/x8b/xa9/xe6/x96/x87/xe4/xbb/xb6') (s.find, s.ext,) = (find, ext) s.appuifw.app.screen = 'normal' s.appuifw.app.body = s.body = s.appuifw.Listbox(s.list_root()) s.appuifw.app.exit_key_handler = s.exit s.menuChoose = (s.ru('/xe9/x80/x89/xe6/x8b/xa9'), s.choose_item) s.menuDir = (s.ru('/xe6/x96/xb0/xe5/xbb/xba'), s._createfolder) s.menuOpen = (s.ru('/xe6/x89/x93/xe5/xbc/x80'), s.browse_forward) s.menuMark = (s.ru('/xe6/xa0/x87/xe8/xae/xb0'), ((s.ru('/xe5/x85/xa8/xe9/x80/x89'), lambda :s.mark(1) ), (s.ru('/xe5/x85/xa8/xe6/xb6/x88'), lambda :s.mark(0) ))) s.menuBack = (s.ru('/xe6/x93/x8d/xe4/xbd/x9c'), ((s.ru('/xe6/x94/xb9/xe5/x90/x8d'), s._rename), (s.ru('/xe6/x96/xb0/xe5/xbb/xba'), s._createfolder))) s.curlist = s.list_root() if (not path): s.root() else: try: path = s.ru(path) except: pass s.curdir = s.os.path.normpath(path) if s.os.path.exists(s.ur(s.curdir)): pfile = None if s.os.path.isfile(s.ur(path)): pfile = s.os.path.basename(s.curdir).lower() s.curdir = s.os.path.dirname(s.curdir) if s.os.path.isdir(s.ur(s.curdir)): if (s.curdir[-1] != '//'): s.curdir = (s.curdir + '//') s.listdir(posfile=pfile) else: s.root() s.body.bind(63586, s.mark) s.body.bind(63495, s.browse_back) s.body.bind(63557, s.browse_forward) s.body.bind(63496, s.choose_item) s.body.bind(63497, lambda :s.construct_menu(-1) ) s.body.bind(63498, lambda :s.construct_menu(1) ) s.body.bind(42, lambda :s.move(1) ) s.body.bind(35, lambda :s.move(0) ) s.body.bind(48, lambda :s.listslice(u'0') ) s.body.bind(49, lambda :s.listslice(u'1') ) s.body.bind(50, lambda :s.listslice(u'2') ) s.body.bind(51, lambda :s.listslice(u'3') ) s.body.bind(52, lambda :s.listslice(u'4') ) s.body.bind(53, lambda :s.listslice(u'5') ) s.body.bind(54, lambda :s.listslice(u'6') ) s.body.bind(55, lambda :s.listslice(u'7') ) s.body.bind(56, lambda :s.listslice(u'8') ) s.body.bind(57, lambda :s.listslice(u'9') ) s.body.bind(8, s._remove) s.construct_menu(0) s.lock.wait() s.body.bind(63586, None) s.body.bind(63495, None) s.body.bind(63557, None) s.body.bind(63496, None) s.body.bind(63497, None) s.body.bind(63498, None) s.body.bind(42, None) s.body.bind(35, None) s.body.bind(48, None) s.body.bind(49, None) s.body.bind(50, None) s.body.bind(51, None) s.body.bind(52, None) s.body.bind(53, None) s.body.bind(54, None) s.body.bind(55, None) s.body.bind(56, None) s.body.bind(57, None) s.appuifw.app.body = s.oldbody s.appuifw.app.screen = s.oldscreen s.appuifw.app.exit_key_handler = s.oldexitkeyhandler s.appuifw.app.menu = s.oldmenu s.appuifw.app.title = s.oldtitle try: s.appuifw.app.body.focus = s.oldfocus except: pass tmp = None if s.choice_made: tmp = s.curdir if ((s.find == 'dir') and (tmp[:-1] != '//')): tmp += '//' if (s.curdir != u'root'): if (s.find == 'file'): if (s.markmod == False): s.curdir = s.os.path.split(s.curdir)[0] else: s.curdir = s.curdir if (s.markmod == False): if (s.curdir[-1] != '//'): s.curdir += '//' return tmp def root(s, prevdir = None): if (s.appuifw.app.title[-1] == u'*'): s.appuifw.app.title = s.appuifw.app.title[:-1] t = s.list_root() posindex = 0 for i in range(len(t)): if (t[i] == prevdir): posindex = i break s.body.set_list(t, posindex) s.curdir = u'root' s.curlist = s.list_root() s.construct_menu(0) def playsound(s): global s_fm s.capturer.start() try: i = s.body.current() path = (s.curdir + s.curlist[i]) s_fm = s.audio.Sound.open(path) s_fm.play(times=1, callback=s.AudioCallback) except: s.capturer.stop() def AudioCallback(s, prev_state, cur_state, err_code): if (prev_state == s.audio.EPlaying): s.capturer.stop() def keycap(s, key): try: s_fm.stop() s_fm.close() except: pass s.capturer.stop() def construct_menu(s, add): def _set(x): if (s.soundmod and ((len(x) > 1) and ((s.menuChoose in x) and (s.find != 'dir')))): x = ([(s.ru('/xe6/x92/xad/xe6/x94/xbe'), s.playsound)] + x) s.appuifw.app.menu = x i = (s.body.current() + add) if (i == -1): i = (len(s.curlist) - 1) elif (i == len(s.curlist)): i = 0 if (s.curdir == u'root'): if (s.find == 'dir'): _set([s.menuChoose, s.menuOpen]) else: _set([s.menuOpen]) return elif (i == 0): _set([s.menuChoose, s.menuDir]) return else: path = (s.curdir + s.curlist[i][1:-1]) if s.os.path.isdir(s.ur(path)): if (s.find == 'dir'): _set([s.menuChoose, s.menuOpen, s.menuBack]) else: _set([s.menuOpen, s.menuMark, s.menuBack]) else: _set([s.menuChoose, s.menuMark, s.menuBack]) def del_dir(s, path): for name in s.os.listdir(path): new = ((path + '//') + name) if s.os.path.isdir(new): s.del_dir(new) try: s.os.rmdir(new) except: pass else: try: s.os.remove(new) except: pass def _remove(s): i = s.body.current() if (s.marknum == 1): if s.appuifw.query(('%s%d%s' % (s.ru('/xe5/x88/xa0/xe9/x99/xa4/xe6/xa0/x87/xe8/xae/xb0 '), len(s.selectfile), s.ru(' /xe9/xa1/xb9'))), 'query'): for x in range(len(s.selectfile)): if s.os.path.isdir(s.ur(s.selectfile[x])): try: s.del_dir(s.ur(s.selectfile[x])) s.os.rmdir(s.ur(s.selectfile[x])) s.curlist.remove((('+[' + s.os.path.split(s.os.path.realpath(s.selectfile[x]))[-1]) + ']')) s.body.set_list(s.curlist, i) except: pass else: try: s.os.remove(s.ur(s.selectfile[x])) s.curlist.remove(('+' + s.os.path.split(s.os.path.realpath(s.selectfile[x]))[-1])) s.body.set_list(s.curlist, i) except: pass s.marknum = 0 s.selectfile = [] s.appuifw.app.title = (u'%s' % s.title) else: return elif ((s.curdir != u'root') and (i != 0)): item = (s.curdir + s.curlist[i]) if s.os.path.isdir(s.ur((s.curdir + s.curlist[i][1:-1]))): if s.appuifw.query(((s.ru('/xe5/x88/xa0/xe9/x99/xa4/xe7/x9b/xae/xe5/xbd/x95/n< ') + s.curlist[i][1:-1]) + ' >'), 'query'): try: s.del_dir(s.ur((s.curdir + s.curlist[i][1:-1]))) s.os.rmdir(s.ur((s.curdir + s.curlist[i][1:-1]))) s.curlist.pop(i) s.body.set_list(s.curlist, i) except: pass else: return elif s.appuifw.query(((s.ru('/xe5/x88/xa0/xe9/x99/xa4/xe6/x96/x87/xe4/xbb/xb6/n< ') + s.curlist[i]) + ' >'), 'query'): try: s.os.remove(s.ur(item)) s.curlist.pop(i) s.body.set_list(s.curlist, i) except: pass else: return def list_root(s): resultlist = [] for drive in s.e32.drive_list(): resultlist.append(drive) return resultlist def listslice(s, keycode): x = s.body.current() if (s.curdir == u'root'): return if (keycode == u'1'): s.index = s.curlist[x] if (s.appuifw.app.title.find('*') <= 0): s.fileinfo() if (s.curnumstring == u''): return s.curnumstring = s.curnumstring[:-1] if (s.curnumstring == u''): if (s.appuifw.app.title[-1] == u'*'): s.appuifw.app.title = s.appuifw.app.title[:-1] s.curlist = s.fulllist s.body.set_list(s.fulllist, s.curlist.index(s.index)) return else: s.curnumstring += keycode if (s.appuifw.app.title[-1] != u'*'): s.appuifw.app.title += u'*' resultlist = [s.curlist[0]] if (keycode == u'0'): s.txt = s.appuifw.query(s.ru('/xe7/xad/x9b/xe9/x80/x89/xe5/x85/xb3/xe9/x94/xae/xe5/xad/x97:'), 'text', s.txt) if (s.txt == None): return for i in range(0, len(s.curnumlist1)): if (s.curnumlist1[i].lower().find(s.txt.lower()) >= 0): resultlist.append(s.fulllist[(i + 1)]) for i in range(0, len(s.curnumlist)): if s.curnumlist[i].startswith(s.curnumstring): resultlist.append(s.fulllist[(i + 1)]) s.curlist = resultlist index = 0 if (len(resultlist) > 1): index = 1 s.body.set_list(resultlist, index) def listdir(s, prevdir = None, posfile = None): if (s.appuifw.app.title[-1] == u'*'): s.appuifw.app.title = s.appuifw.app.title[:-1] resultlist = [s.backitem] s.curnumlist = [] s.curnumlist1 = [] s.curnumstring = u'' s.body.set_list([s.workitem]) s.e32.ao_yield() (templist, files, folders,) = (s.os.listdir(s.ur(s.curdir)), [], []) posindex = 1 if templist: for item in templist: if s.os.path.isfile((s.ur(s.curdir) + item)): if (s.find == 'file'): if (len(s.ext) > 0): for extension in s.ext: if (s.os.path.splitext(item)[1].lower() == extension.lower()): files.append(item) else: files.append(item) else: folders.append(item) templist = folders for i in range(len(templist)): item = s.ru(templist[i]) if (item.lower() == prevdir): posindex = (i + 1) resultlist.append((('[' + item) + ']')) for x in range(len(s.selectfile)): if ((s.curdir + item) == s.selectfile[x]): resultlist.append((('+[' + item) + ']')) resultlist.remove((('[' + item) + ']')) s.curnumlist.append(s._manager__s2d(item)) s.curnumlist1.append(item) templist = files for i in range(len(templist)): item = s.ru(templist[i]) if (item.lower() == posfile): posindex = ((len(folders) + i) + 1) resultlist.append(item) for x in range(len(s.selectfile)): if ((s.curdir + item) == s.selectfile[x]): resultlist.append(('+' + item)) resultlist.remove(item) s.curnumlist.append(s._manager__s2d(item)) s.curnumlist1.append(item) s.body.set_list(resultlist, posindex) s.curlist = resultlist s.fulllist = resultlist s.construct_menu(0) def browse_back(s): if (s.curdir == u'root'): return elif (len(s.curdir) == 3): s.root(s.curdir[:-1]) else: ind = s.curdir[:-1].rfind('//') prevdir = s.curdir[(ind + 1):-1].lower() s.curdir = s.os.path.dirname(s.curdir[:-1]) if (s.curdir[-1] != '//'): s.curdir += '//' s.listdir(prevdir) s.appuifw.app.title = (u'%s' % s.title) s.marktitle() def _rename(s): i = s.body.current() if (s.curlist[i].startswith('+') or (i == 0)): return item = (s.curdir + s.curlist[i]) item1 = (s.curdir + s.curlist[i][1:-1]) if s.os.path.isdir(s.ur(item1)): s.i = 1 name = s.curlist[i][1:-1] if s.os.path.isfile(s.ur(item)): s.i = 0 name = s.curlist[i] name = s.appuifw.query(s.ru('/xe8/xbe/x93/xe5/x85/xa5/xe6/x96/xb0/xe5/x90/x8d'), 'text', name) if (name is None): return fname = ((s.curdir + '//') + name) if s.os.path.exists(s.ur(fname)): s.appuifw.note(s.ru('/xe5/x90/x8c/xe5/x90/x8d/xe6/x96/x87/xe4/xbb/xb6/xe5/xb7/xb2/xe7/xbb/x8f/xe5/xad/x98/xe5/x9c/xa8'), 'error') return if (s.i == 1): s.os.rename(s.ur(item1), s.ur(fname)) s.curlist.pop(i) s.curlist.append((('[' + name) + ']')) s.body.set_list(s.curlist, s.curlist.index((('[' + name) + ']'))) else: s.os.rename(s.ur(item), s.ur(fname)) s.curlist.pop(i) s.curlist.append(name) s.body.set_list(s.curlist, s.curlist.index(name)) def _createfolder(s): name = s.appuifw.query(s.ru('/xe6/x96/xb0/xe5/xbb/xba/xe7/x9b/xae/xe5/xbd/x95'), 'text', u'new folder') if (name is None): return fname = s.ur(((s.curdir + '//') + name)) if s.os.path.exists(fname): s.appuifw.note(s.ru('/xe5/x90/x8c/xe5/x90/x8d/xe7/x9b/xae/xe5/xbd/x95/xe5/xb7/xb2/xe7/xbb/x8f/xe5/xad/x98/xe5/x9c/xa8'), 'error') return s.os.mkdir(fname) s.curlist.append((('[' + name) + ']')) s.body.set_list(s.curlist, s.curlist.index((('[' + name) + ']'))) def browse_forward(s): i = s.body.current() if (s.curdir == u'root'): path = (s.e32.drive_list()[i] + '//') elif (i == 0): s.browse_back() return elif s.curlist[i].startswith('+'): path = ((s.curdir + s.curlist[i][2:-1]) + '//') else: path = ((s.curdir + s.curlist[i][1:-1]) + '//') if s.os.path.isdir(s.ur(path)): s.curdir = path s.listdir() else: s.choose_item() s.appuifw.app.title = (u'%s' % s.title) s.marktitle() def ch_made(s, p): s.curdir = p s.choice_made = True s.lock.signal() def mark(s, setmark = None): i = s.body.current() if (setmark == 0): if ((s.curdir != u'root') and (i != 0)): for x in range(len(s.curlist)): if (s.curlist[x].startswith('+') and (x != 0)): s.curlist[x] = s.curlist[x].replace(u'+', '') if s.os.path.isdir(s.ur((s.curdir + s.curlist[x][1:-1]))): del s.selectfile[s.selectfile.index((s.curdir + s.curlist[x][1:-1]))] else: del s.selectfile[s.selectfile.index((s.curdir + s.curlist[x]))] if (setmark == 1): if ((s.curdir != u'root') and (i != 0)): for x in range(len(s.curlist)): if ((not s.curlist[x].startswith('+')) and (x != 0)): if (s.markmod == False): if s.os.path.isdir(s.ur((s.curdir + s.curlist[x][1:-1]))): s.selectfile.append((s.curdir + s.curlist[x][1:-1])) else: s.selectfile.append((s.curdir + s.curlist[x])) s.curlist[x] = ('+' + s.curlist[x]) elif s.os.path.isfile(s.ur((s.curdir + s.curlist[x]))): s.selectfile.append((s.curdir + s.curlist[x])) s.curlist[x] = ('+' + s.curlist[x]) if ((s.curdir != u'root') and ((i != 0) and (setmark == None))): if (not s.curlist[i].startswith('+')): if (s.markmod == False): if s.os.path.isdir(s.ur((s.curdir + s.curlist[i][1:-1]))): s.selectfile.append((s.curdir + s.curlist[i][1:-1])) else: s.selectfile.append((s.curdir + s.curlist[i])) s.curlist[i] = ('+' + s.curlist[i]) elif s.os.path.isfile(s.ur((s.curdir + s.curlist[i]))): s.selectfile.append((s.curdir + s.curlist[i])) s.curlist[i] = ('+' + s.curlist[i]) else: s.curlist[i] = s.curlist[i].replace(u'+', '') if s.os.path.isdir(s.ur((s.curdir + s.curlist[i][1:-1]))): del s.selectfile[s.selectfile.index((s.curdir + s.curlist[i][1:-1]))] else: del s.selectfile[s.selectfile.index((s.curdir + s.curlist[i]))] s.body.set_list(s.curlist, i) s.marktitle() def marktitle(s): if (len(s.selectfile) == 0): s.marknum = 0 if (s.appuifw.app.title.find('*') >= 0): s.appuifw.app.title = (u'%s*' % s.title) else: s.appuifw.app.title = (u'%s' % s.title) else: s.marknum = 1 if (s.appuifw.app.title.find('*') >= 0): s.appuifw.app.title = (u'%s*/n%s: %02d' % (s.title, s.ru('/xe5/xb7/xb2/xe9/x80/x89'), len(s.selectfile))) else: s.appuifw.app.title = (u'%s/n%s: %02d' % (s.title, s.ru('/xe5/xb7/xb2/xe9/x80/x89'), len(s.selectfile))) def fileinfo(s): i = s.body.current() item = (s.curdir + s.curlist[i]) if s.curlist[i].startswith('+'): item = (s.curdir + s.curlist[i][1:]) if s.os.path.isfile(s.ur(item)): filesize = s.os.stat(s.ur(item)).st_size if (filesize > 1048575): filesize = ('%s:%fMb' % (s.ru('/xe5/xa4/xa7/xe5/xb0/x8f'), float(((((filesize / 10.24) / 100.0) / 10.24) / 100.0)))) elif (filesize > 1024): filesize = ('%s:%fKb' % (s.ru('/xe5/xa4/xa7/xe5/xb0/x8f'), float(((filesize / 10.24) / 100.0)))) else: filesize = ('%s:%2db' % (s.ru('/xe5/xa4/xa7/xe5/xb0/x8f'), filesize)) s.appuifw.note(filesize, 'info') def move(s, op): i = s.body.current() if (op == 0): i += 6 if (i > len(s.curlist)): i = 0 s.body.set_list(s.curlist, i) else: i -= 6 if (i < 0): i = len(s.curlist) s.body.set_list(s.curlist, i) def choose_item(s): i = s.body.current() if (s.curdir == u'root'): if (s.find == 'dir'): s.ch_made((s.e32.drive_list()[i] + '//')) else: s.browse_forward() elif (i == 0): s.browse_back() else: item = (s.curdir + s.curlist[i]) if s.curlist[i].startswith('+'): item1 = (s.curdir + s.curlist[i][2:-1]) item = (s.curdir + s.curlist[i][1:]) else: item1 = (s.curdir + s.curlist[i][1:-1]) if s.os.path.isdir(s.ur(item1)): if (s.find == 'dir'): s.ch_made(item1) else: s.browse_forward() elif ((s.markmod != False) and (len(s.selectfile) != 0)): s.ch_made(s.selectfile) else: if item.endswith(']'): return if (s.markmod != False): s.ch_made([item]) else: s.ch_made(item) def exit(s): s.choice_made = False s.lock.signal() if __name__=="__main__": if query(de8("开始?"),"query") : begin() else : del note,query,makedirs,mktime print "-"*30