Skip to content

Commit

Permalink
FunctionDialog: Syntax highlight function prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
mborgerson committed Sep 24, 2023
1 parent 3126e6e commit 15103d4
Showing 1 changed file with 15 additions and 6 deletions.
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 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

0 comments on commit 15103d4

Please sign in to comment.