2016-09-05 10 views
0

私はここでダウンロードしたpydbgバイナリを使用しています:前の回答でお勧めの通りhttp://www.lfd.uci.edu/~gohlke/pythonlibs/#pydbgpydbg 64ビットenumerate_processes()空リストを返す

私は32ビット版を32ビットPythonインタプリタで動作させることができますが、64ビット版を64ビットPythonで動作させることはできません。 enumerate_processes()は常に空のリストを返します。何か間違っていますか?

テストコード:

import pydbg 

if __name__ == "__main__": 
    print(pydbg.pydbg().enumerate_processes()) 

32ビット作業:

>C:\Python27-32\python-32bit.exe 
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:19:22) [MSC v.1500 32 bit (Intel)] on win32 
... 
>C:\Python27-32\python-32bit.exe pydbg_test.py 
[(0L, '[System Process]'), (4L, 'System'), <redacted for brevity>] 

64ビットが空のリストが得られる:

>python 
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32 
... 
>python pydbg_test.py 
[] 

答えて

1

をPydbgが間違っPROCESSENTRY32構造を定義します。

ベターpsutil等維持パッケージを使用するか、使用のctypes直接、例えば:

from ctypes import windll, Structure, c_char, sizeof 
from ctypes.wintypes import BOOL, HANDLE, DWORD, LONG, ULONG, POINTER 

class PROCESSENTRY32(Structure): 
    _fields_ = [ 
     ('dwSize', DWORD), 
     ('cntUsage', DWORD), 
     ('th32ProcessID', DWORD), 
     ('th32DefaultHeapID', POINTER(ULONG)), 
     ('th32ModuleID', DWORD), 
     ('cntThreads', DWORD), 
     ('th32ParentProcessID', DWORD), 
     ('pcPriClassBase', LONG), 
     ('dwFlags', DWORD), 
     ('szExeFile', c_char * 260), 
    ] 

windll.kernel32.CreateToolhelp32Snapshot.argtypes = [DWORD, DWORD] 
windll.kernel32.CreateToolhelp32Snapshot.restype = HANDLE 
windll.kernel32.Process32First.argtypes = [HANDLE, POINTER(PROCESSENTRY32)] 
windll.kernel32.Process32First.restype = BOOL 
windll.kernel32.Process32Next.argtypes = [HANDLE, POINTER(PROCESSENTRY32)] 
windll.kernel32.Process32Next.restype = BOOL 
windll.kernel32.CloseHandle.argtypes = [HANDLE] 
windll.kernel32.CloseHandle.restype = BOOL 

pe = PROCESSENTRY32() 
pe.dwSize = sizeof(PROCESSENTRY32) 

snapshot = windll.kernel32.CreateToolhelp32Snapshot(2, 0) 
found_proc = windll.kernel32.Process32First(snapshot, pe) 
while found_proc: 
    print(pe.th32ProcessID, pe.szExeFile) 
    found_proc = windll.kernel32.Process32Next(snapshot, pe) 

windll.kernel32.CloseHandle(snapshot) 
関連する問題