// Copyright (c) 2015-2026 Vector 35 Inc // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. #pragma once #ifdef BINARYNINJACORE_LIBRARY #include "constantdata.h" #include "variable.h" #include "ilsourcelocation.h" #else #include "binaryninjaapi.h" #endif #include "base/function_ref.h" #include #include #ifdef BINARYNINJACORE_LIBRARY namespace BinaryNinjaCore #else namespace BinaryNinja #endif { #ifdef BINARYNINJACORE_LIBRARY typedef size_t ExprId; #endif class MediumLevelILFunction; template struct MediumLevelILInstructionAccessor {}; struct MediumLevelILInstruction; struct MediumLevelILConstantInstruction; struct MediumLevelILConstantDataInstruction; struct MediumLevelILOneOperandInstruction; struct MediumLevelILTwoOperandInstruction; struct MediumLevelILTwoOperandWithCarryInstruction; struct MediumLevelILDoublePrecisionInstruction; struct MediumLevelILLabel; struct LowLevelILInstruction; class MediumLevelILOperand; class MediumLevelILOperandList; /*! \ingroup mediumlevelil */ struct SSAVariable { Variable var; size_t version = 0; // TODO: `= default` these when we can rely on C++20 bool operator==(const SSAVariable& other) const { return var == other.var && version == other.version; } bool operator!=(const SSAVariable& other) const { return !(*this == other); } bool operator<(const SSAVariable& other) const { if (var != other.var) return var < other.var; return version < other.version; } }; /*! \ingroup mediumlevelil */ enum MediumLevelILOperandType : uint8_t { IntegerMediumLevelOperand, ConstantDataMediumLevelOperand, IndexMediumLevelOperand, IntrinsicMediumLevelOperand, ExprMediumLevelOperand, VariableMediumLevelOperand, SSAVariableMediumLevelOperand, IndexListMediumLevelOperand, IndexMapMediumLevelOperand, VariableListMediumLevelOperand, SSAVariableListMediumLevelOperand, ExprListMediumLevelOperand, ConstraintMediumLevelOperand }; /*! \ingroup mediumlevelil */ enum MediumLevelILOperandUsage : uint8_t { SourceExprMediumLevelOperandUsage, SourceVariableMediumLevelOperandUsage, SourceSSAVariableMediumLevelOperandUsage, PartialSSAVariableSourceMediumLevelOperandUsage, DestExprMediumLevelOperandUsage, DestVariableMediumLevelOperandUsage, DestSSAVariableMediumLevelOperandUsage, LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage, CarryExprMediumLevelOperandUsage, StackExprMediumLevelOperandUsage, ConditionExprMediumLevelOperandUsage, HighVariableMediumLevelOperandUsage, LowVariableMediumLevelOperandUsage, HighSSAVariableMediumLevelOperandUsage, LowSSAVariableMediumLevelOperandUsage, OffsetMediumLevelOperandUsage, ConstantMediumLevelOperandUsage, ConstantDataMediumLevelOperandUsage, VectorMediumLevelOperandUsage, IntrinsicMediumLevelOperandUsage, TargetMediumLevelOperandUsage, TrueTargetMediumLevelOperandUsage, FalseTargetMediumLevelOperandUsage, DestMemoryVersionMediumLevelOperandUsage, SourceMemoryVersionMediumLevelOperandUsage, TargetsMediumLevelOperandUsage, SourceMemoryVersionsMediumLevelOperandUsage, OutputVariablesMediumLevelOperandUsage, OutputVariablesSubExprMediumLevelOperandUsage, OutputExprsMediumLevelOperandUsage, OutputSSAVariablesMediumLevelOperandUsage, OutputSSAVariablesSubExprMediumLevelOperandUsage, OutputExprsSubExprMediumLevelOperandUsage, OutputSSAMemoryVersionMediumLevelOperandUsage, ParameterExprsMediumLevelOperandUsage, SourceExprsMediumLevelOperandUsage, UntypedParameterExprsMediumLevelOperandUsage, UntypedParameterSSAExprsMediumLevelOperandUsage, ParameterSSAMemoryVersionMediumLevelOperandUsage, SourceSSAVariablesMediumLevelOperandUsages, ConstraintMediumLevelOperandUsage }; } // namespace BinaryNinjaCore namespace std { #ifdef BINARYNINJACORE_LIBRARY template <> struct hash #else template <> struct hash #endif { #ifdef BINARYNINJACORE_LIBRARY typedef BinaryNinjaCore::SSAVariable argument_type; #else typedef BinaryNinja::SSAVariable argument_type; #endif size_t operator()(argument_type const& value) const { return std::hash()(((uint64_t)value.var.ToIdentifier()) ^ ((uint64_t)value.version << 40)); } }; template <> struct hash { typedef BNMediumLevelILOperation argument_type; typedef int result_type; result_type operator()(argument_type const& value) const { return (result_type)value; } }; #ifdef BINARYNINJACORE_LIBRARY template <> struct hash #else template <> struct hash #endif { #ifdef BINARYNINJACORE_LIBRARY typedef BinaryNinjaCore::MediumLevelILOperandUsage argument_type; #else typedef BinaryNinja::MediumLevelILOperandUsage argument_type; #endif typedef int result_type; result_type operator()(argument_type const& value) const { return (result_type)value; } }; } // namespace std #ifdef BINARYNINJACORE_LIBRARY namespace BinaryNinjaCore #else namespace BinaryNinja #endif { #ifdef BINARYNINJACORE_LIBRARY #define _STD_VECTOR vector #define _STD_SET set #define _STD_UNORDERED_MAP unordered_map #define _STD_MAP map #else #define _STD_VECTOR std::vector #define _STD_SET std::set #define _STD_UNORDERED_MAP std::unordered_map #define _STD_MAP std::map #endif /*! \ingroup mediumlevelil */ class MediumLevelILInstructionAccessException : public ExceptionWithStackTrace { public: MediumLevelILInstructionAccessException() : ExceptionWithStackTrace("invalid access to MLIL instruction") {} }; /*! \ingroup mediumlevelil */ class MediumLevelILIntegerList { struct ListIterator { typedef std::forward_iterator_tag iterator_category; typedef uint64_t value_type; typedef std::ptrdiff_t difference_type; typedef void pointer; typedef value_type reference; #ifdef BINARYNINJACORE_LIBRARY MediumLevelILFunction* function; #else Ref function; #endif size_t offset; size_t count; bool operator==(const ListIterator& a) const; bool operator!=(const ListIterator& a) const; bool operator<(const ListIterator& a) const; ListIterator& operator++(); uint64_t operator*(); MediumLevelILFunction* GetFunction() const { return function; } }; ListIterator m_start; public: typedef ListIterator const_iterator; MediumLevelILIntegerList(MediumLevelILFunction* func, size_t offset, size_t count); const_iterator begin() const; const_iterator end() const; size_t size() const; uint64_t operator[](size_t i) const; operator _STD_VECTOR() const; }; /*! \ingroup mediumlevelil */ class MediumLevelILIndexList { struct ListIterator { typedef std::forward_iterator_tag iterator_category; typedef size_t value_type; typedef std::ptrdiff_t difference_type; typedef void pointer; typedef value_type reference; MediumLevelILIntegerList::const_iterator pos; bool operator==(const ListIterator& a) const { return pos == a.pos; } bool operator!=(const ListIterator& a) const { return pos != a.pos; } bool operator<(const ListIterator& a) const { return pos < a.pos; } ListIterator& operator++() { ++pos; return *this; } size_t operator*(); }; MediumLevelILIntegerList m_list; public: typedef ListIterator const_iterator; MediumLevelILIndexList(MediumLevelILFunction* func, size_t offset, size_t count); const_iterator begin() const; const_iterator end() const; size_t size() const; size_t operator[](size_t i) const; operator _STD_VECTOR() const; }; /*! \ingroup mediumlevelil */ class MediumLevelILIndexMap { struct ListIterator { typedef std::forward_iterator_tag iterator_category; typedef std::pair value_type; typedef std::ptrdiff_t difference_type; typedef void pointer; typedef value_type reference; MediumLevelILIntegerList::const_iterator pos; bool operator==(const ListIterator& a) const { return pos == a.pos; } bool operator!=(const ListIterator& a) const { return pos != a.pos; } bool operator<(const ListIterator& a) const { return pos < a.pos; } ListIterator& operator++() { ++pos; ++pos; return *this; } const std::pair operator*(); }; MediumLevelILIntegerList m_list; public: typedef ListIterator const_iterator; MediumLevelILIndexMap(MediumLevelILFunction* func, size_t offset, size_t count); const_iterator begin() const; const_iterator end() const; size_t size() const; size_t operator[](uint64_t) const; operator _STD_MAP() const; }; /*! \ingroup mediumlevelil */ class MediumLevelILVariableList { struct ListIterator { typedef std::forward_iterator_tag iterator_category; typedef Variable value_type; typedef std::ptrdiff_t difference_type; typedef void pointer; typedef value_type reference; MediumLevelILIntegerList::const_iterator pos; bool operator==(const ListIterator& a) const { return pos == a.pos; } bool operator!=(const ListIterator& a) const { return pos != a.pos; } bool operator<(const ListIterator& a) const { return pos < a.pos; } ListIterator& operator++() { ++pos; return *this; } const Variable operator*(); }; MediumLevelILIntegerList m_list; public: typedef ListIterator const_iterator; MediumLevelILVariableList(MediumLevelILFunction* func, size_t offset, size_t count); const_iterator begin() const; const_iterator end() const; size_t size() const; const Variable operator[](size_t i) const; operator _STD_VECTOR() const; }; /*! \ingroup mediumlevelil */ class MediumLevelILSSAVariableList { struct ListIterator { typedef std::forward_iterator_tag iterator_category; typedef SSAVariable value_type; typedef std::ptrdiff_t difference_type; typedef void pointer; typedef value_type reference; MediumLevelILIntegerList::const_iterator pos; bool operator==(const ListIterator& a) const { return pos == a.pos; } bool operator!=(const ListIterator& a) const { return pos != a.pos; } bool operator<(const ListIterator& a) const { return pos < a.pos; } ListIterator& operator++() { ++pos; ++pos; return *this; } const SSAVariable operator*(); }; MediumLevelILIntegerList m_list; public: typedef ListIterator const_iterator; MediumLevelILSSAVariableList( MediumLevelILFunction* func, size_t offset, size_t count); const_iterator begin() const; const_iterator end() const; size_t size() const; const SSAVariable operator[](size_t i) const; operator _STD_VECTOR() const; }; /*! \ingroup mediumlevelil */ class MediumLevelILInstructionList { struct ListIterator { typedef std::forward_iterator_tag iterator_category; typedef MediumLevelILInstruction value_type; typedef std::ptrdiff_t difference_type; typedef void pointer; typedef value_type reference; size_t instructionIndex; MediumLevelILIntegerList::const_iterator pos; bool operator==(const ListIterator& a) const { return pos == a.pos; } bool operator!=(const ListIterator& a) const { return pos != a.pos; } bool operator<(const ListIterator& a) const { return pos < a.pos; } ListIterator& operator++() { ++pos; return *this; } const MediumLevelILInstruction operator*(); }; MediumLevelILIntegerList m_list; size_t m_instructionIndex; public: typedef ListIterator const_iterator; MediumLevelILInstructionList(MediumLevelILFunction* func, size_t offset, size_t count, size_t instructionIndex); const_iterator begin() const; const_iterator end() const; size_t size() const; const MediumLevelILInstruction operator[](size_t i) const; operator _STD_VECTOR() const; operator _STD_VECTOR() const; }; /*! \ingroup mediumlevelil */ struct MediumLevelILInstructionBase : public BNMediumLevelILInstruction { #ifdef BINARYNINJACORE_LIBRARY MediumLevelILFunction* function; #else Ref function; #endif size_t exprIndex, instructionIndex; MediumLevelILOperandList GetOperands() const; uint64_t GetRawOperandAsInteger(size_t operand) const; ConstantData GetRawOperandAsConstantData(size_t operand) const; size_t GetRawOperandAsIndex(size_t operand) const; MediumLevelILInstruction GetRawOperandAsExpr(size_t operand) const; Variable GetRawOperandAsVariable(size_t operand) const; SSAVariable GetRawOperandAsSSAVariable(size_t operand) const; SSAVariable GetRawOperandAsPartialSSAVariableSource(size_t operand) const; MediumLevelILIndexList GetRawOperandAsIndexList(size_t operand) const; MediumLevelILIndexMap GetRawOperandAsIndexMap(size_t operand) const; MediumLevelILVariableList GetRawOperandAsVariableList(size_t operand) const; MediumLevelILSSAVariableList GetRawOperandAsSSAVariableList(size_t operand) const; MediumLevelILInstructionList GetRawOperandAsExprList(size_t operand) const; PossibleValueSet GetRawOperandAsPossibleValueSet(size_t operand) const; void UpdateRawOperand(size_t operandIndex, ExprId value); void UpdateRawOperandAsSSAVariableList(size_t operandIndex, const _STD_VECTOR& vars); void UpdateRawOperandAsExprList(size_t operandIndex, const _STD_VECTOR& exprs); void UpdateRawOperandAsExprList(size_t operandIndex, const _STD_VECTOR& exprs); RegisterValue GetValue() const; PossibleValueSet GetPossibleValues( const _STD_SET& options = _STD_SET()) const; Confidence> GetType() const; // Return (and leak) a string describing the instruction for debugger use char* Dump() const; size_t GetSSAVarVersion(const Variable& var); size_t GetSSAMemoryVersion(); Variable GetVariableForRegister(uint32_t reg); Variable GetVariableForFlag(uint32_t flag); Variable GetVariableForStackLocation(int64_t offset); PossibleValueSet GetPossibleSSAVarValues(const SSAVariable& var); RegisterValue GetRegisterValue(uint32_t reg); RegisterValue GetRegisterValueAfter(uint32_t reg); PossibleValueSet GetPossibleRegisterValues(uint32_t reg); PossibleValueSet GetPossibleRegisterValuesAfter(uint32_t reg); RegisterValue GetFlagValue(uint32_t flag); RegisterValue GetFlagValueAfter(uint32_t flag); PossibleValueSet GetPossibleFlagValues(uint32_t flag); PossibleValueSet GetPossibleFlagValuesAfter(uint32_t flag); RegisterValue GetStackContents(int32_t offset, size_t len); RegisterValue GetStackContentsAfter(int32_t offset, size_t len); PossibleValueSet GetPossibleStackContents(int32_t offset, size_t len); PossibleValueSet GetPossibleStackContentsAfter(int32_t offset, size_t len); BNILBranchDependence GetBranchDependence(size_t branchInstr); BNILBranchDependence GetBranchDependence(const MediumLevelILInstruction& branch); _STD_UNORDERED_MAP GetAllBranchDependence(); size_t GetSSAInstructionIndex() const; size_t GetNonSSAInstructionIndex() const; size_t GetSSAExprIndex() const; size_t GetNonSSAExprIndex() const; MediumLevelILInstruction GetSSAForm() const; MediumLevelILInstruction GetNonSSAForm() const; size_t GetLowLevelILInstructionIndex() const; size_t GetLowLevelILExprIndex() const; size_t GetHighLevelILInstructionIndex() const; size_t GetHighLevelILExprIndex() const; bool HasLowLevelIL() const; LowLevelILInstruction GetLowLevelIL() const; void MarkInstructionForRemoval(); void Replace(ExprId expr); void SetAttributes(uint32_t attributes); void SetAttribute(BNILInstructionAttribute attribute, bool state = true); void ClearAttribute(BNILInstructionAttribute attribute); template MediumLevelILInstructionAccessor& As() { if (operation != N) throw MediumLevelILInstructionAccessException(); return *(MediumLevelILInstructionAccessor*)this; } MediumLevelILOneOperandInstruction& AsOneOperand() { return *(MediumLevelILOneOperandInstruction*)this; } MediumLevelILTwoOperandInstruction& AsTwoOperand() { return *(MediumLevelILTwoOperandInstruction*)this; } MediumLevelILTwoOperandWithCarryInstruction& AsTwoOperandWithCarry() { return *(MediumLevelILTwoOperandWithCarryInstruction*)this; } template const MediumLevelILInstructionAccessor& As() const { if (operation != N) throw MediumLevelILInstructionAccessException(); return *(const MediumLevelILInstructionAccessor*)this; } const MediumLevelILConstantInstruction& AsConstant() const { return *(const MediumLevelILConstantInstruction*)this; } const MediumLevelILConstantDataInstruction& AsConstantData() const { return *(const MediumLevelILConstantDataInstruction*)this; } const MediumLevelILOneOperandInstruction& AsOneOperand() const { return *(const MediumLevelILOneOperandInstruction*)this; } const MediumLevelILTwoOperandInstruction& AsTwoOperand() const { return *(const MediumLevelILTwoOperandInstruction*)this; } const MediumLevelILTwoOperandWithCarryInstruction& AsTwoOperandWithCarry() const { return *(const MediumLevelILTwoOperandWithCarryInstruction*)this; } }; /*! \ingroup mediumlevelil */ struct MediumLevelILInstruction : public MediumLevelILInstructionBase { MediumLevelILInstruction(); MediumLevelILInstruction( MediumLevelILFunction* func, const BNMediumLevelILInstruction& instr, size_t expr, size_t instrIdx); MediumLevelILInstruction(const MediumLevelILInstructionBase& instr); void VisitExprs(bn::base::function_ref func) const; ExprId CopyTo(MediumLevelILFunction* dest, const ILSourceLocation& sourceLocation = {}) const; ExprId CopyTo(MediumLevelILFunction* dest, bn::base::function_ref subExprHandler, const ILSourceLocation& sourceLocation = {}) const; // Templated accessors for instruction operands, use these for efficient access to a known instruction template MediumLevelILInstruction GetSourceExpr() const { return As().GetSourceExpr(); } template Variable GetSourceVariable() const { return As().GetSourceVariable(); } template SSAVariable GetSourceSSAVariable() const { return As().GetSourceSSAVariable(); } template MediumLevelILInstruction GetDestExpr() const { return As().GetDestExpr(); } template Variable GetDestVariable() const { return As().GetDestVariable(); } template SSAVariable GetDestSSAVariable() const { return As().GetDestSSAVariable(); } template MediumLevelILInstruction GetLeftExpr() const { return As().GetLeftExpr(); } template MediumLevelILInstruction GetRightExpr() const { return As().GetRightExpr(); } template MediumLevelILInstruction GetCarryExpr() const { return As().GetCarryExpr(); } template MediumLevelILInstruction GetStackExpr() const { return As().GetStackExpr(); } template MediumLevelILInstruction GetConditionExpr() const { return As().GetConditionExpr(); } template Variable GetHighVariable() const { return As().GetHighVariable(); } template Variable GetLowVariable() const { return As().GetLowVariable(); } template SSAVariable GetHighSSAVariable() const { return As().GetHighSSAVariable(); } template SSAVariable GetLowSSAVariable() const { return As().GetLowSSAVariable(); } template uint64_t GetOffset() const { return As().GetOffset(); } template int64_t GetConstant() const { return As().GetConstant(); } template ConstantData GetConstantData() const { return As().GetConstantData(); } template int64_t GetVector() const { return As().GetVector(); } template uint32_t GetIntrinsic() const { return As().GetIntrinsic(); } template size_t GetTarget() const { return As().GetTarget(); } template size_t GetTrueTarget() const { return As().GetTrueTarget(); } template size_t GetFalseTarget() const { return As().GetFalseTarget(); } template size_t GetDestMemoryVersion() const { return As().GetDestMemoryVersion(); } template size_t GetSourceMemoryVersion() const { return As().GetSourceMemoryVersion(); } template MediumLevelILIndexMap GetTargets() const { return As().GetTargets(); } template MediumLevelILIndexList GetSourceMemoryVersions() const { return As().GetSourceMemoryVersions(); } template _STD_VECTOR GetOutputVariables() const { return As().GetOutputVariables(); } template _STD_VECTOR GetOutputSSAVariables() const { return As().GetOutputSSAVariables(); } template MediumLevelILInstructionList GetOutputExprs() const { return As().GetOutputExprs(); } template MediumLevelILInstructionList GetParameterExprs() const { return As().GetParameterExprs(); } template MediumLevelILInstructionList GetSourceExprs() const { return As().GetSourceExprs(); } template MediumLevelILSSAVariableList GetSourceSSAVariables() const { return As().GetSourceSSAVariables(); } template PossibleValueSet GetConstraint() const { return As().GetConstraint(); } template void SetDestSSAVersion(size_t version) { As().SetDestSSAVersion(version); } template void SetSourceSSAVersion(size_t version) { As().SetSourceSSAVersion(version); } template void SetHighSSAVersion(size_t version) { As().SetHighSSAVersion(version); } template void SetLowSSAVersion(size_t version) { As().SetLowSSAVersion(version); } template void SetDestMemoryVersion(size_t version) { As().SetDestMemoryVersion(version); } template void SetSourceMemoryVersion(size_t version) { As().SetSourceMemoryVersion(version); } template void SetOutputSSAVariables(const _STD_VECTOR& vars) { As().SetOutputSSAVariables(vars); } template void SetOutputExprs(const _STD_VECTOR& outputs) { As().SetOutputExprs(outputs); } template void SetParameterExprs(const _STD_VECTOR& params) { As().SetParameterExprs(params); } template void SetParameterExprs(const _STD_VECTOR& params) { As().SetParameterExprs(params); } template void SetSourceExprs(const _STD_VECTOR& params) { As().SetSourceExprs(params); } template void SetSourceExprs(const _STD_VECTOR& params) { As().SetSourceExprs(params); } bool GetOperandIndexForUsage(MediumLevelILOperandUsage usage, size_t& operandIndex) const; // Generic accessors for instruction operands, these will throw a MediumLevelILInstructionAccessException // on type mismatch. These are slower than the templated versions above. MediumLevelILInstruction GetSourceExpr() const; Variable GetSourceVariable() const; SSAVariable GetSourceSSAVariable() const; MediumLevelILInstruction GetDestExpr() const; Variable GetDestVariable() const; SSAVariable GetDestSSAVariable() const; MediumLevelILInstruction GetLeftExpr() const; MediumLevelILInstruction GetRightExpr() const; MediumLevelILInstruction GetCarryExpr() const; MediumLevelILInstruction GetStackExpr() const; MediumLevelILInstruction GetConditionExpr() const; Variable GetHighVariable() const; Variable GetLowVariable() const; SSAVariable GetHighSSAVariable() const; SSAVariable GetLowSSAVariable() const; uint64_t GetOffset() const; int64_t GetConstant() const; ConstantData GetConstantData() const; int64_t GetVector() const; uint32_t GetIntrinsic() const; size_t GetTarget() const; size_t GetTrueTarget() const; size_t GetFalseTarget() const; size_t GetDestMemoryVersion() const; size_t GetSourceMemoryVersion() const; MediumLevelILIndexMap GetTargets() const; MediumLevelILIndexList GetSourceMemoryVersions() const; _STD_VECTOR GetOutputVariables() const; _STD_VECTOR GetOutputSSAVariables() const; MediumLevelILInstructionList GetOutputExprs() const; MediumLevelILInstructionList GetParameterExprs() const; MediumLevelILInstructionList GetSourceExprs() const; MediumLevelILSSAVariableList GetSourceSSAVariables() const; }; /*! \ingroup mediumlevelil */ class MediumLevelILOperand { MediumLevelILInstruction m_instr; MediumLevelILOperandUsage m_usage; MediumLevelILOperandType m_type; size_t m_operandIndex; public: MediumLevelILOperand( const MediumLevelILInstruction& instr, MediumLevelILOperandUsage usage, size_t operandIndex); MediumLevelILOperandType GetType() const { return m_type; } MediumLevelILOperandUsage GetUsage() const { return m_usage; } uint64_t GetInteger() const; ConstantData GetConstantData() const; size_t GetIndex() const; uint32_t GetIntrinsic() const; MediumLevelILInstruction GetExpr() const; Variable GetVariable() const; SSAVariable GetSSAVariable() const; MediumLevelILIndexList GetIndexList() const; MediumLevelILIndexMap GetIndexMap() const; MediumLevelILVariableList GetVariableList() const; MediumLevelILSSAVariableList GetSSAVariableList() const; MediumLevelILInstructionList GetExprList() const; }; /*! \ingroup mediumlevelil */ class MediumLevelILOperandList { struct ListIterator { typedef std::forward_iterator_tag iterator_category; typedef MediumLevelILOperand value_type; typedef std::ptrdiff_t difference_type; typedef void pointer; typedef value_type reference; const MediumLevelILOperandList* owner; size_t index; constexpr bool operator==(const ListIterator& a) const { return index == a.index; } constexpr auto operator<=>(const ListIterator& a) const { return index <=> a.index; } ListIterator& operator++() { ++index; return *this; } const MediumLevelILOperand operator*(); }; MediumLevelILInstruction m_instr; const MediumLevelILOperandUsage* m_usages; const uint8_t* m_indices; uint8_t m_count; public: typedef ListIterator const_iterator; MediumLevelILOperandList(const MediumLevelILInstruction& instr, const MediumLevelILOperandUsage* usages, const uint8_t* indices, uint8_t count); const_iterator begin() const; const_iterator end() const; size_t size() const; const MediumLevelILOperand operator[](size_t i) const; operator _STD_VECTOR() const; }; /*! \ingroup mediumlevelil */ struct MediumLevelILConstantInstruction : public MediumLevelILInstructionBase { int64_t GetConstant() const { return GetRawOperandAsInteger(0); } }; /*! \ingroup mediumlevelil */ struct MediumLevelILConstantDataInstruction : public MediumLevelILInstructionBase { ConstantData GetConstantData() const { return GetRawOperandAsConstantData(0); } }; /*! \ingroup mediumlevelil */ struct MediumLevelILOneOperandInstruction : public MediumLevelILInstructionBase { MediumLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(0); } }; /*! \ingroup mediumlevelil */ struct MediumLevelILTwoOperandInstruction : public MediumLevelILInstructionBase { MediumLevelILInstruction GetLeftExpr() const { return GetRawOperandAsExpr(0); } MediumLevelILInstruction GetRightExpr() const { return GetRawOperandAsExpr(1); } }; /*! \ingroup mediumlevelil */ struct MediumLevelILTwoOperandWithCarryInstruction : public MediumLevelILInstructionBase { MediumLevelILInstruction GetLeftExpr() const { return GetRawOperandAsExpr(0); } MediumLevelILInstruction GetRightExpr() const { return GetRawOperandAsExpr(1); } 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. template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { Variable GetDestVariable() const { return GetRawOperandAsVariable(0); } MediumLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(1); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { Variable GetDestVariable() const { return GetRawOperandAsVariable(0); } uint64_t GetOffset() const { return GetRawOperandAsInteger(1); } MediumLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(2); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { Variable GetHighVariable() const { return GetRawOperandAsVariable(0); } Variable GetLowVariable() const { return GetRawOperandAsVariable(1); } MediumLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(2); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { SSAVariable GetDestSSAVariable() const { return GetRawOperandAsSSAVariable(0); } MediumLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(2); } void SetDestSSAVersion(size_t version) { UpdateRawOperand(1, version); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { SSAVariable GetDestSSAVariable() const { return GetRawOperandAsSSAVariable(0); } SSAVariable GetSourceSSAVariable() const { return GetRawOperandAsPartialSSAVariableSource(0); } uint64_t GetOffset() const { return GetRawOperandAsInteger(3); } MediumLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(4); } void SetDestSSAVersion(size_t version) { UpdateRawOperand(1, version); } void SetSourceSSAVersion(size_t version) { UpdateRawOperand(2, version); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { SSAVariable GetHighSSAVariable() const { return GetRawOperandAsSSAVariable(0); } SSAVariable GetLowSSAVariable() const { return GetRawOperandAsSSAVariable(2); } MediumLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(4); } void SetHighSSAVersion(size_t version) { UpdateRawOperand(1, version); } void SetLowSSAVersion(size_t version) { UpdateRawOperand(3, version); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { SSAVariable GetDestSSAVariable() const { return GetRawOperandAsSSAVariable(0); } SSAVariable GetSourceSSAVariable() const { return GetRawOperandAsPartialSSAVariableSource(0); } MediumLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(3); } void SetDestMemoryVersion(size_t version) { UpdateRawOperand(1, version); } void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(2, version); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { SSAVariable GetDestSSAVariable() const { return GetRawOperandAsSSAVariable(0); } SSAVariable GetSourceSSAVariable() const { return GetRawOperandAsPartialSSAVariableSource(0); } uint64_t GetOffset() const { return GetRawOperandAsInteger(3); } MediumLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(4); } void SetDestMemoryVersion(size_t version) { UpdateRawOperand(1, version); } void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(2, version); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { Variable GetDestVariable() const { return GetRawOperandAsVariable(0); } Variable GetSourceVariable() const { return GetRawOperandAsVariable(1); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { SSAVariable GetDestSSAVariable() const { return GetRawOperandAsSSAVariable(0); } void SetDestSSAVersion(size_t version) { UpdateRawOperand(1, version); } SSAVariable GetSourceSSAVariable() const { return GetRawOperandAsSSAVariable(2); } void SetSourceSSAVersion(size_t version) { UpdateRawOperand(3, version); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { Variable GetSourceVariable() const { return GetRawOperandAsVariable(0); } PossibleValueSet GetConstraint() const { return GetRawOperandAsPossibleValueSet(1); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { SSAVariable GetSourceSSAVariable() const { return GetRawOperandAsSSAVariable(0); } void SetSourceSSAVersion(size_t version) { UpdateRawOperand(1, version); } PossibleValueSet GetConstraint() const { return GetRawOperandAsPossibleValueSet(2); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { MediumLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(0); } uint64_t GetOffset() const { return GetRawOperandAsInteger(1); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { MediumLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(0); } size_t GetSourceMemoryVersion() const { return GetRawOperandAsIndex(1); } void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(1, version); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { MediumLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(0); } uint64_t GetOffset() const { return GetRawOperandAsInteger(1); } size_t GetSourceMemoryVersion() const { return GetRawOperandAsIndex(2); } void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(2, version); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(0); } MediumLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(1); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(0); } uint64_t GetOffset() const { return GetRawOperandAsInteger(1); } MediumLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(2); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(0); } size_t GetDestMemoryVersion() const { return GetRawOperandAsIndex(1); } size_t GetSourceMemoryVersion() const { return GetRawOperandAsIndex(2); } MediumLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(3); } void SetDestMemoryVersion(size_t version) { UpdateRawOperand(1, version); } void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(2, version); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(0); } uint64_t GetOffset() const { return GetRawOperandAsInteger(1); } size_t GetDestMemoryVersion() const { return GetRawOperandAsIndex(2); } size_t GetSourceMemoryVersion() const { return GetRawOperandAsIndex(3); } MediumLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(4); } void SetDestMemoryVersion(size_t version) { UpdateRawOperand(2, version); } void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(3, version); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { Variable GetSourceVariable() const { return GetRawOperandAsVariable(0); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { Variable GetSourceVariable() const { return GetRawOperandAsVariable(0); } uint64_t GetOffset() const { return GetRawOperandAsInteger(1); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { Variable GetHighVariable() const { return GetRawOperandAsVariable(0); } Variable GetLowVariable() const { return GetRawOperandAsVariable(1); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { SSAVariable GetSourceSSAVariable() const { return GetRawOperandAsSSAVariable(0); } 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 GetDestSSAVariable() const { return GetRawOperandAsSSAVariable(0); } SSAVariable GetSourceSSAVariable() const { return GetRawOperandAsPartialSSAVariableSource(0); } uint64_t GetOffset() const { return GetRawOperandAsInteger(3); } void SetDestSSAVersion(size_t version) { UpdateRawOperand(1, version); } void SetSourceSSAVersion(size_t version) { UpdateRawOperand(2, version); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { SSAVariable GetDestSSAVariable() const { return GetRawOperandAsSSAVariable(0); } SSAVariable GetSourceSSAVariable() const { return GetRawOperandAsPartialSSAVariableSource(0); } void SetDestMemoryVersion(size_t version) { UpdateRawOperand(1, version); } void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(2, version); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { SSAVariable GetDestSSAVariable() const { return GetRawOperandAsSSAVariable(0); } SSAVariable GetSourceSSAVariable() const { return GetRawOperandAsPartialSSAVariableSource(0); } uint64_t GetOffset() const { return GetRawOperandAsInteger(3); } void SetDestMemoryVersion(size_t version) { UpdateRawOperand(1, version); } void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(2, version); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { SSAVariable GetSourceSSAVariable() const { return GetRawOperandAsSSAVariable(0); } uint64_t GetOffset() const { return GetRawOperandAsInteger(2); } void SetSourceSSAVersion(size_t version) { UpdateRawOperand(1, version); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { SSAVariable GetSourceSSAVariable() const { return GetRawOperandAsSSAVariable(0); } void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(1, version); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { SSAVariable GetSourceSSAVariable() const { return GetRawOperandAsSSAVariable(0); } uint64_t GetOffset() const { return GetRawOperandAsInteger(2); } void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(1, version); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { SSAVariable GetHighSSAVariable() const { return GetRawOperandAsSSAVariable(0); } SSAVariable GetLowSSAVariable() const { return GetRawOperandAsSSAVariable(2); } void SetHighSSAVersion(size_t version) { UpdateRawOperand(1, version); } void SetLowSSAVersion(size_t version) { UpdateRawOperand(3, version); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { Variable GetSourceVariable() const { return GetRawOperandAsVariable(0); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { Variable GetSourceVariable() const { return GetRawOperandAsVariable(0); } uint64_t GetOffset() const { return GetRawOperandAsInteger(1); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(0); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(0); } MediumLevelILIndexMap GetTargets() const { return GetRawOperandAsIndexMap(1); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(0); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILCallInstruction { MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(2); } MediumLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(3); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILCallInstruction { MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(2); } MediumLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExpr(3).GetRawOperandAsExprList(0); } MediumLevelILInstruction GetStackExpr() const { return GetRawOperandAsExpr(4); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILCallInstruction { MediumLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(2); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILCallInstruction { MediumLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExpr(2).GetRawOperandAsExprList(0); } MediumLevelILInstruction GetStackExpr() const { return GetRawOperandAsExpr(3); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILCallInstruction { MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(2); } MediumLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(3); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILCallInstruction { MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(2); } MediumLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExpr(3).GetRawOperandAsExprList(0); } MediumLevelILInstruction GetStackExpr() const { return GetRawOperandAsExpr(4); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { MediumLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(0); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { MediumLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(0); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { Variable GetDestVariable() const { return GetRawOperandAsVariable(0); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { Variable GetDestVariable() const { return GetRawOperandAsVariable(0); } uint64_t GetOffset() const { return GetRawOperandAsInteger(1); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(0); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILCallSSAInstruction { size_t GetDestMemoryVersion() const { return GetRawOperandAsExpr(0).GetRawOperandAsIndex(0); } 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 SetParameterExprs(const _STD_VECTOR& params) { UpdateRawOperandAsExprList(2, params); } void SetParameterExprs(const _STD_VECTOR& params) { UpdateRawOperandAsExprList(2, params); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILCallSSAInstruction { size_t GetDestMemoryVersion() const { return GetRawOperandAsExpr(0).GetRawOperandAsIndex(0); } MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(1); } MediumLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExpr(2).GetRawOperandAsExprList(1); } size_t GetSourceMemoryVersion() const { return GetRawOperandAsExpr(2).GetRawOperandAsIndex(0); } 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 SetParameterExprs(const _STD_VECTOR& params) { GetRawOperandAsExpr(2).UpdateRawOperandAsExprList(1, params); } void SetParameterExprs(const _STD_VECTOR& params) { GetRawOperandAsExpr(2).UpdateRawOperandAsExprList(1, params); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILCallSSAInstruction { size_t GetDestMemoryVersion() const { return GetRawOperandAsExpr(0).GetRawOperandAsIndex(0); } 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 SetParameterExprs(const _STD_VECTOR& params) { UpdateRawOperandAsExprList(1, params); } void SetParameterExprs(const _STD_VECTOR& params) { UpdateRawOperandAsExprList(1, params); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILCallSSAInstruction { size_t GetDestMemoryVersion() const { return GetRawOperandAsExpr(0).GetRawOperandAsIndex(0); } MediumLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExpr(1).GetRawOperandAsExprList(1); } size_t GetSourceMemoryVersion() const { return GetRawOperandAsExpr(1).GetRawOperandAsIndex(0); } 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 SetParameterExprs(const _STD_VECTOR& params) { GetRawOperandAsExpr(1).UpdateRawOperandAsExprList(1, params); } void SetParameterExprs(const _STD_VECTOR& params) { GetRawOperandAsExpr(1).UpdateRawOperandAsExprList(1, params); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILCallSSAInstruction { size_t GetDestMemoryVersion() const { return GetRawOperandAsExpr(0).GetRawOperandAsIndex(0); } 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 SetParameterExprs(const _STD_VECTOR& params) { UpdateRawOperandAsExprList(2, params); } void SetParameterExprs(const _STD_VECTOR& params) { UpdateRawOperandAsExprList(2, params); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILCallSSAInstruction { size_t GetDestMemoryVersion() const { return GetRawOperandAsExpr(0).GetRawOperandAsIndex(0); } MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(1); } MediumLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExpr(2).GetRawOperandAsExprList(1); } size_t GetSourceMemoryVersion() const { return GetRawOperandAsExpr(2).GetRawOperandAsIndex(0); } 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 SetParameterExprs(const _STD_VECTOR& params) { GetRawOperandAsExpr(2).UpdateRawOperandAsExprList(1, params); } void SetParameterExprs(const _STD_VECTOR& params) { GetRawOperandAsExpr(2).UpdateRawOperandAsExprList(1, params); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { MediumLevelILInstructionList GetSourceExprs() const { return GetRawOperandAsExprList(0); } void SetSourceExprs(const _STD_VECTOR& exprs) { UpdateRawOperandAsExprList(0, exprs); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { MediumLevelILInstruction GetConditionExpr() const { return GetRawOperandAsExpr(0); } size_t GetTrueTarget() const { return GetRawOperandAsIndex(1); } size_t GetFalseTarget() const { return GetRawOperandAsIndex(2); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { size_t GetTarget() const { return GetRawOperandAsIndex(0); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { MediumLevelILVariableList GetOutputVariables() const { return GetRawOperandAsVariableList(0); } uint32_t GetIntrinsic() const { return (uint32_t)GetRawOperandAsInteger(2); } MediumLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(3); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { MediumLevelILSSAVariableList GetOutputSSAVariables() const { return GetRawOperandAsSSAVariableList(0); } uint32_t GetIntrinsic() const { return (uint32_t)GetRawOperandAsInteger(2); } MediumLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(3); } void SetOutputSSAVariables(const _STD_VECTOR& vars) { UpdateRawOperandAsSSAVariableList(0, vars); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { MediumLevelILSSAVariableList GetOutputSSAVariables() const { return GetRawOperandAsExpr(0).GetRawOperandAsSSAVariableList(1); } size_t GetDestMemoryVersion() const { return GetRawOperandAsExpr(0).GetRawOperandAsIndex(0); } size_t GetSourceMemoryVersion() const { return GetRawOperandAsIndex(4); } uint32_t GetIntrinsic() const { return (uint32_t)GetRawOperandAsInteger(1); } MediumLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(2); } 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); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { Variable GetDestVariable() const { return GetRawOperandAsVariable(0); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { SSAVariable GetDestSSAVariable() const { return GetRawOperandAsSSAVariable(0); } SSAVariable GetSourceSSAVariable() const { return GetRawOperandAsPartialSSAVariableSource(0); } void SetDestSSAVersion(size_t version) { UpdateRawOperand(1, version); } void SetSourceSSAVersion(size_t version) { UpdateRawOperand(2, version); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { int64_t GetVector() const { return GetRawOperandAsInteger(0); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { SSAVariable GetDestSSAVariable() const { return GetRawOperandAsSSAVariable(0); } MediumLevelILSSAVariableList GetSourceSSAVariables() const { return GetRawOperandAsSSAVariableList(2); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { size_t GetDestMemoryVersion() const { return GetRawOperandAsIndex(0); } MediumLevelILIndexList GetSourceMemoryVersions() const { return GetRawOperandAsIndexList(1); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILConstantInstruction { int64_t GetConstant() const { return GetRawOperandAsInteger(0); } int64_t GetOffset() const { return GetRawOperandAsInteger(1); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase { MediumLevelILInstructionList GetSourceExprs() const { return GetRawOperandAsExprList(0); } void SetSourceExprs(const _STD_VECTOR& exprs) { UpdateRawOperandAsExprList(0, exprs); } }; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILInstructionBase {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILConstantInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILConstantInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILConstantInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILConstantInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILConstantDataInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandWithCarryInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandWithCarryInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandWithCarryInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandWithCarryInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILTwoOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor : public MediumLevelILOneOperandInstruction {}; #undef _STD_VECTOR #undef _STD_SET #undef _STD_UNORDERED_MAP #undef _STD_MAP } // namespace BinaryNinjaCore #ifdef BINARYNINJACORE_LIBRARY #define IL_INS_NS BinaryNinjaCore #else #define IL_INS_NS BinaryNinja #endif template<> struct fmt::formatter { // -> normal, ? -> debug char presentation = ' '; format_context::iterator format(const IL_INS_NS::MediumLevelILInstruction& obj, format_context& ctx) const; constexpr auto parse(format_parse_context& ctx) -> format_parse_context::iterator { auto it = ctx.begin(), end = ctx.end(); if (it != end && *it == '?') presentation = *it++; if (it != end && *it != '}') report_error("invalid format"); return it; } }; #undef IL_INS_NS