Skip to content

Commit

Permalink
PyQt5 compability fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
elikaski committed Jul 28, 2019
1 parent 739e1aa commit eafec83
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 57 deletions.
8 changes: 4 additions & 4 deletions DIE.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,11 @@ def add_menu_items(self):

# Parser View
self.add_menu_item_helper("DIE:parsersview", "Parsers View", 'DIE Parsers View',
self.DIE_show_parsersview_Handler(self), self.icon_list["plugins"], '') # todo crash
self.DIE_show_parsersview_Handler(self), self.icon_list["plugins"], '')

# Exceptions View
self.add_menu_item_helper("DIE:exceptionsview", "Exceptions View", 'DIE Exceptions View',
self.DIE_show_exceptionsview_Handler(self), self.icon_list["exception_view"], '') # todo crash
self.DIE_show_exceptionsview_Handler(self), self.icon_list["exception_view"], '')

# Value View
self.add_menu_item_helper("DIE:valueview", "Value View", 'DIE Value View',
Expand Down Expand Up @@ -360,7 +360,7 @@ def add_menu_items(self):

# About
self.add_menu_item_helper("DIE:about", "About", 'DIE About',
self.DIE_show_about_Handler(self), -1, '') # todo crash
self.DIE_show_about_Handler(self), -1, '')


def del_menu_items(self):
Expand Down Expand Up @@ -440,7 +440,7 @@ def show_parser_view(self):
self.parser_view.Show()

###########################################################################
# Parser View
# Exceptions View
def show_breakpoint_view(self):
self.bp_view.Show()

Expand Down
18 changes: 7 additions & 11 deletions DIE/UI/AboutScreen.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@


from idaapi import Form
import os
import DIE.Lib.DieConfig
from PyQt5 import QtGui, QtCore, QtWidgets

from sark.qt import QtGui, QtCore, QtWidgets

class AboutWindow(QtWidgets.QDialog):
def __init__(self):
Expand All @@ -20,13 +17,12 @@ def initUI(self):
image = QtGui.QImage(os.path.join(config.icons_path, "logo.png"))
pixmap = QtGui.QPixmap.fromImage(image)


logo = QtGui.QLabel(self)
logo = QtWidgets.QLabel(self)
logo.setFixedSize(pixmap.size())
logo.move(0.5*(self.width() - logo.width()), 20)
logo.setPixmap(pixmap)

title = QtGui.QLabel("DIE",self)
title = QtWidgets.QLabel("DIE", self)
title.setAlignment(QtCore.Qt.AlignCenter)
font = title.font()
font.setPointSize(16)
Expand All @@ -35,25 +31,25 @@ def initUI(self):
title.setFixedWidth(400)
title.move(0, logo.height() + logo.y() + 20)

subtitle = QtGui.QLabel("Dynamic IDA Enrichment framework",self)
subtitle = QtWidgets.QLabel("Dynamic IDA Enrichment framework", self)
font = subtitle.font()
font.setPointSize(14)
subtitle.setFont(font)
subtitle.setAlignment(QtCore.Qt.AlignCenter)
subtitle.setFixedWidth(400)
subtitle.move(0, title.height() + title.y() + 10)

version = QtGui.QLabel("Version 0.1",self)
version = QtWidgets.QLabel("Version 0.1", self)
font = subtitle.font()
font.setPointSize(12)
version.setFont(font)
version.setAlignment(QtCore.Qt.AlignCenter)
version.setFixedWidth(400)
version.move(0, subtitle.height() + subtitle.y() + 30)

author = QtGui.QLabel("Written by Yaniv Balmas @ynvb - Check Point Software Technologies",self)
author = QtWidgets.QLabel("Written by Yaniv Balmas @ynvb - Check Point Software Technologies",self)
font = subtitle.font()
font.setPointSize(12)
font.setPointSize(10)
author.setFont(font)
author.setAlignment(QtCore.Qt.AlignCenter)
author.setFixedWidth(400)
Expand Down
25 changes: 12 additions & 13 deletions DIE/UI/BPView.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from PyQt5 import QtGui, QtCore, QtWidgets

from idaapi import PluginForm

from DIE.Lib import BpHandler
Expand All @@ -25,22 +24,22 @@ def OnCreate(self, form):
"""
Called when the view is created
"""
self.bp_tree_widget = QtGui.QTreeWidget()
self.bp_tree_widget = QtWidgets.QTreeWidget()
self.bp_handler = BpHandler.get_bp_handler()
self.die_icons = DIE.UI.Die_Icons.get_die_icons()

# Get parent widget
self.parent = self.FormToPySideWidget(form)
self.parent = self.FormToPyQtWidget(form)

self._add_parser_data()

toolbar = QtGui.QToolBar()
action_refresh = QtGui.QAction(self.die_icons.icon_refresh, "Refresh", toolbar)
toolbar = QtWidgets.QToolBar()
action_refresh = QtWidgets.QAction(self.die_icons.icon_refresh, "Refresh", toolbar)
action_refresh.triggered.connect(self.refresh)
toolbar.addAction(action_refresh)


layout = QtGui.QGridLayout()
layout = QtWidgets.QGridLayout()
layout.addWidget(toolbar)
layout.addWidget(self.bp_tree_widget)

Expand All @@ -59,46 +58,46 @@ def _add_parser_data(self):
if self.bp_tree_widget is not None:
self.bp_tree_widget.clear()
else:
self.bp_tree_widget = QtGui.QTreeWidget()
self.bp_tree_widget = QtWidgets.QTreeWidget()

root_item = self.bp_tree_widget.invisibleRootItem()

self.bp_tree_widget.setHeaderLabel("Breakpoints")

# Excluded Modules
module_item = QtGui.QTreeWidgetItem()
module_item = QtWidgets.QTreeWidgetItem()
module_item.setText(0, "Excluded Modules")
module_item.setFlags(QtCore.Qt.ItemIsEnabled)

row = 0
for module in self.bp_handler.excluded_modules:
current_row_item = QtGui.QTreeWidgetItem()
current_row_item = QtWidgets.QTreeWidgetItem()
current_row_item.setFlags(QtCore.Qt.ItemIsEnabled)
current_row_item.setText(0, module)
module_item.insertChild(row, current_row_item)
row += 1

# Excluded Functions
function_item = QtGui.QTreeWidgetItem()
function_item = QtWidgets.QTreeWidgetItem()
function_item.setText(0, "Excluded Functions")
function_item.setFlags(QtCore.Qt.ItemIsEnabled)

row = 0
for function in self.bp_handler.excluded_funcNames:
current_row_item = QtGui.QTreeWidgetItem()
current_row_item = QtWidgets.QTreeWidgetItem()
current_row_item.setFlags(QtCore.Qt.ItemIsEnabled)
current_row_item.setText(0, function)
function_item.insertChild(row, current_row_item)
row += 1

# Excluded Addresses
ea_item = QtGui.QTreeWidgetItem()
ea_item = QtWidgets.QTreeWidgetItem()
ea_item.setText(0, "Excluded Addresses")
ea_item.setFlags(QtCore.Qt.ItemIsEnabled)

row = 0
for ea in self.bp_handler.excluded_bp_ea:
current_row_item = QtGui.QTreeWidgetItem()
current_row_item = QtWidgets.QTreeWidgetItem()
current_row_item.setFlags(QtCore.Qt.ItemIsEnabled)
current_row_item.setText(0, hex(ea))
ea_item.insertChild(row, current_row_item)
Expand Down
26 changes: 8 additions & 18 deletions DIE/UI/FunctionViewEx.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@
import idautils
import idc
from idaapi import PluginForm
#from PySide import QtGui, QtCore
from PyQt5 import QtCore, QtGui, QtWidgets

import DIE.UI.Die_Icons
import DIE.UI.ValueViewEx
import DIE.UI.ParserView
import DIE.UI.BPView

import DIE.Lib.IDAConnector
import DIE.Lib.DIEDb
import DIE.Lib.BpHandler

import sark.ui


class FunctionView(PluginForm):
"""
DIE Function View
Expand Down Expand Up @@ -656,7 +655,7 @@ def highlight_item(self, item):
@param item: module item
"""
try:
item.setBackground(QtCore.Qt.GlobalColor.yellow)
item.setBackground(QtCore.Qt.yellow)
cur_font = item.font()
cur_font.setBold(True)
item.setFont(cur_font)
Expand Down Expand Up @@ -708,7 +707,7 @@ def clear_highlights(self):
for persistent_index in self.highligthed_items:
if persistent_index.isValid():
item = self.functionModel.itemFromIndex(persistent_index)
item.setBackground(QtCore.Qt.GlobalColor.white)
item.setBackground(QtCore.Qt.white)
cur_font = item.font()
cur_font.setBold(False)
item.setFont(cur_font)
Expand All @@ -733,7 +732,7 @@ def find_function(self, function_name):

for item in matched_items:
self.functionTreeView.expand(item.index())
self.functionTreeView.scrollTo(item.index(), QtGui.QAbstractItemView.ScrollHint.PositionAtTop)
self.functionTreeView.scrollTo(item.index(), QtWidgets.QAbstractItemView.PositionAtTop)
self.highlight_item_row(item)

def find_context_list(self, context_list):
Expand All @@ -749,7 +748,7 @@ def find_context_list(self, context_list):

for func_context in context_list:
context_id = id(func_context)
matched_items = self.functionModel.match(root_index, DIE.UI.ContextId_Role, context_id, -1, QtCore.Qt.MatchFlag.MatchRecursive|QtCore.Qt.MatchFlag.MatchExactly)
matched_items = self.functionModel.match(root_index, DIE.UI.ContextId_Role, context_id, -1, QtCore.Qt.MatchRecursive|QtCore.Qt.MatchExactly)

for index in matched_items:
if not index.isValid():
Expand All @@ -760,7 +759,7 @@ def find_context_list(self, context_list):

item = self.functionModel.itemFromIndex(index)
self.functionTreeView.expand(index)
self.functionTreeView.scrollTo(index, QtGui.QAbstractItemView.ScrollHint.PositionAtTop)
self.functionTreeView.scrollTo(index, QtWidgets.QAbstractItemView.PositionAtTop)
self.highlight_item_row(item)

return True
Expand All @@ -772,7 +771,6 @@ def find_context_list(self, context_list):
###############################################################################################
# Slots.

#@QtCore.Slot(QtCore.QModelIndex)
@QtCore.pyqtSlot(QtCore.QModelIndex)
def itemDoubleClickSlot(self, index):
"""
Expand All @@ -798,7 +796,6 @@ def itemDoubleClickSlot(self, index):
idc.Jump(ea)
return True

#@QtCore.Slot(QtCore.QPoint)
@QtCore.pyqtSlot(QtCore.QPoint)
def onCustomContextMenu(self, point):
index = self.functionTreeView.indexAt(point)
Expand All @@ -818,7 +815,6 @@ def onCustomContextMenu(self, point):
self.context_menu_param = is_value_item
self.value_context_menu.exec_(self.functionTreeView.mapToGlobal(point))

#@QtCore.Slot(str)
@QtCore.pyqtSlot(str)
def on_exclude_func(self, function):

Expand All @@ -831,7 +827,6 @@ def on_exclude_func(self, function):
self.bp_handler.add_bp_funcname_exception(function.function_name)
return

#@QtCore.Slot(str)
@QtCore.pyqtSlot(str)
def on_exclude_func_adrs(self, function):

Expand All @@ -847,7 +842,6 @@ def on_exclude_func_adrs(self, function):

return

#@QtCore.Slot(str)
@QtCore.pyqtSlot(str)
def on_exclude_ea(self, function_context):

Expand All @@ -860,7 +854,6 @@ def on_exclude_ea(self, function_context):
self.bp_handler.add_bp_ea_exception(function_context.calling_ea)
return

#@QtCore.Slot(str)
@QtCore.pyqtSlot(str)
def on_show_callgraph(self, function_context):

Expand All @@ -887,7 +880,6 @@ def on_show_callgraph(self, function_context):

return

#@QtCore.Slot(str)
@QtCore.pyqtSlot(str)
def on_exclude_library(self, function):

Expand All @@ -902,7 +894,6 @@ def on_exclude_library(self, function):

return

#@QtCore.Slot(str)
@QtCore.pyqtSlot(str)
def on_value_detail(self, value):
if not self.value_view.isVisible():
Expand All @@ -921,7 +912,7 @@ def on_thread_combobox_change(self, thread_id):

hidden_threads = ".*" + self._make_thread_id_data(thread_id) + ".*"

threadProxyModel = QtGui.QSortFilterProxyModel()
threadProxyModel = QtCore.QSortFilterProxyModel()
threadProxyModel.setFilterRole(DIE.UI.ThreadId_Role)
threadProxyModel.setFilterRegExp(hidden_threads)

Expand All @@ -946,7 +937,6 @@ def on_bpview_button(self):
###############################################################################################
# View Delegates.

#class TreeViewDelegate(QtGui.QStyledItemDelegate):
class TreeViewDelegate(QtWidgets.QStyledItemDelegate):
"""
Delegate for parsed value viewing in the tree view
Expand All @@ -967,7 +957,7 @@ def createEditor(self, parent, option, index):
line_txt = "%d, %s, %s" % (parsed_val.score, parsed_val.data, parsed_val.description)
lines.append(line_txt)

combo_box = QtGui.QComboBox(parent)
combo_box = QtWidgets.QComboBox(parent)
combo_box.addItems(lines)

return combo_box
Expand Down
12 changes: 6 additions & 6 deletions DIE/UI/ParserView.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from DIE.Lib import DataParser
from idaapi import PluginForm
#from PySide import QtGui, QtCore
from PyQt5 import QtGui, QtCore, QtWidgets


class ParserView(PluginForm):
"""
DIE Value View
Expand All @@ -23,14 +23,14 @@ def OnCreate(self, form):
Called when the view is created
"""
self.data_parser = DataParser.getParser()
self.ptable_widget = QtGui.QTreeWidget()
self.ptable_widget = QtWidgets.QTreeWidget()

# Get parent widget
self.parent = self.FormToPySideWidget(form)
self.parent = self.FormToPyQtWidget(form)

self._add_parser_data()

layout = QtGui.QGridLayout()
layout = QtWidgets.QGridLayout()
layout.addWidget(self.ptable_widget)

self.parent.setLayout(layout)
Expand Down Expand Up @@ -61,7 +61,7 @@ def _add_parser_data(self):
root_item = self.ptable_widget.invisibleRootItem()

for parser in parser_list:
current_row_item = QtGui.QTreeWidgetItem()
current_row_item = QtWidgets.QTreeWidgetItem()
current_row_item.setFlags(QtCore.Qt.ItemIsEnabled)
current_row_item.setText(0, parser)

Expand All @@ -71,7 +71,7 @@ def _add_parser_data(self):
current_row_item.setText(column+1, currext_text)

root_item.insertChild(row, current_row_item)
row +=1
row += 1



Expand Down
Loading

1 comment on commit eafec83

@ynvb
Copy link
Owner

@ynvb ynvb commented on eafec83 Jul 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect - this fixes all UI issues for IDA >6.9 (!)

Please sign in to comment.