Skip to content

Commit

Permalink
Support prototype editing in pseudocode view
Browse files Browse the repository at this point in the history
  • Loading branch information
mborgerson committed Sep 16, 2023
1 parent b206d15 commit 58e190d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
14 changes: 12 additions & 2 deletions angrmanagement/ui/dialogs/retype_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import angr
import pycparser
from angr.analyses.decompiler.structured_codegen.c import CConstruct, CVariable
from angr.analyses.decompiler.structured_codegen.c import CConstruct, CVariable, CFunction
from angr.sim_variable import SimVariable
from PySide6.QtGui import Qt
from PySide6.QtGui import Qt, QFont
from PySide6.QtCore import QSize
from PySide6.QtWidgets import QDialog, QDialogButtonBox, QHBoxLayout, QLabel, QLineEdit, QPushButton, QVBoxLayout

from angrmanagement.config import Conf

if TYPE_CHECKING:
from angr.sim_type import SimType

Expand All @@ -27,6 +30,8 @@ def __init__(self, textchanged_callback, predefined_types=None, parent=None):

self.textChanged.connect(textchanged_callback)

self.setFont(QFont(Conf.disasm_font))

def set_type(self, type_: "SimType", cvariable: CVariable = None):
self._cvariable = cvariable
if cvariable is not None and isinstance(cvariable.unified_variable, SimVariable):
Expand Down Expand Up @@ -114,6 +119,9 @@ def __init__(

self.setLayout(self.main_layout)

def sizeHint(self): # pylint:disable=no-self-use
return QSize(600, 50)

#
# Private methods
#
Expand All @@ -139,6 +147,8 @@ def _init_widgets(self):
if self._node is not None:
if isinstance(self._node, CVariable) and self._node.unified_variable and self._node_type is not None:
type_box.set_type(self._node_type, cvariable=self._node)
elif isinstance(self._node, CFunction):
type_box.setText(self._node.functy.c_repr(name=self._node.demangled_name, full=True, name_parens=False))

type_box.selectAll()
self._type_box = type_box
Expand Down
2 changes: 2 additions & 0 deletions angrmanagement/ui/views/code_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ def _on_codegen_changes(self, already_regenerated=False, event: Optional[str] =

# update self
self.codegen.am_obj = new_codegen
elif event == "retype_function":
self.decompile(clear_prototype=False, reset_cache=True)

# regenerate text in the end
self.codegen.regenerate_text()
Expand Down
8 changes: 7 additions & 1 deletion angrmanagement/ui/widgets/qccode_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,12 @@ def retype_node(self, *args, node=None, node_type=None): # pylint: disable=unus

new_node_type = dialog.new_type
if new_node_type is not None and self._code_view is not None and node is not None:

if isinstance(node, CFunction):
self._code_view.function.prototype = new_node_type
self._code_view.codegen.am_event(event="retype_function", node=node)
return

# need workspace for altering callbacks of changes
variable_kb = self._code_view.codegen._variable_kb
# specify the type
Expand Down Expand Up @@ -623,7 +629,7 @@ def _initialize_context_menus(self):
self.action_xref,
]

self.function_name_actions = [self.action_rename_node, self.action_xref]
self.function_name_actions = [self.action_rename_node, self.action_xref, self.action_retype_node]

self.constant_actions = [
self.action_hex,
Expand Down

0 comments on commit 58e190d

Please sign in to comment.