G
Grant Olson
pyasm 0.1 - x86 assembler for Python
This release is for early adopters only. It is not properly packaged and
doesn't have very good documentation. It is however a functional assembler
that should be of interest to some people.
Current output targets include Windows-style COFF files that can be
subsequently linked to produce executables, and more interestingly output
can target memory in an existing Python process and binding within a Python
namespace. That's right, you can now generate dynamic inline assembly
straight from Python! A simple hello world function implementation is
listed at the end of this message.
The files test\test_object_creation.py and test\test_winmem.py in the
distribution probably give the best examples of usage.
Future plans include targeting ELF file formats and Linux memory at runtime,
and of course real documentation.
The package is available at:
http://mysite.verizon.net/olsongt/pyasm-0.1.zip
Enjoy,
-Grant
#############################################
# PYTHON HELLO WORLD IN ASSEMBLY
#############################################
import pyasm.winmem
from pyasm.x86asm import assembler, CDECL
from pyasm.x86cpToMemory import CpToMemory
nonePointer = id(None)
a = assembler()
a.ADStr("hello_world", "Hello world!\n\0")
a.AP("test_print", CDECL)
a.AddLocal("self")
a.AddLocal("args")
#a.AI("INT 3")
a.AI("PUSH hello_world")
a.AI("CALL PySys_WriteStdout")
#a.AI("INT 3")
a.AI("MOV EAX,%s" % id(None))
a.AI("ADD [EAX],0x1") #refcount manipulation
a.EP()
mem = CpToMemory(a.Compile(),pyasm.winmem)
mem.MakeMemory()
mem.BindPythonFunctions(globals())
test_print() # calls the assembly function
This release is for early adopters only. It is not properly packaged and
doesn't have very good documentation. It is however a functional assembler
that should be of interest to some people.
Current output targets include Windows-style COFF files that can be
subsequently linked to produce executables, and more interestingly output
can target memory in an existing Python process and binding within a Python
namespace. That's right, you can now generate dynamic inline assembly
straight from Python! A simple hello world function implementation is
listed at the end of this message.
The files test\test_object_creation.py and test\test_winmem.py in the
distribution probably give the best examples of usage.
Future plans include targeting ELF file formats and Linux memory at runtime,
and of course real documentation.
The package is available at:
http://mysite.verizon.net/olsongt/pyasm-0.1.zip
Enjoy,
-Grant
#############################################
# PYTHON HELLO WORLD IN ASSEMBLY
#############################################
import pyasm.winmem
from pyasm.x86asm import assembler, CDECL
from pyasm.x86cpToMemory import CpToMemory
nonePointer = id(None)
a = assembler()
a.ADStr("hello_world", "Hello world!\n\0")
a.AP("test_print", CDECL)
a.AddLocal("self")
a.AddLocal("args")
#a.AI("INT 3")
a.AI("PUSH hello_world")
a.AI("CALL PySys_WriteStdout")
#a.AI("INT 3")
a.AI("MOV EAX,%s" % id(None))
a.AI("ADD [EAX],0x1") #refcount manipulation
a.EP()
mem = CpToMemory(a.Compile(),pyasm.winmem)
mem.MakeMemory()
mem.BindPythonFunctions(globals())
test_print() # calls the assembly function