CPU : Intel Pentium M (Centrino) 1.2GHz
RAM : 1GB
OS : Windows XP Professional SP3 (Japanese)
Python: Python 2.5 (install from MSI installer)
Install Dir : C:\Python25
Visual Studio : Visual C++ 2008 Express Edision (SP1)
Subversion: TortoiseSVN 1.6.x
> setup.py build_ext
running build_ext
error: Python was built with Visual Studio 2003;
extensions must be built with a compiler than can generate compatible binaries.
Visual Studio 2003 was not found on this system. If you have Cygwin installed,
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.
噢!!为什么? 我的命令行窗口环境在VC++ 工具下确认是可用的!!
> cl
Microsoft(R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
...
> link
Microsoft (R) Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation. All rights reserved.
> C:\Python25\python.exe
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pydbg
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pydbg\__init__.py", line 47, in <module>
from pydbg import *
File "C:\in_vitro\SVNWORK\paimei\pydbg\pydbg.py", line 32, in <module>
import pydasm
ImportError: DLL load failed: 指定されたモジュールが見つかりません。
> dumpbin /dependents C:\Python25\Lib\site-packages\pydbg\pydasm.pyd
^^^^^^^^^^^^^^^^ pydasm.pyd was bundled!!
...
Image has the following dependencies:
MSVCR90.dll
python26.dll
KERNEL32.dll
...
> C:\Python25\python.exe
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pydbg
>>>
好的,没有任何错误。
最后,调用calc.exe ,得到它的PID,例子如下:
from pydbg import *
from pydbg.defines import *
def handler_breakpoint (pydbg):
if pydbg.first_breakpoint:
print "[*] Hit 1st breakpoint!"
return DBG_CONTINUE
print "[*] Hit breakpoint!"
return DBG_CONTINUE
dbg = pydbg()
dbg.set_callback(EXCEPTION_BREAKPOINT, handler_breakpoint)
dbg.attach(XXXXX) # pid of calc.exe
recv = dbg.func_resolve("user32", "ShowWindow")
dbg.bp_set(recv)
dbg.debug_event_loop()
例如:
> C:\Python25\python.exe
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pydbg import *
>>> from pydbg.defines import *
>>> def handler_breakpoint (pydbg):
... if pydbg.first_breakpoint:
... print "[*] Hit 1st breakpoint!"
... return DBG_CONTINUE
... print "[*] Hit breakpoint!"
... return DBG_CONTINUE
...
>>> dbg = pydbg()
>>> dbg.set_callback(EXCEPTION_BREAKPOINT, handler_breakpoint)
>>> dbg.attach(5084)
<pydbg.pydbg.pydbg instance at 0x00BF8198>
>>> recv = dbg.func_resolve("user32", "ShowWindow")
>>> dbg.bp_set(recv)
<pydbg.pydbg.pydbg instance at 0x00BF8198>
>>> dbg.debug_event_loop()
[*] Hit 1st breakpoint!
[*] Hit breakpoint!
...
(minimize, or restore calc window)
...
[*] Hit breakpoint!
>>> quit()