# Copyright (c) 2018-2025 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.importctypesimportstructfromtypingimport(Optional,List,Union,Mapping,MutableMapping,Generator,NewType,Tuple,ClassVar,Dict,Set,Callable,Any,Iterator,overload)fromdataclassesimportdataclassfrom.importdeprecation# Binary Ninja componentsfrom.import_binaryninjacoreascorefrom.enumsimportMediumLevelILOperation,ILBranchDependence,DataFlowQueryOption,FunctionGraphType,DeadStoreElimination,ILInstructionAttribute,StringTypefrom.importbasicblockfrom.importfunctionfrom.importtypesfrom.importlowlevelilfrom.importhighlevelilfrom.importflowgraphfrom.importvariablefrom.importarchitecturefrom.importbinaryviewfrom.importtypesas_typesfrom.interactionimportshow_graph_reportfrom.commonilimport(BaseILInstruction,Constant,BinaryOperation,UnaryOperation,Comparison,SSA,Phi,FloatingPoint,ControlFlow,Terminal,Call,Localcall,Syscall,Tailcall,Return,Signed,Arithmetic,Carry,DoublePrecision,Memory,Load,Store,RegisterStack,SetVar,Intrinsic,VariableInstruction,SSAVariableInstruction,AliasedVariableInstruction,ILSourceLocation,invalid_il_index)TokenList=List['function.InstructionTextToken']ExpressionIndex=NewType('ExpressionIndex',int)InstructionIndex=NewType('InstructionIndex',int)Index=Union[ExpressionIndex,InstructionIndex]InstructionOrExpression=Union['MediumLevelILInstruction',Index]MLILInstructionsType=Generator['MediumLevelILInstruction',None,None]MLILBasicBlocksType=Generator['MediumLevelILBasicBlock',None,None]OperandsType=Tuple[ExpressionIndex,ExpressionIndex,ExpressionIndex,ExpressionIndex,ExpressionIndex]MediumLevelILOperandType=Union[int,float,'MediumLevelILOperationAndSize','MediumLevelILInstruction','lowlevelil.ILIntrinsic','variable.Variable','SSAVariable',List[int],List['variable.Variable'],List['SSAVariable'],List['MediumLevelILInstruction'],Dict[int,int],'variable.ConstantData']MediumLevelILVisitorCallback=Callable[[str,MediumLevelILOperandType,str,Optional['MediumLevelILInstruction']],bool]StringOrType=Union[str,'_types.Type','_types.TypeBuilder']ILInstructionAttributeSet=Union[Set[ILInstructionAttribute],List[ILInstructionAttribute]]LLILSSAToMLILInstructionMapping=MutableMapping['lowlevelil.InstructionIndex',InstructionIndex][docs]@dataclass(frozen=True)classLLILSSAToMLILExpressionMap:lower_index:'lowlevelil.ExpressionIndex'higher_index:ExpressionIndexmap_lower_to_higher:boolmap_higher_to_lower:boollower_to_higher_direct:boolhigher_to_lower_direct:booldef_to_core_struct(self):result=core.BNExprMapInfo()result.lowerIndex=self.lower_indexresult.higherIndex=self.higher_indexresult.mapLowerToHigher=self.map_lower_to_higherresult.mapHigherToLower=self.map_higher_to_lowerresult.lowerToHigherDirect=self.lower_to_higher_directresult.higherToLowerDirect=self.higher_to_lower_directreturnresult LLILSSAToMLILExpressionMapping=List['LLILSSAToMLILExpressionMap'][docs]@dataclass(frozen=True,repr=False,order=True)classSSAVariable:var:'variable.Variable'version:intdef__repr__(self):returnf"<SSAVariable:{self.var} version{self.version}>"@propertydefname(self)->str:returnself.var.name@propertydeftype(self)->'types.Type':returnself.var.type@propertydeffunction(self)->'function.Function':"""returns the source Function object which this variable belongs to"""returnself.var.function@propertydefil_function(self)->'function.ILFunctionType':"""returns the il Function object which this variable belongs to"""returnself.var._il_function@propertydefdead_store_elimination(self)->DeadStoreElimination:"""returns the dead store elimination setting for this variable (read-only)"""returnself.var.dead_store_elimination@propertydefdef_site(self)->Optional[Union['MediumLevelILInstruction','highlevelil.HighLevelILInstruction']]:"""Gets the IL instructions where this SSAVariable is defined."""returnself.il_function.get_ssa_var_definition(self)@propertydefuse_sites(self)->List[Union['MediumLevelILInstruction','highlevelil.HighLevelILInstruction']]:"""Gets the list of IL instructions where this SSAVariable is used inside of this function."""returnself.il_function.get_ssa_var_uses(self) [docs]classMediumLevelILLabel:[docs]def__init__(self,handle:Optional[core.BNMediumLevelILLabel]=None):ifhandleisNone:self.handle=(core.BNMediumLevelILLabel*1)()core.BNMediumLevelILInitLabel(self.handle)else:self.handle=handle @propertydefref(self)->bool:returnself.handle[0].ref@ref.setterdefref(self,value):self.handle[0].ref=value@propertydefresolved(self)->bool:returnself.handle[0].resolved@propertydefoperand(self)->InstructionIndex:returnInstructionIndex(self.handle[0].operand)@operand.setterdefoperand(self,value:InstructionIndex):self.handle[0].operand=int(value) [docs]@dataclass(frozen=True,repr=False)classMediumLevelILOperationAndSize:operation:MediumLevelILOperationsize:intdef__repr__(self):ifself.size==0:returnf"<MediumLevelILOperationAndSize:{self.operation.name}>"returnf"<MediumLevelILOperationAndSize:{self.operation.name}{self.size}>" [docs]@dataclass(frozen=True)classCoreMediumLevelILInstruction:operation:MediumLevelILOperationattributes:intsource_operand:intsize:intoperands:OperandsTypeaddress:int[docs]@classmethoddeffrom_BNMediumLevelILInstruction(cls,instr:core.BNMediumLevelILInstruction)->'CoreMediumLevelILInstruction':operands:OperandsType=tuple([ExpressionIndex(instr.operands[i])foriinrange(5)])# type: ignorereturncls(MediumLevelILOperation(instr.operation),instr.attributes,instr.sourceOperand,instr.size,operands,instr.address) [docs]@dataclass(frozen=True)classMediumLevelILInstruction(BaseILInstruction):"""``class MediumLevelILInstruction`` Medium Level Intermediate Language Instructions are infinite length tree-basedinstructions. Tree-based instructions use infix notation with the left hand operand being the destination operand.Infix notation is thus more natural to read than other notations (e.g. x86 ``mov eax, 0`` vs. MLIL ``eax = 0``)."""function:'MediumLevelILFunction'expr_index:ExpressionIndexinstr:CoreMediumLevelILInstructioninstr_index:InstructionIndex# ILOperations is deprecated and will be removed in a future version once BNIL Graph no longer uses it# Use the visit methods visit, visit_all, and visit_operandsILOperations:ClassVar[Mapping[MediumLevelILOperation,List[Tuple[str,str]]]]={MediumLevelILOperation.MLIL_NOP:[],MediumLevelILOperation.MLIL_SET_VAR:[("dest","var"),("src","expr")],MediumLevelILOperation.MLIL_SET_VAR_FIELD:[("dest","var"),("offset","int"),("src","expr")],MediumLevelILOperation.MLIL_SET_VAR_SPLIT:[("high","var"),("low","var"),("src","expr")],MediumLevelILOperation.MLIL_LOAD:[("src","expr")],MediumLevelILOperation.MLIL_LOAD_STRUCT:[("src","expr"),("offset","int")],MediumLevelILOperation.MLIL_STORE:[("dest","expr"),("src","expr")],MediumLevelILOperation.MLIL_STORE_STRUCT:[("dest","expr"),("offset","int"),("src","expr")],MediumLevelILOperation.MLIL_VAR:[("src","var")],MediumLevelILOperation.MLIL_VAR_FIELD:[("src","var"),("offset","int")],MediumLevelILOperation.MLIL_VAR_SPLIT:[("high","var"),("low","var")],MediumLevelILOperation.MLIL_ADDRESS_OF:[("src","var")],MediumLevelILOperation.MLIL_ADDRESS_OF_FIELD:[("src","var"),("offset","int")],MediumLevelILOperation.MLIL_CONST:[("constant","int")],MediumLevelILOperation.MLIL_CONST_PTR:[("constant","int")],MediumLevelILOperation.MLIL_EXTERN_PTR:[("constant","int"),("offset","int")],MediumLevelILOperation.MLIL_FLOAT_CONST:[("constant","float")],MediumLevelILOperation.MLIL_IMPORT:[("constant","int")],MediumLevelILOperation.MLIL_CONST_DATA:[("constant","ConstantData")],MediumLevelILOperation.MLIL_CONST_DATA:[("constant","ConstantData")],MediumLevelILOperation.MLIL_ADD:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_ADC:[("left","expr"),("right","expr"),("carry","expr")],MediumLevelILOperation.MLIL_SUB:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_SBB:[("left","expr"),("right","expr"),("carry","expr")],MediumLevelILOperation.MLIL_AND:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_OR:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_XOR:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_LSL:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_LSR:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_ASR:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_ROL:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_RLC:[("left","expr"),("right","expr"),("carry","expr")],MediumLevelILOperation.MLIL_ROR:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_RRC:[("left","expr"),("right","expr"),("carry","expr")],MediumLevelILOperation.MLIL_MUL:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_MULU_DP:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_MULS_DP:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_DIVU:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_DIVU_DP:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_DIVS:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_DIVS_DP:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_MODU:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_MODU_DP:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_MODS:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_MODS_DP:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_NEG:[("src","expr")],MediumLevelILOperation.MLIL_NOT:[("src","expr")],MediumLevelILOperation.MLIL_SX:[("src","expr")],MediumLevelILOperation.MLIL_ZX:[("src","expr")],MediumLevelILOperation.MLIL_LOW_PART:[("src","expr")],MediumLevelILOperation.MLIL_JUMP:[("dest","expr")],MediumLevelILOperation.MLIL_JUMP_TO:[("dest","expr"),("targets","target_map")],MediumLevelILOperation.MLIL_RET_HINT:[("dest","expr")],MediumLevelILOperation.MLIL_CALL:[("output","var_list"),("dest","expr"),("params","expr_list")],MediumLevelILOperation.MLIL_CALL_UNTYPED:[("output","expr"),("dest","expr"),("params","expr"),("stack","expr")],MediumLevelILOperation.MLIL_CALL_OUTPUT:[("dest","var_list")],MediumLevelILOperation.MLIL_CALL_PARAM:[("src","expr_list")],MediumLevelILOperation.MLIL_SEPARATE_PARAM_LIST:[("params","expr_list")],MediumLevelILOperation.MLIL_SHARED_PARAM_SLOT:[("params","expr_list")],MediumLevelILOperation.MLIL_RET:[("src","expr_list")],MediumLevelILOperation.MLIL_NORET:[],MediumLevelILOperation.MLIL_IF:[("condition","expr"),("true","int"),("false","int")],MediumLevelILOperation.MLIL_GOTO:[("dest","int")],MediumLevelILOperation.MLIL_CMP_E:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_CMP_NE:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_CMP_SLT:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_CMP_ULT:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_CMP_SLE:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_CMP_ULE:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_CMP_SGE:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_CMP_UGE:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_CMP_SGT:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_CMP_UGT:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_TEST_BIT:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_BOOL_TO_INT:[("src","expr")],MediumLevelILOperation.MLIL_ADD_OVERFLOW:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_SYSCALL:[("output","var_list"),("params","expr_list")],MediumLevelILOperation.MLIL_SYSCALL_UNTYPED:[("output","expr"),("params","expr"),("stack","expr")],MediumLevelILOperation.MLIL_TAILCALL:[("output","var_list"),("dest","expr"),("params","expr_list")],MediumLevelILOperation.MLIL_TAILCALL_UNTYPED:[("output","expr"),("dest","expr"),("params","expr"),("stack","expr")],MediumLevelILOperation.MLIL_BP:[],MediumLevelILOperation.MLIL_TRAP:[("vector","int")],MediumLevelILOperation.MLIL_INTRINSIC:[("output","var_list"),("intrinsic","intrinsic"),("params","expr_list")],MediumLevelILOperation.MLIL_INTRINSIC_SSA:[("output","var_ssa_list"),("intrinsic","intrinsic"),("params","expr_list")],MediumLevelILOperation.MLIL_MEMORY_INTRINSIC_OUTPUT_SSA:[("dest_memory","int"),("output","var_ssa_list")],MediumLevelILOperation.MLIL_MEMORY_INTRINSIC_SSA:[("output","expr"),("intrinsic","intrinsic"),("params","expr_list"),("src_memory","int")],MediumLevelILOperation.MLIL_FREE_VAR_SLOT:[("dest","var")],MediumLevelILOperation.MLIL_FREE_VAR_SLOT_SSA:[("prev","var_ssa_dest_and_src")],MediumLevelILOperation.MLIL_UNDEF:[],MediumLevelILOperation.MLIL_UNIMPL:[],MediumLevelILOperation.MLIL_UNIMPL_MEM:[("src","expr")],MediumLevelILOperation.MLIL_FADD:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_FSUB:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_FMUL:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_FDIV:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_FSQRT:[("src","expr")],MediumLevelILOperation.MLIL_FNEG:[("src","expr")],MediumLevelILOperation.MLIL_FABS:[("src","expr")],MediumLevelILOperation.MLIL_FLOAT_TO_INT:[("src","expr")],MediumLevelILOperation.MLIL_INT_TO_FLOAT:[("src","expr")],MediumLevelILOperation.MLIL_FLOAT_CONV:[("src","expr")],MediumLevelILOperation.MLIL_ROUND_TO_INT:[("src","expr")],MediumLevelILOperation.MLIL_FLOOR:[("src","expr")],MediumLevelILOperation.MLIL_CEIL:[("src","expr")],MediumLevelILOperation.MLIL_FTRUNC:[("src","expr")],MediumLevelILOperation.MLIL_FCMP_E:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_FCMP_NE:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_FCMP_LT:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_FCMP_LE:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_FCMP_GE:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_FCMP_GT:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_FCMP_O:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_FCMP_UO:[("left","expr"),("right","expr")],MediumLevelILOperation.MLIL_SET_VAR_SSA:[("dest","var_ssa"),("src","expr")],MediumLevelILOperation.MLIL_SET_VAR_SSA_FIELD:[("dest","var_ssa_dest_and_src"),("prev","var_ssa_dest_and_src"),("offset","int"),("src","expr")],MediumLevelILOperation.MLIL_SET_VAR_SPLIT_SSA:[("high","var_ssa"),("low","var_ssa"),("src","expr")],MediumLevelILOperation.MLIL_SET_VAR_ALIASED:[("dest","var_ssa_dest_and_src"),("prev","var_ssa_dest_and_src"),("src","expr")],MediumLevelILOperation.MLIL_SET_VAR_ALIASED_FIELD:[("dest","var_ssa_dest_and_src"),("prev","var_ssa_dest_and_src"),("offset","int"),("src","expr")],MediumLevelILOperation.MLIL_VAR_SSA:[("src","var_ssa")],MediumLevelILOperation.MLIL_VAR_SSA_FIELD:[("src","var_ssa"),("offset","int")],MediumLevelILOperation.MLIL_VAR_ALIASED:[("src","var_ssa")],MediumLevelILOperation.MLIL_VAR_ALIASED_FIELD:[("src","var_ssa"),("offset","int")],MediumLevelILOperation.MLIL_VAR_SPLIT_SSA:[("high","var_ssa"),("low","var_ssa")],MediumLevelILOperation.MLIL_CALL_SSA:[("output","expr"),("output_dest_memory","int"),("dest","expr"),("params","expr_list"),("src_memory","int")],MediumLevelILOperation.MLIL_CALL_UNTYPED_SSA:[("output","expr"),("dest","expr"),("params","expr"),("stack","expr")],MediumLevelILOperation.MLIL_SYSCALL_SSA:[("output","expr"),("params","expr_list"),("src_memory","int")],MediumLevelILOperation.MLIL_SYSCALL_UNTYPED_SSA:[("output","expr"),("params","expr"),("stack","expr")],MediumLevelILOperation.MLIL_TAILCALL_SSA:[("output","expr"),("output_dest_memory","int"),("dest","expr"),("params","expr_list"),("src_memory","int")],MediumLevelILOperation.MLIL_TAILCALL_UNTYPED_SSA:[("output","expr"),("dest","expr"),("params","expr"),("stack","expr")],MediumLevelILOperation.MLIL_CALL_OUTPUT_SSA:[("dest_memory","int"),("dest","var_ssa_list")],MediumLevelILOperation.MLIL_CALL_PARAM_SSA:[("src_memory","int"),("src","expr_list")],MediumLevelILOperation.MLIL_LOAD_SSA:[("src","expr"),("src_memory","int")],MediumLevelILOperation.MLIL_LOAD_STRUCT_SSA:[("src","expr"),("offset","int"),("src_memory","int")],MediumLevelILOperation.MLIL_STORE_SSA:[("dest","expr"),("dest_memory","int"),("src_memory","int"),("src","expr")],MediumLevelILOperation.MLIL_STORE_STRUCT_SSA:[("dest","expr"),("offset","int"),("dest_memory","int"),("src_memory","int"),("src","expr")],MediumLevelILOperation.MLIL_VAR_PHI:[("dest","var_ssa"),("src","var_ssa_list")],MediumLevelILOperation.MLIL_MEM_PHI:[("dest_memory","int"),("src_memory","int_list")]}[docs]@staticmethoddefshow_mlil_hierarchy():"""Opens a new tab showing the MLIL hierarchy which includes classes which caneasily be used with isinstance to match multiple types of IL instructions."""graph=flowgraph.FlowGraph()nodes={}forinstructioninILInstruction.values():instruction.add_subgraph(graph,nodes)show_graph_report("MLIL Class Hierarchy Graph",graph) [docs]@classmethoddefcreate(cls,func:'MediumLevelILFunction',expr_index:ExpressionIndex,instr_index:Optional[InstructionIndex]=None)->'MediumLevelILInstruction':assertfunc.archisnotNone,"Attempted to create IL instruction with function missing an Architecture"inst=core.BNGetMediumLevelILByIndex(func.handle,expr_index)assertinstisnotNone,"core.BNGetMediumLevelILByIndex returned None"ifinstr_indexisNone:instr_index=core.BNGetMediumLevelILInstructionForExpr(func.handle,expr_index)assertinstr_indexisnotNone,"core.BNGetMediumLevelILInstructionForExpr returned None"instr=CoreMediumLevelILInstruction.from_BNMediumLevelILInstruction(inst)returnILInstruction[instr.operation](func,expr_index,instr,instr_index)# type: ignore [docs]defcopy_to(self,dest:'MediumLevelILFunction',sub_expr_handler:Optional[Callable[['MediumLevelILInstruction'],ExpressionIndex]]=None)->ExpressionIndex:"""``copy_to`` deep copies an expression into a new IL function.If provided, the function ``sub_expr_handler`` will be called on every copied sub-expression.. warning:: This function should ONLY be called as a part of a lifter or workflow. It will otherwise not do anything useful as analysis will not be running.:param MediumLevelILFunction dest: Function to copy the expression to:param sub_expr_handler: Optional function to call on every copied sub-expression:return: Index of the copied expression in the target function"""returnself.function.copy_expr_to(self,dest,sub_expr_handler) def__str__(self):tokens=self.tokensiftokensisNone:return"invalid"result=""fortokenintokens:result+=token.textreturnresultdef__repr__(self):returnf"<{self.__class__.__name__}:{self}>"def__eq__(self,other:'MediumLevelILInstruction')->bool:ifnotisinstance(other,MediumLevelILInstruction):returnNotImplementedreturnself.function==other.functionandself.expr_index==other.expr_indexdef__lt__(self,other:'MediumLevelILInstruction')->bool:ifnotisinstance(other,MediumLevelILInstruction):returnNotImplementedreturnself.function==other.functionandself.expr_index<other.expr_indexdef__le__(self,other:'MediumLevelILInstruction')->bool:ifnotisinstance(other,MediumLevelILInstruction):returnNotImplementedreturnself.function==other.functionandself.expr_index<=other.expr_indexdef__gt__(self,other:'MediumLevelILInstruction')->bool:ifnotisinstance(other,MediumLevelILInstruction):returnNotImplementedreturnself.function==other.functionandself.expr_index>other.expr_indexdef__ge__(self,other:'MediumLevelILInstruction')->bool:ifnotisinstance(other,MediumLevelILInstruction):returnNotImplementedreturnself.function==other.functionandself.expr_index>=other.expr_indexdef__hash__(self):returnhash((self.function,self.expr_index))@propertydefoperands(self)->List[MediumLevelILOperandType]:"""Operands for the instructionConsider using more specific APIs for ``src``, ``dest``, ``params``, etc where appropriate."""returnlist(map(lambdax:x[1],self.detailed_operands))@propertydefraw_operands(self)->OperandsType:"""Raw operand expression indices as specified by the core structure (read-only)"""returnself.instr.operands@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:"""Returns a list of tuples containing the name of the operand, the operand, and the type of the operand.Useful for iterating over all operands of an instruction and sub-instructions."""return[][docs]deftraverse(self,cb:Callable[['MediumLevelILInstruction',Any],Any],*args:Any,**kwargs:Any)->Iterator[Any]:"""``traverse`` is a generator that allows you to traverse the MediumLevelILInstruction in a depth-first manner. It will yield theresult of the callback function for each node in the tree. Arguments can be passed to the callback function using``args`` and ``kwargs``. See the `Developer Docs <https://docs.binary.ninja/dev/concepts.html#walking-ils>`_ for more examples.:param Callable[[MediumLevelILInstruction, Any], Any] cb: The callback function to call for each node in the MediumLevelILInstruction:param Any args: Custom user-defined arguments:param Any kwargs: Custom user-defined keyword arguments:return: An iterator of the results of the callback function:rtype: Iterator[Any]:Example:>>> def get_constant_less_than_value(inst: MediumLevelILInstruction, value: int) -> int:>>> if isinstance(inst, Constant) and inst.constant < value:>>> return inst.constant>>>>>> list(inst.traverse(get_constant_less_than_value, 10))"""if(result:=cb(self,*args,**kwargs))isnotNone:yieldresultfor_,op,_inself.detailed_operands:ifisinstance(op,MediumLevelILInstruction):yield fromop.traverse(cb,*args,**kwargs)elifisinstance(op,list)andall(isinstance(i,MediumLevelILInstruction)foriinop):foriinop:yield fromi.traverse(cb,*args,**kwargs)# type: ignore [docs]@deprecation.deprecated(deprecated_in="4.0.4907",details="Use :py:func:`MediumLevelILInstruction.traverse` instead.")defvisit_all(self,cb:MediumLevelILVisitorCallback,name:str="root",parent:Optional['MediumLevelILInstruction']=None)->bool:"""Visits all operands of this instruction and all operands of any sub-instructions.Using pre-order traversal.:param MediumLevelILVisitorCallback cb: Callback function that takes the name of the operand, the operand, operand type, and parent instruction:return: True if all instructions were visited, False if the callback returned False"""ifcb(name,self,"MediumLevelILInstruction",parent)==False:returnFalseforname,op,opTypeinself.detailed_operands:ifisinstance(op,MediumLevelILInstruction):ifnotop.visit_all(cb,name,self):returnFalseelifisinstance(op,list)andall(isinstance(i,MediumLevelILInstruction)foriinop):foriinop:ifnoti.visit_all(cb,name,self):# type: ignorereturnFalseelifcb(name,op,opType,self)==False:returnFalsereturnTrue [docs]@deprecation.deprecated(deprecated_in="4.0.4907",details="Use :py:func:`MediumLevelILInstruction.traverse` instead.")defvisit_operands(self,cb:MediumLevelILVisitorCallback,name:str="root",parent:Optional['MediumLevelILInstruction']=None)->bool:"""Visits all leaf operands of this instruction and any sub-instructions.:param MediumLevelILVisitorCallback cb: Callback function that takes the name of the operand, the operand, operand type, and parent instruction:return: True if all instructions were visited, False if the callback returned False"""forname,op,opTypeinself.detailed_operands:ifisinstance(op,MediumLevelILInstruction):ifnotop.visit_operands(cb,name,self):returnFalseelifisinstance(op,list)andall(isinstance(i,MediumLevelILInstruction)foriinop):foriinop:ifnoti.visit_operands(cb,name,self):# type: ignorereturnFalseelifcb(name,op,opType,self)==False:returnFalsereturnTrue [docs]@deprecation.deprecated(deprecated_in="4.0.4907",details="Use :py:func:`MediumLevelILInstruction.traverse` instead.")defvisit(self,cb:MediumLevelILVisitorCallback,name:str="root",parent:Optional['MediumLevelILInstruction']=None)->bool:"""Visits all MediumLevelILInstructions in the operands of this instruction and any sub-instructions.In the callback you provide, you likely only need to interact with the second argument (see the example below).:param MediumLevelILVisitorCallback cb: Callback function that takes the name of the operand, the operand, operand type, and parent instruction:return: True if all instructions were visited, False if the callback returned False:Example:>>> def visitor(_a, inst, _c, _d) -> bool:>>> if isinstance(inst, Constant):>>> print(f"Found constant: {inst.constant}")>>> return False # Stop recursion (once we find a constant, don't recurse in to any sub-instructions (which there won't actually be any...))>>> # Otherwise, keep recursing the subexpressions of this instruction; if no return value is provided, it'll keep descending>>>>>> # Finds all constants used in the program>>> for inst in current_mlil.instructions:>>> inst.visit(visitor)"""ifcb(name,self,"MediumLevelILInstruction",parent)==False:returnFalseforname,op,_inself.detailed_operands:ifisinstance(op,MediumLevelILInstruction):ifnotop.visit(cb,name,self):returnFalseelifisinstance(op,list)andall(isinstance(i,MediumLevelILInstruction)foriinop):foriinop:ifnoti.visit(cb,name,self):# type: ignorereturnFalsereturnTrue @propertydeftokens(self)->TokenList:"""MLIL tokens (read-only)"""# Special case for the helper instructions which don't have tokensifisinstance(self,(MediumLevelILCallParam,MediumLevelILCallParamSsa)):return[]count=ctypes.c_ulonglong()tokens=ctypes.POINTER(core.BNInstructionTextToken)()assertself.function.archisnotNone,f"type(self.function):{type(self.function)} "result=core.BNGetMediumLevelILExprText(self.function.handle,self.function.arch.handle,self.expr_index,tokens,count,None)assertresult,"core.BNGetMediumLevelILExprText returned False"try:returnfunction.InstructionTextToken._from_core_struct(tokens,count.value)finally:core.BNFreeInstructionText(tokens,count.value)@propertydefil_basic_block(self)->'MediumLevelILBasicBlock':"""IL basic block object containing this expression (read-only) (only available on finalized functions)"""core_block=core.BNGetMediumLevelILBasicBlockForInstruction(self.function.handle,self.instr_index)assertcore_blockisnotNoneassertself.function.source_functionisnotNonereturnMediumLevelILBasicBlock(core_block,self.function,self.function.source_function.view)@propertydefssa_form(self)->'MediumLevelILInstruction':"""SSA form of expression (read-only)"""ssa_func=self.function.ssa_formassertssa_funcisnotNonereturnMediumLevelILInstruction.create(ssa_func,ExpressionIndex(core.BNGetMediumLevelILSSAExprIndex(self.function.handle,self.expr_index)))@propertydefnon_ssa_form(self)->'MediumLevelILInstruction':"""Non-SSA form of expression (read-only)"""non_ssa_func=self.function.non_ssa_formassertnon_ssa_funcisnotNonereturnMediumLevelILInstruction.create(non_ssa_func,ExpressionIndex(core.BNGetMediumLevelILNonSSAExprIndex(self.function.handle,self.expr_index)))@propertydefvalue(self)->variable.RegisterValue:"""Value of expression if constant or a known value (read-only)"""value=core.BNGetMediumLevelILExprValue(self.function.handle,self.expr_index)result=variable.RegisterValue.from_BNRegisterValue(value,self.function.arch)returnresult@propertydefpossible_values(self)->variable.PossibleValueSet:"""Possible values of expression using path-sensitive static data flow analysis (read-only)"""value=core.BNGetMediumLevelILPossibleExprValues(self.function.handle,self.expr_index,None,0)result=variable.PossibleValueSet(self.function.arch,value)core.BNFreePossibleValueSet(value)returnresult@propertydefbranch_dependence(self)->Mapping[int,ILBranchDependence]:"""Set of branching instructions that must take the true or false path to reach this instruction"""count=ctypes.c_ulonglong()deps=core.BNGetAllMediumLevelILBranchDependence(self.function.handle,self.instr_index,count)assertdepsisnotNone,"core.BNGetAllMediumLevelILBranchDependence returned None"result={}foriinrange(0,count.value):result[deps[i].branch]=ILBranchDependence(deps[i].dependence)core.BNFreeILBranchDependenceList(deps)returnresult@propertydeflow_level_il(self)->Optional['lowlevelil.LowLevelILInstruction']:"""Low level IL form of this expression"""expr=self.function.get_low_level_il_expr_index(self.expr_index)ifexprisNoneorself.function.low_level_ilisNone:returnNonereturnlowlevelil.LowLevelILInstruction.create(self.function.low_level_il.ssa_form,expr,None)@propertydefllil(self)->Optional['lowlevelil.LowLevelILInstruction']:"""Alias for low_level_il"""returnself.low_level_il@propertydefllils(self)->List['lowlevelil.LowLevelILInstruction']:exprs=self.function.get_low_level_il_expr_indexes(self.expr_index)ifself.function.low_level_ilisNone:return[]result=[]forexprinexprs:result.append(lowlevelil.LowLevelILInstruction.create(self.function.low_level_il.ssa_form,expr,None))returnresult@propertydefhigh_level_il(self)->Optional[highlevelil.HighLevelILInstruction]:"""High level IL form of this expression"""expr=self.function.get_high_level_il_expr_index(self.expr_index)ifexprisNoneorself.function.high_level_ilisNone:returnNonereturnhighlevelil.HighLevelILInstruction.create(self.function.high_level_il,expr,False)@propertydefhlil(self)->Optional[highlevelil.HighLevelILInstruction]:"""Alias for high_level_il"""returnself.high_level_il@propertydefhlils(self)->List[highlevelil.HighLevelILInstruction]:exprs=self.function.get_high_level_il_expr_indexes(self.expr_index)result=[]ifself.function.high_level_ilisNone:returnresultforexprinexprs:result.append(highlevelil.HighLevelILInstruction.create(self.function.high_level_il,expr,False))returnresult@propertydefssa_memory_version(self)->int:"""Version of active memory contents in SSA form for this instruction"""returncore.BNGetMediumLevelILSSAMemoryVersionAtILInstruction(self.function.handle,self.instr_index)@propertydefssa_memory_version_after(self)->int:"""Version of active memory contents in SSA form after this instruction"""returncore.BNGetMediumLevelILSSAMemoryVersionAfterILInstruction(self.function.handle,self.instr_index)@propertydefprefix_operands(self)->List[MediumLevelILOperandType]:"""All operands in the expression tree in prefix order"""result:List[MediumLevelILOperandType]=[MediumLevelILOperationAndSize(self.operation,self.size)]foroperandinself.operands:ifisinstance(operand,MediumLevelILInstruction):result.extend(operand.prefix_operands)else:result.append(operand)returnresult@propertydefpostfix_operands(self)->List[MediumLevelILOperandType]:"""All operands in the expression tree in postfix order"""result:List[MediumLevelILOperandType]=[]foroperandinself.operands:ifisinstance(operand,MediumLevelILInstruction):result.extend(operand.postfix_operands)else:result.append(operand)result.append(MediumLevelILOperationAndSize(self.operation,self.size))returnresult@propertydefinstruction_operands(self)->List['MediumLevelILInstruction']:return[iforiinself.operandsifisinstance(i,MediumLevelILInstruction)]@propertydefvars_written(self)->List[Union[variable.Variable,SSAVariable]]:"""List of variables written by instruction"""return[]@propertydefvars_read(self)->List[Union[variable.Variable,SSAVariable]]:"""List of variables read by instruction"""result=[]foroperandinself.operands:ifisinstance(operand,(variable.Variable,SSAVariable)):result.append(operand)elifisinstance(operand,MediumLevelILInstruction):result+=operand.vars_readreturnresult@propertydefvars_address_taken(self)->List[Union[variable.Variable,SSAVariable]]:"""Non-unique list of variables whose address is taken by instruction"""result=[]foroperandinself.instruction_operands:result.extend(operand.vars_address_taken)returnresult@propertydefexpr_type(self)->Optional['types.Type']:"""Type of expression"""result=core.BNGetMediumLevelILExprType(self.function.handle,self.expr_index)ifresult.type:platform=Noneifself.function.source_function:platform=self.function.source_function.platformreturntypes.Type.create(result.type,platform=platform,confidence=result.confidence)returnNone@propertydefattributes(self)->Set[ILInstructionAttribute]:"""The set of optional attributes placed on the instruction"""result:Set[ILInstructionAttribute]=set()forflaginILInstructionAttribute:ifself.instr.attributes&flag.value!=0:result.add(flag)returnresult@staticmethoddef_make_options_array(options:Optional[List[DataFlowQueryOption]]):ifoptionsisNone:options=[]idx=0option_array=(ctypes.c_int*len(options))()foroptioninoptions:option_array[idx]=optionidx+=1returnoption_array,len(options)[docs]defget_possible_values(self,options:Optional[List[DataFlowQueryOption]]=None)->variable.PossibleValueSet:option_array,size=MediumLevelILInstruction._make_options_array(options)value=core.BNGetMediumLevelILPossibleExprValues(self.function.handle,self.expr_index,option_array,size)result=variable.PossibleValueSet(self.function.arch,value)core.BNFreePossibleValueSet(value)returnresult [docs]defget_ssa_var_possible_values(self,ssa_var:SSAVariable,options:List[DataFlowQueryOption]=[]):var_data=ssa_var.var.to_BNVariable()option_array,size=MediumLevelILInstruction._make_options_array(options)value=core.BNGetMediumLevelILPossibleSSAVarValues(self.function.handle,var_data,ssa_var.version,self.instr_index,option_array,size)result=variable.PossibleValueSet(self.function.arch,value)core.BNFreePossibleValueSet(value)returnresult [docs]defget_ssa_var_version(self,var:variable.Variable)->int:var_data=var.to_BNVariable()returncore.BNGetMediumLevelILSSAVarVersionAtILInstruction(self.function.handle,var_data,self.instr_index) [docs]defget_ssa_var_version_after(self,var:variable.Variable)->int:var_data=var.to_BNVariable()returncore.BNGetMediumLevelILSSAVarVersionAfterILInstruction(self.function.handle,var_data,self.instr_index) [docs]defget_var_for_reg(self,reg:'architecture.RegisterType')->variable.Variable:reg=self.function.arch.get_reg_index(reg)result=core.BNGetMediumLevelILVariableForRegisterAtInstruction(self.function.handle,reg,self.instr_index)returnvariable.Variable.from_BNVariable(self.function,result) [docs]defget_var_for_reg_after(self,reg:'architecture.RegisterType')->variable.Variable:reg=self.function.arch.get_reg_index(reg)result=core.BNGetMediumLevelILVariableForRegisterAfterInstruction(self.function.handle,reg,self.instr_index)returnvariable.Variable.from_BNVariable(self.function,result) [docs]defget_var_for_flag(self,flag:'architecture.FlagType')->variable.Variable:flag=self.function.arch.get_flag_index(flag)result=core.BNGetMediumLevelILVariableForFlagAtInstruction(self.function.handle,flag,self.instr_index)returnvariable.Variable.from_BNVariable(self.function,result) [docs]defget_var_for_flag_after(self,flag:'architecture.FlagType')->variable.Variable:flag=self.function.arch.get_flag_index(flag)result=core.BNGetMediumLevelILVariableForFlagAfterInstruction(self.function.handle,flag,self.instr_index)returnvariable.Variable.from_BNVariable(self.function,result) [docs]defget_var_for_stack_location(self,offset:int)->variable.Variable:result=core.BNGetMediumLevelILVariableForStackLocationAtInstruction(self.function.handle,offset,self.instr_index)returnvariable.Variable.from_BNVariable(self.function,result) [docs]defget_var_for_stack_location_after(self,offset:int)->variable.Variable:result=core.BNGetMediumLevelILVariableForStackLocationAfterInstruction(self.function.handle,offset,self.instr_index)returnvariable.Variable.from_BNVariable(self.function,result) [docs]defget_reg_value(self,reg:'architecture.RegisterType')->'variable.RegisterValue':reg=self.function.arch.get_reg_index(reg)value=core.BNGetMediumLevelILRegisterValueAtInstruction(self.function.handle,reg,self.instr_index)result=variable.RegisterValue.from_BNRegisterValue(value,self.function.arch)returnresult [docs]defget_reg_value_after(self,reg:'architecture.RegisterType')->'variable.RegisterValue':reg=self.function.arch.get_reg_index(reg)value=core.BNGetMediumLevelILRegisterValueAfterInstruction(self.function.handle,reg,self.instr_index)result=variable.RegisterValue.from_BNRegisterValue(value,self.function.arch)returnresult [docs]defget_possible_reg_values(self,reg:'architecture.RegisterType',options:Optional[List[DataFlowQueryOption]]=None)->'variable.PossibleValueSet':option_array,size=MediumLevelILInstruction._make_options_array(options)reg=self.function.arch.get_reg_index(reg)value=core.BNGetMediumLevelILPossibleRegisterValuesAtInstruction(self.function.handle,reg,self.instr_index,option_array,size)result=variable.PossibleValueSet(self.function.arch,value)core.BNFreePossibleValueSet(value)returnresult [docs]defget_possible_reg_values_after(self,reg:'architecture.RegisterType',options:Optional[List[DataFlowQueryOption]]=None)->'variable.PossibleValueSet':reg=self.function.arch.get_reg_index(reg)option_array,size=MediumLevelILInstruction._make_options_array(options)value=core.BNGetMediumLevelILPossibleRegisterValuesAfterInstruction(self.function.handle,reg,self.instr_index,option_array,size)result=variable.PossibleValueSet(self.function.arch,value)core.BNFreePossibleValueSet(value)returnresult [docs]defget_flag_value(self,flag:'architecture.FlagType')->'variable.RegisterValue':flag=self.function.arch.get_flag_index(flag)value=core.BNGetMediumLevelILFlagValueAtInstruction(self.function.handle,flag,self.instr_index)result=variable.RegisterValue.from_BNRegisterValue(value,self.function.arch)returnresult [docs]defget_flag_value_after(self,flag:'architecture.FlagType')->'variable.RegisterValue':flag=self.function.arch.get_flag_index(flag)value=core.BNGetMediumLevelILFlagValueAfterInstruction(self.function.handle,flag,self.instr_index)result=variable.RegisterValue.from_BNRegisterValue(value,self.function.arch)returnresult [docs]defget_possible_flag_values(self,flag:'architecture.FlagType',options:Optional[List[DataFlowQueryOption]]=None)->'variable.PossibleValueSet':flag=self.function.arch.get_flag_index(flag)option_array,size=MediumLevelILInstruction._make_options_array(options)value=core.BNGetMediumLevelILPossibleFlagValuesAtInstruction(self.function.handle,flag,self.instr_index,option_array,size)result=variable.PossibleValueSet(self.function.arch,value)core.BNFreePossibleValueSet(value)returnresult [docs]defget_possible_flag_values_after(self,flag:'architecture.FlagType',options:Optional[List[DataFlowQueryOption]]=None)->'variable.PossibleValueSet':flag=self.function.arch.get_flag_index(flag)option_array,size=MediumLevelILInstruction._make_options_array(options)value=core.BNGetMediumLevelILPossibleFlagValuesAfterInstruction(self.function.handle,flag,self.instr_index,option_array,size)result=variable.PossibleValueSet(self.function.arch,value)core.BNFreePossibleValueSet(value)returnresult [docs]defget_stack_contents(self,offset:int,size:int)->'variable.RegisterValue':value=core.BNGetMediumLevelILStackContentsAtInstruction(self.function.handle,offset,size,self.instr_index)result=variable.RegisterValue.from_BNRegisterValue(value,self.function.arch)returnresult [docs]defget_stack_contents_after(self,offset:int,size:int)->'variable.RegisterValue':value=core.BNGetMediumLevelILStackContentsAfterInstruction(self.function.handle,offset,size,self.instr_index)result=variable.RegisterValue.from_BNRegisterValue(value,self.function.arch)returnresult [docs]defget_possible_stack_contents(self,offset:int,size:int,options:Optional[List[DataFlowQueryOption]]=None)->'variable.PossibleValueSet':option_array,option_size=MediumLevelILInstruction._make_options_array(options)value=core.BNGetMediumLevelILPossibleStackContentsAtInstruction(self.function.handle,offset,size,self.instr_index,option_array,option_size)result=variable.PossibleValueSet(self.function.arch,value)core.BNFreePossibleValueSet(value)returnresult [docs]defget_possible_stack_contents_after(self,offset:int,size:int,options:Optional[List[DataFlowQueryOption]]=None)->'variable.PossibleValueSet':option_array,option_size=MediumLevelILInstruction._make_options_array(options)value=core.BNGetMediumLevelILPossibleStackContentsAfterInstruction(self.function.handle,offset,size,self.instr_index,option_array,option_size)result=variable.PossibleValueSet(self.function.arch,value)core.BNFreePossibleValueSet(value)returnresult [docs]defget_branch_dependence(self,branch_instr:int)->ILBranchDependence:returnILBranchDependence(core.BNGetMediumLevelILBranchDependence(self.function.handle,self.instr_index,branch_instr)) [docs]defget_split_var_for_definition(self,var:variable.Variable)->variable.Variable:"""Gets the unique variable for a definition instruction. This unique variable can be passedto ``Function.split_var`` to split a variable at a definition. The given ``var`` is theassigned variable to query.:param Variable var: variable to query:rtype: Variable"""returnvariable.Variable(self.function.source_function,var.source_type,core.BNGetDefaultIndexForMediumLevelILVariableDefinition(self.function.handle,var.to_BNVariable(),self.instr_index),var.storage) @propertydefoperation(self)->MediumLevelILOperation:returnself.instr.operation@propertydefsize(self)->int:returnself.instr.size@propertydefaddress(self)->int:returnself.instr.address@propertydefsource_operand(self)->ExpressionIndex:returnExpressionIndex(self.instr.source_operand)@propertydefsource_location(self)->ILSourceLocation:returnILSourceLocation.from_instruction(self)@propertydefcore_operands(self)->OperandsType:returnself.instr.operandsdef_get_int(self,operand_index:int)->int:value=self.instr.operands[operand_index]return(value&((1<<63)-1))-(value&(1<<63))def_get_float(self,operand_index:int)->float:value=self.instr.operands[operand_index]ifself.instr.size==4:returnstruct.unpack("f",struct.pack("I",value&0xffffffff))[0]elifself.instr.size==8:returnstruct.unpack("d",struct.pack("Q",value))[0]else:returnfloat(value)def_get_constant_data(self,operand_index1:int,operand_index2:int)->variable.ConstantData:state=variable.RegisterValueType(self.instr.operands[operand_index1])value=self.instr.operands[operand_index2]returnvariable.ConstantData(value,0,state,core.max_confidence,self.instr.size,self.function.source_function)def_get_expr(self,operand_index:int)->'MediumLevelILInstruction':returnMediumLevelILInstruction.create(self.function,ExpressionIndex(self.instr.operands[operand_index]))def_get_intrinsic(self,operand_index:int)->'lowlevelil.ILIntrinsic':assertself.function.archisnotNone,"Attempting to create ILIntrinsic from function with no Architecture"returnlowlevelil.ILIntrinsic(self.function.arch,architecture.IntrinsicIndex(self.instr.operands[operand_index]))def_get_var(self,operand_index:int)->variable.Variable:value=self.instr.operands[operand_index]returnvariable.Variable.from_identifier(self.function,value)def_get_var_ssa(self,operand_index1:int,operand_index2:int)->SSAVariable:var=variable.Variable.from_identifier(self.function,self.instr.operands[operand_index1])version=self.instr.operands[operand_index2]returnSSAVariable(var,version)def_get_var_ssa_dest_and_src(self,operand_index1:int,operand_index2:int)->SSAVariable:var=variable.Variable.from_identifier(self.function,self.instr.operands[operand_index1])dest_version=self.instr.operands[operand_index2]returnSSAVariable(var,dest_version)def_get_int_list(self,operand_index:int)->List[int]:count=ctypes.c_ulonglong()operand_list=core.BNMediumLevelILGetOperandList(self.function.handle,self.expr_index,operand_index,count)assertoperand_listisnotNone,"core.BNMediumLevelILGetOperandList returned None"value:List[int]=[]try:forjinrange(count.value):value.append(operand_list[j])returnvaluefinally:core.BNMediumLevelILFreeOperandList(operand_list)def_get_var_list(self,operand_index1:int,operand_index2:int)->List[variable.Variable]:# We keep this extra parameter around because when this function is called# the subclasses that call this don't use the next operand# without this parameter it looks like this operand is being skipped unintentionally# rather this operand is being skipped intentionally._=operand_index2count=ctypes.c_ulonglong()operand_list=core.BNMediumLevelILGetOperandList(self.function.handle,self.expr_index,operand_index1,count)assertoperand_listisnotNone,"core.BNMediumLevelILGetOperandList returned None"value:List[variable.Variable]=[]try:forjinrange(count.value):value.append(variable.Variable.from_identifier(self.function,operand_list[j]))returnvaluefinally:core.BNMediumLevelILFreeOperandList(operand_list)def_get_var_ssa_list(self,operand_index1:int,_:int)->List[SSAVariable]:count=ctypes.c_ulonglong()operand_list=core.BNMediumLevelILGetOperandList(self.function.handle,self.expr_index,operand_index1,count)assertoperand_listisnotNone,"core.BNMediumLevelILGetOperandList returned None"value=[]try:forjinrange(count.value//2):var_id=operand_list[j*2]var_version=operand_list[(j*2)+1]value.append(SSAVariable(variable.Variable.from_identifier(self.function,var_id),var_version))returnvaluefinally:core.BNMediumLevelILFreeOperandList(operand_list)def_get_expr_list(self,operand_index1:int,_:int)->List['MediumLevelILInstruction']:count=ctypes.c_ulonglong()operand_list=core.BNMediumLevelILGetOperandList(self.function.handle,self.expr_index,operand_index1,count)assertoperand_listisnotNone,"core.BNMediumLevelILGetOperandList returned None"value:List['MediumLevelILInstruction']=[]try:forjinrange(count.value):value.append(MediumLevelILInstruction.create(self.function,operand_list[j],None))returnvaluefinally:core.BNMediumLevelILFreeOperandList(operand_list)def_get_target_map(self,operand_index1:int,_:int)->Dict[int,int]:count=ctypes.c_ulonglong()operand_list=core.BNMediumLevelILGetOperandList(self.function.handle,self.expr_index,operand_index1,count)assertoperand_listisnotNone,"core.BNMediumLevelILGetOperandList returned None"value:Dict[int,int]={}try:forjinrange(count.value//2):key=operand_list[j*2]target=operand_list[(j*2)+1]value[key]=targetreturnvaluefinally:core.BNMediumLevelILFreeOperandList(operand_list)def_get_constraint(self,operand_index:int)->variable.PossibleValueSet:value=core.BNGetCachedMediumLevelILPossibleValueSet(self.function.handle,self.instr.operands[operand_index])result=variable.PossibleValueSet(self.function.arch,value)core.BNFreePossibleValueSet(value)returnresult [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILConstBase(MediumLevelILInstruction,Constant):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILCallBase(MediumLevelILInstruction,Call):@propertydefoutput(self)->List[Union[SSAVariable,variable.Variable]]:returnNotImplemented@propertydefvars_written(self)->List[Union[SSAVariable,variable.Variable]]:returnself.output@propertydefparams(self)->List[Union[SSAVariable,variable.Variable,MediumLevelILInstruction]]:returnNotImplemented@propertydefvars_read(self)->List[Union[SSAVariable,variable.Variable]]:result=[]forparaminself.params:ifisinstance(param,MediumLevelILInstruction):result.extend(param.vars_read)elifisinstance(param,(variable.Variable,SSAVariable)):result.append(param)else:assertFalse,"Call.params returned object other than Variable, SSAVariable or MediumLevelILInstruction"returnresult [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILUnaryBase(MediumLevelILInstruction,UnaryOperation):@propertydefsrc(self)->MediumLevelILInstruction:returnself._get_expr(0)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("src",self.src,"MediumLevelILInstruction")] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILBinaryBase(MediumLevelILInstruction,BinaryOperation):@propertydefleft(self)->MediumLevelILInstruction:returnself._get_expr(0)@propertydefright(self)->MediumLevelILInstruction:returnself._get_expr(1)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("left",self.left,"MediumLevelILInstruction"),("right",self.right,"MediumLevelILInstruction"),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILComparisonBase(MediumLevelILBinaryBase,Comparison):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILCarryBase(MediumLevelILInstruction,Carry):@propertydefleft(self)->MediumLevelILInstruction:returnself._get_expr(0)@propertydefright(self)->MediumLevelILInstruction:returnself._get_expr(1)@propertydefcarry(self)->MediumLevelILInstruction:returnself._get_expr(2)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("left",self.left,"MediumLevelILInstruction"),("right",self.right,"MediumLevelILInstruction"),("carry",self.carry,"MediumLevelILInstruction"),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILNop(MediumLevelILInstruction):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILNoret(MediumLevelILInstruction,Terminal):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILBp(MediumLevelILInstruction,Terminal):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILUndef(MediumLevelILInstruction):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILUnimpl(MediumLevelILInstruction):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILLoad(MediumLevelILInstruction,Load):@propertydefsrc(self)->MediumLevelILInstruction:returnself._get_expr(0)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("src",self.src,"MediumLevelILInstruction")] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILVar(MediumLevelILInstruction,VariableInstruction):@propertydefsrc(self)->variable.Variable:returnself._get_var(0)@propertydefvar(self)->variable.Variable:returnself._get_var(0)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("var",self.var,"Variable")] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILAddressOf(MediumLevelILInstruction):@propertydefsrc(self)->variable.Variable:returnself._get_var(0)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("src",self.src,"Variable")]@propertydefvars_address_taken(self)->List[variable.Variable]:return[self.src] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILConst(MediumLevelILConstBase):@propertydefconstant(self)->int:returnself._get_int(0)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("constant",self.constant,"int")] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILConstPtr(MediumLevelILConstBase):@propertydefconstant(self)->int:returnself._get_int(0)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("constant",self.constant,"int")]@propertydefstring(self)->Optional[Tuple[str,StringType]]:returnself.function.view.check_for_string_annotation_type(self.constant,True,True,0) [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILFloatConst(MediumLevelILConstBase,FloatingPoint):@propertydefconstant(self)->float:returnself._get_float(0)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("constant",self.constant,"float")] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILImport(MediumLevelILConstBase):@propertydefconstant(self)->int:returnself._get_int(0)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("constant",self.constant,"int")] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILConstData(MediumLevelILConstBase):@propertydefconstant(self)->variable.ConstantData:returnself._get_constant_data(0,1)@propertydefconstant_data(self)->variable.ConstantData:returnself._get_constant_data(0,1)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("constant",self.constant,"ConstantData")] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILNeg(MediumLevelILUnaryBase,Arithmetic):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILNot(MediumLevelILUnaryBase,Arithmetic):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILSx(MediumLevelILUnaryBase,Arithmetic):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILZx(MediumLevelILUnaryBase,Arithmetic):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILLowPart(MediumLevelILUnaryBase,Arithmetic):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILJump(MediumLevelILInstruction,Terminal):@propertydefdest(self)->MediumLevelILInstruction:returnself._get_expr(0)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("dest",self.dest,"MediumLevelILInstruction")] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILRetHint(MediumLevelILInstruction,ControlFlow):@propertydefdest(self)->MediumLevelILInstruction:returnself._get_expr(0)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("dest",self.dest,"MediumLevelILInstruction")] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILCallOutput(MediumLevelILInstruction):@propertydefdest(self)->List[variable.Variable]:returnself._get_var_list(0,1)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("dest",self.dest,"List[Variable]")]@propertydefvars_written(self)->List[variable.Variable]:returnself.dest [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILCallParam(MediumLevelILInstruction):def__repr__(self):returnf"<MediumLevelILCallParam:{self.src}>"@propertydefsrc(self)->List[MediumLevelILInstruction]:returnself._get_expr_list(0,1)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("src",self.src,"List[MediumLevelILInstruction]")] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILSeparateParamList(MediumLevelILInstruction):def__repr__(self):returnf"<MediumLevelILSeparateParamList:{self.params}>"@propertydefparams(self)->List[MediumLevelILInstruction]:returnself._get_expr_list(0,1)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("params",self.params,"List[MediumLevelILInstruction]")] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILSharedParamSlot(MediumLevelILInstruction):def__repr__(self):returnf"<MediumLevelILSharedParamSlot:{self.params}>"@propertydefparams(self)->List[MediumLevelILInstruction]:returnself._get_expr_list(0,1)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("params",self.params,"List[MediumLevelILInstruction]")] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILRet(MediumLevelILInstruction,Return):@propertydefsrc(self)->List[MediumLevelILInstruction]:returnself._get_expr_list(0,1)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("src",self.src,"List[MediumLevelILInstruction]")] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILGoto(MediumLevelILInstruction,Terminal):@propertydefdest(self)->InstructionIndex:returnInstructionIndex(self._get_int(0))@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("dest",self.dest,"InstructionIndex")] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILBoolToInt(MediumLevelILInstruction):@propertydefsrc(self)->MediumLevelILInstruction:returnself._get_expr(0)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("src",self.src,"MediumLevelILInstruction")] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILFreeVarSlot(MediumLevelILInstruction,RegisterStack):@propertydefdest(self)->variable.Variable:returnself._get_var(0)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("dest",self.dest,"Variable")] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILTrap(MediumLevelILInstruction,Terminal):@propertydefvector(self)->int:returnself._get_int(0)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("vector",self.vector,"int")] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILFreeVarSlotSsa(MediumLevelILInstruction,SSA,RegisterStack):@propertydefdest(self)->SSAVariable:returnself._get_var_ssa_dest_and_src(0,1)@propertydefprev(self)->SSAVariable:returnself._get_var_ssa_dest_and_src(0,2)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("dest",self.dest,"SSAVariable"),("prev",self.prev,"SSAVariable"),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILUnimplMem(MediumLevelILInstruction,Memory):@propertydefsrc(self)->MediumLevelILInstruction:returnself._get_expr(0)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("src",self.src,"MediumLevelILInstruction")] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILFsqrt(MediumLevelILUnaryBase,Arithmetic,FloatingPoint):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILFneg(MediumLevelILUnaryBase,Arithmetic,FloatingPoint):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILFabs(MediumLevelILUnaryBase,Arithmetic,FloatingPoint):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILFloatToInt(MediumLevelILUnaryBase,Arithmetic,FloatingPoint):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILIntToFloat(MediumLevelILUnaryBase,Arithmetic,FloatingPoint):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILFloatConv(MediumLevelILUnaryBase,Arithmetic,FloatingPoint):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILRoundToInt(MediumLevelILUnaryBase,Arithmetic,FloatingPoint):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILFloor(MediumLevelILUnaryBase,Arithmetic,FloatingPoint):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILCeil(MediumLevelILUnaryBase,Arithmetic,FloatingPoint):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILFtrunc(MediumLevelILUnaryBase,Arithmetic,FloatingPoint):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILVarSsa(MediumLevelILInstruction,SSAVariableInstruction):@propertydefsrc(self)->SSAVariable:returnself._get_var_ssa(0,1)@propertydefvar(self)->SSAVariable:returnself._get_var_ssa(0,1)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("var",self.var,"SSAVariable")] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILVarAliased(MediumLevelILInstruction,SSA,AliasedVariableInstruction):@propertydefsrc(self)->SSAVariable:returnself._get_var_ssa(0,1)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("src",self.src,"SSAVariable")] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILSetVar(MediumLevelILInstruction,SetVar):@propertydefdest(self)->variable.Variable:returnself._get_var(0)@propertydefsrc(self)->MediumLevelILInstruction:returnself._get_expr(1)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("dest",self.dest,"Variable"),("src",self.src,"MediumLevelILInstruction"),]@propertydefvars_written(self)->List[variable.Variable]:return[self.dest]@propertydefvars_read(self)->List[Union[variable.Variable,SSAVariable]]:returnself.src.vars_read [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILLoadStruct(MediumLevelILInstruction,Load):@propertydefsrc(self)->MediumLevelILInstruction:returnself._get_expr(0)@propertydefoffset(self)->int:returnself._get_int(1)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("src",self.src,"MediumLevelILInstruction"),("offset",self.offset,"int"),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILStore(MediumLevelILInstruction,Store):@propertydefdest(self)->MediumLevelILInstruction:returnself._get_expr(0)@propertydefsrc(self)->MediumLevelILInstruction:returnself._get_expr(1)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("dest",self.dest,"MediumLevelILInstruction"),("src",self.src,"MediumLevelILInstruction"),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILVarField(MediumLevelILInstruction):@propertydefsrc(self)->variable.Variable:returnself._get_var(0)@propertydefoffset(self)->int:returnself._get_int(1)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("src",self.src,"Variable"),("offset",self.offset,"int"),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILVarSplit(MediumLevelILInstruction):@propertydefhigh(self)->variable.Variable:returnself._get_var(0)@propertydeflow(self)->variable.Variable:returnself._get_var(1)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("high",self.high,"Variable"),("low",self.low,"Variable"),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILAddressOfField(MediumLevelILInstruction):@propertydefsrc(self)->variable.Variable:returnself._get_var(0)@propertydefoffset(self)->int:returnself._get_int(1)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("src",self.src,"Variable"),("offset",self.offset,"int")] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILExternPtr(MediumLevelILConstBase):@propertydefconstant(self)->int:returnself._get_int(0)@propertydefoffset(self)->int:returnself._get_int(1)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("constant",self.constant,"int"),("offset",self.offset,"int"),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILAdd(MediumLevelILBinaryBase,Arithmetic):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILSub(MediumLevelILBinaryBase,Arithmetic):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILAnd(MediumLevelILBinaryBase,Arithmetic):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILOr(MediumLevelILBinaryBase,Arithmetic):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILXor(MediumLevelILBinaryBase,Arithmetic):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILLsl(MediumLevelILBinaryBase,Arithmetic):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILLsr(MediumLevelILBinaryBase,Arithmetic):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILAsr(MediumLevelILBinaryBase,Arithmetic):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILRol(MediumLevelILBinaryBase,Arithmetic):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILRor(MediumLevelILBinaryBase,Arithmetic):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILMul(MediumLevelILBinaryBase,Arithmetic):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILMuluDp(MediumLevelILBinaryBase,DoublePrecision):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILMulsDp(MediumLevelILBinaryBase,DoublePrecision,Signed):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILDivu(MediumLevelILBinaryBase,Arithmetic):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILDivuDp(MediumLevelILBinaryBase,DoublePrecision):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILDivs(MediumLevelILBinaryBase,Arithmetic,Signed):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILDivsDp(MediumLevelILBinaryBase,DoublePrecision,Signed):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILModu(MediumLevelILBinaryBase,Arithmetic):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILModuDp(MediumLevelILBinaryBase,DoublePrecision):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILMods(MediumLevelILBinaryBase,Arithmetic,Signed):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILModsDp(MediumLevelILBinaryBase,DoublePrecision,Signed):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILCmpE(MediumLevelILComparisonBase):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILCmpNe(MediumLevelILComparisonBase):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILCmpSlt(MediumLevelILComparisonBase,Signed):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILCmpUlt(MediumLevelILComparisonBase):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILCmpSle(MediumLevelILComparisonBase,Signed):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILCmpUle(MediumLevelILComparisonBase):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILCmpSge(MediumLevelILComparisonBase,Signed):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILCmpUge(MediumLevelILComparisonBase):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILCmpSgt(MediumLevelILComparisonBase,Signed):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILCmpUgt(MediumLevelILComparisonBase):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILTestBit(MediumLevelILComparisonBase):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILAddOverflow(MediumLevelILBinaryBase,Arithmetic):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILSyscall(MediumLevelILInstruction,Syscall):@propertydefoutput(self)->List[variable.Variable]:returnself._get_var_list(0,1)@propertydefparams(self)->List[MediumLevelILInstruction]:returnself._get_expr_list(2,3)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('output',self.output,'List[Variable]'),('params',self.params,'List[MediumLevelILInstruction]'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILVarSsaField(MediumLevelILInstruction,SSA):@propertydefsrc(self)->SSAVariable:returnself._get_var_ssa(0,1)@propertydefoffset(self)->int:returnself._get_int(2)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('src',self.src,'SSAVariable'),('offset',self.offset,'int'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILVarAliasedField(MediumLevelILInstruction,SSA):@propertydefsrc(self)->SSAVariable:returnself._get_var_ssa(0,1)@propertydefoffset(self)->int:returnself._get_int(2)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('src',self.src,'SSAVariable'),('offset',self.offset,'int'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILVarSplitSsa(MediumLevelILInstruction,SSA):@propertydefhigh(self)->SSAVariable:returnself._get_var_ssa(0,1)@propertydeflow(self)->SSAVariable:returnself._get_var_ssa(2,3)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('high',self.high,'SSAVariable'),('low',self.low,'SSAVariable'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILCallOutputSsa(MediumLevelILInstruction,SSA):@propertydefdest_memory(self)->int:returnself._get_int(0)@propertydefdest(self)->List[SSAVariable]:returnself._get_var_ssa_list(1,2)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('dest_memory',self.dest_memory,'int'),('dest',self.dest,'List[SSAVariable]'),]@propertydefvars_written(self)->List[SSAVariable]:returnself.dest [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILCallParamSsa(MediumLevelILInstruction,SSA):def__repr__(self):returnf"<MediumLevelILCallParamSsa:{self.src}>"@propertydefsrc_memory(self)->int:returnself._get_int(0)@propertydefsrc(self)->List[MediumLevelILInstruction]:returnself._get_expr_list(1,2)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('src_memory',self.src_memory,'int'),('src',self.src,'List[MediumLevelILInstruction]'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILLoadSsa(MediumLevelILInstruction,Load,SSA):@propertydefsrc(self)->MediumLevelILInstruction:returnself._get_expr(0)@propertydefsrc_memory(self)->int:returnself._get_int(1)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('src',self.src,'MediumLevelILInstruction'),('src_memory',self.src_memory,'int'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILVarPhi(MediumLevelILInstruction,SetVar,Phi,SSA):@propertydefdest(self)->SSAVariable:returnself._get_var_ssa(0,1)@propertydefsrc(self)->List[SSAVariable]:returnself._get_var_ssa_list(2,3)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('dest',self.dest,'SSAVariable'),('src',self.src,'List[SSAVariable]'),]@propertydefvars_read(self)->List[SSAVariable]:returnself.src@propertydefvars_written(self)->List[SSAVariable]:return[self.dest] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILMemPhi(MediumLevelILInstruction,Memory,Phi):@propertydefdest_memory(self)->int:returnself._get_int(0)@propertydefsrc_memory(self)->List[int]:returnself._get_int_list(1)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('dest_memory',self.dest_memory,'int'),('src_memory',self.src_memory,'List[int]'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILSetVarSsa(MediumLevelILInstruction,SetVar,SSA):@propertydefdest(self)->SSAVariable:returnself._get_var_ssa(0,1)@propertydefsrc(self)->MediumLevelILInstruction:returnself._get_expr(2)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('dest',self.dest,'SSAVariable'),('src',self.src,'MediumLevelILInstruction'),]@propertydefvars_read(self)->List[Union[variable.Variable,SSAVariable]]:returnself.src.vars_read@propertydefvars_written(self)->List[SSAVariable]:return[self.dest] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILFcmpE(MediumLevelILComparisonBase,FloatingPoint):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILFcmpNe(MediumLevelILComparisonBase,FloatingPoint):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILFcmpLt(MediumLevelILComparisonBase,FloatingPoint):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILFcmpLe(MediumLevelILComparisonBase,FloatingPoint):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILFcmpGe(MediumLevelILComparisonBase,FloatingPoint):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILFcmpGt(MediumLevelILComparisonBase,FloatingPoint):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILFcmpO(MediumLevelILComparisonBase,FloatingPoint):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILFcmpUo(MediumLevelILComparisonBase,FloatingPoint):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILFadd(MediumLevelILBinaryBase,Arithmetic,FloatingPoint):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILFsub(MediumLevelILBinaryBase,Arithmetic,FloatingPoint):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILFmul(MediumLevelILBinaryBase,Arithmetic,FloatingPoint):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILFdiv(MediumLevelILBinaryBase,Arithmetic,FloatingPoint):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILJumpTo(MediumLevelILInstruction,Terminal):@propertydefdest(self)->MediumLevelILInstruction:returnself._get_expr(0)@propertydeftargets(self)->Dict[int,int]:returnself._get_target_map(1,2)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('dest',self.dest,'MediumLevelILInstruction'),('targets',self.targets,'Dict[int, int]'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILSetVarAliased(MediumLevelILInstruction,SetVar,SSA):@propertydefdest(self)->SSAVariable:returnself._get_var_ssa_dest_and_src(0,1)@propertydefprev(self)->SSAVariable:returnself._get_var_ssa_dest_and_src(0,2)@propertydefsrc(self)->MediumLevelILInstruction:returnself._get_expr(3)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('dest',self.dest,'SSAVariable'),('prev',self.prev,'SSAVariable'),('src',self.src,'MediumLevelILInstruction'),]@propertydefvars_read(self)->List[Union[variable.Variable,SSAVariable]]:returnself.src.vars_read@propertydefvars_written(self)->List[SSAVariable]:return[self.dest] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILSyscallUntyped(MediumLevelILCallBase,Syscall):@propertydefoutput(self)->List[variable.Variable]:inst=self._get_expr(0)assertisinstance(inst,MediumLevelILCallOutput),"MediumLevelILCallUntyped return bad type for 'output'"returninst.dest@propertydefparams(self)->List[MediumLevelILInstruction]:inst=self._get_expr(1)assertisinstance(inst,MediumLevelILCallParam),"MediumLevelILCallUntyped return bad type for 'params'"returninst.src@propertydefstack(self)->MediumLevelILInstruction:returnself._get_expr(2)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('output',self.output,'List[Variable]'),('params',self.params,'List[MediumLevelILInstruction]'),('stack',self.stack,'MediumLevelILInstruction'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILIntrinsic(MediumLevelILInstruction,Intrinsic):@propertydefoutput(self)->List[variable.Variable]:returnself._get_var_list(0,1)@propertydefintrinsic(self)->'lowlevelil.ILIntrinsic':returnself._get_intrinsic(2)@propertydefparams(self)->List[MediumLevelILInstruction]:returnself._get_expr_list(3,4)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('output',self.output,'List[Variable]'),('intrinsic',self.intrinsic,"ILIntrinsic"),('params',self.params,'List[MediumLevelILInstruction]'),]@propertydefvars_read(self)->List[variable.Variable]:result:List[variable.Variable]=[]foriinself.params:result.extend(i.vars_read)# type: ignorereturnresult@propertydefvars_written(self)->List[variable.Variable]:returnself.output [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILIntrinsicSsa(MediumLevelILInstruction,SSA):@propertydefoutput(self)->List[SSAVariable]:returnself._get_var_ssa_list(0,1)@propertydefintrinsic(self)->'lowlevelil.ILIntrinsic':returnself._get_intrinsic(2)@propertydefparams(self)->List[MediumLevelILInstruction]:returnself._get_expr_list(3,4)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('output',self.output,'List[SSAVariable]'),('intrinsic',self.intrinsic,'ILIntrinsic'),('params',self.params,'List[MediumLevelILInstruction]'),]@propertydefvars_read(self)->List[SSAVariable]:result:List[SSAVariable]=[]foriinself.params:result.extend(i.vars_read)# type: ignorereturnresult@propertydefvars_written(self)->List[SSAVariable]:returnself.output [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILMemoryIntrinsicOutputSsa(MediumLevelILInstruction,SSA):def__repr__(self):returnf"<MediumLevelILMemoryIntrinsicOutputSsa:{self.dest_memory}{self.output}>"@propertydefdest_memory(self)->int:returnself._get_int(0)@propertydefoutput(self)->List[SSAVariable]:returnself._get_var_ssa_list(1,2)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("dest_memory",self.dest_memory,"int"),("output",self.output,"List[SSAVariable]"),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILMemoryIntrinsicSsa(MediumLevelILInstruction,SSA):@propertydefoutput(self)->List[SSAVariable]:inst=self._get_expr(0)assertisinstance(inst,MediumLevelILMemoryIntrinsicOutputSsa),"MediumLevelILMemoryIntrinsicSsa expected MediumLevelILMemoryIntrinsicOutputSsa as first operand"returninst.output@propertydefdest_memory(self)->int:inst=self._get_expr(0)assertisinstance(inst,MediumLevelILMemoryIntrinsicOutputSsa),"MediumLevelILMemoryIntrinsicSsa expected MediumLevelILMemoryIntrinsicOutputSsa as first operand"returninst.dest_memory@propertydefintrinsic(self)->'lowlevelil.ILIntrinsic':returnself._get_intrinsic(1)@propertydefparams(self)->List[MediumLevelILInstruction]:returnself._get_expr_list(2,3)@propertydefsrc_memory(self)->int:returnself._get_int(4)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[("output",self.output,"List[SSAVariable]"),("dest_memory",self.dest_memory,"int"),("intrinsic",self.intrinsic,"ILIntrinsic"),("params",self.params,"List[MediumLevelILInstruction]"),("src_memory",self.src_memory,"int"),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILSetVarSsaField(MediumLevelILInstruction,SetVar,SSA):@propertydefdest(self)->SSAVariable:returnself._get_var_ssa_dest_and_src(0,1)@propertydefprev(self)->SSAVariable:returnself._get_var_ssa_dest_and_src(0,2)@propertydefoffset(self)->int:returnself._get_int(3)@propertydefsrc(self)->MediumLevelILInstruction:returnself._get_expr(4)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('dest',self.dest,'SSAVariable'),('prev',self.prev,'SSAVariable'),('offset',self.offset,'int'),('src',self.src,'MediumLevelILInstruction'),]@propertydefvars_read(self)->List[SSAVariable]:return[self.prev,*self.src.vars_read]# type: ignore # we're guaranteed not to return non-SSAVariables here@propertydefvars_written(self)->List[SSAVariable]:return[self.dest] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILSetVarSplitSsa(MediumLevelILInstruction,SetVar,SSA):@propertydefhigh(self)->SSAVariable:returnself._get_var_ssa(0,1)@propertydeflow(self)->SSAVariable:returnself._get_var_ssa(2,3)@propertydefsrc(self)->MediumLevelILInstruction:returnself._get_expr(4)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('high',self.high,'SSAVariable'),('low',self.low,'SSAVariable'),('src',self.src,'MediumLevelILInstruction'),]@propertydefvars_read(self)->List[Union[variable.Variable,SSAVariable]]:returnself.src.vars_read@propertydefvars_written(self)->List[SSAVariable]:return[self.high,self.low] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILSetVarAliasedField(MediumLevelILInstruction,SetVar,SSA):@propertydefdest(self)->SSAVariable:returnself._get_var_ssa_dest_and_src(0,1)@propertydefprev(self)->SSAVariable:returnself._get_var_ssa_dest_and_src(0,2)@propertydefoffset(self)->int:returnself._get_int(3)@propertydefsrc(self)->MediumLevelILInstruction:returnself._get_expr(4)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('dest',self.dest,'SSAVariable'),('prev',self.prev,'SSAVariable'),('offset',self.offset,'int'),('src',self.src,'MediumLevelILInstruction'),]@propertydefvars_read(self)->List[SSAVariable]:return[self.prev,*self.src.vars_read]# type: ignore # we're guaranteed not to return non-SSAVariables here [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILSyscallSsa(MediumLevelILCallBase,Syscall,SSA):@propertydefoutput(self)->List[SSAVariable]:inst=self._get_expr(0)assertisinstance(inst,MediumLevelILCallOutputSsa),"MediumLevelILSyscallSsa return bad type for output"returninst.dest@propertydefoutput_dest_memory(self)->int:inst=self._get_expr(0)assertisinstance(inst,MediumLevelILCallOutputSsa),"MediumLevelILSyscallSsa return bad type for output"returninst.dest_memory@propertydefparams(self)->List[MediumLevelILInstruction]:returnself._get_expr_list(1,2)@propertydefsrc_memory(self)->int:returnself._get_int(3)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('output',self.output,'List[SSAVariable]'),('output_dest_memory',self.output_dest_memory,'int'),('params',self.params,'List[MediumLevelILInstruction]'),('src_memory',self.src_memory,'int'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILSyscallUntypedSsa(MediumLevelILCallBase,Syscall,SSA):@propertydefoutput(self)->List[SSAVariable]:inst=self._get_expr(0)assertisinstance(inst,MediumLevelILCallOutputSsa),"MediumLevelILSyscallUntypedSsa return bad type for 'output'"returninst.dest@propertydefoutput_dest_memory(self)->int:inst=self._get_expr(0)assertisinstance(inst,MediumLevelILCallOutputSsa),"MediumLevelILSyscallUntypedSsa return bad type for 'output_dest_memory'"returninst.dest_memory@propertydefparams(self)->List[MediumLevelILInstruction]:inst=self._get_expr(1)assertisinstance(inst,MediumLevelILCallParamSsa),"MediumLevelILSyscallUntypedSsa return bad type for 'params'"returninst.src@propertydefparams_src_memory(self)->int:inst=self._get_expr(1)assertisinstance(inst,MediumLevelILCallParamSsa),"MediumLevelILSyscallUntypedSsa return bad type for 'params_src_memory'"returninst.src_memory@propertydefstack(self)->MediumLevelILInstruction:returnself._get_expr(2)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('output',self.output,'List[SSAVariable]'),('output_dest_memory',self.output_dest_memory,'int'),('params',self.params,'List[SSAVariable]'),('params_src_memory',self.params_src_memory,'int'),('stack',self.stack,'MediumLevelILInstruction'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILLoadStructSsa(MediumLevelILInstruction,Load,SSA):@propertydefsrc(self)->MediumLevelILInstruction:returnself._get_expr(0)@propertydefoffset(self)->int:returnself._get_int(1)@propertydefsrc_memory(self)->int:returnself._get_int(2)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('src',self.src,'MediumLevelILInstruction'),('offset',self.offset,'int'),('src_memory',self.src_memory,'int'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILSetVarField(MediumLevelILInstruction,SetVar):@propertydefdest(self)->variable.Variable:returnself._get_var(0)@propertydefoffset(self)->int:returnself._get_int(1)@propertydefsrc(self)->MediumLevelILInstruction:returnself._get_expr(2)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('dest',self.dest,'Variable'),('offset',self.offset,'int'),('src',self.src,'MediumLevelILInstruction'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILSetVarSplit(MediumLevelILInstruction,SetVar):@propertydefhigh(self)->variable.Variable:returnself._get_var(0)@propertydeflow(self)->variable.Variable:returnself._get_var(1)@propertydefsrc(self)->MediumLevelILInstruction:returnself._get_expr(2)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('high',self.high,'Variable'),('low',self.low,'Variable'),('src',self.src,'MediumLevelILInstruction'),]@propertydefvars_written(self)->List[variable.Variable]:return[self.high,self.low] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILStoreStruct(MediumLevelILInstruction,Store):@propertydefdest(self)->MediumLevelILInstruction:returnself._get_expr(0)@propertydefoffset(self)->int:returnself._get_int(1)@propertydefsrc(self)->MediumLevelILInstruction:returnself._get_expr(2)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('dest',self.dest,'MediumLevelILInstruction'),('offset',self.offset,'int'),('src',self.src,'MediumLevelILInstruction'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILAdc(MediumLevelILCarryBase):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILSbb(MediumLevelILCarryBase):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILRlc(MediumLevelILCarryBase):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILRrc(MediumLevelILCarryBase):pass [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILCall(MediumLevelILCallBase,Localcall):@propertydefoutput(self)->List[variable.Variable]:returnself._get_var_list(0,1)@propertydefdest(self)->MediumLevelILInstruction:returnself._get_expr(2)@propertydefparams(self)->List[MediumLevelILInstruction]:returnself._get_expr_list(3,4)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('output',self.output,'List[Variable]'),('dest',self.dest,'MediumLevelILInstruction'),('params',self.params,'List[MediumLevelILInstruction]'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILIf(MediumLevelILInstruction,Terminal):@propertydefcondition(self)->MediumLevelILInstruction:returnself._get_expr(0)@propertydeftrue(self)->InstructionIndex:returnself._get_int(1)@propertydeffalse(self)->InstructionIndex:returnself._get_int(2)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('condition',self.condition,'MediumLevelILInstruction'),('true',self.true,'InstructionIndex'),('false',self.false,'InstructionIndex'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILTailcallUntyped(MediumLevelILCallBase,Tailcall):@propertydefoutput(self)->List[variable.Variable]:inst=self._get_expr(0)assertisinstance(inst,MediumLevelILCallOutput),"MediumLevelILTailcallUntyped return bad type for 'output'"returninst.dest@propertydefdest(self)->MediumLevelILInstruction:returnself._get_expr(1)@propertydefparams(self)->List[MediumLevelILInstruction]:inst=self._get_expr(2)assertisinstance(inst,MediumLevelILCallParam),"MediumLevelILTailcallUntyped return bad type for 'params'"returninst.src@propertydefstack(self)->MediumLevelILInstruction:returnself._get_expr(3)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('output',self.output,'List[Variable]'),('dest',self.dest,'MediumLevelILInstruction'),('params',self.params,'List[MediumLevelILInstruction]'),('stack',self.stack,'MediumLevelILInstruction'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILCallSsa(MediumLevelILCallBase,Localcall,SSA):@propertydefoutput(self)->List[SSAVariable]:inst=self._get_expr(0)assertisinstance(inst,MediumLevelILCallOutputSsa),"MediumLevelILCallSsa return bad type for output"returninst.dest@propertydefoutput_dest_memory(self)->int:inst=self._get_expr(0)assertisinstance(inst,MediumLevelILCallOutputSsa),"MediumLevelILCallSsa return bad type for output"returninst.dest_memory@propertydefdest(self)->MediumLevelILInstruction:returnself._get_expr(1)@propertydefparams(self)->List[MediumLevelILInstruction]:returnself._get_expr_list(2,3)@propertydefsrc_memory(self)->int:returnself._get_int(4)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('output',self.output,'List[SSAVariable]'),('output_dest_memory',self.output_dest_memory,'int'),('dest',self.dest,'MediumLevelILInstruction'),('params',self.params,'List[MediumLevelILInstruction]'),('src_memory',self.src_memory,'int'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILCallUntypedSsa(MediumLevelILCallBase,Localcall,SSA):@propertydefoutput(self)->List[SSAVariable]:inst=self._get_expr(0)assertisinstance(inst,MediumLevelILCallOutputSsa),"MediumLevelILCallUntypedSsa return bad type for output"returninst.dest@propertydefoutput_dest_memory(self)->int:inst=self._get_expr(0)assertisinstance(inst,MediumLevelILCallOutputSsa),"MediumLevelILCallUntypedSsa return bad type for output"returninst.dest_memory@propertydefdest(self)->MediumLevelILInstruction:returnself._get_expr(1)@propertydefparams(self)->List[MediumLevelILInstruction]:inst=self._get_expr(2)assertisinstance(inst,MediumLevelILCallParamSsa),"MediumLevelILCallUntypedSsa return bad type for 'params'"returninst.src@propertydefparams_src_memory(self):inst=self._get_expr(2)assertisinstance(inst,MediumLevelILCallParamSsa),"MediumLevelILCallUntypedSsa return bad type for 'params_src_memory'"returninst.src_memory@propertydefstack(self)->MediumLevelILInstruction:returnself._get_expr(3)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('output',self.output,'List[SSAVariable]'),('output_dest_memory',self.output_dest_memory,'int'),('dest',self.dest,'MediumLevelILInstruction'),('params',self.params,'List[SSAVariable]'),('params_src_memory',self.params_src_memory,'int'),('stack',self.stack,'MediumLevelILInstruction'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILTailcall(MediumLevelILCallBase,Tailcall):@propertydefoutput(self)->List[variable.Variable]:returnself._get_var_list(0,1)@propertydefdest(self)->MediumLevelILInstruction:returnself._get_expr(2)@propertydefparams(self)->List[MediumLevelILInstruction]:returnself._get_expr_list(3,4)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('output',self.output,'List[Variable]'),('dest',self.dest,'MediumLevelILInstruction'),('params',self.params,'List[MediumLevelILInstruction]'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILTailcallSsa(MediumLevelILCallBase,Tailcall,SSA):@propertydefoutput(self)->List[SSAVariable]:inst=self._get_expr(0)assertisinstance(inst,MediumLevelILCallOutputSsa),"MediumLevelILTailcallSsa return bad type for output"returninst.dest@propertydefoutput_dest_memory(self)->int:inst=self._get_expr(0)assertisinstance(inst,MediumLevelILCallOutputSsa),"MediumLevelILTailcallSsa return bad type for output"returninst.dest_memory@propertydefdest(self)->MediumLevelILInstruction:returnself._get_expr(1)@propertydefparams(self)->List[MediumLevelILInstruction]:returnself._get_expr_list(2,3)@propertydefsrc_memory(self)->int:returnself._get_int(4)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('output',self.output,'List[SSAVariable]'),('output_dest_memory',self.output_dest_memory,'int'),('dest',self.dest,'MediumLevelILInstruction'),('params',self.params,'List[MediumLevelILInstruction]'),('src_memory',self.src_memory,'int'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILTailcallUntypedSsa(MediumLevelILCallBase,Tailcall,SSA):@propertydefoutput(self)->List[SSAVariable]:inst=self._get_expr(0)assertisinstance(inst,MediumLevelILCallOutputSsa),"MediumLevelILTailcallUntypedSsa return bad type for 'output'"returninst.dest@propertydefoutput_dest_memory(self)->int:inst=self._get_expr(0)assertisinstance(inst,MediumLevelILCallOutputSsa),"MediumLevelILTailcallUntypedSsa return bad type for 'output'"returninst.dest_memory@propertydefdest(self)->MediumLevelILInstruction:returnself._get_expr(1)@propertydefparams(self)->List[MediumLevelILInstruction]:inst=self._get_expr(2)assertisinstance(inst,MediumLevelILCallParamSsa),"MediumLevelILTailcallUntypedSsa return bad type for 'params'"returninst.src@propertydefstack(self)->MediumLevelILInstruction:returnself._get_expr(3)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('output',self.output,'List[SSAVariable]'),('output_dest_memory',self.output_dest_memory,'int'),('dest',self.dest,'MediumLevelILInstruction'),('params',self.params,'List[SSAVariable]'),('stack',self.stack,'MediumLevelILInstruction'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILStoreSsa(MediumLevelILInstruction,Store,SSA):@propertydefdest(self)->MediumLevelILInstruction:returnself._get_expr(0)@propertydefdest_memory(self)->int:returnself._get_int(1)@propertydefsrc_memory(self)->int:returnself._get_int(2)@propertydefsrc(self)->MediumLevelILInstruction:returnself._get_expr(3)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('dest',self.dest,'MediumLevelILInstruction'),('dest_memory',self.dest_memory,'int'),('src_memory',self.src_memory,'int'),('src',self.src,'MediumLevelILInstruction'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILCallUntyped(MediumLevelILCallBase,Localcall):@propertydefoutput(self)->List[variable.Variable]:inst=self._get_expr(0)assertisinstance(inst,MediumLevelILCallOutput),"MediumLevelILCallUntyped return bad type for 'output'"returninst.dest@propertydefdest(self)->MediumLevelILInstruction:returnself._get_expr(1)@propertydefparams(self)->List[MediumLevelILInstruction]:inst=self._get_expr(2)assertisinstance(inst,MediumLevelILCallParam),"MediumLevelILCallUntyped return bad type for 'params'"returninst.src@propertydefstack(self)->MediumLevelILInstruction:returnself._get_expr(3)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('output',self.output,'List[Variable]'),('dest',self.dest,'MediumLevelILInstruction'),('params',self.params,'List[MediumLevelILInstruction]'),('stack',self.stack,'MediumLevelILInstruction'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILStoreStructSsa(MediumLevelILInstruction,Store,SSA):@propertydefdest(self)->MediumLevelILInstruction:returnself._get_expr(0)@propertydefoffset(self)->int:returnself._get_int(1)@propertydefdest_memory(self)->int:returnself._get_int(2)@propertydefsrc_memory(self)->int:returnself._get_int(3)@propertydefsrc(self)->MediumLevelILInstruction:returnself._get_expr(4)@propertydefdetailed_operands(self)->List[Tuple[str,MediumLevelILOperandType,str]]:return[('dest',self.dest,'MediumLevelILInstruction'),('offset',self.offset,'int'),('dest_memory',self.dest_memory,'int'),('src_memory',self.src_memory,'int'),('src',self.src,'MediumLevelILInstruction'),] [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILAssert(MediumLevelILInstruction):@propertydefsrc(self)->variable.Variable:returnself._get_var(0)@propertydefconstraint(self)->variable.PossibleValueSet:returnself._get_constraint(1) [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILAssertSsa(MediumLevelILInstruction,SSA):@propertydefsrc(self)->SSAVariable:returnself._get_var_ssa(0,1)@propertydefconstraint(self)->variable.PossibleValueSet:returnself._get_constraint(2) [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILForceVer(MediumLevelILInstruction):@propertydefdest(self)->variable.Variable:returnself._get_var(0)@propertydefsrc(self)->variable.Variable:returnself._get_var(1) [docs]@dataclass(frozen=True,repr=False,eq=False)classMediumLevelILForceVerSsa(MediumLevelILInstruction,SSA):@propertydefdest(self)->SSAVariable:returnself._get_var_ssa(0,1)@propertydefsrc(self)->SSAVariable:returnself._get_var_ssa(2,3) ILInstruction={MediumLevelILOperation.MLIL_NOP:MediumLevelILNop,# [],MediumLevelILOperation.MLIL_NORET:MediumLevelILNoret,# [],MediumLevelILOperation.MLIL_BP:MediumLevelILBp,# [],MediumLevelILOperation.MLIL_UNDEF:MediumLevelILUndef,# [],MediumLevelILOperation.MLIL_UNIMPL:MediumLevelILUnimpl,# [],MediumLevelILOperation.MLIL_LOAD:MediumLevelILLoad,# [("src", "expr")],MediumLevelILOperation.MLIL_VAR:MediumLevelILVar,# [("src", "var")],MediumLevelILOperation.MLIL_ADDRESS_OF:MediumLevelILAddressOf,# [("src", "var")],MediumLevelILOperation.MLIL_CONST:MediumLevelILConst,# [("constant", "int")],MediumLevelILOperation.MLIL_CONST_PTR:MediumLevelILConstPtr,# [("constant", "int")],MediumLevelILOperation.MLIL_FLOAT_CONST:MediumLevelILFloatConst,# [("constant", "float")],MediumLevelILOperation.MLIL_IMPORT:MediumLevelILImport,# [("constant", "int")],MediumLevelILOperation.MLIL_CONST_DATA:MediumLevelILConstData,# [("constant", "ConstData")],MediumLevelILOperation.MLIL_SET_VAR:MediumLevelILSetVar,# [("dest", "var"), ("src", "expr")],MediumLevelILOperation.MLIL_LOAD_STRUCT:MediumLevelILLoadStruct,# [("src", "expr"), ("offset", "int")],MediumLevelILOperation.MLIL_STORE:MediumLevelILStore,# [("dest", "expr"), ("src", "expr")],MediumLevelILOperation.MLIL_VAR_FIELD:MediumLevelILVarField,# [("src", "var"), ("offset", "int")],MediumLevelILOperation.MLIL_VAR_SPLIT:MediumLevelILVarSplit,# [("high", "var"), ("low", "var")],MediumLevelILOperation.MLIL_ADDRESS_OF_FIELD:MediumLevelILAddressOfField,# [("src", "var"), ("offset", "int")],MediumLevelILOperation.MLIL_EXTERN_PTR:MediumLevelILExternPtr,# [("constant", "int"), ("offset", "int")],MediumLevelILOperation.MLIL_ADD:MediumLevelILAdd,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_SUB:MediumLevelILSub,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_AND:MediumLevelILAnd,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_OR:MediumLevelILOr,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_XOR:MediumLevelILXor,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_LSL:MediumLevelILLsl,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_LSR:MediumLevelILLsr,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_ASR:MediumLevelILAsr,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_ROL:MediumLevelILRol,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_ROR:MediumLevelILRor,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_MUL:MediumLevelILMul,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_MULU_DP:MediumLevelILMuluDp,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_MULS_DP:MediumLevelILMulsDp,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_DIVU:MediumLevelILDivu,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_DIVU_DP:MediumLevelILDivuDp,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_DIVS:MediumLevelILDivs,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_DIVS_DP:MediumLevelILDivsDp,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_MODU:MediumLevelILModu,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_MODU_DP:MediumLevelILModuDp,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_MODS:MediumLevelILMods,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_MODS_DP:MediumLevelILModsDp,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_NEG:MediumLevelILNeg,# [("src", "expr")],MediumLevelILOperation.MLIL_NOT:MediumLevelILNot,# [("src", "expr")],MediumLevelILOperation.MLIL_SX:MediumLevelILSx,# [("src", "expr")],MediumLevelILOperation.MLIL_ZX:MediumLevelILZx,# [("src", "expr")],MediumLevelILOperation.MLIL_LOW_PART:MediumLevelILLowPart,# [("src", "expr")],MediumLevelILOperation.MLIL_JUMP:MediumLevelILJump,# [("dest", "expr")],MediumLevelILOperation.MLIL_RET_HINT:MediumLevelILRetHint,# [("dest", "expr")],MediumLevelILOperation.MLIL_CALL_OUTPUT:MediumLevelILCallOutput,# [("dest", "var_list")],MediumLevelILOperation.MLIL_CALL_PARAM:MediumLevelILCallParam,# [("src", "expr_list")],MediumLevelILOperation.MLIL_SEPARATE_PARAM_LIST:MediumLevelILSeparateParamList,# [("src", "expr_list")],MediumLevelILOperation.MLIL_SHARED_PARAM_SLOT:MediumLevelILSharedParamSlot,# [("src", "expr_list")],MediumLevelILOperation.MLIL_RET:MediumLevelILRet,# [("src", "expr_list")],MediumLevelILOperation.MLIL_GOTO:MediumLevelILGoto,# [("dest", "int")],MediumLevelILOperation.MLIL_BOOL_TO_INT:MediumLevelILBoolToInt,# [("src", "expr")],MediumLevelILOperation.MLIL_FREE_VAR_SLOT:MediumLevelILFreeVarSlot,# [("dest", "var")],MediumLevelILOperation.MLIL_TRAP:MediumLevelILTrap,# [("vector", "int")],MediumLevelILOperation.MLIL_FREE_VAR_SLOT_SSA:MediumLevelILFreeVarSlotSsa,# [("prev", "var_ssa_dest_and_src")],MediumLevelILOperation.MLIL_UNIMPL_MEM:MediumLevelILUnimplMem,# [("src", "expr")],MediumLevelILOperation.MLIL_FSQRT:MediumLevelILFsqrt,# [("src", "expr")],MediumLevelILOperation.MLIL_FNEG:MediumLevelILFneg,# [("src", "expr")],MediumLevelILOperation.MLIL_FABS:MediumLevelILFabs,# [("src", "expr")],MediumLevelILOperation.MLIL_FLOAT_TO_INT:MediumLevelILFloatToInt,# [("src", "expr")],MediumLevelILOperation.MLIL_INT_TO_FLOAT:MediumLevelILIntToFloat,# [("src", "expr")],MediumLevelILOperation.MLIL_FLOAT_CONV:MediumLevelILFloatConv,# [("src", "expr")],MediumLevelILOperation.MLIL_ROUND_TO_INT:MediumLevelILRoundToInt,# [("src", "expr")],MediumLevelILOperation.MLIL_FLOOR:MediumLevelILFloor,# [("src", "expr")],MediumLevelILOperation.MLIL_CEIL:MediumLevelILCeil,# [("src", "expr")],MediumLevelILOperation.MLIL_FTRUNC:MediumLevelILFtrunc,# [("src", "expr")],MediumLevelILOperation.MLIL_VAR_SSA:MediumLevelILVarSsa,# [("src", "var_ssa")],MediumLevelILOperation.MLIL_VAR_ALIASED:MediumLevelILVarAliased,# [("src", "var_ssa")],MediumLevelILOperation.MLIL_CMP_E:MediumLevelILCmpE,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_CMP_NE:MediumLevelILCmpNe,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_CMP_SLT:MediumLevelILCmpSlt,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_CMP_ULT:MediumLevelILCmpUlt,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_CMP_SLE:MediumLevelILCmpSle,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_CMP_ULE:MediumLevelILCmpUle,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_CMP_SGE:MediumLevelILCmpSge,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_CMP_UGE:MediumLevelILCmpUge,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_CMP_SGT:MediumLevelILCmpSgt,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_CMP_UGT:MediumLevelILCmpUgt,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_TEST_BIT:MediumLevelILTestBit,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_ADD_OVERFLOW:MediumLevelILAddOverflow,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_SYSCALL:MediumLevelILSyscall,# [("output", "var_list"), ("params", "expr_list")],MediumLevelILOperation.MLIL_VAR_SSA_FIELD:MediumLevelILVarSsaField,# [("src", "var_ssa"), ("offset", "int")],MediumLevelILOperation.MLIL_VAR_ALIASED_FIELD:MediumLevelILVarAliasedField,# [("src", "var_ssa"), ("offset", "int")],MediumLevelILOperation.MLIL_VAR_SPLIT_SSA:MediumLevelILVarSplitSsa,# [("high", "var_ssa"), ("low", "var_ssa")],MediumLevelILOperation.MLIL_CALL_OUTPUT_SSA:MediumLevelILCallOutputSsa,# [("dest_memory", "int"), ("dest", "var_ssa_list")],MediumLevelILOperation.MLIL_CALL_PARAM_SSA:MediumLevelILCallParamSsa,# [("src_memory", "int"), ("src", "expr_list")],MediumLevelILOperation.MLIL_LOAD_SSA:MediumLevelILLoadSsa,# [("src", "expr"), ("src_memory", "int")],MediumLevelILOperation.MLIL_VAR_PHI:MediumLevelILVarPhi,# [("dest", "var_ssa"), ("src", "var_ssa_list")],MediumLevelILOperation.MLIL_MEM_PHI:MediumLevelILMemPhi,# [("dest_memory", "int"), ("src_memory", "int_list")],MediumLevelILOperation.MLIL_SET_VAR_SSA:MediumLevelILSetVarSsa,# [("dest", "var_ssa"), ("src", "expr")],MediumLevelILOperation.MLIL_FCMP_E:MediumLevelILFcmpE,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_FCMP_NE:MediumLevelILFcmpNe,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_FCMP_LT:MediumLevelILFcmpLt,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_FCMP_LE:MediumLevelILFcmpLe,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_FCMP_GE:MediumLevelILFcmpGe,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_FCMP_GT:MediumLevelILFcmpGt,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_FCMP_O:MediumLevelILFcmpO,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_FCMP_UO:MediumLevelILFcmpUo,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_FADD:MediumLevelILFadd,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_FSUB:MediumLevelILFsub,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_FMUL:MediumLevelILFmul,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_FDIV:MediumLevelILFdiv,# [("left", "expr"), ("right", "expr")],MediumLevelILOperation.MLIL_JUMP_TO:MediumLevelILJumpTo,# [("dest", "expr"), ("targets", "target_map")],MediumLevelILOperation.MLIL_SET_VAR_ALIASED:MediumLevelILSetVarAliased,# [("prev", "var_ssa_dest_and_src"), ("src", "expr")],MediumLevelILOperation.MLIL_SYSCALL_UNTYPED:MediumLevelILSyscallUntyped,# [("output", "expr"), ("params", "expr"), ("stack", "expr")],MediumLevelILOperation.MLIL_TAILCALL:MediumLevelILTailcall,# [("output", "var_list"), ("dest", "expr"), ("params", "expr_list")],MediumLevelILOperation.MLIL_INTRINSIC:MediumLevelILIntrinsic,# [("output", "var_list"), ("intrinsic", "intrinsic"), ("params", "expr_list")],MediumLevelILOperation.MLIL_INTRINSIC_SSA:MediumLevelILIntrinsicSsa,# [("output", "var_ssa_list"), ("intrinsic", "intrinsic"), ("params", "expr_list")],MediumLevelILOperation.MLIL_MEMORY_INTRINSIC_OUTPUT_SSA:MediumLevelILMemoryIntrinsicOutputSsa,# [("dest_memory", "int"), ("output", "var_ssa_list")],MediumLevelILOperation.MLIL_MEMORY_INTRINSIC_SSA:MediumLevelILMemoryIntrinsicSsa,# [("output", "expr"), ("intrinsic", "intrinsic"), ("params", "expr_list"), ("src_memory", "int")],MediumLevelILOperation.MLIL_SET_VAR_SSA_FIELD:MediumLevelILSetVarSsaField,# [("prev", "var_ssa_dest_and_src"), ("offset", "int"), ("src", "expr")],MediumLevelILOperation.MLIL_SET_VAR_SPLIT_SSA:MediumLevelILSetVarSplitSsa,# [("high", "var_ssa"), ("low", "var_ssa"), ("src", "expr")],MediumLevelILOperation.MLIL_SET_VAR_ALIASED_FIELD:MediumLevelILSetVarAliasedField,# [("prev", "var_ssa_dest_and_src"), ("offset", "int"), ("src", "expr")],MediumLevelILOperation.MLIL_SYSCALL_SSA:MediumLevelILSyscallSsa,# [("output", "expr"), ("params", "expr_list"), ("src_memory", "int")],MediumLevelILOperation.MLIL_SYSCALL_UNTYPED_SSA:MediumLevelILSyscallUntypedSsa,# [("output", "expr"), ("params", "expr"), ("stack", "expr")],MediumLevelILOperation.MLIL_LOAD_STRUCT_SSA:MediumLevelILLoadStructSsa,# [("src", "expr"), ("offset", "int"), ("src_memory", "int")],MediumLevelILOperation.MLIL_SET_VAR_FIELD:MediumLevelILSetVarField,# [("dest", "var"), ("offset", "int"), ("src", "expr")],MediumLevelILOperation.MLIL_SET_VAR_SPLIT:MediumLevelILSetVarSplit,# [("high", "var"), ("low", "var"), ("src", "expr")],MediumLevelILOperation.MLIL_STORE_STRUCT:MediumLevelILStoreStruct,# [("dest", "expr"), ("offset", "int"), ("src", "expr")],MediumLevelILOperation.MLIL_ADC:MediumLevelILAdc,# [("left", "expr"), ("right", "expr"), ("carry", "expr")],MediumLevelILOperation.MLIL_SBB:MediumLevelILSbb,# [("left", "expr"), ("right", "expr"), ("carry", "expr")],MediumLevelILOperation.MLIL_RLC:MediumLevelILRlc,# [("left", "expr"), ("right", "expr"), ("carry", "expr")],MediumLevelILOperation.MLIL_RRC:MediumLevelILRrc,# [("left", "expr"), ("right", "expr"), ("carry", "expr")],MediumLevelILOperation.MLIL_TAILCALL_UNTYPED:MediumLevelILTailcallUntyped,# [("output", "expr"), ("dest", "expr"), ("params", "expr"), ("stack", "expr")],MediumLevelILOperation.MLIL_CALL_SSA:MediumLevelILCallSsa,# [("output", "expr"), ("dest", "expr"), ("params", "expr_list"), ("src_memory", "int")],MediumLevelILOperation.MLIL_CALL_UNTYPED_SSA:MediumLevelILCallUntypedSsa,# [("output", "expr"), ("dest", "expr"), ("params", "expr"), ("stack", "expr")],MediumLevelILOperation.MLIL_TAILCALL_SSA:MediumLevelILTailcallSsa,# [("output", "expr"), ("dest", "expr"), ("params", "expr_list"), ("src_memory", "int")],MediumLevelILOperation.MLIL_TAILCALL_UNTYPED_SSA:MediumLevelILTailcallUntypedSsa,# [("output", "expr"), ("dest", "expr"), ("params", "expr"), ("stack", "expr")],MediumLevelILOperation.MLIL_CALL:MediumLevelILCall,# [("output", "var_list"), ("dest", "expr"), ("params", "expr_list")],MediumLevelILOperation.MLIL_IF:MediumLevelILIf,# [("condition", "expr"), ("true", "int"), ("false", "int")],MediumLevelILOperation.MLIL_STORE_SSA:MediumLevelILStoreSsa,# [("dest", "expr"), ("dest_memory", "int"), ("src_memory", "int"), ("src", "expr")],MediumLevelILOperation.MLIL_CALL_UNTYPED:MediumLevelILCallUntyped,# [("output", "expr"), ("dest", "expr"), ("params", "expr"), ("stack", "expr")],MediumLevelILOperation.MLIL_STORE_STRUCT_SSA:MediumLevelILStoreStructSsa,# [("dest", "expr"), ("offset", "int"), ("dest_memory", "int"), ("src_memory", "int"), ("src", "expr")],MediumLevelILOperation.MLIL_ASSERT:MediumLevelILAssert,MediumLevelILOperation.MLIL_ASSERT_SSA:MediumLevelILAssertSsa,MediumLevelILOperation.MLIL_FORCE_VER:MediumLevelILForceVer,MediumLevelILOperation.MLIL_FORCE_VER_SSA:MediumLevelILForceVerSsa,}[docs]classMediumLevelILExpr:"""``class MediumLevelILExpr`` hold the index of IL Expressions... note:: Deprecated. Use ExpressionIndex instead"""[docs]def__init__(self,index):self._index=index def__int__(self):returnself._index@propertydefindex(self):returnself._index [docs]classMediumLevelILFunction:"""``class MediumLevelILFunction`` contains the list of ExpressionIndex objects that make up a function. ExpressionIndexobjects can be added to the MediumLevelILFunction by calling :func:`append` and passing the result of the various classmethods which return ExpressionIndex objects."""[docs]def__init__(self,arch:Optional['architecture.Architecture']=None,handle:Optional[core.BNMediumLevelILFunction]=None,source_func:Optional['function.Function']=None,low_level_il:Optional['lowlevelil.LowLevelILFunction']=None):_arch=arch_source_function=source_funcifhandleisnotNone:MLILHandle=ctypes.POINTER(core.BNMediumLevelILFunction)_handle=ctypes.cast(handle,MLILHandle)if_source_functionisNone:_source_function=function.Function(handle=core.BNGetMediumLevelILOwnerFunction(_handle))if_archisNone:_arch=_source_function.archelse:iflow_level_ilisNoneandsource_funcisNone:raiseValueError("IL functions must be created with an associated function or LLIL function")iflow_level_ilisNone:_source_function=source_funcelse:_source_function=low_level_il.source_functionif_archisNone:_arch=low_level_il.archfunc_handle=_source_function.handlellil_handle=low_level_il.handleiflow_level_ilisnotNoneelseNone_handle=core.BNCreateMediumLevelILFunction(_arch.handle,func_handle,llil_handle)assert_source_functionisnotNoneassert_archisnotNoneassert_handleisnotNoneself.handle=_handleself._arch=_archself._source_function=_source_functionself._mlil_to_mlil_expr_map:dict['MediumLevelILInstruction',List[Tuple[ExpressionIndex,bool]]]={}self._mlil_to_mlil_instr_map:dict['MediumLevelILInstruction',List[Tuple[InstructionIndex,bool]]]={}self._llil_ssa_to_mlil_expr_map:dict['lowlevelil.LowLevelILInstruction',List[Tuple[ExpressionIndex,bool]]]={}self._llil_ssa_to_mlil_instr_map:dict['lowlevelil.LowLevelILInstruction',List[Tuple[InstructionIndex,bool]]]={} def__del__(self):ifcoreisnotNone:core.BNFreeMediumLevelILFunction(self.handle)def__repr__(self):arch=self.source_function.archform=""ifself.il_formin[FunctionGraphType.MappedMediumLevelILFunctionGraph,FunctionGraphType.MappedMediumLevelILSSAFormFunctionGraph,]:form+=" mapped mlil"ifself.il_formin[FunctionGraphType.MediumLevelILSSAFormFunctionGraph,FunctionGraphType.MappedMediumLevelILSSAFormFunctionGraph,]:form+=" ssa form"ifarch:returnf"<MediumLevelILFunction{form}:{arch.name}@{self.source_function.start:#x}>"else:returnf"<MediumLevelILFunction{form}:{self.source_function.start:#x}>"def__len__(self):returnint(core.BNGetMediumLevelILInstructionCount(self.handle))def__eq__(self,other):ifnotisinstance(other,self.__class__):returnNotImplementedreturnctypes.addressof(self.handle.contents)==ctypes.addressof(other.handle.contents)def__ne__(self,other):ifnotisinstance(other,self.__class__):returnNotImplementedreturnnot(self==other)def__hash__(self):returnhash(('MLIL',self._source_function))def__getitem__(self,i)->'MediumLevelILInstruction':ifisinstance(i,slice)orisinstance(i,tuple):raiseIndexError("expected integer instruction index")elifisinstance(i,MediumLevelILInstruction):# for backwards compatibilityreturniifi<-len(self)ori>=len(self):raiseIndexError("index out of range")ifi<0:i=len(self)+ireturnMediumLevelILInstruction.create(self,ExpressionIndex(core.BNGetMediumLevelILIndexForInstruction(self.handle,i)),i)def__setitem__(self,i,j):raiseIndexError("instruction modification not implemented")def__iter__(self):count=ctypes.c_ulonglong()blocks=core.BNGetMediumLevelILBasicBlockList(self.handle,count)assertblocksisnotNone,"core.BNGetMediumLevelILBasicBlockList returned None"view=Noneifself._source_functionisnotNone:view=self._source_function.viewtry:foriinrange(0,count.value):core_block=core.BNNewBasicBlockReference(blocks[i])assertcore_blockisnotNone,"Got None from core.BNNewBasicBlockReference"yieldMediumLevelILBasicBlock(core_block,self,view)finally:core.BNFreeBasicBlockList(blocks,count.value)@propertydefcurrent_address(self)->int:"""Current IL Address (read/write)"""returncore.BNMediumLevelILGetCurrentAddress(self.handle)@current_address.setterdefcurrent_address(self,value:int)->None:core.BNMediumLevelILSetCurrentAddress(self.handle,self._arch.handle,value)[docs]defset_current_address(self,value:int,arch:Optional['architecture.Architecture']=None)->None:_arch=archif_archisNone:_arch=self._archcore.BNMediumLevelILSetCurrentAddress(self.handle,_arch.handle,value) def_basic_block_list(self):count=ctypes.c_ulonglong()blocks=core.BNGetMediumLevelILBasicBlockList(self.handle,count)assertblocksisnotNone,"core.BNGetMediumLevelILBasicBlockList returned None"returncount,blocksdef_instantiate_block(self,handle):returnMediumLevelILBasicBlock(handle,self,self.view)@propertydefbasic_blocks(self)->'function.MediumLevelILBasicBlockList':returnfunction.MediumLevelILBasicBlockList(self)[docs]defget_basic_block_at(self,index:int)->Optional['MediumLevelILBasicBlock']:"""``get_basic_block_at`` returns the BasicBlock at the given MLIL instruction ``index``.:param int index: Index of the MLIL instruction of the BasicBlock to retrieve.:Example:>>> current_il_function.get_basic_block_at(current_il_index)<mlil block: x86@40-60>"""block=core.BNGetMediumLevelILBasicBlockForInstruction(self.handle,index)ifnotblock:returnNoneview=Noneifself._source_functionisnotNone:view=self._source_function.viewreturnMediumLevelILBasicBlock(block,self,view) @propertydefinstructions(self)->Generator[MediumLevelILInstruction,None,None]:"""A generator of mlil instructions of the current function"""forblockinself.basic_blocks:yield fromblock[docs]deftraverse(self,cb:Callable[['MediumLevelILInstruction',Any],Any],*args:Any,**kwargs:Any)->Iterator[Any]:"""``traverse`` iterates through all the instructions in the MediumLevelILInstruction and calls the callback function foreach instruction and sub-instruction. See the `Developer Docs <https://docs.binary.ninja/dev/concepts.html#walking-ils>`_ for more examples.:param Callable[[MediumLevelILInstruction, Any], Any] cb: Callback function that takes a HighLevelILInstruction and returns a value:param Any args: Custom user-defined arguments:param Any kwargs: Custom user-defined keyword arguments:return: An iterator of the results of the callback function:rtype: Iterator[Any]:Example:>>> def find_constants(instr) -> Optional[int]:... if isinstance(instr, Constant):... return instr.constant>>> print(list(current_il_function.traverse(find_constants)))"""forinstrinself.instructions:yield frominstr.traverse(cb,*args,**kwargs) [docs]@deprecation.deprecated(deprecated_in="4.0.4907",details="Use :py:func:`MediumLevelILFunction.traverse` instead.")defvisit(self,cb:MediumLevelILVisitorCallback)->bool:"""Iterates over all the instructions in the function and calls the callback functionfor each instruction and each sub-instruction.:param MediumLevelILVisitorCallback cb: Callback function that takes the name of the operand, the operand, operand type, and parent instruction:return: True if all instructions were visited, False if the callback function returned False."""forinstrinself.instructions:ifnotinstr.visit(cb):returnFalsereturnTrue [docs]@deprecation.deprecated(deprecated_in="4.0.4907",details="Use :py:func:`MediumLevelILFunction.traverse` instead.")defvisit_all(self,cb:MediumLevelILVisitorCallback)->bool:"""Iterates over all the instructions in the function and calls the callback function for each instruction and their operands.:param MediumLevelILVisitorCallback cb: Callback function that takes the name of the operand, the operand, operand type, and parent instruction:return: True if all instructions were visited, False if the callback function returned False."""forinstrinself.instructions:ifnotinstr.visit_all(cb):returnFalsereturnTrue [docs]@deprecation.deprecated(deprecated_in="4.0.4907",details="Use :py:func:`MediumLevelILFunction.traverse` instead.")defvisit_operands(self,cb:MediumLevelILVisitorCallback)->bool:"""Iterates over all the instructions in the function and calls the callback function for each operand and the operands of each sub-instruction.:param MediumLevelILVisitorCallback cb: Callback function that takes the name of the operand, the operand, operand type, and parent instruction:return: True if all instructions were visited, False if the callback function returned False."""forinstrinself.instructions:ifnotinstr.visit_operands(cb):returnFalsereturnTrue @propertydefssa_form(self)->Optional['MediumLevelILFunction']:"""Medium level IL in SSA form (read-only)"""result=core.BNGetMediumLevelILSSAForm(self.handle)ifnotresult:returnNonereturnMediumLevelILFunction(self._arch,result,self._source_function)@propertydefnon_ssa_form(self)->Optional['MediumLevelILFunction']:"""Medium level IL in non-SSA (default) form (read-only)"""result=core.BNGetMediumLevelILNonSSAForm(self.handle)ifnotresult:returnNonereturnMediumLevelILFunction(self._arch,result,self._source_function)@propertydeflow_level_il(self)->Optional['lowlevelil.LowLevelILFunction']:"""Low level IL for this function"""result=core.BNGetLowLevelILForMediumLevelIL(self.handle)ifnotresult:returnNonereturnlowlevelil.LowLevelILFunction(self._arch,result,self._source_function)@propertydefllil(self)->Optional['lowlevelil.LowLevelILFunction']:"""Alias for low_level_il"""returnself.low_level_il@propertydefhigh_level_il(self)->Optional[highlevelil.HighLevelILFunction]:"""High level IL for this medium level IL."""result=core.BNGetHighLevelILForMediumLevelIL(self.handle)ifnotresult:returnNonereturnhighlevelil.HighLevelILFunction(self._arch,result,self._source_function)@propertydefhlil(self)->Optional[highlevelil.HighLevelILFunction]:returnself.high_level_il[docs]defget_instruction_start(self,addr:int,arch:Optional['architecture.Architecture']=None)->Optional[InstructionIndex]:_arch=archif_archisNone:ifself._archisNone:raiseException("Attempting to get_instruction_start from a MLIL Function without an Architecture")_arch=self._archresult=core.BNMediumLevelILGetInstructionStart(self.handle,_arch.handle,addr)ifresult>=core.BNGetMediumLevelILInstructionCount(self.handle):returnNonereturnInstructionIndex(result) [docs]defexpr(self,operation:MediumLevelILOperation,a:int=0,b:int=0,c:int=0,d:int=0,e:int=0,size:int=0,source_location:Optional['ILSourceLocation']=None)->ExpressionIndex:_operation=operationifisinstance(operation,str):_operation=MediumLevelILOperation[operation]elifisinstance(operation,MediumLevelILOperation):_operation=operation.valueifsource_locationisnotNone:index=ExpressionIndex(core.BNMediumLevelILAddExprWithLocation(self.handle,_operation,source_location.address,source_location.source_operand,size,a,b,c,d,e))self._record_mlil_to_mlil_expr_map(index,source_location)returnindexelse:returnExpressionIndex(core.BNMediumLevelILAddExpr(self.handle,_operation,size,a,b,c,d,e)) [docs]defget_expr_count(self)->int:"""``get_expr_count`` gives a the total number of expressions in this IL functionYou can use this to enumerate all expressions in conjunction with :py:func:`get_expr`.. warning :: Not all IL expressions are valid, even if their index is within the bounds of the function, they might not be used by the function and might not contain properly structured data.:return: The number of expressions in the function"""returncore.BNGetMediumLevelILExprCount(self.handle) [docs]defget_expr(self,index:ExpressionIndex)->Optional[MediumLevelILInstruction]:"""``get_expr`` retrieves the IL expression at a given expression index in the function... warning :: Not all IL expressions are valid, even if their index is within the bounds of the function, they might not be used by the function and might not contain properly structured data.:param index: Index of desired expression in function:return: A MediumLevelILInstruction object for the expression, if it exists. Otherwise, None"""ifindex>=self.get_expr_count():returnNonereturnMediumLevelILInstruction.create(self,index) [docs]defcopy_expr(self,original:MediumLevelILInstruction)->ExpressionIndex:"""``copy_expr`` makes a shallow copy of the given IL expression, adding a new expression to the IL function... warning:: The copy will not copy any child expressions, but will instead reference them as well (by expression index). This means that you cannot use this function to copy an expression tree to another function. If you want to copy an expression tree, you should use :py:func:`MediumLevelILFunction.copy_expr_to`. Metadata such as expression type and attributes are also not copied.:param MediumLevelILInstruction original: the original IL Instruction you want to copy:return: The index of the newly copied expression"""returnself.expr(original.operation,original.raw_operands[0],original.raw_operands[1],original.raw_operands[2],original.raw_operands[3],original.raw_operands[4],original.size,original.source_location) [docs]defreplace_expr(self,original:InstructionOrExpression,new:InstructionOrExpression)->None:"""``replace_expr`` replace an existing IL instruction in-place with another oneBoth expressions must have been created on the same function. The original expressionwill be replaced completely and the new expression will not be modified.:param ExpressionIndex original: the ExpressionIndex to replace (may also be an expression index):param ExpressionIndex new: the ExpressionIndex to add to the current LowLevelILFunction (may also be an expression index):rtype: None"""ifisinstance(original,MediumLevelILInstruction):assertoriginal.function==selforiginal=original.expr_indexelifisinstance(original,int):original=ExpressionIndex(original)ifisinstance(new,MediumLevelILInstruction):assertnew.function==selfnew=new.expr_indexelifisinstance(new,int):new=ExpressionIndex(new)core.BNReplaceMediumLevelILExpr(self.handle,original,new) [docs]defcopy_expr_to(self,expr:MediumLevelILInstruction,dest:'MediumLevelILFunction',sub_expr_handler:Optional[Callable[[MediumLevelILInstruction],ExpressionIndex]]=None)->ExpressionIndex:"""``copy_expr_to`` deep copies an expression from this function into a target functionIf provided, the function ``sub_expr_handler`` will be called on every copied sub-expression.. warning:: This function should ONLY be called as a part of a lifter or workflow. It will otherwise not do anything useful as analysis will not be running.:param MediumLevelILInstruction expr: Expression in this function to copy:param MediumLevelILFunction dest: Function to copy the expression to:param sub_expr_handler: Optional function to call on every copied sub-expression:return: Index of the copied expression in the target function"""ifsub_expr_handlerisNone:sub_expr_handler=lambdasub_expr:self.copy_expr_to(sub_expr,dest)defdo_copy(expr:MediumLevelILInstruction,dest:'MediumLevelILFunction',sub_expr_handler:Optional[Callable[[MediumLevelILInstruction],ExpressionIndex]]=None)->ExpressionIndex:loc=ILSourceLocation.from_instruction(expr)ifexpr.operation==MediumLevelILOperation.MLIL_NOP:expr:MediumLevelILNopreturndest.nop(loc)ifexpr.operation==MediumLevelILOperation.MLIL_SET_VAR:expr:MediumLevelILSetVarreturndest.set_var(expr.size,expr.dest,sub_expr_handler(expr.src),loc)ifexpr.operation==MediumLevelILOperation.MLIL_SET_VAR_SPLIT:expr:MediumLevelILSetVarSplitreturndest.set_var_split(expr.size,expr.high,expr.low,sub_expr_handler(expr.src),loc)ifexpr.operation==MediumLevelILOperation.MLIL_SET_VAR_FIELD:expr:MediumLevelILSetVarFieldreturndest.set_var_field(expr.size,expr.dest,expr.offset,sub_expr_handler(expr.src),loc)ifexpr.operation==MediumLevelILOperation.MLIL_VAR:expr:MediumLevelILVarreturndest.var(expr.size,expr.src,loc)ifexpr.operation==MediumLevelILOperation.MLIL_VAR_FIELD:expr:MediumLevelILVarFieldreturndest.var_field(expr.size,expr.src,expr.offset,loc)ifexpr.operation==MediumLevelILOperation.MLIL_VAR_SPLIT:expr:MediumLevelILVarSplitreturndest.var_split(expr.size,expr.high,expr.low,loc)ifexpr.operation==MediumLevelILOperation.MLIL_FORCE_VER:expr:MediumLevelILForceVerreturndest.force_ver(expr.size,expr.dest,expr.src,loc)ifexpr.operation==MediumLevelILOperation.MLIL_ASSERT:expr:MediumLevelILAssertreturndest.assert_expr(expr.size,expr.src,expr.constraint,loc)ifexpr.operation==MediumLevelILOperation.MLIL_ADDRESS_OF:expr:MediumLevelILAddressOfreturndest.address_of(expr.src,loc)ifexpr.operation==MediumLevelILOperation.MLIL_ADDRESS_OF_FIELD:expr:MediumLevelILAddressOfFieldreturndest.address_of_field(expr.src,expr.offset,loc)ifexpr.operation==MediumLevelILOperation.MLIL_CALL:expr:MediumLevelILCallparams=[sub_expr_handler(param)forparaminexpr.params]returndest.call(expr.output,sub_expr_handler(expr.dest),params,loc)ifexpr.operation==MediumLevelILOperation.MLIL_CALL_UNTYPED:expr:MediumLevelILCallUntypedparams=[sub_expr_handler(param)forparaminexpr.params]returndest.call_untyped(expr.output,sub_expr_handler(expr.dest),params,sub_expr_handler(expr.stack),loc)ifexpr.operation==MediumLevelILOperation.MLIL_SYSCALL:expr:MediumLevelILSyscallparams=[sub_expr_handler(param)forparaminexpr.params]returndest.system_call(expr.output,params,loc)ifexpr.operation==MediumLevelILOperation.MLIL_SYSCALL_UNTYPED:expr:MediumLevelILSyscallUntypedparams=[sub_expr_handler(param)forparaminexpr.params]returndest.system_call_untyped(expr.output,params,sub_expr_handler(expr.stack),loc)ifexpr.operation==MediumLevelILOperation.MLIL_TAILCALL:expr:MediumLevelILTailcallparams=[sub_expr_handler(param)forparaminexpr.params]returndest.tailcall(expr.output,sub_expr_handler(expr.dest),params,loc)ifexpr.operation==MediumLevelILOperation.MLIL_TAILCALL_UNTYPED:expr:MediumLevelILTailcallUntypedparams=[sub_expr_handler(param)forparaminexpr.params]returndest.tailcall_untyped(expr.output,sub_expr_handler(expr.dest),params,sub_expr_handler(expr.stack),loc)# if expr.operation == MediumLevelILOperation.MLIL_SEPARATE_PARAM_LIST:# expr: MediumLevelILSeparateParamList# params = [sub_expr_handler(param) for param in expr.params]# return dest.separate_param_list(params, loc)# if expr.operation == MediumLevelILOperation.MLIL_SHARED_PARAM_SLOT:# expr: MediumLevelILSharedParamSlot# params = [sub_expr_handler(param) for param in expr.params]# return dest.shared_param_slot(params, loc)ifexpr.operation==MediumLevelILOperation.MLIL_RET:expr:MediumLevelILRetparams=[sub_expr_handler(src)forsrcinexpr.src]returndest.ret(params,loc)ifexpr.operation==MediumLevelILOperation.MLIL_NORET:expr:MediumLevelILNoretreturndest.no_ret(loc)ifexpr.operation==MediumLevelILOperation.MLIL_STORE:expr:MediumLevelILStorereturndest.store(expr.size,sub_expr_handler(expr.dest),sub_expr_handler(expr.src),loc)ifexpr.operation==MediumLevelILOperation.MLIL_STORE_STRUCT:expr:MediumLevelILStoreStructreturndest.store_struct(expr.size,sub_expr_handler(expr.dest),expr.offset,sub_expr_handler(expr.src),loc)ifexpr.operation==MediumLevelILOperation.MLIL_LOAD:expr:MediumLevelILLoadreturndest.load(expr.size,sub_expr_handler(expr.src),loc)ifexpr.operation==MediumLevelILOperation.MLIL_LOAD_STRUCT:expr:MediumLevelILLoadStructreturndest.load_struct(expr.size,sub_expr_handler(expr.src),expr.offset,loc)ifexpr.operation==MediumLevelILOperation.MLIL_JUMP:expr:MediumLevelILJumpreturndest.jump(sub_expr_handler(expr.dest),loc)ifexpr.operationin[MediumLevelILOperation.MLIL_NEG,MediumLevelILOperation.MLIL_NOT,MediumLevelILOperation.MLIL_SX,MediumLevelILOperation.MLIL_ZX,MediumLevelILOperation.MLIL_LOW_PART,MediumLevelILOperation.MLIL_BOOL_TO_INT,MediumLevelILOperation.MLIL_RET_HINT,MediumLevelILOperation.MLIL_UNIMPL_MEM,MediumLevelILOperation.MLIL_FSQRT,MediumLevelILOperation.MLIL_FNEG,MediumLevelILOperation.MLIL_FABS,MediumLevelILOperation.MLIL_FLOAT_TO_INT,MediumLevelILOperation.MLIL_INT_TO_FLOAT,MediumLevelILOperation.MLIL_FLOAT_CONV,MediumLevelILOperation.MLIL_ROUND_TO_INT,MediumLevelILOperation.MLIL_FLOOR,MediumLevelILOperation.MLIL_CEIL,MediumLevelILOperation.MLIL_FTRUNC]:expr:MediumLevelILUnaryBasereturndest.expr(expr.operation,sub_expr_handler(expr.src),size=expr.size,source_location=loc)ifexpr.operationin[MediumLevelILOperation.MLIL_ADD,MediumLevelILOperation.MLIL_SUB,MediumLevelILOperation.MLIL_AND,MediumLevelILOperation.MLIL_OR,MediumLevelILOperation.MLIL_XOR,MediumLevelILOperation.MLIL_LSL,MediumLevelILOperation.MLIL_LSR,MediumLevelILOperation.MLIL_ASR,MediumLevelILOperation.MLIL_ROL,MediumLevelILOperation.MLIL_ROR,MediumLevelILOperation.MLIL_MUL,MediumLevelILOperation.MLIL_MULU_DP,MediumLevelILOperation.MLIL_MULS_DP,MediumLevelILOperation.MLIL_DIVU,MediumLevelILOperation.MLIL_DIVS,MediumLevelILOperation.MLIL_MODU,MediumLevelILOperation.MLIL_MODS,MediumLevelILOperation.MLIL_DIVU_DP,MediumLevelILOperation.MLIL_DIVS_DP,MediumLevelILOperation.MLIL_MODU_DP,MediumLevelILOperation.MLIL_MODS_DP,MediumLevelILOperation.MLIL_CMP_E,MediumLevelILOperation.MLIL_CMP_NE,MediumLevelILOperation.MLIL_CMP_SLT,MediumLevelILOperation.MLIL_CMP_ULT,MediumLevelILOperation.MLIL_CMP_SLE,MediumLevelILOperation.MLIL_CMP_ULE,MediumLevelILOperation.MLIL_CMP_SGE,MediumLevelILOperation.MLIL_CMP_UGE,MediumLevelILOperation.MLIL_CMP_SGT,MediumLevelILOperation.MLIL_CMP_UGT,MediumLevelILOperation.MLIL_TEST_BIT,MediumLevelILOperation.MLIL_ADD_OVERFLOW,MediumLevelILOperation.MLIL_FADD,MediumLevelILOperation.MLIL_FSUB,MediumLevelILOperation.MLIL_FMUL,MediumLevelILOperation.MLIL_FDIV,MediumLevelILOperation.MLIL_FCMP_E,MediumLevelILOperation.MLIL_FCMP_NE,MediumLevelILOperation.MLIL_FCMP_LT,MediumLevelILOperation.MLIL_FCMP_LE,MediumLevelILOperation.MLIL_FCMP_GE,MediumLevelILOperation.MLIL_FCMP_GT,MediumLevelILOperation.MLIL_FCMP_O,MediumLevelILOperation.MLIL_FCMP_UO]:expr:MediumLevelILBinaryBasereturndest.expr(expr.operation,sub_expr_handler(expr.left),sub_expr_handler(expr.right),size=expr.size,source_location=loc)ifexpr.operationin[MediumLevelILOperation.MLIL_ADC,MediumLevelILOperation.MLIL_SBB,MediumLevelILOperation.MLIL_RLC,MediumLevelILOperation.MLIL_RRC]:expr:MediumLevelILCarryBasereturndest.expr(expr.operation,sub_expr_handler(expr.left),sub_expr_handler(expr.right),sub_expr_handler(expr.carry),size=expr.size,source_location=loc)ifexpr.operation==MediumLevelILOperation.MLIL_JUMP_TO:expr:MediumLevelILJumpTolabel_list={}fora,binexpr.targets.items():label_a=dest.get_label_for_source_instruction(b)iflabel_aisNone:returndest.jump(sub_expr_handler(expr.dest),loc)label_list[a]=label_areturndest.jump_to(sub_expr_handler(expr.dest),label_list,loc)ifexpr.operation==MediumLevelILOperation.MLIL_GOTO:expr:MediumLevelILGotolabel_a=dest.get_label_for_source_instruction(expr.dest)iflabel_aisNone:returndest.jump(dest.const_pointer(expr.function.arch.address_size,expr.function[expr.dest].address),loc)returndest.goto(label_a,loc)ifexpr.operation==MediumLevelILOperation.MLIL_IF:expr:MediumLevelILIflabel_a=dest.get_label_for_source_instruction(expr.true)label_b=dest.get_label_for_source_instruction(expr.false)iflabel_aisNoneorlabel_bisNone:returndest.undefined(loc)returndest.if_expr(sub_expr_handler(expr.condition),label_a,label_b,loc)ifexpr.operation==MediumLevelILOperation.MLIL_CONST:expr:MediumLevelILConstreturndest.const(expr.size,expr.constant,loc)ifexpr.operation==MediumLevelILOperation.MLIL_CONST_PTR:expr:MediumLevelILConstPtrreturndest.const_pointer(expr.size,expr.constant,loc)ifexpr.operation==MediumLevelILOperation.MLIL_EXTERN_PTR:expr:MediumLevelILExternPtrreturndest.extern_pointer(expr.size,expr.constant,expr.offset,loc)ifexpr.operation==MediumLevelILOperation.MLIL_FLOAT_CONST:expr:MediumLevelILFloatConstreturndest.float_const_raw(expr.size,expr.raw_operands[0],loc)ifexpr.operation==MediumLevelILOperation.MLIL_IMPORT:expr:MediumLevelILImportreturndest.imported_address(expr.size,expr.constant,loc)ifexpr.operation==MediumLevelILOperation.MLIL_CONST_DATA:expr:MediumLevelILConstDatareturndest.const_data(expr.size,expr.constant_data,loc)ifexpr.operation==MediumLevelILOperation.MLIL_BP:expr:MediumLevelILBpreturndest.breakpoint(loc)ifexpr.operation==MediumLevelILOperation.MLIL_TRAP:expr:MediumLevelILTrapreturndest.trap(expr.vector,loc)ifexpr.operation==MediumLevelILOperation.MLIL_INTRINSIC:expr:MediumLevelILIntrinsicparams=[sub_expr_handler(param)forparaminexpr.params]returndest.intrinsic(expr.output,expr.intrinsic,params,loc)ifexpr.operation==MediumLevelILOperation.MLIL_FREE_VAR_SLOT:expr:MediumLevelILFreeVarSlotreturndest.free_var_slot(expr.dest,loc)ifexpr.operation==MediumLevelILOperation.MLIL_UNDEF:expr:MediumLevelILUndefreturndest.undefined(loc)ifexpr.operation==MediumLevelILOperation.MLIL_UNIMPL:expr:MediumLevelILUnimplreturndest.unimplemented(loc)raiseNotImplementedError(f"unknown expr operation{expr.operation} in copy_expr_to")new_index=do_copy(expr,dest,sub_expr_handler)# Copy expression metadata as welldest.set_expr_attributes(new_index,expr.attributes)returnnew_index [docs]deftranslate(self,expr_handler:Callable[['MediumLevelILFunction','MediumLevelILBasicBlock','MediumLevelILInstruction'],ExpressionIndex])->'MediumLevelILFunction':"""``translate`` clones an IL function and modifies its expressions as specified bya given ``expr_handler``, returning the updated IL function.:param expr_handler: Function to modify an expression and copy it to the new function. The function should have the following signature: expr_handler(new_func: MediumLevelILFunction, old_block: MediumLevelILBasicBlock, old_instr: MediumLevelILInstruction) -> ExpressionIndex Where: - **new_func** (*MediumLevelILFunction*): New function to receive translated instructions - **old_block** (*MediumLevelILBasicBlock*): Original block containing old_instr - **old_instr** (*MediumLevelILInstruction*): Original instruction - **returns** (*ExpressionIndex*): Expression index of newly created instruction in ``new_func``:return: Cloned IL function with modifications"""propagated_func=MediumLevelILFunction(self.arch,low_level_il=self.low_level_il)propagated_func.prepare_to_copy_function(self)forblockinself.basic_blocks:propagated_func.prepare_to_copy_block(block)forinstr_indexinrange(block.start,block.end):instr:MediumLevelILInstruction=self[InstructionIndex(instr_index)]propagated_func.set_current_address(instr.address,block.arch)propagated_func.append(expr_handler(propagated_func,block,instr),ILSourceLocation.from_instruction(instr))returnpropagated_func [docs]defset_expr_attributes(self,expr:InstructionOrExpression,value:ILInstructionAttributeSet):"""``set_expr_attributes`` allows modification of instruction attributes but ONLY during lifting... warning:: This function should ONLY be called as a part of a lifter. It will otherwise not do anything useful as there's no way to trigger re-analysis of IL levels at this time.:param ExpressionIndex expr: the ExpressionIndex to replace (may also be an expression index):param set(ILInstructionAttribute) value: the set of attributes to place on the instruction:rtype: None"""ifisinstance(expr,MediumLevelILInstruction):expr=expr.expr_indexelifisinstance(expr,int):expr=ExpressionIndex(expr)result=0forflaginvalue:result|=flag.valuecore.BNSetMediumLevelILExprAttributes(self.handle,expr,result) [docs]defappend(self,expr:ExpressionIndex,source_location:Optional['ILSourceLocation']=None)->InstructionIndex:"""``append`` adds the ExpressionIndex ``expr`` to the current MediumLevelILFunction.:param ExpressionIndex expr: the ExpressionIndex to add to the current MediumLevelILFunction:param ILSourceLocation source_location: Optional source location for the instruction:return: Index of added instruction in the current function:rtype: int"""index=InstructionIndex(core.BNMediumLevelILAddInstruction(self.handle,expr))self._record_mlil_to_mlil_instr_map(index,source_location)returnindex def_record_mlil_to_mlil_instr_map(self,index,source_location:'ILSourceLocation'):# Update internal mappings to remember thisifsource_locationisnotNone:ifsource_location.source_mlil_instructionisnotNone:ifsource_location.source_mlil_instructionnotinself._mlil_to_mlil_instr_map:self._mlil_to_mlil_instr_map[source_location.source_mlil_instruction]=[]self._mlil_to_mlil_instr_map[source_location.source_mlil_instruction].append((index,source_location.il_direct))ifsource_location.source_llil_instructionisnotNone \
andsource_location.source_llil_instruction.function.il_form==FunctionGraphType.LowLevelILSSAFormFunctionGraph:ifsource_location.source_llil_instructionnotinself._llil_ssa_to_mlil_instr_map:self._llil_ssa_to_mlil_instr_map[source_location.source_llil_instruction]=[]self._llil_ssa_to_mlil_instr_map[source_location.source_llil_instruction].append((index,source_location.il_direct))def_record_mlil_to_mlil_expr_map(self,index,source_location:'ILSourceLocation'):# Update internal mappings to remember thisifsource_location.source_mlil_instructionisnotNone:ifsource_location.source_mlil_instructionnotinself._mlil_to_mlil_expr_map:self._mlil_to_mlil_expr_map[source_location.source_mlil_instruction]=[]self._mlil_to_mlil_expr_map[source_location.source_mlil_instruction].append((index,source_location.il_direct))ifsource_location.source_llil_instructionisnotNone \
andsource_location.source_llil_instruction.function.il_form==FunctionGraphType.LowLevelILSSAFormFunctionGraph:ifsource_location.source_llil_instructionnotinself._llil_ssa_to_mlil_expr_map:self._llil_ssa_to_mlil_expr_map[source_location.source_llil_instruction]=[]self._llil_ssa_to_mlil_expr_map[source_location.source_llil_instruction].append((index,source_location.il_direct))def_get_llil_ssa_to_mlil_instr_map(self,from_builders:bool)->LLILSSAToMLILInstructionMapping:llil_ssa_to_mlil_instr_map={}iffrom_builders:# TODO: Handle LLIL SSA -> MLIL mappings in case someone is brave enough to try# lifting LLILSSA->MLIL themselves instead of an MLIL->MLIL translation# (which is the only one I've seen people do so far)for(old_instr,new_indices)inself._mlil_to_mlil_instr_map.items():old_instr:MediumLevelILInstructionnew_indices:List[InstructionIndex]# Look up the LLIL SSA instruction for the old instr in its function# And then store that mapping for the new functionfor(new_index,new_direct)innew_indices:# Instructions are always mapped 1 to 1. If the map is marked indirect# then just ignore itifnew_direct:old_llil_ssa_index=old_instr.function.get_low_level_il_instruction_index(old_instr.instr_index)ifold_llil_ssa_indexisnotNone:llil_ssa_to_mlil_instr_map[old_llil_ssa_index]=new_indexelse:forinstrinself.instructions:llil_ssa_index=self.get_low_level_il_instruction_index(instr.instr_index)llil_ssa_to_mlil_instr_map[llil_ssa_index]=instr.instr_indexreturnllil_ssa_to_mlil_instr_mapdef_get_llil_ssa_to_mlil_expr_map(self,from_builders:bool)->LLILSSAToMLILExpressionMapping:llil_ssa_to_mlil_expr_map=[]iffrom_builders:# TODO: Handle LLIL SSA -> MLIL mappings in case someone is brave enough to try# lifting LLILSSA->MLIL themselves instead of an MLIL->MLIL translation# (which is the only one I've seen people do so far)for(old_expr,new_indices)inself._mlil_to_mlil_expr_map.items():old_expr:MediumLevelILInstructionnew_indices:List[ExpressionIndex]# Look up the LLIL SSA expression for the old expr in its function# And then store that mapping for the new functionold_llil_ssa_direct=old_expr.function.get_low_level_il_expr_index(old_expr.expr_index)old_llil_ssa_indices=old_expr.function.get_low_level_il_expr_indexes(old_expr.expr_index)forold_indexinold_llil_ssa_indices:old_reverse_direct=old_expr.function.low_level_il.ssa_form.get_medium_level_il_expr_index(old_index)old_reverse_all=old_expr.function.low_level_il.ssa_form.get_medium_level_il_expr_indexes(old_index)for(new_index,new_direct)innew_indices:lower_to_higher_direct=new_directandold_reverse_direct==old_expr.expr_indexhigher_to_lower_direct=new_directandold_index==old_llil_ssa_directmap_lower_to_higher=old_expr.expr_indexinold_reverse_allmap_higher_to_lower=Truellil_ssa_to_mlil_expr_map.append(LLILSSAToMLILExpressionMap(old_index,new_index,map_lower_to_higher,map_higher_to_lower,lower_to_higher_direct,higher_to_lower_direct))else:forinstrinself.instructions:forexprininstr.traverse(lambdae:e):llil_ssa_direct=self.get_low_level_il_expr_index(expr.expr_index)llil_ssa_indices=self.get_low_level_il_expr_indexes(expr.expr_index)forllil_ssa_indexinllil_ssa_indices:reverse_direct=self.low_level_il.ssa_form.get_medium_level_il_expr_index(llil_ssa_index)reverse_all=self.low_level_il.ssa_form.get_medium_level_il_expr_indexes(llil_ssa_index)lower_to_higher_direct=reverse_direct==expr.expr_indexhigher_to_lower_direct=llil_ssa_index==llil_ssa_directmap_lower_to_higher=expr.expr_indexinreverse_allmap_higher_to_lower=Truellil_ssa_to_mlil_expr_map.append(LLILSSAToMLILExpressionMap(llil_ssa_index,expr.expr_index,map_lower_to_higher,map_higher_to_lower,lower_to_higher_direct,higher_to_lower_direct))returnllil_ssa_to_mlil_expr_map[docs]defnop(self,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``nop`` no operation, this instruction does nothing:param loc: Location of expression:return: The no operation expression:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_NOP,source_location=loc) [docs]defset_var(self,size:int,dest:'variable.Variable',src:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``set_var`` sets the variable ``dest`` of size ``size`` to the expression ``src``:param int size: the size of the variable in bytes:param Variable dest: the variable being set:param ExpressionIndex src: expression with the value to set the variable to:param ILSourceLocation loc: location of returned expression:return: The expression ``dest = src``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_SET_VAR,dest.identifier,src,size=size,source_location=loc) [docs]defset_var_field(self,size:int,dest:'variable.Variable',offset:int,src:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``set_var_field`` sets the field ``offset`` of variable ``dest`` of size ``size`` to the expression ``src``:param int size: the size of the field in bytes:param Variable dest: the variable being set:param int offset: offset of field in the variable:param ExpressionIndex src: expression with the value to set the field to:param ILSourceLocation loc: location of returned expression:return: The expression ``dest:offset = src``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_SET_VAR_FIELD,dest.identifier,offset,src,size=size,source_location=loc) [docs]defset_var_split(self,size:int,hi:'variable.Variable',lo:'variable.Variable',src:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``set_var_split`` uses ``hi`` and ``lo`` as a single extended variable of size ``2*size``setting ``hi:lo`` to the expression ``src``:param int size: the size of each variable in bytes:param Variable hi: the high variable being set:param Variable lo: the low variable being set:param ExpressionIndex src: expression with the value to set the variables to:param ILSourceLocation loc: location of returned expression:return: The expression ``hi:lo = src``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_SET_VAR_SPLIT,hi.identifier,lo.identifier,src,size=size,source_location=loc) [docs]defload(self,size:int,src:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``load`` Reads ``size`` bytes from the expression ``src``:param int size: number of bytes to read:param ExpressionIndex src: the expression to read memory from:param ILSourceLocation loc: location of returned expression:return: The expression ``[addr].size``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_LOAD,src,size=size,source_location=loc) [docs]defload_struct(self,size:int,src:ExpressionIndex,offset:int,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``load_struct`` Reads ``size`` bytes at the offset ``offset`` from the expression ``src``:param int size: number of bytes to read:param ExpressionIndex src: the expression to read memory from:param int offset: offset of field in the memory:param ILSourceLocation loc: location of returned expression:return: The expression ``[(src + offset)].size`` (often rendered ``src->offset.size``):rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_LOAD_STRUCT,src,offset,size=size,source_location=loc) [docs]defstore(self,size:int,dest:ExpressionIndex,src:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``store`` Writes ``size`` bytes to expression ``dest`` read from expression ``src``:param int size: number of bytes to write:param ExpressionIndex dest: the expression to write to:param ExpressionIndex src: the expression to be written:param ILSourceLocation loc: location of returned expression:return: The expression ``[dest].size = src``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_STORE,dest,src,size=size,source_location=loc) [docs]defstore_struct(self,size:int,dest:ExpressionIndex,offset:int,src:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``store_struct`` Writes ``size`` bytes to expression ``dest`` at the offset ``offset`` read from expression ``src``:param int size: number of bytes to write:param ExpressionIndex dest: the expression to write to:param int offset: offset of field in the memory:param ExpressionIndex src: the expression to be written:param ILSourceLocation loc: location of returned expression:return: The expression ``[(dest + offset)].size = src`` (often rendered ``dest->offset.size``):rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_STORE_STRUCT,dest,offset,src,size=size,source_location=loc) [docs]defvar(self,size:int,src:'variable.Variable',loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``var`` returns the variable ``src`` of size ``size``:param int size: the size of the variable in bytes:param Variable src: the variable being read:param ILSourceLocation loc: location of returned expression:return: An expression for the given variable:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_VAR,src.identifier,size=size,source_location=loc) [docs]defvar_field(self,size:int,src:'variable.Variable',offset:int,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``var_field`` returns the field at offset ``offset`` from variable ``src`` of size ``size``:param int size: the size of the field in bytes:param Variable src: the variable being read:param int offset: offset of field in the variable:param ILSourceLocation loc: location of returned expression:return: The expression ``var:offset.size``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_VAR_FIELD,src.identifier,offset,size=size,source_location=loc) [docs]defvar_split(self,size:int,hi:'variable.Variable',lo:'variable.Variable',loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``var_split`` combines variables ``hi`` and ``lo`` of size ``size`` into an expression of size ``2*size``:param int size: the size of each variable in bytes:param Variable hi: the variable holding high part of value:param Variable lo: the variable holding low part of value:param ILSourceLocation loc: location of returned expression:return: The expression ``hi:lo``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_VAR_SPLIT,hi.identifier,lo.identifier,size=size,source_location=loc) [docs]defassert_expr(self,size:int,src:'variable.Variable',constraint:'variable.PossibleValueSet',loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``assert_expr`` assert ``constraint`` is the value of the given variable ``src``.Used when setting user variable values.:param int size: size of value in the constraint:param Variable src: variable to constrain:param variable.PossibleValueSet constraint: asserted value of variable:param ILSourceLocation loc: location of returned expression:return: The expression ``ASSERT(src, constraint)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_ASSERT,src.identifier,ExpressionIndex(self.cache_possible_value_set(constraint)),size=size,source_location=loc) [docs]defforce_ver(self,size:int,dest:'variable.Variable',src:'variable.Variable',loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``force_ver`` creates a new version of the variable ``dest`` in ``src``Effectively, this is like saying src = dest, which analysis can then use as a newvariable definition site.:param int size: size of the variable:param Variable dest: the variable to force a new version of:param Variable src: the variable created with the new version:param ILSourceLocation loc: location of returned expression:return: The expression ``FORCE_VER(reg)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_FORCE_VER,dest.identifier,src.identifier,size=size,source_location=loc) [docs]defaddress_of(self,var:'variable.Variable',loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``address_of`` takes the address of ``var``:param Variable var: the variable having its address taken:param ILSourceLocation loc: location of returned expression:return: The expression ``&var``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_ADDRESS_OF,var.identifier,size=0,source_location=loc) [docs]defaddress_of_field(self,var:'variable.Variable',offset:int,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``address_of_field`` takes the address of ``var`` at the offset ``offset``:param Variable var: the variable having its address taken:param int offset: the offset of the taken address:param ILSourceLocation loc: location of returned expression:return: The expression ``&var:offset``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_ADDRESS_OF_FIELD,var.identifier,offset,size=0,source_location=loc) [docs]defconst(self,size:int,value:int,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``const`` returns an expression for the constant integer ``value`` of size ``size``:param int size: the size of the constant in bytes:param int value: integer value of the constant:param ILSourceLocation loc: location of returned expression:return: A constant expression of given value and size:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_CONST,value,size=size,source_location=loc) [docs]defconst_pointer(self,size:int,value:int,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``const_pointer`` returns an expression for the constant pointer ``value`` of size ``size``:param int size: the size of the pointer in bytes:param int value: address referenced by the pointer:param ILSourceLocation loc: location of returned expression:return: A constant expression of given value and size:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_CONST_PTR,value,size=size,source_location=loc) [docs]defextern_pointer(self,size:int,value:int,offset:int,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``extern_pointer`` returns an expression for the external pointer ``value`` at offset ``offset`` of size ``size``:param int size: the size of the pointer in bytes:param int value: address referenced by the pointer:param int offset: offset applied to the address:param loc: location of returned expression:return: A constant expression of given value and size:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_EXTERN_PTR,value,offset,size=size,source_location=loc) [docs]deffloat_const_raw(self,size:int,value:int,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``float_const_raw`` returns an expression for the constant raw binary floating pointvalue ``value`` with size ``size``:param int size: the size of the constant in bytes:param int value: integer value for the raw binary representation of the constant:param ILSourceLocation loc: location of returned expression:return: A constant expression of given value and size:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_FLOAT_CONST,value,size=size,source_location=loc) [docs]deffloat_const_single(self,value:float,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``float_const_single`` returns an expression for the single precision floating point value ``value``:param float value: float value for the constant:param ILSourceLocation loc: location of returned expression:return: A constant expression of given value and size:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_FLOAT_CONST,struct.unpack("I",struct.pack("f",value))[0],size=4,source_location=loc) [docs]deffloat_const_double(self,value:float,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``float_const_double`` returns an expression for the double precision floating point value ``value``:param float value: float value for the constant:param ILSourceLocation loc: location of returned expression:return: A constant expression of given value and size:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_FLOAT_CONST,struct.unpack("Q",struct.pack("d",value))[0],size=8,source_location=loc) [docs]defimported_address(self,size:int,value:int,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``imported_address`` returns an expression for an imported value with address ``value`` and size ``size``:param int size: size of the imported value:param int value: address of the imported value:param ILSourceLocation loc: location of returned expression:return: A constant expression of given value and size:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_IMPORT,value,size=size,source_location=loc) [docs]defconst_data(self,size:int,data:'variable.ConstantData',loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``const_data`` returns an expression for the constant data ``data``:param int size: size of the data:param ConstantData data: value of the data:param ILSourceLocation loc: location of returned expression:return: A constant expression of given value and size:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_CONST_DATA,data.type,data.value,size=size,source_location=loc) [docs]defadd(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``add`` adds expression ``a`` to expression ``b`` returning an expression of ``size`` bytes:param int size: the size of the result in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``add.<size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_ADD,a,b,size=size,source_location=loc) [docs]defadd_carry(self,size:int,a:ExpressionIndex,b:ExpressionIndex,carry:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``add_carry`` adds expression ``a`` to expression ``b`` with carry from ``carry`` returning an expression of ``size`` bytes:param int size: the size of the result in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ExpressionIndex carry: Carried value expression:param ILSourceLocation loc: location of returned expression:return: The expression ``adc.<size>(a, b, carry)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_ADC,a,b,carry,size=size,source_location=loc) [docs]defsub(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``sub`` subtracts expression ``a`` to expression ``b`` returning an expression of ``size`` bytes:param int size: the size of the result in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``sub.<size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_SUB,a,b,size=size,source_location=loc) [docs]defsub_borrow(self,size:int,a:ExpressionIndex,b:ExpressionIndex,carry:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``sub_borrow`` subtracts expression ``a`` to expression ``b`` with borrow from ``carry`` returning an expression of ``size`` bytes:param int size: the size of the result in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ExpressionIndex carry: Carried value expression:param ILSourceLocation loc: location of returned expression:return: The expression ``sbb.<size>(a, b, carry)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_SBB,a,b,carry,size=size,source_location=loc) [docs]defand_expr(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``and_expr`` bitwise and's expression ``a`` and expression ``b`` returning an expression of ``size`` bytes:param int size: the size of the result in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``and.<size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_AND,a,b,size=size,source_location=loc) [docs]defor_expr(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``or_expr`` bitwise or's expression ``a`` and expression ``b`` returning an expression of ``size`` bytes:param int size: the size of the result in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``or.<size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_OR,a,b,size=size,source_location=loc) [docs]defxor_expr(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``xor_expr`` xor's expression ``a`` and expression ``b`` returning an expression of ``size`` bytes:param int size: the size of the result in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``xor.<size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_XOR,a,b,size=size,source_location=loc) [docs]defshift_left(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``shift_left`` left shifts expression ``a`` by expression ``b`` returning an expression of ``size`` bytes:param int size: the size of the result in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``lsl.<size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_LSL,a,b,size=size,source_location=loc) [docs]deflogical_shift_right(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``logical_shift_right`` logically right shifts expression ``a`` by expression ``b`` returning an expression of ``size`` bytes:param int size: the size of the result in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``lsr.<size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_LSR,a,b,size=size,source_location=loc) [docs]defarith_shift_right(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``arith_shift_right`` arithmetically right shifts expression ``a`` by expression ``b`` returning an expression of ``size`` bytes:param int size: the size of the result in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``asr.<size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_ASR,a,b,size=size,source_location=loc) [docs]defrotate_left(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``rotate_left`` bitwise rotates left expression ``a`` by expression ``b`` returning an expression of ``size`` bytes:param int size: the size of the result in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``rol.<size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_ROL,a,b,size=size,source_location=loc) [docs]defrotate_left_carry(self,size:int,a:ExpressionIndex,b:ExpressionIndex,carry:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``rotate_left_carry`` bitwise rotates left expression ``a`` by expression ``b`` with carry from ``carry`` returning an expression of ``size`` bytes:param int size: the size of the result in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ExpressionIndex carry: Carried value expression:param ILSourceLocation loc: location of returned expression:return: The expression ``rlc.<size>(a, b, carry)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_RLC,a,b,carry,size=size,source_location=loc) [docs]defrotate_right(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``rotate_right`` bitwise rotates right expression ``a`` by expression ``b`` returning an expression of ``size`` bytes:param int size: the size of the result in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``ror.<size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_ROR,a,b,size=size,source_location=loc) [docs]defrotate_right_carry(self,size:int,a:ExpressionIndex,b:ExpressionIndex,carry:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``rotate_right_carry`` bitwise rotates right expression ``a`` by expression ``b`` with carry from ``carry`` returning an expression of ``size`` bytes:param int size: the size of the result in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ExpressionIndex carry: Carried value expression:param ILSourceLocation loc: location of returned expression:return: The expression ``rrc.<size>(a, b, carry)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_RRC,a,b,carry,size=size,source_location=loc) [docs]defmult(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``mult`` multiplies expression ``a`` by expression ``b`` and returns an expression.Both the operands and return value are ``size`` bytes as the product's upper half is discarded.:param int size: the size of the result and input operands, in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``mult.<size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_MUL,a,b,size=size,source_location=loc) [docs]defmult_double_prec_signed(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``mult_double_prec_signed`` signed multiplies expression ``a`` by expression ``b`` and returns an expression.Both the operands are ``size`` bytes and the returned expression is of size ``2*size`` bytes.:param int size: the size of the result and input operands, in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``muls.dp.<2*size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_MULS_DP,a,b,size=size,source_location=loc) [docs]defmult_double_prec_unsigned(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``mult_double_prec_unsigned`` unsigned multiplies expression ``a`` by expression ``b`` and returnisan expression.Both the operands are ``size`` bytes and the returned expression is of size ``2*size`` bytes.:param int size: the size of the result and input operands, in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``mulu.dp.<2*size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_MULU_DP,a,b,size=size,source_location=loc) [docs]defdiv_signed(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``div_signed`` signed divides expression ``a`` by expression ``b`` and returns an expression.Both the operands and return value are ``size`` bytes.:param int size: the size of the result and input operands, in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``divs.<size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_DIVS,a,b,size=size,source_location=loc) [docs]defdiv_double_prec_signed(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``div_double_prec_signed`` signed divides double precision expression ``a`` by expression ``b`` and returns an expression.The first operand is of size ``2*size`` bytes and the other operand and return value are of size ``size`` bytes.:param int size: the size of the result and input operands, in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``divs.dp.<size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_DIVS_DP,a,b,size=size,source_location=loc) [docs]defdiv_unsigned(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``div_unsigned`` unsigned divides expression ``a`` by expression ``b`` and returns an expression.Both the operands and return value are ``size`` bytes.:param int size: the size of the result and input operands, in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``divu.<size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_DIVU,a,b,size=size,source_location=loc) [docs]defdiv_double_prec_unsigned(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``div_double_prec_unsigned`` unsigned divides double precision expression ``a`` by expression ``b`` and returns an expression.The first operand is of size ``2*size`` bytes and the other operand and return value are of size ``size`` bytes.:param int size: the size of the result and input operands, in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``divu.dp.<size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_DIVU_DP,a,b,size=size,source_location=loc) [docs]defmod_signed(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``mod_signed`` signed modulus expression ``a`` by expression ``b`` and returns an expression.Both the operands and return value are ``size`` bytes.:param int size: the size of the result and input operands, in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``mods.<size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_MODS,a,b,size=size,source_location=loc) [docs]defmod_double_prec_signed(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``mod_double_prec_signed`` signed modulus double precision expression ``a`` by expression ``b`` and returns an expression.The first operand is of size ``2*size`` bytes and the other operand and return value are of size ``size`` bytes.:param int size: the size of the result and input operands, in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``mods.dp.<size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_MODS_DP,a,b,size=size,source_location=loc) [docs]defmod_unsigned(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``mod_unsigned`` unsigned modulus expression ``a`` by expression ``b`` and returns an expression.Both the operands and return value are ``size`` bytes.:param int size: the size of the result and input operands, in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``modu.<size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_MODU,a,b,size=size,source_location=loc) [docs]defmod_double_prec_unsigned(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``mod_double_prec_unsigned`` unsigned modulus double precision expression ``a`` by expression ``b`` and returns an expression.The first operand is of size ``2*size`` bytes and the other operand and return value are of size ``size`` bytes.:param int size: the size of the result and input operands, in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``modu.dp.<size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_MODU_DP,a,b,size=size,source_location=loc) [docs]defneg_expr(self,size:int,value:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``neg_expr`` two's complement sign negation of expression ``value`` of size ``size``:param int size: the size of the result in bytes:param ExpressionIndex value: the expression to negate:param ILSourceLocation loc: location of returned expression:return: The expression ``neg.<size>(value)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_NEG,value,size=size,source_location=loc) [docs]defnot_expr(self,size:int,value:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``not_expr`` bitwise inversion of expression ``value`` of size ``size``:param int size: the size of the result in bytes:param ExpressionIndex value: the expression to bitwise invert:param ILSourceLocation loc: location of returned expression:return: The expression ``not.<size>(value)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_NOT,value,size=size,source_location=loc) [docs]defsign_extend(self,size:int,value:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``sign_extend`` two's complement sign-extends the expression in ``value`` to ``size`` bytes:param int size: the size of the result in bytes:param ExpressionIndex value: the expression to sign extend:param ILSourceLocation loc: location of returned expression:return: The expression ``sx.<size>(value)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_SX,value,size=size,source_location=loc) [docs]defzero_extend(self,size:int,value:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``zero_extend`` zero-extends the expression in ``value`` to ``size`` bytes:param int size: the size of the result in bytes:param ExpressionIndex value: the expression to zero extend:param ILSourceLocation loc: location of returned expression:return: The expression ``zx.<size>(value)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_ZX,value,size=size,source_location=loc) [docs]deflow_part(self,size:int,value:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``low_part`` truncates the expression in ``value`` to ``size`` bytes:param int size: the size of the result in bytes:param ExpressionIndex value: the expression to zero extend:param ILSourceLocation loc: location of returned expression:return: The expression ``(value).<size>``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_LOW_PART,value,size=size,source_location=loc) [docs]defjump(self,dest:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``jump`` returns an expression which jumps (branches) to the expression ``dest``:param ExpressionIndex dest: the expression to jump to:param ILSourceLocation loc: location of returned expression:return: The expression ``jump(dest)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_JUMP,dest,size=0,source_location=loc) [docs]defjump_to(self,dest:ExpressionIndex,targets:Mapping[int,MediumLevelILLabel],loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``jump_to`` returns an expression which jumps (branches) various targets in ``targets``choosing the target in ``targets`` based on the value calculated by ``dest``:param ExpressionIndex dest: the expression choosing which jump target to use:param Mapping[int, MediumLevelILLabel] targets: the list of targets for jump locations:param ILSourceLocation loc: location of returned expression:return: The expression ``jump(dest)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_JUMP_TO,dest,len(targets)*2,self.add_label_map(targets),size=0,source_location=loc) [docs]defcall(self,output:List['variable.Variable'],dest:ExpressionIndex,params:List[ExpressionIndex],loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``call`` returns an expression which calls the function in the expression ``dest``with the parameters defined in ``params`` returning values in the variables in ``output``.:param List['variable.Variable'] output: output variables:param ExpressionIndex dest: the expression to call:param List[ExpressionIndex] params: parameter variables:param ILSourceLocation loc: location of returned expression:return: The expression ``output = call(dest, params...)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_CALL,len(output),self.add_variable_list(output),dest,len(params),self.add_operand_list(params),size=0,source_location=loc) [docs]defcall_untyped(self,output:List['variable.Variable'],dest:ExpressionIndex,params:List[ExpressionIndex],stack:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``call_untyped`` returns an expression which calls the function in the expression ``dest``with the parameters defined in ``params`` returning values in the variables in ``output``where stack resolution could not be determined and the top of the stack has to be specified in ``stack``:param List['variable.Variable'] output: output variables:param ExpressionIndex dest: the expression to call:param List[ExpressionIndex] params: parameter variables:param ExpressionIndex stack: expression of top of stack:param ILSourceLocation loc: location of returned expression:return: The expression ``output = call(dest, params..., stack = stack)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_CALL_UNTYPED,self.expr(MediumLevelILOperation.MLIL_CALL_OUTPUT,len(output),self.add_variable_list(output),size=0,source_location=loc),dest,self.expr(MediumLevelILOperation.MLIL_CALL_PARAM,len(params),self.add_operand_list(params),size=0,source_location=loc),stack,size=0,source_location=loc) [docs]defsystem_call(self,output:List['variable.Variable'],params:List[ExpressionIndex],loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``system_call`` returns an expression which performs a system callwith the parameters defined in ``params`` returning values in the variables in ``output``.:param List['variable.Variable'] output: output variables:param List[ExpressionIndex] params: parameter variables:param ILSourceLocation loc: location of returned expression:return: The expression ``output = syscall(dest, params...)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_SYSCALL,len(output),self.add_variable_list(output),len(params),self.add_operand_list(params),size=0,source_location=loc) [docs]defsystem_call_untyped(self,output:List['variable.Variable'],params:List[ExpressionIndex],stack:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``system_call_untyped`` returns an expression which performs a system callwith the parameters defined in ``params`` returning values in the variables in ``output``where stack resolution could not be determined and the top of the stack has to be specified in ``stack``:param List['variable.Variable'] output: output variables:param List[ExpressionIndex] params: parameter variables:param ExpressionIndex stack: expression of top of stack:param ILSourceLocation loc: location of returned expression:return: The expression ``output = syscall(dest, params..., stack = stack)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_SYSCALL_UNTYPED,self.expr(MediumLevelILOperation.MLIL_CALL_OUTPUT,len(output),self.add_variable_list(output),size=0,source_location=loc),self.expr(MediumLevelILOperation.MLIL_CALL_PARAM,len(params),self.add_operand_list(params),size=0,source_location=loc),stack,size=0,source_location=loc) [docs]deftailcall(self,output:List['variable.Variable'],dest:ExpressionIndex,params:List[ExpressionIndex],loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``tailcall`` returns an expression which tailcalls the function in the expression ``dest``with the parameters defined in ``params`` returning values in the variables in ``output``.:param List['variable.Variable'] output: output variables:param ExpressionIndex dest: the expression to call:param List[ExpressionIndex] params: parameter variables:param ILSourceLocation loc: location of returned expression:return: The expression ``output = tailcall(dest, params...)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_TAILCALL,len(output),self.add_variable_list(output),dest,len(params),self.add_operand_list(params),size=0,source_location=loc) [docs]deftailcall_untyped(self,output:List['variable.Variable'],dest:ExpressionIndex,params:List[ExpressionIndex],stack:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``tailcall_untyped`` returns an expression which tailcalls the function in the expression ``dest``with the parameters defined in ``params`` returning values in the variables in ``output``where stack resolution could not be determined and the top of the stack has to be specified in ``stack``:param List['variable.Variable'] output: output variables:param ExpressionIndex dest: the expression to call:param List[ExpressionIndex] params: parameter variables:param ExpressionIndex stack: expression of top of stack:param ILSourceLocation loc: location of returned expression:return: The expression ``output = tailcall(dest, params..., stack = stack)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_TAILCALL_UNTYPED,self.expr(MediumLevelILOperation.MLIL_CALL_OUTPUT,len(output),self.add_variable_list(output),size=0,source_location=loc),dest,self.expr(MediumLevelILOperation.MLIL_CALL_PARAM,len(params),self.add_operand_list(params),size=0,source_location=loc),stack,size=0,source_location=loc) [docs]defret(self,sources:List[ExpressionIndex],loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``ret`` returns an expression which jumps (branches) to the calling function,returning a result specified by the expressions in ``sources``.:param List[ExpressionIndex] sources: list of returned expressions:param ILSourceLocation loc: location of returned expression:return: The expression ``return sources...``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_RET,len(sources),self.add_operand_list(sources),size=0,source_location=loc) [docs]defno_ret(self,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``no_ret`` returns an expression that halts execution:param ILSourceLocation loc: location of returned expression:return: The expression ``noreturn``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_NORET,size=0,source_location=loc) [docs]defcompare_equal(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``compare_equal`` returns comparison expression of size ``size`` checking if expression ``a`` is equal toexpression ``b``:param int size: size in bytes:param ExpressionIndex a: LHS of comparison:param ExpressionIndex b: RHS of comparison:param ILSourceLocation loc: location of returned expression:return: a comparison expression.:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_CMP_E,a,b,size=size,source_location=loc) [docs]defcompare_not_equal(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``compare_not_equal`` returns comparison expression of size ``size`` checking if expression ``a`` is not equal toexpression ``b``:param int size: size in bytes:param ExpressionIndex a: LHS of comparison:param ExpressionIndex b: RHS of comparison:param ILSourceLocation loc: location of returned expression:return: a comparison expression.:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_CMP_NE,a,b,size=size,source_location=loc) [docs]defcompare_signed_less_than(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``compare_signed_less_than`` returns comparison expression of size ``size`` checking if expression ``a`` issigned less than expression ``b``:param int size: size in bytes:param ExpressionIndex a: LHS of comparison:param ExpressionIndex b: RHS of comparison:param ILSourceLocation loc: location of returned expression:return: a comparison expression.:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_CMP_SLT,a,b,size=size,source_location=loc) [docs]defcompare_unsigned_less_than(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``compare_unsigned_less_than`` returns comparison expression of size ``size`` checking if expression ``a`` isunsigned less than expression ``b``:param int size: size in bytes:param ExpressionIndex a: LHS of comparison:param ExpressionIndex b: RHS of comparison:param ILSourceLocation loc: location of returned expression:return: a comparison expression.:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_CMP_ULT,a,b,size=size,source_location=loc) [docs]defcompare_signed_less_equal(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``compare_signed_less_equal`` returns comparison expression of size ``size`` checking if expression ``a`` issigned less than or equal to expression ``b``:param int size: size in bytes:param ExpressionIndex a: LHS of comparison:param ExpressionIndex b: RHS of comparison:param ILSourceLocation loc: location of returned expression:return: a comparison expression.:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_CMP_SLE,a,b,size=size,source_location=loc) [docs]defcompare_unsigned_less_equal(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``compare_unsigned_less_equal`` returns comparison expression of size ``size`` checking if expression ``a`` isunsigned less than or equal to expression ``b``:param int size: size in bytes:param ExpressionIndex a: LHS of comparison:param ExpressionIndex b: RHS of comparison:param ILSourceLocation loc: location of returned expression:return: a comparison expression.:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_CMP_ULE,a,b,size=size,source_location=loc) [docs]defcompare_signed_greater_equal(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``compare_signed_greater_equal`` returns comparison expression of size ``size`` checking if expression ``a`` issigned greater than or equal to expression ``b``:param int size: size in bytes:param ExpressionIndex a: LHS of comparison:param ExpressionIndex b: RHS of comparison:param ILSourceLocation loc: location of returned expression:return: a comparison expression.:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_CMP_SGE,a,b,size=size,source_location=loc) [docs]defcompare_unsigned_greater_equal(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``compare_unsigned_greater_equal`` returns comparison expression of size ``size`` checking if expression ``a``is unsigned greater than or equal to expression ``b``:param int size: size in bytes:param ExpressionIndex a: LHS of comparison:param ExpressionIndex b: RHS of comparison:param ILSourceLocation loc: location of returned expression:return: a comparison expression.:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_CMP_UGE,a,b,size=size,source_location=loc) [docs]defcompare_signed_greater_than(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``compare_signed_greater_than`` returns comparison expression of size ``size`` checking if expression ``a`` issigned greater than or equal to expression ``b``:param int size: size in bytes:param ExpressionIndex a: LHS of comparison:param ExpressionIndex b: RHS of comparison:param ILSourceLocation loc: location of returned expression:return: a comparison expression.:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_CMP_SGT,a,b,size=size,source_location=loc) [docs]defcompare_unsigned_greater_than(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``compare_unsigned_greater_than`` returns comparison expression of size ``size`` checking if expression ``a`` isunsigned greater than or equal to expression ``b``:param int size: size in bytes:param ExpressionIndex a: LHS of comparison:param ExpressionIndex b: RHS of comparison:param ILSourceLocation loc: location of returned expression:return: a comparison expression.:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_CMP_UGT,a,b,size=size,source_location=loc) [docs]deftest_bit(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``test_bit`` returns an expression of size ``size`` that tells whether expression ``a`` has its bit with anindex of the expression ``b`` is set:param int size: size in bytes:param ExpressionIndex a: an expression to be tested:param ExpressionIndex b: an expression for the index of the big:param ILSourceLocation loc: location of returned expression:return: the result expression.:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_TEST_BIT,a,b,size=size,source_location=loc) [docs]defbool_to_int(self,size:int,a:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``bool_to_int`` returns an expression of size ``size`` converting the boolean expression ``a`` to an integer:param int size: size in bytes:param ExpressionIndex a: boolean expression to be converted:param ILSourceLocation loc: location of returned expression:return: the converted integer expression.:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_BOOL_TO_INT,a,size=size,source_location=loc) [docs]defbreakpoint(self,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``breakpoint`` returns a processor breakpoint expression.:param ILSourceLocation loc: location of returned expression:return: a breakpoint expression.:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_BP,source_location=loc) [docs]deftrap(self,value:int,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``trap`` returns a processor trap (interrupt) expression of the given integer ``value``.:param int value: trap (interrupt) number:param ILSourceLocation loc: location of returned expression:return: a trap expression.:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_TRAP,value,source_location=loc) [docs]defintrinsic(self,outputs:List['variable.Variable'],intrinsic:'architecture.IntrinsicType',params:List[ExpressionIndex],loc:Optional['ILSourceLocation']=None):"""``intrinsic`` return an intrinsic expression.:param List[Variable] outputs: list of output variables:param IntrinsicType intrinsic: which intrinsic to call:param List[ExpressionIndex] params: parameters to intrinsic:param ILSourceLocation loc: location of returned expression:return: an intrinsic expression.:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_INTRINSIC,len(outputs),self.add_variable_list(outputs),self.arch.get_intrinsic_index(intrinsic),len(params),self.add_operand_list(params),size=0,source_location=loc) [docs]deffree_var_slot(self,var:'variable.Variable',loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``free_var_slot`` return an expression that clears the slot of the variable ``var`` which is in a register stack:param Variable var: variable to free:param ILSourceLocation loc: location of returned expression:return: the expression ``free_var_slot(var)``"""returnself.expr(MediumLevelILOperation.MLIL_FREE_VAR_SLOT,var.identifier,source_location=loc) [docs]defundefined(self,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``undefined`` returns the undefined expression. This should be used for instructions which perform functions butaren't important for dataflow or partial emulation purposes.:param ILSourceLocation loc: location of returned expression:return: the undefined expression.:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_UNDEF,source_location=loc) [docs]defunimplemented(self,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``unimplemented`` returns the unimplemented expression. This should be used for all instructions which aren'timplemented.:param ILSourceLocation loc: location of returned expression:return: the unimplemented expression.:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_UNIMPL,source_location=loc) [docs]defunimplemented_memory_ref(self,size:int,addr:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``unimplemented_memory_ref`` a memory reference to expression ``addr`` of size ``size`` with unimplemented operation.:param int size: size in bytes of the memory reference:param ExpressionIndex addr: expression to reference memory:param ILSourceLocation loc: location of returned expression:return: the unimplemented memory reference expression.:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_UNIMPL_MEM,addr,size=size,source_location=loc) [docs]deffloat_add(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``float_add`` adds floating point expression ``a`` to expression ``b``and returning an expression of ``size`` bytes.:param int size: the size of the result in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``fadd.<size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_FADD,a,b,size=size,source_location=loc) [docs]deffloat_sub(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``float_sub`` subtracts floating point expression ``b`` from expression ``a``and returning an expression of ``size`` bytes.:param int size: the size of the result in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``fsub.<size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_FSUB,a,b,size=size,source_location=loc) [docs]deffloat_mult(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``float_mult`` multiplies floating point expression ``a`` by expression ``b``and returning an expression of ``size`` bytes.:param int size: the size of the result in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``fmul.<size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_FMUL,a,b,size=size,source_location=loc) [docs]deffloat_div(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``float_div`` divides floating point expression ``a`` by expression ``b``and returning an expression of ``size`` bytes.:param int size: the size of the result in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``fdiv.<size>(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_FDIV,a,b,size=size,source_location=loc) [docs]deffloat_sqrt(self,size:int,value:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``float_sqrt`` returns square root of floating point expression ``value`` of size ``size``:param int size: the size of the result in bytes:param ExpressionIndex value: the expression to calculate the square root of:param ILSourceLocation loc: location of returned expression:return: The expression ``sqrt.<size>(value)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_FSQRT,value,size=size,source_location=loc) [docs]deffloat_neg(self,size:int,value:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``float_neg`` returns sign negation of floating point expression ``value`` of size ``size``:param int size: the size of the result in bytes:param ExpressionIndex value: the expression to negate:param ILSourceLocation loc: location of returned expression:return: The expression ``fneg.<size>(value)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_FNEG,value,size=size,source_location=loc) [docs]deffloat_abs(self,size:int,value:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``float_abs`` returns absolute value of floating point expression ``value`` of size ``size``:param int size: the size of the result in bytes:param ExpressionIndex value: the expression to get the absolute value of:param ILSourceLocation loc: location of returned expression:return: The expression ``fabs.<size>(value)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_FABS,value,size=size,source_location=loc) [docs]deffloat_to_int(self,size:int,value:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``float_to_int`` returns integer value of floating point expression ``value`` of size ``size``:param int size: the size of the result in bytes:param ExpressionIndex value: the expression to convert to an int:param ILSourceLocation loc: location of returned expression:return: The expression ``int.<size>(value)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_FLOAT_TO_INT,value,size=size,source_location=loc) [docs]defint_to_float(self,size:int,value:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``int_to_float`` returns floating point value of integer expression ``value`` of size ``size``:param int size: the size of the result in bytes:param ExpressionIndex value: the expression to convert to a float:param ILSourceLocation loc: location of returned expression:return: The expression ``float.<size>(value)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_INT_TO_FLOAT,value,size=size,source_location=loc) [docs]deffloat_convert(self,size:int,value:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``int_to_float`` converts floating point value of expression ``value`` to size ``size``:param int size: the size of the result in bytes:param ExpressionIndex value: the expression to negate:param ILSourceLocation loc: location of returned expression:return: The expression ``fconvert.<size>(value)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_FLOAT_CONV,value,size=size,source_location=loc) [docs]defround_to_int(self,size:int,value:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``round_to_int`` rounds a floating point value to the nearest integer:param int size: the size of the result in bytes:param ExpressionIndex value: the expression to round to the nearest integer:param ILSourceLocation loc: location of returned expression:return: The expression ``roundint.<size>(value)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_ROUND_TO_INT,value,size=size,source_location=loc) [docs]deffloor(self,size:int,value:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``floor`` rounds a floating point value to an integer towards negative infinity:param int size: the size of the result in bytes:param ExpressionIndex value: the expression to round down:param ILSourceLocation loc: location of returned expression:return: The expression ``roundint.<size>(value)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_FLOOR,value,size=size,source_location=loc) [docs]defceil(self,size:int,value:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``ceil`` rounds a floating point value to an integer towards positive infinity:param int size: the size of the result in bytes:param ExpressionIndex value: the expression to round up:param ILSourceLocation loc: location of returned expression:return: The expression ``roundint.<size>(value)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_CEIL,value,size=size,source_location=loc) [docs]deffloat_trunc(self,size:int,value:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``float_trunc`` rounds a floating point value to an integer towards zero:param int size: the size of the result in bytes:param ExpressionIndex value: the expression to truncate:param ILSourceLocation loc: location of returned expression:return: The expression ``roundint.<size>(value)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_FTRUNC,value,size=size,source_location=loc) [docs]deffloat_compare_equal(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``float_compare_equal`` returns floating point comparison expression of size ``size`` checking ifexpression ``a`` is equal to expression ``b``:param int size: the size of the operands in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``a f== b``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_FCMP_E,a,b,size=size,source_location=loc) [docs]deffloat_compare_not_equal(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``float_compare_not_equal`` returns floating point comparison expression of size ``size`` checking ifexpression ``a`` is not equal to expression ``b``:param int size: the size of the operands in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``a f!= b``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_FCMP_NE,a,b,size=size,source_location=loc) [docs]deffloat_compare_less_than(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``float_compare_less_than`` returns floating point comparison expression of size ``size`` checking ifexpression ``a`` is less than expression ``b``:param int size: the size of the operands in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``a f< b``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_FCMP_LT,a,b,size=size,source_location=loc) [docs]deffloat_compare_less_equal(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``float_compare_less_equal`` returns floating point comparison expression of size ``size`` checking ifexpression ``a`` is less than or equal to expression ``b``:param int size: the size of the operands in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``a f<= b``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_FCMP_LE,a,b,size=size,source_location=loc) [docs]deffloat_compare_greater_equal(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``float_compare_greater_equal`` returns floating point comparison expression of size ``size`` checking ifexpression ``a`` is greater than or equal to expression ``b``:param int size: the size of the operands in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``a f>= b``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_FCMP_GE,a,b,size=size,source_location=loc) [docs]deffloat_compare_greater_than(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``float_compare_greater_than`` returns floating point comparison expression of size ``size`` checking ifexpression ``a`` is greater than expression ``b``:param int size: the size of the operands in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``a f> b``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_FCMP_GT,a,b,size=size,source_location=loc) [docs]deffloat_compare_ordered(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``float_compare_ordered`` returns floating point comparison expression of size ``size`` checking ifexpression ``a`` is ordered relative to expression ``b``:param int size: the size of the operands in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``is_ordered(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_FCMP_O,a,b,size=size,source_location=loc) [docs]deffloat_compare_unordered(self,size:int,a:ExpressionIndex,b:ExpressionIndex,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``float_compare_unordered`` returns floating point comparison expression of size ``size`` checking ifexpression ``a`` is unordered relative to expression ``b``:param int size: the size of the operands in bytes:param ExpressionIndex a: LHS expression:param ExpressionIndex b: RHS expression:param ILSourceLocation loc: location of returned expression:return: The expression ``is_unordered(a, b)``:rtype: ExpressionIndex"""returnself.expr(MediumLevelILOperation.MLIL_FCMP_UO,a,b,size=size,source_location=loc) [docs]defgoto(self,label:MediumLevelILLabel,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``goto`` returns a goto expression which jumps to the provided MediumLevelILLabel.:param MediumLevelILLabel label: Label to jump to:param ILSourceLocation loc: location of returned expression:return: the ExpressionIndex that jumps to the provided label:rtype: ExpressionIndex"""iflocisnotNone:index=ExpressionIndex(core.BNMediumLevelILGotoWithLocation(self.handle,label.handle,loc.address,loc.source_operand))self._record_mlil_to_mlil_expr_map(index,loc)returnindexelse:returnExpressionIndex(core.BNMediumLevelILGoto(self.handle,label.handle)) [docs]defif_expr(self,operand:ExpressionIndex,t:MediumLevelILLabel,f:MediumLevelILLabel,loc:Optional['ILSourceLocation']=None)->ExpressionIndex:"""``if_expr`` returns the ``if`` expression which depending on condition ``operand`` jumps to the MediumLevelILLabel``t`` when the condition expression ``operand`` is non-zero and ``f`` when it's zero.:param ExpressionIndex operand: comparison expression to evaluate.:param MediumLevelILLabel t: Label for the true branch:param MediumLevelILLabel f: Label for the false branch:param ILSourceLocation loc: location of returned expression:return: the ExpressionIndex for the if expression:rtype: ExpressionIndex"""iflocisnotNone:index=ExpressionIndex(core.BNMediumLevelILIfWithLocation(self.handle,operand,t.handle,f.handle,loc.address,loc.source_operand))self._record_mlil_to_mlil_expr_map(index,loc)returnindexelse:returnExpressionIndex(core.BNMediumLevelILIf(self.handle,operand,t.handle,f.handle)) [docs]defmark_label(self,label:MediumLevelILLabel)->None:"""``mark_label`` assigns a MediumLevelILLabel to the current IL address.:param MediumLevelILLabel label::rtype: None"""core.BNMediumLevelILMarkLabel(self.handle,label.handle) [docs]defadd_label_map(self,labels:Mapping[int,MediumLevelILLabel])->ExpressionIndex:"""``add_label_map`` returns a label list expression for the given list of MediumLevelILLabel objects.:param labels: the list of MediumLevelILLabel to get a label list expression from:type labels: dict(int, MediumLevelILLabel):return: the label list expression:rtype: ExpressionIndex"""label_list=(ctypes.POINTER(core.BNMediumLevelILLabel)*len(labels))()value_list=(ctypes.c_ulonglong*len(labels))()fori,(key,value)inenumerate(labels.items()):value_list[i]=keylabel_list[i]=value.handlereturnExpressionIndex(core.BNMediumLevelILAddLabelMap(self.handle,value_list,label_list,len(labels))) [docs]defadd_operand_list(self,operands:List[ExpressionIndex])->ExpressionIndex:"""``add_operand_list`` returns an operand list expression for the given list of integer operands.:param operands: list of operand numbers:type operands: list(int):return: an operand list expression:rtype: ExpressionIndex"""operand_list=(ctypes.c_ulonglong*len(operands))()foriinrange(len(operands)):operand_list[i]=operands[i]returnExpressionIndex(core.BNMediumLevelILAddOperandList(self.handle,operand_list,len(operands))) [docs]defadd_variable_list(self,vars:List['variable.Variable'])->ExpressionIndex:"""``add_variable_list`` returns a variable list expression for the given list of variables.:param vars: list of variables:type vars: list(variable.Variable):return: a variable list expression:rtype: ExpressionIndex"""operand_list=(ctypes.c_uint64*len(vars))()foriinrange(len(vars)):operand_list[i]=vars[i].identifierreturnExpressionIndex(core.BNMediumLevelILAddOperandList(self.handle,operand_list,len(vars))) [docs]defcache_possible_value_set(self,pvs:'variable.PossibleValueSet')->int:"""Cache a PossibleValueSet in the IL function, returning its index for use in an expression operand:param pvs: PossibleValueSet to cache:return: Index of the PossibleValueSet in the cache"""returncore.BNCacheMediumLevelILPossibleValueSet(self.handle,pvs._to_core_struct()) [docs]deffinalize(self)->None:"""``finalize`` ends the function and computes the list of basic blocks.:rtype: None"""core.BNFinalizeMediumLevelILFunction(self.handle) [docs]defgenerate_ssa_form(self,analyze_conditionals:bool=True,handle_aliases:bool=True,known_not_aliases:Optional[List["variable.Variable"]]=None,known_aliases:Optional[List["variable.Variable"]]=None)->None:"""``generate_ssa_form`` generate SSA form given the current MLIL:param bool analyze_conditionals: whether or not to analyze conditionals, defaults to ``True``:param bool handle_aliases: whether or not to handle aliases, defaults to ``True``:param list(Variable) known_not_aliases: optional list of variables known to be not aliased:param list(Variable) known_aliases: optional list of variables known to be aliased:rtype: None"""ifknown_not_aliasesisNone:known_not_aliases=[]ifknown_aliasesisNone:known_aliases=[]known_not_alias_list=(core.BNVariable*len(known_not_aliases))()foriinrange(len(known_not_aliases)):known_not_alias_list[i]=known_not_aliases[i].to_BNVariable()known_alias_list=(core.BNVariable*len(known_aliases))()foriinrange(len(known_aliases)):known_alias_list[i]=known_aliases[i].to_BNVariable()core.BNGenerateMediumLevelILSSAForm(self.handle,analyze_conditionals,handle_aliases,known_not_alias_list,len(known_not_alias_list),known_alias_list,len(known_alias_list)) [docs]defprepare_to_copy_function(self,src:'MediumLevelILFunction'):"""``prepare_to_copy_function`` sets up state in this MLIL function in preparationof copying instructions from ``src``It enables use of :py:func:`get_label_for_source_instruction` during function transformation.:param MediumLevelILFunction src: function about to be copied from"""core.BNPrepareToCopyMediumLevelILFunction(self.handle,src.handle) [docs]defprepare_to_copy_block(self,src:'MediumLevelILBasicBlock'):"""``prepare_to_copy_block`` sets up state when copying a function in preparationof copying the instructions from the block ``src``It enables use of :py:func:`get_label_for_source_instruction` during function transformation.:param MediumLevelILBasicBlock src: block about to be copied from"""core.BNPrepareToCopyMediumLevelILBasicBlock(self.handle,src.handle) [docs]defget_label_for_source_instruction(self,i:InstructionIndex)->Optional['MediumLevelILLabel']:"""Get the MediumLevelILLabel for a given source instruction. The source instruction must beat the start of a basic block in the source function passed to :py:func:`prepare_to_copy_function`.The label will be marked resolved when its source block is passed to :py:func:`prepare_to_copy_block`... warning:: The instruction index parameter for this pertains to the *source function* passed to `prepare_to_copy_function`, not the current function... note:: The returned label is to an internal object with the same lifetime as the containing MediumLevelILFunction.:param i: The source instruction index:return: The MediumLevelILLabel for the source instruction"""label=core.BNGetLabelForMediumLevelILSourceInstruction(self.handle,i)ifnotlabel:returnNonereturnMediumLevelILLabel(handle=label) [docs]defget_ssa_instruction_index(self,instr:InstructionIndex)->InstructionIndex:returnInstructionIndex(core.BNGetMediumLevelILSSAInstructionIndex(self.handle,instr)) [docs]defget_non_ssa_instruction_index(self,instr:InstructionIndex)->InstructionIndex:returnInstructionIndex(core.BNGetMediumLevelILNonSSAInstructionIndex(self.handle,instr)) [docs]defget_ssa_var_definition(self,ssa_var:Union[SSAVariable,MediumLevelILVarSsa])->Optional[MediumLevelILInstruction]:"""Gets the instruction that contains the given SSA variable's definition.Since SSA variables can only be defined once, this will return the single instruction where that occurs.For SSA variable version 0s, which don't have definitions, this will return None instead."""ifisinstance(ssa_var,MediumLevelILVarSsa):ssa_var=ssa_var.varifnotisinstance(ssa_var,SSAVariable):raiseValueError("Expected SSAVariable")var_data=ssa_var.var.to_BNVariable()result=core.BNGetMediumLevelILSSAVarDefinition(self.handle,var_data,ssa_var.version)ifresult>=core.BNGetMediumLevelILInstructionCount(self.handle):returnNonereturnself[result] [docs]defget_ssa_memory_definition(self,version:int)->Optional[MediumLevelILInstruction]:result=core.BNGetMediumLevelILSSAMemoryDefinition(self.handle,version)ifresult>=core.BNGetMediumLevelILInstructionCount(self.handle):returnNonereturnself[result] [docs]defget_ssa_var_uses(self,ssa_var:Union[SSAVariable,MediumLevelILVarSsa])->List[MediumLevelILInstruction]:"""Gets all the instructions that use the given SSA variable."""ifisinstance(ssa_var,MediumLevelILVarSsa):ssa_var=ssa_var.varifnotisinstance(ssa_var,SSAVariable):raiseValueError("Expected SSAVariable")count=ctypes.c_ulonglong()var_data=ssa_var.var.to_BNVariable()instrs=core.BNGetMediumLevelILSSAVarUses(self.handle,var_data,ssa_var.version,count)assertinstrsisnotNone,"core.BNGetMediumLevelILSSAVarUses returned None"result=[]foriinrange(0,count.value):result.append(self[instrs[i]])core.BNFreeILInstructionList(instrs)returnresult [docs]defget_ssa_memory_uses(self,version:int)->List[MediumLevelILInstruction]:count=ctypes.c_ulonglong()instrs=core.BNGetMediumLevelILSSAMemoryUses(self.handle,version,count)assertinstrsisnotNone,"core.BNGetMediumLevelILSSAMemoryUses returned None"result=[]foriinrange(0,count.value):result.append(self[instrs[i]])core.BNFreeILInstructionList(instrs)returnresult [docs]defis_ssa_var_live(self,ssa_var:SSAVariable)->bool:"""``is_ssa_var_live`` determines if ``ssa_var`` is live at any point in the function:param SSAVariable ssa_var: the SSA variable to query:return: whether the variable is live at any point in the function:rtype: bool"""var_data=ssa_var.var.to_BNVariable()returncore.BNIsMediumLevelILSSAVarLive(self.handle,var_data,ssa_var.version) [docs]defis_ssa_var_live_at(self,ssa_var:SSAVariable,instr:InstructionIndex)->bool:"""``is_ssa_var_live_at`` determines if ``ssa_var`` is live at a given point in the function; counts phi's as uses"""returncore.BNIsMediumLevelILSSAVarLiveAt(self.handle,ssa_var.var.to_BNVariable(),ssa_var.version,instr) [docs]defis_var_live_at(self,var:'variable.Variable',instr:InstructionIndex)->bool:"""``is_var_live_at`` determines if ``var`` is live at a given point in the function"""returncore.BNIsMediumLevelILVarLiveAt(self.handle,var.to_BNVariable(),instr) [docs]defget_var_definitions(self,var:'variable.Variable')->List[MediumLevelILInstruction]:count=ctypes.c_ulonglong()var_data=var.to_BNVariable()instrs=core.BNGetMediumLevelILVariableDefinitions(self.handle,var_data,count)assertinstrsisnotNone,"core.BNGetMediumLevelILVariableDefinitions returned None"result=[]foriinrange(0,count.value):result.append(self[instrs[i]])core.BNFreeILInstructionList(instrs)returnresult [docs]defget_var_uses(self,var:'variable.Variable')->List[MediumLevelILInstruction]:count=ctypes.c_ulonglong()var_data=var.to_BNVariable()instrs=core.BNGetMediumLevelILVariableUses(self.handle,var_data,count)assertinstrsisnotNone,"core.BNGetMediumLevelILVariableUses returned None"try:result=[]foriinrange(0,count.value):result.append(self[instrs[i]])returnresultfinally:core.BNFreeILInstructionList(instrs) [docs]defget_live_instructions_for_var(self,var:'variable.Variable',include_last_use:bool=True)->List[MediumLevelILInstruction]:"""``get_live_instructions_for_var`` computes the list of instructions for which ``var`` is live.If ``include_last_use`` is False, the last use of the variable will not be included in thelist (this allows for easier computation of overlaps in liveness between two variables).If the variable is never used, this function will return an empty list.:param SSAVariable var: the variable to query:param bool include_last_use: whether to include the last use of the variable in the list of instructions:return: list of instructions for which ``var`` is live:rtype: list(MediumLevelILInstruction)"""count=ctypes.c_ulonglong()var_data=var.to_BNVariable()instrs=core.BNGetMediumLevelILLiveInstructionsForVariable(self.handle,var_data,include_last_use,count)assertinstrsisnotNone,"core.BNGetMediumLevelILLiveInstructionsForVariable returned None"result=[]foriinrange(0,count.value):result.append(self[instrs[i]])core.BNFreeILInstructionList(instrs)returnresult [docs]defget_ssa_var_value(self,ssa_var:SSAVariable)->'variable.RegisterValue':var_data=ssa_var.var.to_BNVariable()value=core.BNGetMediumLevelILSSAVarValue(self.handle,var_data,ssa_var.version)result=variable.RegisterValue.from_BNRegisterValue(value,self._arch)returnresult [docs]defget_instruction_index_for_expr(self,expr:ExpressionIndex)->Optional[InstructionIndex]:result=core.BNGetMediumLevelILInstructionForExpr(self.handle,expr)ifresult>=core.BNGetMediumLevelILInstructionCount(self.handle):returnNonereturnInstructionIndex(result) [docs]defget_expr_index_for_instruction(self,instr:InstructionIndex)->ExpressionIndex:result=core.BNGetMediumLevelILIndexForInstruction(self.handle,instr)returnExpressionIndex(result) [docs]defget_low_level_il_instruction_index(self,instr:InstructionIndex)->Optional['lowlevelil.InstructionIndex']:low_il=self.low_level_iliflow_ilisNone:returnNonelow_il=low_il.ssa_formiflow_ilisNone:returnNoneresult=core.BNGetLowLevelILInstructionIndex(self.handle,instr)ifresult>=core.BNGetLowLevelILInstructionCount(low_il.handle):returnNonereturnlowlevelil.InstructionIndex(result) [docs]defget_low_level_il_expr_index(self,expr:ExpressionIndex)->Optional['lowlevelil.ExpressionIndex']:low_il=self.low_level_iliflow_ilisNone:returnNonelow_il=low_il.ssa_formiflow_ilisNone:returnNoneresult=core.BNGetLowLevelILExprIndex(self.handle,expr)ifresult>=core.BNGetLowLevelILExprCount(low_il.handle):returnNonereturnlowlevelil.ExpressionIndex(result) [docs]defget_low_level_il_expr_indexes(self,expr:ExpressionIndex)->List['lowlevelil.ExpressionIndex']:count=ctypes.c_ulonglong()exprs=core.BNGetLowLevelILExprIndexes(self.handle,expr,count)assertexprsisnotNone,"core.BNGetLowLevelILExprIndexes returned None"result:List['lowlevelil.ExpressionIndex']=[]foriinrange(0,count.value):result.append(lowlevelil.ExpressionIndex(exprs[i]))core.BNFreeILInstructionList(exprs)returnresult [docs]defget_high_level_il_instruction_index(self,instr:InstructionIndex)->Optional['highlevelil.InstructionIndex']:high_il=self.high_level_ilifhigh_ilisNone:returnNoneresult=core.BNGetHighLevelILInstructionIndex(self.handle,instr)ifresult>=core.BNGetHighLevelILInstructionCount(high_il.handle):returnNonereturnhighlevelil.InstructionIndex(result) [docs]defget_high_level_il_expr_index(self,expr:ExpressionIndex)->Optional['highlevelil.ExpressionIndex']:high_il=self.high_level_ilifhigh_ilisNone:returnNoneresult=core.BNGetHighLevelILExprIndex(self.handle,expr)ifresult>=core.BNGetHighLevelILExprCount(high_il.handle):returnNonereturnhighlevelil.ExpressionIndex(result) [docs]defget_high_level_il_expr_indexes(self,expr:ExpressionIndex)->List['highlevelil.ExpressionIndex']:count=ctypes.c_ulonglong()exprs=core.BNGetHighLevelILExprIndexes(self.handle,expr,count)assertexprsisnotNone,"core.BNGetHighLevelILExprIndexes returned None"result:List['highlevelil.ExpressionIndex']=[]foriinrange(0,count.value):result.append(highlevelil.ExpressionIndex(exprs[i]))core.BNFreeILInstructionList(exprs)returnresult [docs]defcreate_graph(self,settings:Optional['function.DisassemblySettings']=None)->flowgraph.CoreFlowGraph:ifsettingsisnotNone:settings_obj=settings.handleelse:settings_obj=Nonereturnflowgraph.CoreFlowGraph(core.BNCreateMediumLevelILFunctionGraph(self.handle,settings_obj)) [docs]defcreate_graph_immediate(self,settings:Optional['function.DisassemblySettings']=None)->flowgraph.CoreFlowGraph:ifsettingsisnotNone:settings_obj=settings.handleelse:settings_obj=Nonereturnflowgraph.CoreFlowGraph(core.BNCreateMediumLevelILImmediateFunctionGraph(self.handle,settings_obj)) @propertydefarch(self)->'architecture.Architecture':returnself._arch@propertydefview(self)->'binaryview.BinaryView':returnself.source_function.view@propertydefsource_function(self)->'function.Function':returnself._source_function@source_function.setterdefsource_function(self,value):self._source_function=value@propertydefil_form(self)->FunctionGraphType:iflen(list(self.basic_blocks))<1:returnFunctionGraphType.InvalidILViewTypereturnFunctionGraphType(core.BNGetBasicBlockFunctionGraphType(list(self.basic_blocks)[0].handle))@propertydefvars(self)->List['variable.Variable']:"""This gets just the MLIL variables - you may be interested in the union of `MediumLevelIlFunction.aliased_vars` and `MediumLevelIlFunction.source_function.parameter_vars` for all the variables used in the function"""ifself.source_functionisNone:return[]ifself.il_formin[FunctionGraphType.MediumLevelILSSAFormFunctionGraph,FunctionGraphType.MappedMediumLevelILSSAFormFunctionGraph]:returnself.ssa_varsifself.il_formin[FunctionGraphType.MediumLevelILFunctionGraph,FunctionGraphType.MappedMediumLevelILFunctionGraph]:count=ctypes.c_ulonglong()core_variables=core.BNGetMediumLevelILVariables(self.handle,count)assertcore_variablesisnotNone,"core.BNGetMediumLevelILVariables returned None"result=[]try:forvar_iinrange(count.value):result.append(variable.Variable(self,core_variables[var_i].type,core_variables[var_i].index,core_variables[var_i].storage))returnresultfinally:core.BNFreeVariableList(core_variables)return[]@propertydefaliased_vars(self)->List["variable.Variable"]:"""This returns a list of Variables that are taken reference to and used elsewhere. You may also wish to consider `MediumLevelIlFunction.vars` and `MediumLevelIlFunction.source_function.parameter_vars`"""ifself.source_functionisNone:return[]ifself.il_formin[FunctionGraphType.MediumLevelILFunctionGraph,FunctionGraphType.MediumLevelILSSAFormFunctionGraph]:count=ctypes.c_ulonglong()core_variables=core.BNGetMediumLevelILAliasedVariables(self.handle,count)assertcore_variablesisnotNone,"core.BNGetMediumLevelILAliasedVariables returned None"try:result=[]forvar_iinrange(count.value):result.append(variable.Variable(self,core_variables[var_i].type,core_variables[var_i].index,core_variables[var_i].storage))returnresultfinally:core.BNFreeVariableList(core_variables)return[]@propertydefssa_vars(self)->List[SSAVariable]:"""This gets just the MLIL SSA variables - you may be interested in the union of `MediumLevelIlFunction.aliased_vars` and `MediumLevelIlFunction.source_function.parameter_vars` for all the variables used in the function"""ifself.source_functionisNone:return[]ifself.il_formin[FunctionGraphType.MediumLevelILSSAFormFunctionGraph,FunctionGraphType.MappedMediumLevelILSSAFormFunctionGraph]:variable_count=ctypes.c_ulonglong()core_variables=core.BNGetMediumLevelILVariables(self.handle,variable_count)assertcore_variablesisnotNone,"core.BNGetMediumLevelILVariables returned None"try:result=[]forvar_iinrange(variable_count.value):version_count=ctypes.c_ulonglong()versions=core.BNGetMediumLevelILVariableSSAVersions(self.handle,core_variables[var_i],version_count)assertversionsisnotNone,"core.BNGetMediumLevelILVariableSSAVersions returned None"try:forversion_iinrange(version_count.value):result.append(SSAVariable(variable.Variable(self,core_variables[var_i].type,core_variables[var_i].index,core_variables[var_i].storage),versions[version_i]))finally:core.BNFreeILInstructionList(versions)returnresultfinally:core.BNFreeVariableList(core_variables)elifself.il_formin[FunctionGraphType.MediumLevelILFunctionGraph,FunctionGraphType.MappedMediumLevelILFunctionGraph]:returnself.ssa_form.ssa_varsreturn[][docs]defget_expr_type(self,expr_index:int)->Optional['types.Type']:"""Get type of expression:param int expr_index: index of the expression to retrieve:rtype: Optional['types.Type']"""result=core.BNGetMediumLevelILExprType(self.handle,expr_index)ifresult.type:platform=Noneifself.source_function:platform=self.source_function.platformreturntypes.Type.create(result.type,platform=platform,confidence=result.confidence)returnNone [docs]defset_expr_type(self,expr_index:int,expr_type:Optional[StringOrType])->None:"""Set type of expressionThis API is only meant for workflows or for debugging purposes, since the changes they make are not persistentand get lost after a database save and reload. To make persistent changes to the analysis, one should use otherAPIs to, for example, change the type of variables. The analysis will then propagate the type of the variableand update the type of related expressions.:param int expr_index: index of the expression to set:param StringOrType: new type of the expression"""ifexpr_typeisnotNone:ifisinstance(expr_type,str):(expr_type,_)=self.view.parse_type_string(expr_type)tc=expr_type._to_core_struct()else:tc=core.BNTypeWithConfidence()tc.type=Nonetc.confidence=0core.BNSetMediumLevelILExprType(self.handle,expr_index,tc) [docs]classMediumLevelILBasicBlock(basicblock.BasicBlock):"""The ``MediumLevelILBasicBlock`` object is returned during analysis and should not be directly instantiated."""[docs]def__init__(self,handle:core.BNBasicBlockHandle,owner:MediumLevelILFunction,view:Optional['binaryview.BinaryView']=None):super(MediumLevelILBasicBlock,self).__init__(handle,view)self._il_function=owner def__iter__(self):foridxinrange(self.start,self.end):yieldself._il_function[idx]@overloaddef__getitem__(self,idx:int)->'MediumLevelILInstruction':...@overloaddef__getitem__(self,idx:slice)->List['MediumLevelILInstruction']:...def__getitem__(self,idx:Union[int,slice])->Union[List['MediumLevelILInstruction'],'MediumLevelILInstruction']:size=self.end-self.startifisinstance(idx,slice):return[self[index]forindexinrange(*idx.indices(size))]# type: ignoreifidx>sizeoridx<-size:raiseIndexError("list index is out of range")ifidx>=0:returnself._il_function[idx+self.start]else:returnself._il_function[self.end+idx]def__hash__(self):returnhash((self.start,self.end,self._il_function))def__contains__(self,instruction):ifnotisinstance(instruction,MediumLevelILInstruction)orinstruction.il_basic_block!=self:returnFalseifself.start<=instruction.instr_index<=self.end:returnTrueelse:returnFalsedef__repr__(self):arch=self.archifarch:returnf"<{self.__class__.__name__}:{arch.name}@{self.start}-{self.end}>"else:returnf"<{self.__class__.__name__}:{self.start}-{self.end}>"def_create_instance(self,handle:core.BNBasicBlockHandle)->'MediumLevelILBasicBlock':"""Internal method by super to instantiate child instances"""returnMediumLevelILBasicBlock(handle,self.il_function,self.view)@propertydefinstruction_count(self)->int:returnself.end-self.start@propertydefil_function(self)->'MediumLevelILFunction':returnself._il_function