Pyasm - Python x86 Assembler

Jul. 31, 2009
comments

Pyasm generates runable x86 machine code and uses ctypes to execute it.

Features

  • Macros
  • Runtime Assembly
  • Syscall interface
  • callbacks to python from assembly
  • many common assembly operations coded

Download

Install

pyasm is a python package installable by any of the following commands:

cd pyasm; python setup.py install
easy_install pyasm

Example (Hello World)

from pyasm import Program
from pyasm.data import String
from pyasm.macro import syscall
from pyasm.instructions import mov, ret, push, add
from pyasm.registers import eax, ebx, ecx, edx, ebp
import sys

def example():
    msg = 'Hello World!'
    prog = Program(
        mov(ebx, 1),
        mov(ecx, String(msg)),
        mov(edx, len(msg)),
        syscall('write'),
        ret(),
    )
    fun = prog.compile()
    fun()

if __name__ == '__main__':
    example()

License

GNU AGPLv3 or later, Copyright 2008 Florian Bösch