Advertisement
wandrake

Untitled

Nov 22nd, 2012
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.90 KB | None | 0 0
  1. from PyQt4 import QtGui, QtCore, QtWebKit
  2. import sys, os
  3. import resources
  4.  
  5. os.chdir(os.path.dirname(__file__))
  6. path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
  7.  
  8. if not path in sys.path:
  9.     sys.path.insert(1, path)
  10. del path
  11.  
  12. from util import *
  13.  
  14. class MainSyntaxHighlighter(QtGui.QSyntaxHighlighter):
  15.     def highlightBlock(self, text):
  16.         format = QtGui.QTextCharFormat()
  17.         format.setForeground(QtCore.Qt.darkMagenta)
  18.  
  19.         pattern = "(eax|ax|ah|al|ebx|bx|bh|bl|ecx|cx|ch|cl|edx|dx|dh|dl|"
  20.         pattern += "esp|sp|ebp|bp|esi|si|edi|di|cs|ds|ss|es|fs|gs|rax|rbx|"
  21.         pattern += "rcx|rdx|rsi|rdi|rbp|rsp|rflags|rip)"
  22.  
  23.         re = QtCore.QRegExp(pattern)
  24.         index = re.indexIn(text, 0)
  25.         while index >= 0:
  26.             length = re.matchedLength()
  27.             self.setFormat(index, length, format)
  28.             index = re.indexIn(text, index+length)
  29.  
  30.         format.setForeground(QtCore.Qt.blue)
  31.         pattern = '([0-9a-fA-F]{8})'# ([^ ]*) +'
  32.  
  33.         re = QtCore.QRegExp(pattern)
  34.         index = re.indexIn(text, 0)
  35.         while index >= 0:
  36.             #index =
  37.             length = re.matchedLength()
  38.             self.setFormat(index, length, format)
  39.             index = re.indexIn(text, index+length)
  40.  
  41.         format.setForeground(QtCore.Qt.darkGreen)
  42.         pattern = 'Section.*:'
  43.  
  44.         re = QtCore.QRegExp(pattern)
  45.         index = re.indexIn(text, 0)
  46.         while index >= 0:
  47.             length = re.matchedLength()
  48.             self.setFormat(index, length, format)
  49.             index = re.indexIn(text, index+length)
  50.  
  51. '''
  52. class TextWidget(QtGui.QTextEdit):
  53.    def __init__(self, mainWindow):
  54.        super(TextWidget, self).__init__(mainWindow)
  55.        self.setFont(QtGui.QFont('Courier', 9))
  56.  
  57.    def printRaw(self, toPrint):
  58.        self.setPlainText(toPrint)
  59. '''
  60. import threading
  61. class ANALyzer(QtCore.QThread):
  62.     contentChanged = QtCore.pyqtSignal()
  63.  
  64.     def __init__(self, process):
  65.         QtCore.QThread.__init__(self)
  66.         self.process = process
  67.  
  68.     def run(self):
  69.         process = self.process
  70.         self.stuff = '<html><head><link rel="stylesheet" href="style.css" type="text/css" /></head><body>'
  71.         self.stuff += '<div class="content">'
  72.         self.stuff += ''.join('<div class="row" onClick="SectionViewer.show(\'%s\')">' % s.name + \
  73.             '<div class="section">0x%08x-0x%08x: %s section</div></div>' % \
  74.             (r[0], r[1], s.name) for (r, s) in process.sections.items())
  75.         self.stuff += '</div></body></html>'
  76.         # self.stuff = "<h1>te a me mi puppi la fava</h1>"
  77.         self.contentChanged.emit()
  78.  
  79. class SectionViewer(QtCore.QObject):
  80.     contentReady = QtCore.pyqtSignal()
  81.  
  82.     def __init__(self, proc):
  83.         QtCore.QObject.__init__(self)
  84.         self.proc = proc
  85.  
  86.     def show(name):
  87.         print "Mah!"
  88.         self.stuff = self.proc.sections[name].getHTML()
  89.         self.contentReady.emit()
  90.  
  91. class MainView(QtGui.QMainWindow):
  92.     def __init__(self):
  93.         super(MainView, self).__init__()
  94.         self.initUI()
  95.  
  96.     def showLoading(self):
  97.         self.webView.setHtml('<h1>Loading...</h1>', QtCore.QUrl('qrc:/'))
  98.  
  99.     def showHtml(self):
  100.         stuff = self.anal.stuff
  101.         self.webView.setHtml(stuff, QtCore.QUrl('qrc:/'))
  102.         self.webView.page().mainFrame().addToJavaScriptWindowObject("SectionViewer", self.sectView);
  103.  
  104.     def showView(self):
  105.         stuff = sectView.stuff
  106.         self.webView.setHtml(stuff, QtCore.QUrl('qrc:/'))
  107.  
  108.     def openStuff(self):
  109.         fileName = QtGui.QFileDialog.getOpenFileName(
  110.             self, 'Open File', '', 'Files (*.*)')
  111.         #toPrint = loader.SPUTA_FUORI_IL_ROSPO(fileName)
  112.         #self.textWidget.printRaw(toPrint)
  113.  
  114.         self.showLoading()
  115.  
  116.         self.process = loader.SPUTA_FUORI_IL_MOSTO(fileName)
  117.         self.sectView = SectionViewer(self.process)
  118.         self.sectView.contentReady.connect(self.showView)
  119.  
  120.         self.anal = ANALyzer(self.process)
  121.         self.anal.contentChanged.connect(self.showHtml)
  122.         self.anal.start()
  123.         print "prima questo"
  124.         #html = loader.SPUTA_FUORI_IL_BOSCO(fileName)        
  125.         #self.webView.setHtml(html, QtCore.QUrl('qrc:/'))
  126.  
  127.     def initUI(self):
  128.         openAction = QtGui.QAction(\
  129.             QtGui.QIcon(':icons/open.png'), 'Open', self)
  130.  
  131.         openAction.setShortcut('Ctrl+O')
  132.         openAction.triggered.connect(self.openStuff)
  133.  
  134.         self.toolbar = self.addToolBar('Stuff')
  135.         self.toolbar.addAction(openAction)
  136.  
  137.         self.setGeometry(100, 100, 800, 600)
  138.         self.setWindowTitle('QTDisassa!')
  139.         self.show()
  140.         #self.showMaximized()
  141.        
  142.         self.webView = QtWebKit.QWebView(self)
  143.         self.setCentralWidget(self.webView)
  144.  
  145. def main():
  146.    
  147.     app = QtGui.QApplication(sys.argv)
  148.     mainView = MainView()
  149.     sys.exit(app.exec_())
  150.  
  151.  
  152. if __name__ == '__main__':
  153.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement