Skip to content

Commit b0bf390

Browse files
committed
Merge StructConstant with Constant
1 parent 9320b6d commit b0bf390

File tree

4 files changed

+5
-39
lines changed

4 files changed

+5
-39
lines changed

decompiler/backend/variabledeclarations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from decompiler.structures.ast.syntaxtree import AbstractSyntaxTree
1313
from decompiler.structures.pseudo import GlobalVariable, Integer, Variable
1414
from decompiler.structures.pseudo.complextypes import Struct
15-
from decompiler.structures.pseudo.expressions import StructConstant
15+
from decompiler.structures.pseudo.expressions import Constant
1616
from decompiler.structures.pseudo.typing import ArrayType, CustomType, Pointer
1717
from decompiler.structures.visitors.ast_dataflowobjectvisitor import BaseAstDataflowObjectVisitor
1818
from decompiler.task import DecompilerTask
@@ -105,6 +105,6 @@ def visit_global_variable(self, expr: GlobalVariable):
105105
self._global_vars.add(expr.copy(ssa_label=0, ssa_name=None))
106106
if not expr.is_constant or expr.type == Pointer(CustomType.void()):
107107
self._global_vars.add(expr.copy(ssa_label=0, ssa_name=None))
108-
if isinstance(expr.initial_value, StructConstant):
108+
if isinstance(expr.initial_value, Constant) and isinstance(expr.initial_value.value, dict):
109109
for member_value in expr.initial_value.value.values():
110110
self.visit(member_value)

decompiler/frontend/binaryninja/handlers/globals.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
Integer,
3131
OperationType,
3232
Pointer,
33-
StructConstant,
3433
Symbol,
3534
UnaryOperation,
3635
)
@@ -288,7 +287,7 @@ def _lift_struct_helper(self, variable, parent, struct_type):
288287
lift = self._lifter.lift(dv, view=self._view)
289288
values[member_type.offset] = lift.initial_value
290289
return self._build_global_variable(
291-
variable.name, s_type, variable.address, StructConstant(values, s_type), parent.ssa_memory_version if parent else 0
290+
variable.name, s_type, variable.address, Constant(values, s_type), parent.ssa_memory_version if parent else 0
292291
)
293292

294293
def _lift_enum_type(self, variable: DataVariable, parent: Optional[MediumLevelILInstruction] = None, **_):

decompiler/structures/pseudo/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
IntrinsicSymbol,
1111
NotUseableConstant,
1212
RegisterPair,
13-
StructConstant,
1413
Symbol,
1514
Tag,
1615
UnknownExpression,

decompiler/structures/pseudo/expressions.py

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from typing import TYPE_CHECKING, Generic, Iterator, List, Optional, Tuple, TypeVar, Union, final
3636

3737
from ...util.insertion_ordered_set import InsertionOrderedSet
38-
from .complextypes import Enum, Struct
38+
from .complextypes import Enum
3939
from .typing import CustomType, Type, UnknownType
4040

4141
T = TypeVar("T")
@@ -165,8 +165,7 @@ def accept(self, visitor: DataflowObjectVisitorInterface[T]) -> T:
165165
class Constant(Expression[DecompiledType]):
166166
"""Represents a constant expression type."""
167167

168-
# python 3.12 allows writing: type ValueType = int | float | str | bytes | dict[str, ValueType]
169-
ValueType = int | float | str | bytes | list["ValueType"] | dict[str, "ValueType"]
168+
ValueType = int | float | str | bytes | Expression | list["ValueType"] | dict[int, "ValueType"]
170169

171170
def __init__(
172171
self,
@@ -566,34 +565,3 @@ def copy(self) -> RegisterPair:
566565
def accept(self, visitor: DataflowObjectVisitorInterface[T]) -> T:
567566
"""Invoke the appropriate visitor for this Expression."""
568567
return visitor.visit_register_pair(self)
569-
570-
571-
class StructConstant(Constant):
572-
"""This class represents constant structs.
573-
The value is a dictionary mapping offsets to the corresponding fields' value.
574-
The vartype is a 'Struct' (a special ComplexType), which provides a mapping from offsets to field names."""
575-
576-
def __init__(self, value: dict[int, Expression], vartype: Struct, tags: Optional[Tuple[Tag, ...]] = None):
577-
super().__init__(
578-
value,
579-
vartype=vartype,
580-
tags=tags,
581-
)
582-
583-
def __eq__(self, __value):
584-
return isinstance(__value, StructConstant) and super().__eq__(__value)
585-
586-
def __hash__(self):
587-
return hash(tuple(sorted(self.value.items())))
588-
589-
def __str__(self) -> str:
590-
"""Return a string representation of the struct"""
591-
592-
return str(self.value)
593-
594-
def __iter__(self) -> Iterator[Expression]:
595-
yield from self.value.values()
596-
597-
def copy(self) -> StructConstant:
598-
"""Generate a copy of the UnknownExpression with the same message."""
599-
return StructConstant(self.value, self._type)

0 commit comments

Comments
 (0)