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/highlevelil.py | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'python/highlevelil.py') diff --git a/python/highlevelil.py b/python/highlevelil.py index bb1f6129..4c81f687 100644 --- a/python/highlevelil.py +++ b/python/highlevelil.py @@ -210,7 +210,11 @@ class HighLevelILInstruction(BaseILInstruction): ], HighLevelILOperation.HLIL_DEREF_FIELD_SSA: [ ("src", "expr"), ("src_memory", "int"), ("offset", "int"), ("member_index", "member_index") - ], HighLevelILOperation.HLIL_ADDRESS_OF: [("src", "expr")], HighLevelILOperation.HLIL_CONST: [ + ], HighLevelILOperation.HLIL_ADDRESS_OF: [("src", "expr")], HighLevelILOperation.HLIL_PASS_BY_REF: [ + ("src", "expr") + ], HighLevelILOperation.HLIL_RETURN_BY_REF: [ + ("src", "expr") + ], HighLevelILOperation.HLIL_CONST: [ ("constant", "int") ], HighLevelILOperation.HLIL_CONST_PTR: [("constant", "int")], HighLevelILOperation.HLIL_EXTERN_PTR: [ ("constant", "int"), ("offset", "int") @@ -1743,6 +1747,16 @@ class HighLevelILAddressOf(HighLevelILUnaryBase): return [*self.src.vars_address_taken] +@dataclass(frozen=True, repr=False, eq=False) +class HighLevelILPassByRef(HighLevelILUnaryBase): + pass + + +@dataclass(frozen=True, repr=False, eq=False) +class HighLevelILReturnByRef(HighLevelILUnaryBase): + pass + + @dataclass(frozen=True, repr=False, eq=False) class HighLevelILConst(HighLevelILInstruction, Constant): @property @@ -2429,6 +2443,8 @@ ILInstruction = { HighLevelILOperation.HLIL_DEREF_FIELD_SSA: HighLevelILDerefFieldSsa, # ("src", "expr"), ("src_memory", "int"), ("offset", "int"), ("member_index", "member_index"), HighLevelILOperation.HLIL_ADDRESS_OF: HighLevelILAddressOf, # ("src", "expr"), + HighLevelILOperation.HLIL_PASS_BY_REF: HighLevelILPassByRef, # ("src", "expr"), + HighLevelILOperation.HLIL_RETURN_BY_REF: HighLevelILReturnByRef, # ("src", "expr"), HighLevelILOperation.HLIL_CONST: HighLevelILConst, # ("constant", "int"), HighLevelILOperation.HLIL_CONST_PTR: HighLevelILConstPtr, # ("constant", "int"), HighLevelILOperation.HLIL_EXTERN_PTR: HighLevelILExternPtr, # ("constant", "int"), ("offset", "int"), @@ -3380,6 +3396,30 @@ class HighLevelILFunction: """ return self.expr(HighLevelILOperation.HLIL_ADDRESS_OF, src, size=0, source_location=loc) + def pass_by_ref(self, size: int, src: ExpressionIndex, loc: Optional['ILSourceLocation'] = None) -> ExpressionIndex: + """ + ``pass_by_ref`` indicates that ``value`` is being passed by reference to a call with a pointer size of ``size`` + + :param int size: the size of the pointer in bytes + :param ExpressionIndex src: the expression containing the reference being passed + :param ILSourceLocation loc: location of returned expression + :return: The expression ``ref *src`` + :rtype: ExpressionIndex + """ + return self.expr(HighLevelILOperation.HLIL_PASS_BY_REF, src, size, source_location=loc) + + def return_by_ref(self, size: int, dest: ExpressionIndex, loc: Optional['ILSourceLocation'] = None) -> ExpressionIndex: + """ + ``return_by_ref`` indicates that ``dest`` is being returned by passing a reference to a call + + :param int size: the size of the value in bytes + :param ExpressionIndex dest: the expression containing the target of the return value + :param ILSourceLocation loc: location of returned expression + :return: The expression ``ref dest`` + :rtype: ExpressionIndex + """ + return self.expr(HighLevelILOperation.HLIL_RETURN_BY_REF, dest, size, source_location=loc) + def const(self, size: int, value: int, loc: Optional['ILSourceLocation'] = None) -> ExpressionIndex: """ ``const`` returns an expression for the constant integer ``value`` of size ``size`` -- cgit v1.3.1