Reverse Engineering Stack Exchange is a question and answer site for researchers and developers who explore the principles of a system through analysis of its structure, function, and operation. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

It would be very useful to have a pure python library that could assemble x86, x64 and ARM instructions. Do you have any recommendations?

I don't mind if they are not pure-python, but that'd be preferred, thanks!

share|improve this question
up vote 4 down vote accepted

Take a look at Pwnies' pwntools. Does all the things you want it to, and has most of it built in already.

For a few examples of it in use, I put up some writeups from Codegate 2013 and the pwnies do their own writeups as well.

Here's a quick example of "I want to dup file descriptor #4 (generally a socket) to stdin/stdout/stderr, and pop a shell".

#!/usr/bin/env python
from pwn import *
context('arm','linux') # Replace either with i386/amd64/mips/etc or freebsd

sc = shellcode.dupsh(4)
for block in sc.blocks:
  print block.text

print enhex(asm(sc))

# An example assemblying custom assembly.
# This works in x86/amd64/mips/arm/ppc/etc.
print enhex(asm('''
mov r0, #0
bx lr

Prints out

// Set r9 = 4
ldr r9, =4

// Set r8 = 2
ldr r8, =2

mov r0, r9
mov r1, r8
svc SYS_dup2
adds r8, #-1
bpl dup_helper
adr r0, bin_sh
mov r2, #0
push {r0, r2}
mov r1, sp
svc SYS_execve
bin_sh: .asciz "/bin/sh"

They've also got nifty tools for testing shellcode. For example:

shellcraft -c i386 -c linux echo "Hello world" | demo32 -
Hello world
share|improve this answer

Some python assembler libraries.

Pyasm - Python x86 Assembler
Pyasm is a full-featured dynamic assembler written entirely in Python. By dynamic, it means that it can be used to generate and execute machine code in python at runtime without requiring the generation of object files and linkage. It essentially allow 'inline' assembly in python modules on x86 platforms.

An easy and powerful assembler engine in python.Although its called pyasm2, this is not per se a successor of Pyasm or pyASM. pyasm2 aims to be as flexible as possible, it will support x86, SSE and SSE2.

d00ks is an ARM assembler and simulator.

AsmJit is a complete JIT and remote assembler for C++ language. It can generate native code for x86 and x64 architectures and supports the whole x86/x64 instruction set - from legacy MMX to the newest AVX2. It has a type-safe API that allows C++ compiler to do a semantic checks at compile-time even before the assembled code is generated or run.

share|improve this answer
None of these assemble x86/x64 and ARM. – Zach Riggle Jul 14 '14 at 23:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.