summaryrefslogtreecommitdiff
path: root/python/examples
diff options
context:
space:
mode:
authorRusty Wagner <rusty.wagner@gmail.com>2025-12-23 13:12:02 -0700
committerRusty Wagner <rusty.wagner@gmail.com>2026-05-22 16:30:56 -0400
commit8d621c51b2797fda7b1dc22243dde611cfc04f68 (patch)
treeba5e6a90e644d21d13e75dabcbd0cc747444443a /python/examples
parent08e34ac325743085911f96b62c81d9a1f2127806 (diff)
Refactor calling conventions to support correct representation of structures
Diffstat (limited to 'python/examples')
-rw-r--r--python/examples/pseudo_python.py25
1 files changed, 23 insertions, 2 deletions
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)]