Skip to content

Commit

Permalink
Merge pull request mandiant#28 from iphelix/master
Browse files Browse the repository at this point in the history
Updated to support IDA 6.9 with PyQt5
  • Loading branch information
jhsmith committed May 26, 2016
2 parents 21ad641 + 2cec19a commit 4fdc6ae
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 132 deletions.
58 changes: 29 additions & 29 deletions python/flare/annotate_IDB_MSDN.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import traceback
import ConfigParser
from ConfigParser import SafeConfigParser
from PySide import QtGui
from PySide import QtCore
from PySide.QtCore import Qt
from PyQt5 import QtWidgets
from PyQt5 import QtCore
from PyQt5.QtCore import Qt

idaapi.require("IDB_MSDN_Annotator")

Expand All @@ -38,7 +38,7 @@
def getDefaultMsdnDataDir():
return os.path.abspath(os.path.join(idaapi.get_user_idadir(), 'MSDN_data'))

class MSDNAnnotationDialog(QtGui.QDialog):
class MSDNAnnotationDialog(QtWidgets.QDialog):

def read_config(self):
config = {}
Expand Down Expand Up @@ -87,10 +87,10 @@ def change_image(self):
int(self.chkConstantsImport
.isChecked()))
img_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'IDB_MSDN_Annotator', 'img'))
self.pic.setPixmap(QtGui.QPixmap(os.path.join(img_path, image)))
self.pic.setPixmap(QtWidgets.QPixmap(os.path.join(img_path, image)))

def on_select_dir(self):
msdnDir = QtGui.QFileDialog.getExistingDirectory(caption='Select directory containing MSDN XML Database')
msdnDir = QtWidgets.QFileDialog.getExistingDirectory(caption='Select directory containing MSDN XML Database')
if len(msdnDir) != 0:
self.dirText.setText(msdnDir)

Expand All @@ -105,11 +105,11 @@ def on_ok_button(self):
msdnpath = os.path.join(self.dirText.text(), IDB_MSDN_Annotator.MSDN_INFO_FILE)
if not os.path.exists(msdnpath):
g_logger.info('Error - no msdn info file: %s', msdnpath)
ret = QtGui.QMessageBox.warning(self, 'MSDN Info Not Found', 'The file %s was not found in the specified MSDN Data Directory' % IDB_MSDN_Annotator.MSDN_INFO_FILE, QtGui.QMessageBox.Ok)
#self.done(QtGui.QDialog.Rejected)
ret = QtWidgets.QMessageBox.warning(self, 'MSDN Info Not Found', 'The file %s was not found in the specified MSDN Data Directory' % IDB_MSDN_Annotator.MSDN_INFO_FILE, QtWidgets.QMessageBox.Ok)
#self.done(QtWidgets.QDialog.Rejected)
return

self.done(QtGui.QDialog.Accepted)
self.done(QtWidgets.QDialog.Accepted)
g_logger.info('Saving config')
self.save_config()
config = self.read_config()
Expand All @@ -133,40 +133,40 @@ def set_form_values(self):
self.dirText.setText(self.config['msdn_data_dir'])

def populate_form(self):
layout = QtGui.QVBoxLayout()
layout = QtWidgets.QVBoxLayout()

# Functions
layout1 = QtGui.QVBoxLayout()
groupBox = QtGui.QGroupBox('Markup Options')
self.chkFunctionsAnnotate = QtGui.QCheckBox("Annotate function names"
layout1 = QtWidgets.QVBoxLayout()
groupBox = QtWidgets.QGroupBox('Markup Options')
self.chkFunctionsAnnotate = QtWidgets.QCheckBox("Annotate function names"
" (see note)")
layout1.addWidget(self.chkFunctionsAnnotate)
self.chkFuntcsRepeatable = QtGui.QCheckBox("Use repeatable comments "
self.chkFuntcsRepeatable = QtWidgets.QCheckBox("Use repeatable comments "
"for function name "
"annotations")
layout1.addWidget(self.chkFuntcsRepeatable)

# Arguments
self.chkArgumentsAnnotate = QtGui.QCheckBox("Annotate function "
self.chkArgumentsAnnotate = QtWidgets.QCheckBox("Annotate function "
"arguments (see note)")
layout1.addWidget(self.chkArgumentsAnnotate)

# Constants
self.chkConstantsImport = QtGui.QCheckBox("Rename constants")
self.chkConstantsImport = QtWidgets.QCheckBox("Rename constants")
layout1.addWidget(self.chkConstantsImport)

groupBox.setLayout(layout1)
layout.addWidget(groupBox)

#MSDN data dir
hlayout = QtGui.QHBoxLayout()
self.selectDirButton = QtGui.QPushButton('...')
hlayout = QtWidgets.QHBoxLayout()
self.selectDirButton = QtWidgets.QPushButton('...')
self.selectDirButton.clicked.connect(self.on_select_dir)
hlayout.addWidget(self.selectDirButton)
self.dirText = QtGui.QLineEdit()
self.dirText = QtWidgets.QLineEdit()
self.dirText.setReadOnly(True)
hlayout.addWidget(self.dirText)
groupBox = QtGui.QGroupBox('MSDN Data Directory')
groupBox = QtWidgets.QGroupBox('MSDN Data Directory')
groupBox.setLayout(hlayout)
layout.addWidget(groupBox)

Expand All @@ -181,32 +181,32 @@ def populate_form(self):
info_string = "Note: Annotating functions and/or arguments allows " \
"you to hover\nthe respective element in order to " \
"show its description."
layout.addWidget(QtGui.QLabel(info_string))
layout.addWidget(QtWidgets.QLabel(info_string))

# Buttons
button_ok = QtGui.QPushButton('&OK')
button_ok = QtWidgets.QPushButton('&OK')
button_ok.setDefault(True)
button_ok.clicked.connect(self.on_ok_button)
#button_ok.clicked.connect(self.close)
layout.addWidget(button_ok)
button_cancel = QtGui.QPushButton('&Cancel')
button_cancel = QtWidgets.QPushButton('&Cancel')
button_cancel.clicked.connect(self.close)
layout.addWidget(button_cancel)

# Image
self.pic = QtGui.QLabel()
self.pic = QtWidgets.QLabel()
self.pic.setGeometry(0, 0, 663, 203)
self.change_image()

# Layout right
layout_r = QtGui.QVBoxLayout()
#layout_r.addWidget(QtGui.QLabel("Annotation preview"))
layout_r = QtWidgets.QVBoxLayout()
#layout_r.addWidget(QtWidgets.QLabel("Annotation preview"))
layout_r.addWidget(self.pic)
groupBox = QtGui.QGroupBox('Annotation preview')
groupBox = QtWidgets.QGroupBox('Annotation preview')
groupBox.setLayout(layout_r)

# Setup layouts
h_layout = QtGui.QHBoxLayout()
h_layout = QtWidgets.QHBoxLayout()
h_layout.addLayout(layout)
#h_layout.addLayout(layout_r)
h_layout.addWidget(groupBox)
Expand All @@ -216,7 +216,7 @@ def __init__(self, parent=None):
self._logger = logging.getLogger(__name__ + '.' +
self.__class__.__name__)
self._logger.debug('Starting UI')
QtGui.QDialog.__init__(self, parent, QtCore.Qt.WindowSystemMenuHint |
QtWidgets.QDialog.__init__(self, parent, QtCore.Qt.WindowSystemMenuHint |
QtCore.Qt.WindowTitleHint)
self.setWindowTitle("MSDN Annotations Configuration")

Expand Down
12 changes: 6 additions & 6 deletions python/flare/apply_callee_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
import ctypes
import logging

from PySide import QtGui
from PySide import QtCore
from PySide.QtCore import Qt
from PyQt5 import QtWidgets
from PyQt5 import QtCore
from PyQt5.QtCore import Qt

import idc
import idaapi
Expand Down Expand Up @@ -237,7 +237,7 @@ def run(self):
res = dlg.exec_()
idaapi.set_script_timeout(oldTo)

if res == QtGui.QDialog.DialogCode.Accepted:
if res == QtWidgets.QDialog.Accepted:
self.logger.debug('Dialog accepted. Input type: %d', dlg.inputType)
else:
self.logger.debug('Dialog rejected')
Expand Down Expand Up @@ -276,14 +276,14 @@ def run(self):
except Exception, err:
self.logger.exception("Exception caught: %s", str(err))

class ApplyCalleeTypeWidget(QtGui.QDialog):
class ApplyCalleeTypeWidget(QtWidgets.QDialog):
UNKNOWN_TYPE = 0
USER_TYPE = 1
STANDARD_TYPE = 2
LOCAL_TYPE = 3

def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
QtWidgets.QDialog.__init__(self, parent)
try:
self.logger = jayutils.getLogger('ApplyCalleeTypeWidget')
self.tinfo = None
Expand Down
44 changes: 24 additions & 20 deletions python/flare/apply_callee_type_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,60 @@
# Form implementation generated from reading ui file 'apply_callee_dialog.ui'
#
# Created: Tue Aug 26 12:16:07 2014
# by: pyside-uic 0.2.15 running on PySide 1.2.1
# by: PyQt5-uic 0.2.15 running on PyQt5 1.2.1
#
# WARNING! All changes made in this file will be lost!

from PySide import QtCore, QtGui
from PyQt5 import QtCore, QtWidgets

class Ui_ApplyCalleeDialog(object):
def setupUi(self, ApplyCalleeDialog):
ApplyCalleeDialog.setObjectName("ApplyCalleeDialog")
ApplyCalleeDialog.resize(682, 313)
self.verticalLayout_2 = QtGui.QVBoxLayout(ApplyCalleeDialog)
self.verticalLayout_2 = QtWidgets.QVBoxLayout(ApplyCalleeDialog)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout = QtWidgets.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.label = QtGui.QLabel(ApplyCalleeDialog)
self.label = QtWidgets.QLabel(ApplyCalleeDialog)
self.label.setObjectName("label")
self.horizontalLayout.addWidget(self.label)
self.te_userTypeText = QtGui.QPlainTextEdit(ApplyCalleeDialog)
self.te_userTypeText = QtWidgets.QPlainTextEdit(ApplyCalleeDialog)
self.te_userTypeText.setObjectName("te_userTypeText")
self.horizontalLayout.addWidget(self.te_userTypeText)
self.verticalLayout.addLayout(self.horizontalLayout)
self.verticalLayout_2.addLayout(self.verticalLayout)
self.horizontalLayout_2 = QtGui.QHBoxLayout()
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.pb_useStandardType = QtGui.QPushButton(ApplyCalleeDialog)
self.pb_useStandardType = QtWidgets.QPushButton(ApplyCalleeDialog)
self.pb_useStandardType.setObjectName("pb_useStandardType")
self.horizontalLayout_2.addWidget(self.pb_useStandardType)
self.pb_useLocalType = QtGui.QPushButton(ApplyCalleeDialog)
self.pb_useLocalType = QtWidgets.QPushButton(ApplyCalleeDialog)
self.pb_useLocalType.setObjectName("pb_useLocalType")
self.horizontalLayout_2.addWidget(self.pb_useLocalType)
spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_2.addItem(spacerItem)
self.verticalLayout_2.addLayout(self.horizontalLayout_2)
self.buttonBox = QtGui.QDialogButtonBox(ApplyCalleeDialog)
self.buttonBox = QtWidgets.QDialogButtonBox(ApplyCalleeDialog)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox")
self.verticalLayout_2.addWidget(self.buttonBox)

self.retranslateUi(ApplyCalleeDialog)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), ApplyCalleeDialog.accept)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), ApplyCalleeDialog.reject)
#QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), ApplyCalleeDialog.accept)
#QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), ApplyCalleeDialog.reject)

self.buttonBox.accepted.connect(ApplyCalleeDialog.accept)
self.buttonBox.rejected.connect(ApplyCalleeDialog.reject)

QtCore.QMetaObject.connectSlotsByName(ApplyCalleeDialog)

def retranslateUi(self, ApplyCalleeDialog):
ApplyCalleeDialog.setWindowTitle(QtGui.QApplication.translate("ApplyCalleeDialog", "ApplyCalleeType", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("ApplyCalleeDialog", "Enter Type\n"
"Declaration", None, QtGui.QApplication.UnicodeUTF8))
self.pb_useStandardType.setText(QtGui.QApplication.translate("ApplyCalleeDialog", "Use Standard Type", None, QtGui.QApplication.UnicodeUTF8))
self.pb_useLocalType.setText(QtGui.QApplication.translate("ApplyCalleeDialog", "Use Local Type", None, QtGui.QApplication.UnicodeUTF8))
ApplyCalleeDialog.setWindowTitle(QtWidgets.QApplication.translate("ApplyCalleeDialog", "ApplyCalleeType", None))
self.label.setText(QtWidgets.QApplication.translate("ApplyCalleeDialog", "Enter Type\n"
"Declaration", None))
self.pb_useStandardType.setText(QtWidgets.QApplication.translate("ApplyCalleeDialog", "Use Standard Type", None))
self.pb_useLocalType.setText(QtWidgets.QApplication.translate("ApplyCalleeDialog", "Use Local Type", None))

8 changes: 4 additions & 4 deletions python/flare/shellcode_hash_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@

QT_AVAILABLE = True
try:
from PySide import QtGui, QtCore
from PyQt5 import QtWidgets, QtCore
from shellcode_widget import ShellcodeWidget
except ImportError:
print 'Falling back to simple dialog-based GUI. \nPlease consider installing the HexRays PySide build available at \n"http://hex-rays.com/products/ida/support/download.shtml"'
print 'Falling back to simple dialog-based GUI. \nPlease consider installing the HexRays PyQt5 build available at \n"http://hex-rays.com/products/ida/support/download.shtml"'
QT_AVAILABLE = False

class RejectionException(Exception):
Expand Down Expand Up @@ -359,9 +359,9 @@ def launchGuiInput(self):
res = dlg.exec_()
#restore the timeout
idaapi.set_script_timeout(oldTo)
if res == QtGui.QDialog.DialogCode.Accepted:
if res == QtWidgets.QDialog.Accepted:
self.logger.debug('Dialog result: accepted')
elif res == QtGui.QDialog.DialogCode.Rejected:
elif res == QtWidgets.QDialog.Rejected:
self.logger.debug('Dialog result: rejected')
raise RejectionException()
else:
Expand Down
22 changes: 11 additions & 11 deletions python/flare/shellcode_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@
import traceback


from PySide import QtGui
from PySide import QtCore
from PySide.QtCore import Qt
from PyQt5 import QtWidgets
from PyQt5 import QtCore
from PyQt5.QtCore import Qt

# Import the compiled UI module
from shellcodechooser import Ui_ShellcodeChooser

import jayutils

class ShellcodeWidget(QtGui.QDialog):
class ShellcodeWidget(QtWidgets.QDialog):
def __init__(self, dbstore, params, parent=None):
QtGui.QDialog.__init__(self, parent)
QtWidgets.QDialog.__init__(self, parent)
try:
self.logger = jayutils.getLogger('ShellcodeWidget')
self.logger.debug('Hello debug')
Expand All @@ -48,7 +48,7 @@ def __init__(self, dbstore, params, parent=None):
self.configData = {}
self.ui=Ui_ShellcodeChooser()
self.ui.setupUi(self)
self.ui.list_hashNames.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
self.ui.list_hashNames.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
self.ui.list_hashNames.currentTextChanged.connect(self.handleTextChange)
self.ui.buttonBox.accepted.connect(self.storeStateAccepted)
self.ui.buttonBox.rejected.connect(self.reject)
Expand All @@ -59,7 +59,7 @@ def __init__(self, dbstore, params, parent=None):
except Exception, err:
self.logger.exception('Error during init: %s', str(err))

custom_accepted = QtCore.Signal()
custom_accepted = QtCore.pyqtSignal()

def storeStateAccepted(self):
self.logger.debug('Storing state on accepted signal')
Expand Down Expand Up @@ -91,12 +91,12 @@ def initData(self):
if self.configData.has_key(hash.hashName):
raise RuntimeError('Duplicate name not allowed')
self.configData[hash.hashName] = hash.hashCode
item = QtGui.QListWidgetItem(hash.hashName)
item = QtWidgets.QListWidgetItem(hash.hashName)
self.ui.list_hashNames.addItem(item)

self.ui.list_hashNames.setCurrentRow(0)
self.ui.cb_dwordArray.setCheckState(QtCore.Qt.CheckState.Checked)
self.ui.cb_createStruct.setCheckState(QtCore.Qt.CheckState.Checked)
self.ui.cb_instrOps.setCheckState(QtCore.Qt.CheckState.Checked)
self.ui.cb_dwordArray.setCheckState(QtCore.Qt.Checked)
self.ui.cb_createStruct.setCheckState(QtCore.Qt.Checked)
self.ui.cb_instrOps.setCheckState(QtCore.Qt.Checked)
return

Loading

0 comments on commit 4fdc6ae

Please sign in to comment.