Exemplo n.º 1
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_frmMain()
        self.ui.setupUi(self)

        QtCore.QObject.connect(self.ui.btnSelDir, QtCore.SIGNAL("clicked()"),
                               self.SelDir_Btn_Clicked)
        QtCore.QObject.connect(self.ui.btnOpenFile, QtCore.SIGNAL("clicked()"),
                               self.OpenFile_Btn_Clicked)
        QtCore.QObject.connect(self.ui.btnDecode, QtCore.SIGNAL("clicked()"),
                               self.Decode_Btn_Clicked)
        QtCore.QObject.connect(self.ui.btnDecodeAll,
                               QtCore.SIGNAL("clicked()"),
                               self.DecodeAll_Btn_Clicked)

        self.ui.txtSavePath.setText(QtCore.QDir.currentPath())

        self.fileList = []
        self.thread = Worker()

        self.connect(self.thread, QtCore.SIGNAL('WorkerDone(int)'),
                     self.WorkerDone)
        self.connect(self.thread, QtCore.SIGNAL('started()'),
                     self.WorkerStarted)
        self.connect(self.thread, QtCore.SIGNAL('finished()'),
                     self.WorkerFinished)
        self.connect(self.thread, QtCore.SIGNAL("terminated()"),
                     self.WorkerFinished)
Exemplo n.º 2
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_frmMain()
        self.ui.setupUi(self)

        QtCore.QObject.connect(self.ui.btnSelDir, QtCore.SIGNAL("clicked()"), self.SelDir_Btn_Clicked)
        QtCore.QObject.connect(self.ui.btnOpenFile, QtCore.SIGNAL("clicked()"), self.OpenFile_Btn_Clicked)
        QtCore.QObject.connect(self.ui.btnDecode, QtCore.SIGNAL("clicked()"), self.Decode_Btn_Clicked)
        QtCore.QObject.connect(self.ui.btnDecodeAll, QtCore.SIGNAL("clicked()"), self.DecodeAll_Btn_Clicked)

        self.ui.txtSavePath.setText(QtCore.QDir.currentPath())

        self.fileList = []
        self.thread = Worker()

        self.connect(self.thread, QtCore.SIGNAL("WorkerDone(int)"), self.WorkerDone)
        self.connect(self.thread, QtCore.SIGNAL("started()"), self.WorkerStarted)
        self.connect(self.thread, QtCore.SIGNAL("finished()"), self.WorkerFinished)
        self.connect(self.thread, QtCore.SIGNAL("terminated()"), self.WorkerFinished)
Exemplo n.º 3
0
class MainForm(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_frmMain()
        self.ui.setupUi(self)

        QtCore.QObject.connect(self.ui.btnSelDir, QtCore.SIGNAL("clicked()"), self.SelDir_Btn_Clicked)
        QtCore.QObject.connect(self.ui.btnOpenFile, QtCore.SIGNAL("clicked()"), self.OpenFile_Btn_Clicked)
        QtCore.QObject.connect(self.ui.btnDecode, QtCore.SIGNAL("clicked()"), self.Decode_Btn_Clicked)
        QtCore.QObject.connect(self.ui.btnDecodeAll, QtCore.SIGNAL("clicked()"), self.DecodeAll_Btn_Clicked)

        self.ui.txtSavePath.setText(QtCore.QDir.currentPath())

        self.fileList = []
        self.thread = Worker()

        self.connect(self.thread, QtCore.SIGNAL("WorkerDone(int)"), self.WorkerDone)
        self.connect(self.thread, QtCore.SIGNAL("started()"), self.WorkerStarted)
        self.connect(self.thread, QtCore.SIGNAL("finished()"), self.WorkerFinished)
        self.connect(self.thread, QtCore.SIGNAL("terminated()"), self.WorkerFinished)

    def WorkerDone(self, n):
        self.MsgBox(u"提示", u"解密成功!")
        self.ui.btnDecode.setEnabled(True)
        self.ui.btnDecodeAll.setEnabled(True)

    def WorkerStarted(self):
        print u"后台线程开始运行"

    def WorkerFinished(self):
        print u"后台线程运行结束!"

    # “选择目录”按钮单击
    def SelDir_Btn_Clicked(self):
        fileDlg = QtGui.QFileDialog(self, u"选择目录", QtCore.QDir.currentPath())
        savePath = fileDlg.getExistingDirectory()
        savePath = unicode(savePath)
        if os.path.isdir(savePath):
            self.ui.txtSavePath.setText(savePath)

    # “打开文件”按钮单击
    def OpenFile_Btn_Clicked(self):
        fileName = QtGui.QFileDialog.getOpenFileName(
            self, u"打开文件", QtCore.QDir.currentPath(), u"PKG资源包(*.pkg);;所有文件(*.*)"
        )
        fileName = unicode(fileName)
        if os.path.isfile(fileName):
            self.ui.txtSrcFile.setText(fileName)
            self.ReadPkgFile(fileName)
            self.ShowFileList()

    # 读取Pkg资源包内的文件列表
    def ReadPkgFile(self, fileName):
        self.fileList = []

        f = open(fileName, "rb")

        self.pkgFileHeader = f.read(4)  # 文件标识(64 00 00 00)
        self.pkgFileHeader, = struct.unpack("l", self.pkgFileHeader)
        if self.pkgFileHeader == 0x64:
            print '"', fileName, '"', " is pkg file!"
        else:
            print '"', fileName, '"', " is not pkg file!"
            f.close()
            return

        self.fileCount = f.read(4)
        self.fileCount, = struct.unpack("l", self.fileCount)
        print u"文件总数:", self.fileCount

        self.fileListPos = f.read(4)
        self.fileListPos, = struct.unpack("l", self.fileListPos)
        print u"文件列表区的偏移地址:", self.fileListPos

        self.fileListSize = f.read(4)
        self.fileListSize, = struct.unpack("l", self.fileListSize)
        print u"文件列表区的大小:", self.fileListSize

        f.seek(self.fileListPos)

        for i in range(0, self.fileCount):
            self.fileList.append([])

            self.tmpFileNameLen = f.read(2)  # 文件名称字符串长度
            self.tmpFileNameLen, = struct.unpack("H", self.tmpFileNameLen)

            self.tmpFileName = f.read(self.tmpFileNameLen)  # 带相对路径的文件名称
            self.fileList[i].append(self.tmpFileName)

            f.read(4)  # 识别标志(00 00 00 00)

            self.tmpFileStartOffset = f.read(4)  # 文件起始偏移地址
            self.tmpFileStartOffset, = struct.unpack("l", self.tmpFileStartOffset)
            self.fileList[i].append(self.tmpFileStartOffset)

            self.tmpFileOriginSize = f.read(4)  # 原始文件大小
            self.tmpFileOriginSize, = struct.unpack("l", self.tmpFileOriginSize)
            self.fileList[i].append(self.tmpFileOriginSize)

            self.tmpFileSize = f.read(4)  # 文件大小
            self.tmpFileSize, = struct.unpack("l", self.tmpFileSize)
            self.fileList[i].append(self.tmpFileSize)

        f.close()

    # 显示文件列表
    def ShowFileList(self):
        self.ui.lstFileList.clear()

        if len(self.fileList) <= 0:
            return

        for item in self.fileList:
            self.ui.lstFileList.addItem(item[0])

    # “解密”按钮单击
    def Decode_Btn_Clicked(self):
        if self.ui.lstFileList.count() <= 0:
            self.MsgBox(u"提示", u"文件列表为空!")
            return

        if len(self.ui.lstFileList.selectedItems()) <= 0:
            self.MsgBox(u"提示", u"未选中文件!")
            return

        savePath = unicode(self.ui.txtSavePath.text())
        pkgFileName = unicode(self.ui.txtSrcFile.text())

        if not os.path.isfile(pkgFileName):
            self.MsgBox(u"提示", u"PKG资源包不存在!")
            return

        self.ui.btnDecode.setEnabled(False)
        self.ui.btnDecodeAll.setEnabled(False)

        index = []
        for i in range(0, self.ui.lstFileList.count()):
            if self.ui.lstFileList.isItemSelected(self.ui.lstFileList.item(i)):
                index.append(i)

        self.thread.savePath = savePath
        self.thread.pkgFileName = pkgFileName
        self.thread.Decode(self.fileList, index)

    # “全部解密”按钮单击
    def DecodeAll_Btn_Clicked(self):
        if self.ui.lstFileList.count() <= 0:
            self.MsgBox(u"提示", u"文件列表为空!")
            return

        savePath = unicode(self.ui.txtSavePath.text())
        pkgFileName = unicode(self.ui.txtSrcFile.text())

        if not os.path.isfile(pkgFileName):
            self.MsgBox(u"提示", u"PKG资源包不存在!")
            return

        self.ui.btnDecode.setEnabled(False)
        self.ui.btnDecodeAll.setEnabled(False)

        index = []
        for i in range(0, self.ui.lstFileList.count()):
            index.append(i)

        self.thread.savePath = savePath
        self.thread.pkgFileName = pkgFileName
        self.thread.Decode(self.fileList, index)

    # 自定义消息框
    def MsgBox(self, title, msg):
        msgbox = QtGui.QMessageBox(self)
        msgbox.setFont(QtGui.QFont("Tahoma", 9))
        msgbox.setWindowTitle(title)
        msgbox.setText(msg)
        msgbox.setIcon(QtGui.QMessageBox.Information)
        msgbox.addButton(u"确定", QtGui.QMessageBox.AcceptRole)
        msgbox.exec_()
Exemplo n.º 4
0
class MainForm(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_frmMain()
        self.ui.setupUi(self)

        QtCore.QObject.connect(self.ui.btnSelDir, QtCore.SIGNAL("clicked()"),
                               self.SelDir_Btn_Clicked)
        QtCore.QObject.connect(self.ui.btnOpenFile, QtCore.SIGNAL("clicked()"),
                               self.OpenFile_Btn_Clicked)
        QtCore.QObject.connect(self.ui.btnDecode, QtCore.SIGNAL("clicked()"),
                               self.Decode_Btn_Clicked)
        QtCore.QObject.connect(self.ui.btnDecodeAll,
                               QtCore.SIGNAL("clicked()"),
                               self.DecodeAll_Btn_Clicked)

        self.ui.txtSavePath.setText(QtCore.QDir.currentPath())

        self.fileList = []
        self.thread = Worker()

        self.connect(self.thread, QtCore.SIGNAL('WorkerDone(int)'),
                     self.WorkerDone)
        self.connect(self.thread, QtCore.SIGNAL('started()'),
                     self.WorkerStarted)
        self.connect(self.thread, QtCore.SIGNAL('finished()'),
                     self.WorkerFinished)
        self.connect(self.thread, QtCore.SIGNAL("terminated()"),
                     self.WorkerFinished)

    def WorkerDone(self, n):
        self.MsgBox(u'提示', u'解密成功!')
        self.ui.btnDecode.setEnabled(True)
        self.ui.btnDecodeAll.setEnabled(True)

    def WorkerStarted(self):
        print u'后台线程开始运行'

    def WorkerFinished(self):
        print u'后台线程运行结束!'

    # “选择目录”按钮单击
    def SelDir_Btn_Clicked(self):
        fileDlg = QtGui.QFileDialog(self, u'选择目录', QtCore.QDir.currentPath())
        savePath = fileDlg.getExistingDirectory()
        savePath = unicode(savePath)
        if os.path.isdir(savePath):
            self.ui.txtSavePath.setText(savePath)

    # “打开文件”按钮单击
    def OpenFile_Btn_Clicked(self):
        fileName = QtGui.QFileDialog.getOpenFileName(
            self, u'打开文件', QtCore.QDir.currentPath(),
            u'PKG资源包(*.pkg);;所有文件(*.*)')
        fileName = unicode(fileName)
        if os.path.isfile(fileName):
            self.ui.txtSrcFile.setText(fileName)
            self.ReadPkgFile(fileName)
            self.ShowFileList()

    # 读取Pkg资源包内的文件列表
    def ReadPkgFile(self, fileName):
        self.fileList = []

        f = open(fileName, 'rb')

        self.pkgFileHeader = f.read(4)  # 文件标识(64 00 00 00)
        self.pkgFileHeader, = struct.unpack('l', self.pkgFileHeader)
        if self.pkgFileHeader == 0x64:
            print '\"', fileName, '\"', ' is pkg file!'
        else:
            print '\"', fileName, '\"', ' is not pkg file!'
            f.close()
            return

        self.fileCount = f.read(4)
        self.fileCount, = struct.unpack('l', self.fileCount)
        print u'文件总数:', self.fileCount

        self.fileListPos = f.read(4)
        self.fileListPos, = struct.unpack('l', self.fileListPos)
        print u'文件列表区的偏移地址:', self.fileListPos

        self.fileListSize = f.read(4)
        self.fileListSize, = struct.unpack('l', self.fileListSize)
        print u'文件列表区的大小:', self.fileListSize

        f.seek(self.fileListPos)

        for i in range(0, self.fileCount):
            self.fileList.append([])

            self.tmpFileNameLen = f.read(2)  # 文件名称字符串长度
            self.tmpFileNameLen, = struct.unpack('H', self.tmpFileNameLen)

            self.tmpFileName = f.read(self.tmpFileNameLen)  # 带相对路径的文件名称
            self.fileList[i].append(self.tmpFileName)

            f.read(4)  # 识别标志(00 00 00 00)

            self.tmpFileStartOffset = f.read(4)  # 文件起始偏移地址
            self.tmpFileStartOffset, = struct.unpack('l',
                                                     self.tmpFileStartOffset)
            self.fileList[i].append(self.tmpFileStartOffset)

            self.tmpFileOriginSize = f.read(4)  # 原始文件大小
            self.tmpFileOriginSize, = struct.unpack('l',
                                                    self.tmpFileOriginSize)
            self.fileList[i].append(self.tmpFileOriginSize)

            self.tmpFileSize = f.read(4)  # 文件大小
            self.tmpFileSize, = struct.unpack('l', self.tmpFileSize)
            self.fileList[i].append(self.tmpFileSize)

        f.close()

    # 显示文件列表
    def ShowFileList(self):
        self.ui.lstFileList.clear()

        if len(self.fileList) <= 0:
            return

        for item in self.fileList:
            self.ui.lstFileList.addItem(item[0])

    # “解密”按钮单击
    def Decode_Btn_Clicked(self):
        if self.ui.lstFileList.count() <= 0:
            self.MsgBox(u'提示', u'文件列表为空!')
            return

        if len(self.ui.lstFileList.selectedItems()) <= 0:
            self.MsgBox(u'提示', u'未选中文件!')
            return

        savePath = unicode(self.ui.txtSavePath.text())
        pkgFileName = unicode(self.ui.txtSrcFile.text())

        if not os.path.isfile(pkgFileName):
            self.MsgBox(u'提示', u'PKG资源包不存在!')
            return

        self.ui.btnDecode.setEnabled(False)
        self.ui.btnDecodeAll.setEnabled(False)

        index = []
        for i in range(0, self.ui.lstFileList.count()):
            if self.ui.lstFileList.isItemSelected(self.ui.lstFileList.item(i)):
                index.append(i)

        self.thread.savePath = savePath
        self.thread.pkgFileName = pkgFileName
        self.thread.Decode(self.fileList, index)

    # “全部解密”按钮单击
    def DecodeAll_Btn_Clicked(self):
        if self.ui.lstFileList.count() <= 0:
            self.MsgBox(u'提示', u'文件列表为空!')
            return

        savePath = unicode(self.ui.txtSavePath.text())
        pkgFileName = unicode(self.ui.txtSrcFile.text())

        if not os.path.isfile(pkgFileName):
            self.MsgBox(u'提示', u'PKG资源包不存在!')
            return

        self.ui.btnDecode.setEnabled(False)
        self.ui.btnDecodeAll.setEnabled(False)

        index = []
        for i in range(0, self.ui.lstFileList.count()):
            index.append(i)

        self.thread.savePath = savePath
        self.thread.pkgFileName = pkgFileName
        self.thread.Decode(self.fileList, index)

    # 自定义消息框
    def MsgBox(self, title, msg):
        msgbox = QtGui.QMessageBox(self)
        msgbox.setFont(QtGui.QFont('Tahoma', 9))
        msgbox.setWindowTitle(title)
        msgbox.setText(msg)
        msgbox.setIcon(QtGui.QMessageBox.Information)
        msgbox.addButton(u'确定', QtGui.QMessageBox.AcceptRole)
        msgbox.exec_()