Darm - An armv7 disassembler
First of all, if you like this post and/or library, don’t hesitate to check
out the project on github, the official tweet (is this
even possible?) or the reddit thread on /r/programming.
Introduction
Darm is a lightweight, highly efficient, BSD 3-Clause licensed ARMv7
disassembler written in C which gives you all the information you need, such
as flags and operands, in a compact structure.
Optionally you can generate a string representation from the given structure,
unlike every other ARMv7 disassembler I’ve come across, which only generate
strings.
Furthermore, darm ships with Python bindings.
Internals
Darm is, as advertised, efficient. Benchmarks will be presented in a follow-up
blogpost, but I’d estimate that for each supported instruction a maximum of a
few dozen if-statements and a handful table lookups are performed.
At the moment of writing this blogpost all regular instructions are supported,
this means all instructions except for the NEON and some funky
coprocessor instructions.
Support for NEON, Thumb2, and the coprocessor instructions is
planned for upcoming versions.
Usage
Darm features a simple C api, as well as Python bindings. Following is a C
snippet disassembling the “add r2, r3, r5, ror #5″ instruction.
#include <stdio.h> #include "darm.h" int main() { darm_t d; darm_str_t str; // disassemble the instruction if(darm_armv7_disasm(&d, 0xe08322e5) == 0) { // print the register indices printf("Rd: %d, Rn: %d, Rm: %d\n", d.Rd, d.Rn, d.Rm); // print a string version of the // disassembled instruction if(darm_str2(&d, &str, 1) == 0) { printf("instr: %s\n", str.instr); } } }
$ gcc sample.c libdarm.so -o sample && ./sample Rd: 2, Rn: 3, Rm: 5 instr: add r2, r3, r5, ror #5
And, of course, the Python equivalent.
import darm d = darm.disasm(0xe08322e5) print d.Rd, d.Rn, d.Rm, d.shift print d
$ python sample.py r2 r3 r5 ROR #5 add r2, r3, r5, ror #5
Documentation
Documentation is currently being worked on and will be available in the
Git repository. For now, please refer to the darm.h header file as most of
the fields and functions are documented there.
License
As outlined in the introduction, darm is BSD 3-Clause licensed. This is
a flexible license which should allow you to use it as you wish.
Support
If you have questions, suggestions, or anything else, feel free to drop me an
email or join the official IRC chat, #darm on freenode.
Interesting
Interesting. I almost choked on my baconator
Thanks so much, I decided to use ‘Darm’ when rebuilding my research project NDroid https://github.com/0-14N/NDroid.