From 8d621c51b2797fda7b1dc22243dde611cfc04f68 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Tue, 23 Dec 2025 13:12:02 -0700 Subject: Refactor calling conventions to support correct representation of structures --- python/examples/pseudo_python.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'python/examples') diff --git a/python/examples/pseudo_python.py b/python/examples/pseudo_python.py index d29d4e57..af06b461 100644 --- a/python/examples/pseudo_python.py +++ b/python/examples/pseudo_python.py @@ -517,6 +517,17 @@ class PseudoPythonFunction(LanguageRepresentationFunction): OperatorPrecedence.UnaryOperatorPrecedence) if parens: tokens.append_close_paren() + elif instr.operation == HighLevelILOperation.HLIL_PASS_BY_REF: + if instr.src.operation == HighLevelILOperation.HLIL_ADDRESS_OF: + self.perform_get_expr_text(instr.src, tokens, settings, + OperatorPrecedence.UnaryOperatorPrecedence) + else: + tokens.append(InstructionTextToken(InstructionTextTokenType.OperationToken, "*")) + self.perform_get_expr_text(instr.src, tokens, settings, + OperatorPrecedence.UnaryOperatorPrecedence) + elif instr.operation == HighLevelILOperation.HLIL_RETURN_BY_REF: + self.perform_get_expr_text(instr.src, tokens, settings, + OperatorPrecedence.UnaryOperatorPrecedence) elif instr.operation in [HighLevelILOperation.HLIL_CMP_E, HighLevelILOperation.HLIL_FCMP_E]: parens = precedence > OperatorPrecedence.EqualityOperatorPrecedence if parens: @@ -1136,23 +1147,33 @@ class PseudoPythonFunctionType(LanguageRepresentationFunctionType): tokens.append(InstructionTextToken(InstructionTextTokenType.KeywordToken, "def ")) tokens.append(InstructionTextToken(InstructionTextTokenType.CodeSymbolToken, func.name, value=func.start)) tokens.append(InstructionTextToken(InstructionTextTokenType.BraceToken, "(")) + params = func.type.parameters for (i, param) in enumerate(func.type.parameters_with_all_locations): if i > 0: tokens.append(InstructionTextToken(InstructionTextTokenType.TextToken, ", ")) + var = param.location.variable_for_parameter(i) tokens.append(InstructionTextToken(InstructionTextTokenType.ArgumentNameToken, param.name, context=InstructionTextTokenContext.LocalVariableTokenContext, - address=param.location.identifier)) + address=var.identifier)) tokens.append(InstructionTextToken(InstructionTextTokenType.TextToken, ": ")) for token in param.type.get_tokens(): token.context = InstructionTextTokenContext.LocalVariableTokenContext - token.address = param.location.identifier + token.address = var.identifier tokens.append(token) + if i < len(params) and params[i].location is not None: + tokens.append(InstructionTextToken(InstructionTextTokenType.TextToken, " @ ")) + tokens.append(InstructionTextToken(InstructionTextTokenType.ValueLocationToken, + params[i].location.to_string(func.arch))) tokens.append(InstructionTextToken(InstructionTextTokenType.BraceToken, ")")) if func.can_return.value and func.type.return_value is not None and not isinstance(func.type.return_value, VoidType): tokens.append(InstructionTextToken(InstructionTextTokenType.TextToken, " -> ")) for token in func.type.return_value.get_tokens(): token.context = InstructionTextTokenContext.FunctionReturnTokenContext tokens.append(token) + if func.type.return_value_location is not None: + tokens.append(InstructionTextToken(InstructionTextTokenType.TextToken, " @ ")) + tokens.append(InstructionTextToken(InstructionTextTokenType.ValueLocationToken, + func.type.return_value_location.location.to_string(func.arch))) tokens.append(InstructionTextToken(InstructionTextTokenType.TextToken, ":")) return [DisassemblyTextLine(tokens, func.start)] -- cgit v1.3.1