你的位置:
问答吧
-> PHP进阶
-> 问题详情
pyasm for python2.5中嵌汇编所需模块下载
本帖最后由 极品黑公子 于 2009-4-24 14:40 编辑
/**
* 总结者:极品黑公子
* QQ:407802734
* ----------------------出来混总是要还的
*/
pyasm在官网中提供到python2.4的模块
为了能用在python2.5中需重新编译
因无人重编
浪费半天时间装环境搞定
丢在这里,以备后人用 2009-04-24
延用命名习惯打包成pyasm_python2.5.rar
解压后将pyasm放到python环境下的
Lib\site-packages中即可
嵌汇编的用法见其官网
http://members.verizon.net/~olsongt/usersGuide.html
编译过程如下:
安装mingw32 -- 即minGW(5.1.4版本号)
工具从sf下载
http://sourceforge.net/project/showfiles.php?group_id=2435
设置其环境变量
lib bin include 都放在PATH中即可
CMD中命令如下
D:\pyasm>python setup.py build -c mingw32
D:\pyasm>python setup.py build -c mingw32 install
编译成功后
将lib.win32-2.5包下的pyasm包拷至python下的Lib\site-packages即可
简单的用法 来源于网上,已保留作者版权
[php]
# -*- coding:utf-8 -*-
# file: test.py
# by: bluebanboom 0(0
# mail: bluebanboom@gmail.com ~
# date: 2008-11-06
# note:
import pyasm.excmem
from pyasm.x86asm import assembler, CDECL, STDCALL, PYTHON
from pyasm.x86cpToMemory import CpToMemory
def main():
a = assembler()
a.ADStr("in_fmt", "ii\0")
a.ADStr("out_fmt", "i\0")
a.AP("sum", PYTHON)
a.ARG("self")
a.ARG("args")
a.AddLocal("x")
a.AddLocal("y")
#a.AI("INT 3")
a.AI("LEA EAX, x")
a.AI("PUSH EAX")
a.AI("LEA EAX, y")
a.AI("PUSH EAX")
a.AI("PUSH in_fmt")
a.AI("PUSH args")
a.AI("CALL PyArg_ParseTuple")
a.AI("ADD ESP, 0xC")
a.AI("MOV EAX, x")
a.AI("MOV EBX, y")
a.AI("ADD EAX, EBX")
a.AI("PUSH EAX")
a.AI("PUSH out_fmt")
a.AI("CALL Py_BuildValue")
a.AI("ADD ESP, 0x8")
a.EP()
mem = CpToMemory(a.Compile())
mem.MakeMemory()
mem.BindPythonFunctions(globals())
print sum(1, 2)
print sum(2, 2)
if __name__ == "__main__":
main()
[/php]
输出结果:
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
****************************************************************
Personal firewall software may warn about the connection IDLE
makes to its subprocess using this computer's internal loopback
interface. This connection is not visible on any external
interface and no data is sent to or received from the Internet.
****************************************************************
IDLE 1.2.1 ==== No Subprocess ====
>>>
>>>
>>>
>>>
3
4
>>>
pyasm for python2.5模块见附见:
pyasm_python2.5.rar (40.22 KB)
下载次数:0
2009-4-24 14:28
作者: 极品黑公子
发布时间: 2009-04-24
很好!职业帮顶!
作者: longtan
发布时间: 2009-04-24
很好!职业帮顶!
longtan 发表于 2009-4-24 14:54你是专业卖广告吧!嘻嘻!!
作者: liexusong
发布时间: 2009-04-24
不错 。。。 可惜与PHP无关。。。。
作者: kakashilw
发布时间: 2009-04-24
python能不能调用win32API啊..如果可以又可以做外挂了.. = =
作者: TankMe
发布时间: 2009-04-24
啥东西没看懂。。。
作者: klaxon
发布时间: 2009-04-25