Ailment: Angr Intermediate Language
Ailment is the Intermediate Language (IL) used by the angr binary analysis framework. It provides a higher-level, more abstract representation of program execution than traditional assembly or micro-code, aiding in static analysis and program transformation. Currently at version 9.2.158, it is actively maintained as a core component of the angr ecosystem, with frequent updates tied to angr's release cadence.
Common errors
-
AttributeError: module 'ailment' has no attribute 'Block'
cause You are trying to import AIL core classes (like Block, Statement, Expression) directly from the top-level 'ailment' package.fixImport these classes from their specific submodules. For example: `from ailment.block import Block`, `from ailment.statement import Assignment`, `from ailment.expression import Const`. -
TypeError: argument of type 'Assignment' is not iterable
cause The `statements` argument for the `Block` constructor expects a list of statement objects, even if there's only one statement.fixWrap your single statement in a list: `Block(addr, size, [my_statement])`. -
AttributeError: 'Load' object has no attribute 'addr' (or similar errors when manipulating Load/Store objects)
cause Your code is likely trying to use the `Load` or `Store` objects with an API compatible with Ailment 8.x, while running on Ailment 9.x or later. In 9.x, `Load` and `Store` are expressions, not statements, and their structure changed.fixRefactor your code to treat `Load` and `Store` as expressions representing memory accesses within other statements (e.g., an `Assignment`). Consult the Ailment 9.x documentation for the updated API. You'll generally find them as the source or destination of an `Assignment` expression.
Warnings
- breaking Ailment is tightly coupled with the angr framework. Mismatched major versions between 'ailment' and 'angr' (e.g., ailment 8.x with angr 9.x) can lead to runtime errors due to API incompatibilities.
- gotcha All AIL objects (Block, Statement, Expression, etc.) are immutable after creation. Attempting to modify their attributes directly will not work or will result in unexpected behavior.
- breaking The representation of memory loads and stores changed significantly in Ailment 9.x. Previously, `Load` and `Store` were standalone statements. In 9.x, they are 'expressions' representing memory access within other statements (e.g., an `Assignment`'s source or destination).
Install
-
pip install ailment
Imports
- Block
from ailment import Block
from ailment.block import Block
- Statement
from ailment import Statement
from ailment.statement import Statement, Assignment
- Expression
from ailment import Expression
from ailment.expression import Expression, Const, Register, BinaryOp
Quickstart
from ailment.expression import Const, Register
from ailment.statement import Assignment
from ailment.block import Block
# Create a 64-bit constant expression with value 0x123
constant_expr = Const(0, None, 64, 0x123)
# Create a 64-bit register expression representing RAX (offset 0 in an abstract context)
# In AIL, registers are often identified by their size and offset within a CPU context.
rax_reg = Register(0, None, 64, 0) # stmt_idx=0, ins_addr=None, size=64 bits, reg_offset=0
# Create an assignment statement: RAX = 0x123
# Arguments: stmt_idx, dst_expression, src_expression
assignment_stmt = Assignment(0, rax_reg, constant_expr)
# Create an AIL block containing the assignment statement
# Arguments: addr, size, statements (must be a list), idx (optional)
# 'addr' and 'size' are the abstract address and size of the block.
ail_block = Block(0x400000, 10, [assignment_stmt])
print(f"Created AIL Block at 0x{ail_block.addr:x}:")
print(f" Statements: {len(ail_block.statements)}")
print(f" First statement: {ail_block.statements[0]}")
print(f" Destination: {ail_block.statements[0].dst}")
print(f" Source: {ail_block.statements[0].src}")