From 08e34ac325743085911f96b62c81d9a1f2127806 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Mon, 27 Apr 2026 16:39:21 -0400 Subject: Extend MLIL call instruction outputs to be expressions --- mediumlevelilinstruction.h | 163 +++++++++++++++++++++------------------------ 1 file changed, 76 insertions(+), 87 deletions(-) (limited to 'mediumlevelilinstruction.h') diff --git a/mediumlevelilinstruction.h b/mediumlevelilinstruction.h index 3d7da6b9..c7663269 100644 --- a/mediumlevelilinstruction.h +++ b/mediumlevelilinstruction.h @@ -143,8 +143,10 @@ namespace BinaryNinja SourceMemoryVersionsMediumLevelOperandUsage, OutputVariablesMediumLevelOperandUsage, OutputVariablesSubExprMediumLevelOperandUsage, + OutputExprsMediumLevelOperandUsage, OutputSSAVariablesMediumLevelOperandUsage, OutputSSAVariablesSubExprMediumLevelOperandUsage, + OutputExprsSubExprMediumLevelOperandUsage, OutputSSAMemoryVersionMediumLevelOperandUsage, ParameterExprsMediumLevelOperandUsage, SourceExprsMediumLevelOperandUsage, @@ -477,6 +479,7 @@ namespace BinaryNinja const MediumLevelILInstruction operator[](size_t i) const; operator _STD_VECTOR() const; + operator _STD_VECTOR() const; }; /*! @@ -763,16 +766,21 @@ namespace BinaryNinja return As().GetSourceMemoryVersions(); } template - MediumLevelILVariableList GetOutputVariables() const + _STD_VECTOR GetOutputVariables() const { return As().GetOutputVariables(); } template - MediumLevelILSSAVariableList GetOutputSSAVariables() const + _STD_VECTOR GetOutputSSAVariables() const { return As().GetOutputSSAVariables(); } template + MediumLevelILInstructionList GetOutputExprs() const + { + return As().GetOutputExprs(); + } + template MediumLevelILInstructionList GetParameterExprs() const { return As().GetParameterExprs(); @@ -829,6 +837,11 @@ namespace BinaryNinja As().SetOutputSSAVariables(vars); } template + void SetOutputExprs(const _STD_VECTOR& outputs) + { + As().SetOutputExprs(outputs); + } + template void SetParameterExprs(const _STD_VECTOR& params) { As().SetParameterExprs(params); @@ -880,8 +893,9 @@ namespace BinaryNinja size_t GetSourceMemoryVersion() const; MediumLevelILIndexMap GetTargets() const; MediumLevelILIndexList GetSourceMemoryVersions() const; - MediumLevelILVariableList GetOutputVariables() const; - MediumLevelILSSAVariableList GetOutputSSAVariables() const; + _STD_VECTOR GetOutputVariables() const; + _STD_VECTOR GetOutputSSAVariables() const; + MediumLevelILInstructionList GetOutputExprs() const; MediumLevelILInstructionList GetParameterExprs() const; MediumLevelILInstructionList GetSourceExprs() const; MediumLevelILSSAVariableList GetSourceSSAVariables() const; @@ -1006,6 +1020,33 @@ namespace BinaryNinja MediumLevelILInstruction GetCarryExpr() const { return GetRawOperandAsExpr(2); } }; + /*! + \ingroup mediumlevelil + */ + struct MediumLevelILCallInstruction : public MediumLevelILInstructionBase + { + MediumLevelILInstructionList GetOutputExprs() const { return GetRawOperandAsExprList(0); } + _STD_VECTOR GetOutputVariables() const; + }; + + /*! + \ingroup mediumlevelil + */ + struct MediumLevelILCallSSAInstruction : public MediumLevelILInstructionBase + { + MediumLevelILInstructionList GetOutputExprs() const + { + return GetRawOperandAsExpr(0).GetRawOperandAsExprList(1); + } + + _STD_VECTOR GetOutputSSAVariables() const; + + void SetOutputExprs(const _STD_VECTOR& outputs) + { + GetRawOperandAsExpr(0).UpdateRawOperandAsExprList(1, outputs); + } + }; + // Implementations of each instruction to fetch the correct operand value for the valid operands, these // are derived from MediumLevelILInstructionBase so that invalid operand accessor functions will generate // a compiler error. @@ -1190,6 +1231,12 @@ namespace BinaryNinja void SetSourceSSAVersion(size_t version) { UpdateRawOperand(1, version); } }; template <> + struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase + { + SSAVariable GetDestSSAVariable() const { return GetRawOperandAsSSAVariable(0); } + void SetDestSSAVersion(size_t version) { UpdateRawOperand(1, version); } + }; + template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { SSAVariable GetSourceSSAVariable() const { return GetRawOperandAsSSAVariable(0); } @@ -1248,65 +1295,50 @@ namespace BinaryNinja }; template <> - struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase + struct MediumLevelILInstructionAccessor : public MediumLevelILCallInstruction { - MediumLevelILVariableList GetOutputVariables() const { return GetRawOperandAsVariableList(0); } MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(2); } MediumLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(3); } }; template <> - struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase + struct MediumLevelILInstructionAccessor : public MediumLevelILCallInstruction { - MediumLevelILVariableList GetOutputVariables() const - { - return GetRawOperandAsExpr(0).GetRawOperandAsVariableList(0); - } - MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(1); } + MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(2); } MediumLevelILInstructionList GetParameterExprs() const { - return GetRawOperandAsExpr(2).GetRawOperandAsExprList(0); + return GetRawOperandAsExpr(3).GetRawOperandAsExprList(0); } - MediumLevelILInstruction GetStackExpr() const { return GetRawOperandAsExpr(3); } + MediumLevelILInstruction GetStackExpr() const { return GetRawOperandAsExpr(4); } }; template <> - struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase + struct MediumLevelILInstructionAccessor : public MediumLevelILCallInstruction { - MediumLevelILVariableList GetOutputVariables() const { return GetRawOperandAsVariableList(0); } MediumLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(2); } }; template <> - struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase + struct MediumLevelILInstructionAccessor : public MediumLevelILCallInstruction { - MediumLevelILVariableList GetOutputVariables() const - { - return GetRawOperandAsExpr(0).GetRawOperandAsVariableList(0); - } MediumLevelILInstructionList GetParameterExprs() const { - return GetRawOperandAsExpr(1).GetRawOperandAsExprList(0); + return GetRawOperandAsExpr(2).GetRawOperandAsExprList(0); } - MediumLevelILInstruction GetStackExpr() const { return GetRawOperandAsExpr(2); } + MediumLevelILInstruction GetStackExpr() const { return GetRawOperandAsExpr(3); } }; template <> - struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase + struct MediumLevelILInstructionAccessor : public MediumLevelILCallInstruction { - MediumLevelILVariableList GetOutputVariables() const { return GetRawOperandAsVariableList(0); } MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(2); } MediumLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(3); } }; template <> - struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase + struct MediumLevelILInstructionAccessor : public MediumLevelILCallInstruction { - MediumLevelILVariableList GetOutputVariables() const - { - return GetRawOperandAsExpr(0).GetRawOperandAsVariableList(0); - } - MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(1); } + MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(2); } MediumLevelILInstructionList GetParameterExprs() const { - return GetRawOperandAsExpr(2).GetRawOperandAsExprList(0); + return GetRawOperandAsExpr(3).GetRawOperandAsExprList(0); } - MediumLevelILInstruction GetStackExpr() const { return GetRawOperandAsExpr(3); } + MediumLevelILInstruction GetStackExpr() const { return GetRawOperandAsExpr(4); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase @@ -1318,24 +1350,21 @@ namespace BinaryNinja { MediumLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(0); } }; + template <> + struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase + { + Variable GetDestVariable() const { return GetRawOperandAsVariable(0); } + }; template <> - struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase + struct MediumLevelILInstructionAccessor : public MediumLevelILCallSSAInstruction { size_t GetDestMemoryVersion() const { return GetRawOperandAsExpr(0).GetRawOperandAsIndex(0); } - MediumLevelILSSAVariableList GetOutputSSAVariables() const - { - return GetRawOperandAsExpr(0).GetRawOperandAsSSAVariableList(1); - } MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(1); } MediumLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(2); } size_t GetSourceMemoryVersion() const { return GetRawOperandAsIndex(4); } void SetDestMemoryVersion(size_t version) { GetRawOperandAsExpr(0).UpdateRawOperand(0, version); } void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(4, version); } - void SetOutputSSAVariables(const _STD_VECTOR& vars) - { - GetRawOperandAsExpr(0).UpdateRawOperandAsSSAVariableList(1, vars); - } void SetParameterExprs(const _STD_VECTOR& params) { UpdateRawOperandAsExprList(2, params); @@ -1343,13 +1372,9 @@ namespace BinaryNinja void SetParameterExprs(const _STD_VECTOR& params) { UpdateRawOperandAsExprList(2, params); } }; template <> - struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase + struct MediumLevelILInstructionAccessor : public MediumLevelILCallSSAInstruction { size_t GetDestMemoryVersion() const { return GetRawOperandAsExpr(0).GetRawOperandAsIndex(0); } - MediumLevelILSSAVariableList GetOutputSSAVariables() const - { - return GetRawOperandAsExpr(0).GetRawOperandAsSSAVariableList(1); - } MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(1); } MediumLevelILInstructionList GetParameterExprs() const { @@ -1359,10 +1384,6 @@ namespace BinaryNinja MediumLevelILInstruction GetStackExpr() const { return GetRawOperandAsExpr(3); } void SetDestMemoryVersion(size_t version) { GetRawOperandAsExpr(0).UpdateRawOperand(0, version); } void SetSourceMemoryVersion(size_t version) { GetRawOperandAsExpr(2).UpdateRawOperand(0, version); } - void SetOutputSSAVariables(const _STD_VECTOR& vars) - { - GetRawOperandAsExpr(0).UpdateRawOperandAsSSAVariableList(1, vars); - } void SetParameterExprs(const _STD_VECTOR& params) { GetRawOperandAsExpr(2).UpdateRawOperandAsExprList(1, params); @@ -1373,21 +1394,13 @@ namespace BinaryNinja } }; template <> - struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase + struct MediumLevelILInstructionAccessor : public MediumLevelILCallSSAInstruction { size_t GetDestMemoryVersion() const { return GetRawOperandAsExpr(0).GetRawOperandAsIndex(0); } - MediumLevelILSSAVariableList GetOutputSSAVariables() const - { - return GetRawOperandAsExpr(0).GetRawOperandAsSSAVariableList(1); - } MediumLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(1); } size_t GetSourceMemoryVersion() const { return GetRawOperandAsIndex(3); } void SetDestMemoryVersion(size_t version) { GetRawOperandAsExpr(0).UpdateRawOperand(0, version); } void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(3, version); } - void SetOutputSSAVariables(const _STD_VECTOR& vars) - { - GetRawOperandAsExpr(0).UpdateRawOperandAsSSAVariableList(1, vars); - } void SetParameterExprs(const _STD_VECTOR& params) { UpdateRawOperandAsExprList(1, params); @@ -1395,13 +1408,9 @@ namespace BinaryNinja void SetParameterExprs(const _STD_VECTOR& params) { UpdateRawOperandAsExprList(1, params); } }; template <> - struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase + struct MediumLevelILInstructionAccessor : public MediumLevelILCallSSAInstruction { size_t GetDestMemoryVersion() const { return GetRawOperandAsExpr(0).GetRawOperandAsIndex(0); } - MediumLevelILSSAVariableList GetOutputSSAVariables() const - { - return GetRawOperandAsExpr(0).GetRawOperandAsSSAVariableList(1); - } MediumLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExpr(1).GetRawOperandAsExprList(1); @@ -1410,10 +1419,6 @@ namespace BinaryNinja MediumLevelILInstruction GetStackExpr() const { return GetRawOperandAsExpr(2); } void SetDestMemoryVersion(size_t version) { GetRawOperandAsExpr(0).UpdateRawOperand(0, version); } void SetSourceMemoryVersion(size_t version) { GetRawOperandAsExpr(1).UpdateRawOperand(0, version); } - void SetOutputSSAVariables(const _STD_VECTOR& vars) - { - GetRawOperandAsExpr(0).UpdateRawOperandAsSSAVariableList(1, vars); - } void SetParameterExprs(const _STD_VECTOR& params) { GetRawOperandAsExpr(1).UpdateRawOperandAsExprList(1, params); @@ -1424,22 +1429,14 @@ namespace BinaryNinja } }; template <> - struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase + struct MediumLevelILInstructionAccessor : public MediumLevelILCallSSAInstruction { size_t GetDestMemoryVersion() const { return GetRawOperandAsExpr(0).GetRawOperandAsIndex(0); } - MediumLevelILSSAVariableList GetOutputSSAVariables() const - { - return GetRawOperandAsExpr(0).GetRawOperandAsSSAVariableList(1); - } MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(1); } MediumLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(2); } size_t GetSourceMemoryVersion() const { return GetRawOperandAsIndex(4); } void SetDestMemoryVersion(size_t version) { GetRawOperandAsExpr(0).UpdateRawOperand(0, version); } void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(4, version); } - void SetOutputSSAVariables(const _STD_VECTOR& vars) - { - GetRawOperandAsExpr(0).UpdateRawOperandAsSSAVariableList(1, vars); - } void SetParameterExprs(const _STD_VECTOR& params) { UpdateRawOperandAsExprList(2, params); @@ -1447,13 +1444,9 @@ namespace BinaryNinja void SetParameterExprs(const _STD_VECTOR& params) { UpdateRawOperandAsExprList(2, params); } }; template <> - struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase + struct MediumLevelILInstructionAccessor : public MediumLevelILCallSSAInstruction { size_t GetDestMemoryVersion() const { return GetRawOperandAsExpr(0).GetRawOperandAsIndex(0); } - MediumLevelILSSAVariableList GetOutputSSAVariables() const - { - return GetRawOperandAsExpr(0).GetRawOperandAsSSAVariableList(1); - } MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(1); } MediumLevelILInstructionList GetParameterExprs() const { @@ -1463,10 +1456,6 @@ namespace BinaryNinja MediumLevelILInstruction GetStackExpr() const { return GetRawOperandAsExpr(3); } void SetDestMemoryVersion(size_t version) { GetRawOperandAsExpr(0).UpdateRawOperand(0, version); } void SetSourceMemoryVersion(size_t version) { GetRawOperandAsExpr(2).UpdateRawOperand(0, version); } - void SetOutputSSAVariables(const _STD_VECTOR& vars) - { - GetRawOperandAsExpr(0).UpdateRawOperandAsSSAVariableList(1, vars); - } void SetParameterExprs(const _STD_VECTOR& params) { GetRawOperandAsExpr(2).UpdateRawOperandAsExprList(1, params); -- cgit v1.3.1