diff --git a/decompiler/structures/pseudo/complextypes.py b/decompiler/structures/pseudo/complextypes.py index 678b0d21d..0ef6ab1eb 100644 --- a/decompiler/structures/pseudo/complextypes.py +++ b/decompiler/structures/pseudo/complextypes.py @@ -108,8 +108,9 @@ class Enum(ComplexType): def add_member(self, member: ComplexTypeMember): self.members[member.value] = member - def get_name_by_value(self, value: int) -> str: - return self.members.get(value).name + def get_name_by_value(self, value: int) -> Optional[str]: + member = self.members.get(value) + return member.name if member is not None else None def declaration(self) -> str: members = ",\n\t".join(f"{x.name} = {x.value}" for x in self.members.values()) diff --git a/decompiler/structures/pseudo/expressions.py b/decompiler/structures/pseudo/expressions.py index 5c59afaf2..4f9774ac6 100644 --- a/decompiler/structures/pseudo/expressions.py +++ b/decompiler/structures/pseudo/expressions.py @@ -191,7 +191,10 @@ def __str__(self) -> str: Constants of type Enum are represented as strings (corresponding enumerator identifiers). """ if isinstance(self._type, Enum): - return self._type.get_name_by_value(self.value) + name = self._type.get_name_by_value(self.value) + if name is not None: + return name + # otherwise, i.e. if value is not found in Enum class, fall through if self._type.is_boolean: return "true" if self.value else "false" if isinstance(self.value, str):