references/bnil-mlil.md
GitHubMLIL Instruction Reference
Medium Level IL translates registers to variables, associates types, resolves call parameters, propagates constants, and eliminates some dead code. Stack operations are abstracted away.
Key Differences from LLIL
- Registers are now variables (with names like
rax,var_260) - Stack concept is removed -- stack accesses become variable references
- Variables have types associated with them
- Call sites have inferred parameters and return values
- Constants are propagated through data flow
- Some dead code is eliminated
The Variable Object
Variables represent a single storage location within a function scope.
Properties
source_type-- Storage location:StackVariableSourceType,RegisterVariableSourceType, orFlagVariableSourceTypestorage-- For register vars: register index. For stack vars: stack offset.index-- Unique identifier across analysis passestype-- TheTypeobject associated with this variable
Variable Naming Convention
RegisterVariableSourceType-> register name (e.g.,rax,rbx)StackVariableSourceType->var_+ hex of negative stack offset (e.g.,var_260)- Reuse of a storage location appends a version counter (e.g.,
rax_1,rax_2)
The Type System
Type objects have a type_class property from the TypeClass enumeration:
| TypeClass | Description |
|---|---|
VoidTypeClass |
Unknown/void type |
BoolTypeClass |
Boolean (0 or !0) |
IntegerTypeClass |
Integer with sign, width, display type |
FloatTypeClass |
IEEE754 floating point (up to 10 bytes) |
PointerTypeClass |
Pointer with target/element_type property |
ArrayTypeClass |
Array with element_type, count, width |
FunctionTypeClass |
Function with return_value, parameters, calling_convention, can_return |
StructureTypeClass |
Struct/class/union with members list (each has name, offset, type) |
EnumerationTypeClass |
Enumeration with members (each has name, value) |
NamedTypeReferenceClass |
Symbolic reference to another type (like C typedef) |
WideCharTypeClass |
Unicode character |
VarArgsTypeClass |
Variadic function parameter marker |
ValueTypeClass |
Constant value (used in demangling) |
All types have a confidence property used for type inference.
Control Flow Instructions
MLIL_JUMP-- Branch todestaddressMLIL_JUMP_TO-- Jump table:destexpression +targetslistMLIL_CALL-- Calldestwithparams, returningoutputMLIL_CALL_UNTYPED-- Call where stack resolution failed (no params/output list)MLIL_TAILCALL-- Tail call todestwithparamsandoutputMLIL_TAILCALL_UNTYPED-- Tail call without resolved paramsMLIL_RET-- Return to callerMLIL_NORET-- Unreachable (after non-returning call)MLIL_IF-- Conditional:condition->true/falsebranchMLIL_GOTO-- Branch to IL instruction idMLIL_SYSCALL-- System call withparamsandoutputMLIL_SYSCALL_UNTYPED-- System call without resolved paramsMLIL_CALL_OUTPUT-- Return valuesdestfrom a callMLIL_CALL_PARAM-- Parameter setsrcfor a callMLIL_RET_HINT-- Indirect jump (internal analysis only)
Variable Reads and Writes
MLIL_SET_VAR-- Set variabledestto expressionsrcMLIL_SET_VAR_FIELD-- Set variabledestatoffsettosrcMLIL_SET_VAR_SPLIT-- Set pairhigh:lowtosrcMLIL_SET_VAR_ALIASED-- Set aliased variableprevtosrcMLIL_SET_VAR_ALIASED_FIELD-- Set field atoffsetof aliased variableMLIL_VAR-- Variable referencesrcMLIL_VAR_FIELD-- Variable + offset:src,offsetMLIL_VAR_SPLIT-- Split pairhigh:lowas single expressionMLIL_VAR_ALIASED-- Aliased variable referenceMLIL_VAR_ALIASED_FIELD-- Aliased variable fieldMLIL_VAR_PHI-- PHI node combining variable versions at block mergeMLIL_MEM_PHI-- Memory PHI for memory modifications across pathsMLIL_LOAD-- Readsizebytes from memory addresssrcMLIL_LOAD_STRUCT-- Read from struct:src+offsetMLIL_STORE-- Storesrcto memory atdestMLIL_STORE_STRUCT-- Store to struct:dest+offsetfromsrcMLIL_ADDRESS_OF-- Address of variablesrcMLIL_ADDRESS_OF_FIELD-- Address of variablesrcatoffsetMLIL_LOW_PART--sizebytes from low end ofsrc
Constants
MLIL_CONST-- Constant integerMLIL_CONST_DATA-- Constant data referenceMLIL_CONST_PTR-- Constant used as pointerMLIL_EXTERN_PTR-- External symbol:constant+offsetMLIL_FLOAT_CONST-- Floating point constantMLIL_IMPORT-- Imported address constant
Arithmetic Operations
MLIL_ADD/MLIL_ADC-- Add / Add with carryMLIL_SUB/MLIL_SBB-- Subtract / Subtract with borrowMLIL_AND/MLIL_OR/MLIL_XOR-- Bitwise AND/OR/XORMLIL_LSL/MLIL_LSR/MLIL_ASR-- ShiftsMLIL_ROL/MLIL_ROR/MLIL_RLC/MLIL_RRC-- RotationsMLIL_MUL/MLIL_MULU_DP/MLIL_MULS_DP-- Multiply (single/double precision)MLIL_DIVU/MLIL_DIVS/MLIL_DIVU_DP/MLIL_DIVS_DP-- DivideMLIL_MODU/MLIL_MODS/MLIL_MODU_DP/MLIL_MODS_DP-- ModulusMLIL_NEG/MLIL_NOT-- Negate/ComplementMLIL_SX/MLIL_ZX-- Sign/Zero extendMLIL_ADD_OVERFLOW-- Overflow of additionMLIL_BOOL_TO_INT-- Bool to integer conversion
Floating Point
MLIL_FADD/MLIL_FSUB/MLIL_FMUL/MLIL_FDIV-- FP arithmeticMLIL_FSQRT/MLIL_FNEG/MLIL_FABS-- FP operationsMLIL_FLOAT_TO_INT/MLIL_INT_TO_FLOAT/MLIL_FLOAT_CONV-- ConversionsMLIL_ROUND_TO_INT/MLIL_FLOOR/MLIL_CEIL/MLIL_FTRUNC-- Rounding
Comparisons
MLIL_CMP_E/MLIL_CMP_NE-- Equal / Not equalMLIL_CMP_SLT/MLIL_CMP_ULT-- Signed/Unsigned less thanMLIL_CMP_SLE/MLIL_CMP_ULE-- Signed/Unsigned less than or equalMLIL_CMP_SGE/MLIL_CMP_UGE-- Signed/Unsigned greater than or equalMLIL_CMP_SGT/MLIL_CMP_UGT-- Signed/Unsigned greater thanMLIL_TEST_BIT-- Test if bitrightis set inleftMLIL_FCMP_E/MLIL_FCMP_NE/MLIL_FCMP_LT/MLIL_FCMP_LE/MLIL_FCMP_GE/MLIL_FCMP_GT-- FP comparisonsMLIL_FCMP_O(ordered) /MLIL_FCMP_UO(unordered)
Miscellaneous
MLIL_NOP-- No operationMLIL_BP-- BreakpointMLIL_TRAP-- Trap withvectorMLIL_INTRINSIC-- Architecture intrinsicMLIL_FREE_VAR_SLOT-- Free register stack slotMLIL_UNDEF-- Undefined behaviorMLIL_UNIMPL/MLIL_UNIMPL_MEM-- Unimplemented (with optional memory access)