Sunday, January 31, 2010

PyASM

Introduction

PyASM is a full-featured dynamic assembler written entirely in Python. By dynamic, I mean 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.

PyASM can also generate object files (for windows) like a traditional standalone assembler, although you're probably better off using one of the many freely available assemblers if this is you primary goal.

Installation

PyASM requires python 2.4 or later. To the best of my knowledge, the only 2.4 specific feature I've used is from x import (a,b,c), but I need to draw a line in the sand somewhere as far as the installations I'll test and support.

Linux Install:

Windows Install:

Hello World!

A simple Windows version of a hello_world.py program is as follows:



#
# Hello World in assembly: hello_World.py
#
#

from pyasm import pyasm

pyasm(globals(),r"""
!CHARS hello_str 'Hello world!\n\0'

!PROC hello_world PYTHON
!ARG self
!ARG args

PUSH hello_str
CALL PySys_WriteStdout
ADD ESP, 0x4
MOV EAX,PyNone
ADD [EAX],1
!ENDPROC
""")

hello_world()



http://members.verizon.net/~olsongt/usersGuide.html

1 comment: