Skip to content

Commit

Permalink
rename functions and fix signature
Browse files Browse the repository at this point in the history
blattm committed Jul 3, 2024
1 parent fc95d20 commit 972b58b
Showing 2 changed files with 13 additions and 13 deletions.
18 changes: 9 additions & 9 deletions decompiler/backend/cexpressiongenerator.py
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@
MAX_GLOBAL_INIT_LENGTH = 128


def get_complex_string_struct_address_offset(vartype) -> str | None:
def get_struct_string_address_offset(vartype) -> int | None:
if not isinstance(vartype, Struct):
return None
if len(vartype.members) != 2:
@@ -43,18 +43,18 @@ def get_complex_string_struct_address_offset(vartype) -> str | None:
return address_offset


INLINE_COMPLEX_STRINGS = False
INLINE_COMPLEX_STRINGS = False
DETECT_COMPLEX_STRINGS = True


def is_complex_string_struct(vartype) -> bool:
def is_struct_string(vartype) -> bool:
if not DETECT_COMPLEX_STRINGS:
return False
return get_complex_string_struct_address_offset(vartype) is not None
return get_struct_string_address_offset(vartype) is not None


def get_data_of_complex_string_struct(variable) -> str:
address_offset = get_complex_string_struct_address_offset(variable.type)
def get_data_of_struct_string(variable) -> GlobalVariable:
address_offset = get_struct_string_address_offset(variable.type)
address = variable.initial_value.value[address_offset]
return address

@@ -67,7 +67,7 @@ def inline_global_variable(var) -> bool:
if var.type.type in [Integer.char(), CustomType.wchar16(), CustomType.wchar32()]:
return True
case Struct():
if INLINE_COMPLEX_STRINGS and is_complex_string_struct(var.type):
if INLINE_COMPLEX_STRINGS and is_struct_string(var.type):
return True
case _:
return False
@@ -252,8 +252,8 @@ def visit_variable(self, expr: expressions.Variable) -> str:
def visit_global_variable(self, expr: expressions.GlobalVariable):
"""Inline a global variable if its initial value is constant and not of void type"""
if inline_global_variable(expr):
if is_complex_string_struct(expr.type):
return self.visit(get_data_of_complex_string_struct(expr))
if is_struct_string(expr.type):
return self.visit(get_data_of_struct_string(expr))
return self.visit(expr.initial_value)
return expr.name

8 changes: 4 additions & 4 deletions decompiler/backend/variabledeclarations.py
Original file line number Diff line number Diff line change
@@ -5,9 +5,9 @@

from decompiler.backend.cexpressiongenerator import (
CExpressionGenerator,
get_data_of_complex_string_struct,
get_data_of_struct_string,
inline_global_variable,
is_complex_string_struct,
is_struct_string,
)
from decompiler.structures.ast.syntaxtree import AbstractSyntaxTree
from decompiler.structures.pseudo import GlobalVariable, Integer, Variable
@@ -74,8 +74,8 @@ def _generate_definitions(global_variables: set[GlobalVariable]) -> Iterator[str
br, bl = "{", "}"
yield f"{base}{variable.type.type} {variable.name}[{hex(variable.type.elements)}] = {br}{CExpressionGenerator().visit(variable.initial_value)}{bl};"
case Struct():
if is_complex_string_struct(variable.type):
yield base + f"struct {variable.type.name} {variable.name} = {CExpressionGenerator().visit(get_data_of_complex_string_struct(variable))};"
if is_struct_string(variable.type):
yield base + f"struct {variable.type.name} {variable.name} = {CExpressionGenerator().visit(get_data_of_struct_string(variable))};"
continue
string = f"struct {variable.type.name} {variable.name}" + "{\n"
for m_type, m_value in zip(variable.type.members.values(), variable.initial_value.value.values()):

0 comments on commit 972b58b

Please sign in to comment.