Miasm is a free and open source (GPLv2) reverse engineering framework.
Miasm aims to analyze / modify / generate binary programs. Here is
a non exhaustive list of features:
Opening / modifying / generating PE / ELF 32 / 64 LE / BE
Assembling / Disassembling X86 / ARM / MIPS / SH4 / MSP430
Representing assembly semantic using intermediate language
Emulating using JIT (dynamic code analysis, unpacking, ...)
Expression simplification for automatic de-obfuscation
...
See the official blog for more examples and demos.
>>> for lbl, irblock in ircfg.blocks.items():
... print(irblock)
loc_0:
R2 = R8 + R0
IRDst = loc_4
Working with IR, for instance by getting side effects:
>>> for lbl, irblock in ircfg.blocks.items():
... for assignblk in irblock:
... rw = assignblk.get_rw()
... for dst, reads in rw.items():
... print('read: ', [str(x) for x in reads])
... print('written:', dst)
... print()
...
read: ['R8', 'R0']
written: R2
read: []
written: IRDst
Import the shellcode thanks to the Container abstraction:
>>> from miasm.analysis.binary import Container
>>> c = Container.from_string(s, loc_db)
>>> c
<miasm.analysis.binary.ContainerUnknown object at 0x7f34cefe6090>
Miasm embeds its own disassembler, intermediate language and
instruction semantic. It is written in Python.
To emulate code, it uses LLVM, GCC, Clang or Python to JIT the
intermediate representation. It can emulate shellcodes and all or parts of
binaries. Python callbacks can be executed to interact with the execution, for
instance to emulate library functions effects.
Documentation
Some documentation ressources are available in the doc folder.
Native jitter components are built when the local build environment supports
them. If native extension compilation fails, installation continues and the
jitter-dependent features are unavailable. Set MIASM_REQUIRE_JIT=1 when
building release wheels or when native jitter support must be present.
To enable non-Python JIT backends, one of the following is mandatory:
GCC
Clang
LLVM with Numba llvmlite (pip install miasm[llvm]), see below
Optional Python features are grouped as extras:
| Extra | Dependency | Enables | Code using it |
| --- | --- | --- | --- |
| cparser | pycparser>=2.17 | C type parsing and C-like expression access helpers | miasm/core/ctypesmngr.py, miasm/core/objc.py |
| z3 | z3-solver==4.16.0.0 | Z3 expression translation, solver-backed dependency graph, DSE constraints, and range tests | miasm/ir/translators/z3_ir.py, miasm/analysis/depgraph.py, miasm/analysis/dse.py |
| llvm | llvmlite==0.44.0 | LLVM JIT backend and LLVM IR export | miasm/jitter/jitcore_llvm.py, miasm/jitter/llvmconvert.py, example/expression/export_llvm.py |
| graph | graphviz | Python Graphviz object export from Miasm graphs | miasm/core/graph.py (DiGraph.graphviz) |
| crypto | pycryptodome | Windows API crypto/hash emulation | miasm/os_dep/win_api_x86_32.py |
| all | runtime extras above | All optional runtime features | Convenience alias for users |
Development/test dependencies are not published as package extras. They live in
[dependency-groups] in pyproject.toml:
| Group | Dependency | Enables | Code using it |
| --- | --- | --- | --- |
| dev | parameterized~=0.8.1 | Test runner parameterization | test/test_all.py |
Configuration
To use the jitter, GCC or LLVM is recommended
GCC (any version)
Clang (any version)
LLVM
Debian (testing/unstable): Not tested
Debian stable/Ubuntu/Kali/whatever: pip install llvmlite or install from llvmlite
Windows: Not tested
Build and install Miasm:
$ cd miasm_directory
$ python -m pip install .
Optional dependencies can be installed with extras, for example:
If something goes wrong during native jitter compilation, Miasm will skip the
failing extension and keep the rest of the package installable. Set
MIASM_REQUIRE_JIT=1 to make native extension failures abort the build.
Windows & IDA
Most of Miasm's IDA plugins use a subset of Miasm functionality.
A quick way to have them working is to add:
pyparsing.py to C:\...\IDA\python\ or pip install pyparsing
miasm/miasm directory to C:\...\IDA\python\
All features excepting JITter related ones will be available. For a more complete installation, please refer to above paragraphs.
Testing
Miasm comes with a set of regression tests. Test-only dependencies are declared
in the dev dependency group. uv sync installs this group by default; use
--extra all when you also want all optional runtime backends for full test
coverage. With pip, install the group explicitly.
uv sync --extra all
# or: python -m pip install --group dev '.[all]'
cd miasm_directory/test
# Run tests using our own test runner
python test_all.py
# Run tests using standard frameworks (slower, require 'parameterized')
python -m unittest test_all.py # sequential, requires 'unittest'
python -m pytest test_all.py # sequential, requires 'pytest'
python -m pytest -n auto test_all.py # parallel, requires 'pytest' and 'pytest-xdist'
Some options can be specified:
Mono threading: -m
Code coverage instrumentation: -c
Only fast tests: -t long (excludes the long tests)