Skip to content

Commit

Permalink
FunctionDialog: Syntax highlight function prototype (angr#1097)
Browse files Browse the repository at this point in the history
* dialogs/__init__.py: Drop import of FunctionsDialog

* ColorSchemeIDA: Use configured color scheme

* FunctionDialog: Syntax highlight function prototype
  • Loading branch information
mborgerson authored Nov 8, 2023
1 parent e359856 commit b19d845
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
2 changes: 0 additions & 2 deletions angrmanagement/ui/dialogs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from .analysis_options import AnalysisOptionsDialog
from .assemble_patch import AssemblePatchDialog
from .breakpoint import BreakpointDialog
from .function import FunctionDialog
from .load_binary import LoadBinary
from .load_docker_prompt import LoadDockerPrompt
from .load_plugins import LoadPlugins
Expand All @@ -11,7 +10,6 @@
"AnalysisOptionsDialog",
"AssemblePatchDialog",
"BreakpointDialog",
"FunctionDialog",
"LoadBinary",
"LoadDockerPrompt",
"LoadPlugins",
Expand Down
21 changes: 15 additions & 6 deletions angrmanagement/ui/dialogs/function.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from pygments.lexers.c_cpp import CLexer
from pyqodeng.core.api import CodeEdit
from pyqodeng.core.modes import PygmentsSyntaxHighlighter
from PySide6.QtCore import QSize, Qt
from PySide6.QtGui import QFont
from PySide6.QtWidgets import (
Expand All @@ -13,6 +16,7 @@
from angrmanagement.config import Conf
from angrmanagement.logic import GlobalInfo
from angrmanagement.ui.dialogs.xref import XRefDialog
from angrmanagement.ui.widgets.qccode_edit import ColorSchemeIDA
from angrmanagement.utils.layout import add_to_grid


Expand Down Expand Up @@ -42,12 +46,6 @@ def _init_widgets(self):

for label, text in [
("Name:", self.function.name),
(
"C Prototype:",
"<Unknown>"
if self.function.prototype is None
else self.function.prototype.c_repr(self.function.name, full=True),
),
("Address:", f"{self.function.addr:x}"),
("Binary:", f"{self.function.binary}"),
("Offset:", f"{self.function.offset:x}"),
Expand All @@ -64,6 +62,17 @@ def _init_widgets(self):
main_layout.addWidget(le, r, 1)
r += 1

main_layout.addWidget(QLabel("C Prototype:"), r, 0)
ce = CodeEdit(self)
if self.function.prototype is not None:
decl = self.function.prototype.c_repr(full=True).replace("()", self.function.name, 1) + ";"
ce.document().setPlainText(decl)
ce.modes.append(PygmentsSyntaxHighlighter(ce.document(), CLexer(), ColorSchemeIDA()))
ce.setFixedHeight(ce.fontMetrics().height() * 2)
ce.setReadOnly(True) # FIXME: Support editing
main_layout.addWidget(ce, r, 1)
r += 1

attrs_group_box = QGroupBox("Attributes")
attrs_layout = QGridLayout()
attrs_group_box.setLayout(attrs_layout)
Expand Down
14 changes: 7 additions & 7 deletions angrmanagement/ui/widgets/qccode_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
from angr.sim_type import SimType
from angr.sim_variable import SimTemporaryVariable, SimVariable
from pyqodeng.core import api, modes, panels
from pyqodeng.core.api.syntax_highlighter import COLOR_SCHEME_KEYS
from PySide6.QtCore import QEvent, Qt
from PySide6.QtGui import QAction, QKeySequence, QTextCharFormat
from PySide6.QtGui import QAction, QKeySequence
from PySide6.QtWidgets import QApplication, QInputDialog, QLineEdit, QMenu

from angrmanagement.ui.dialogs.rename_node import RenameNode
Expand All @@ -28,7 +29,7 @@
from angrmanagement.ui.documents.qcodedocument import QCodeDocument
from angrmanagement.ui.menus.menu import Menu
from angrmanagement.ui.views.disassembly_view import DisassemblyView
from angrmanagement.ui.widgets.qccode_highlighter import QCCodeHighlighter
from angrmanagement.ui.widgets.qccode_highlighter import FORMATS, QCCodeHighlighter

if TYPE_CHECKING:
from PySide6.QtGui import QTextDocument
Expand All @@ -43,11 +44,10 @@ class ColorSchemeIDA(api.ColorScheme):

def __init__(self):
super().__init__("default")

# override existing formats
function_format = QTextCharFormat()
function_format.setForeground(self._get_brush("0000ff"))
self.formats["function"] = function_format
for k, v in FORMATS.items():
if k in COLOR_SCHEME_KEYS:
self.formats[COLOR_SCHEME_KEYS[k]] = v
self.formats[k] = v


class QCCodeEdit(api.CodeEdit):
Expand Down
3 changes: 2 additions & 1 deletion angrmanagement/ui/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
from angrmanagement.logic.debugger.simgr import SimulationDebugger
from angrmanagement.logic.threads import gui_thread_schedule_async
from angrmanagement.plugins import PluginManager
from angrmanagement.ui.dialogs import AnalysisOptionsDialog, FunctionDialog
from angrmanagement.ui.dialogs import AnalysisOptionsDialog
from angrmanagement.ui.dialogs.function import FunctionDialog
from angrmanagement.utils import locate_function
from angrmanagement.utils.daemon_thread import start_daemon_thread

Expand Down

0 comments on commit b19d845

Please sign in to comment.