淘先锋技术网

首页 1 2 3 4 5 6 7
在这里要运行一下程序你需要检查一下你是否安装一下的包import Tkinter 
                                              import tkFileDialog from Tkinter import *


import sys
import  os
import Tkinter
import tkFileDialog
from Tkinter import *

def Brove():
    filename=tkFileDialog.askdirectory()
    text_name.delete(0,END)
    text_name.insert(0,filename)

#file =sys.argv[1]
# reload(sys)
# sys.setdefaultencoding('GB2312')
def hex_to_str(s):
        return ''.join([hex(ord(c)).replace('0x','').zfill(2)  for c in s])//十六进制转换的string的函数

def hextostr(path)://十六进制文件转换为string文件
    if(os.path.exists(path+"token_str.txt")):
        os.remove(path+"token_str.txt")
    dirs = os.listdir(path)
    for i in dirs:
        if os.path.splitext(i)[1]== ".bin":
            print i
            f=open(path+'\\'+i,'rb')
            f_read = f.read()
            f_read_decode = hex_to_str(f_read)
           # print f_read
            print f_read_decode
            print  f_read_decode.swapcase()
            str_token=open(path+"token_str.txt",'a+')
            path_file = path+i
            (filepth,temfilename)= os.path.split(path_file)
            print  filepth,temfilename
            (filename,extension) = os.path.splitext(temfilename)
            print  '============================'
            print filename
            #str_token.write("\n")
            str_token.write(filename+':')
            text_aer.insert("insert", filename+':')
            str_token.write("\n")
            text_aer.insert("insert", '\n')
            str_token.write(f_read_decode.swapcase())
            str_token.write("\n")
            print len(f_read_decode)
            text_aer.insert("insert",f_read_decode)
            text_aer.insert("insert", '\n')
            f.close()
            str_token.close()
def run():
    text_aer.delete(0.0,END)
    path_r = text_name.get()
    hextostr(path_r)
def close():
    root.destroy()
root =Tk()//写了一个简单界面
title = 'hextostring tool'
root.title(title.center(72,' '))
root.geometry("500x360")
root.resizable(0,0)
label_login = Label(root, text="Path:", anchor="center", bg="white")
label_login.place(x=20, y=20, width=50, height=24, anchor="nw")
text_name = Entry(root)
text_name.place(x=80, y=20, width=360)
button_login = Button(root, text="****", anchor="center", activebackground="red", bg="white",
                          relief="flat",command=lambda :Brove())
button_login.place(x=100, y=80, width=60)
button_registry = Button(root, text="**x**", anchor="center", activebackground="red", bg="white",
                         relief="flat", command=lambda: run())
button_registry.place(x=230, y=80, width=60)
button_cancel = Button(root, text="**XX", anchor="center", activebackground="red", bg="white",
                       relief="flat", command=lambda:close())
button_cancel.place(x=350, y=80, width=60)
text_aer=Text(root)
text_aer.place(x=30,y=120,width=440,height=230)
root.mainloop()