pydbg 64 bit enumerate_processes() returning empty list
<p>I'm using pydbg binaries downloaded here: <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/#pydbg" rel="nofollow">http://www.lfd.uci.edu/~gohlke/pythonlibs/#pydbg</a> as recommended in previous answers.</p>

<p>I can get the 32-bit version to work with a 32-bit Python interpreter, but I can't get the 64-bit version to work with 64-bit Python. <code>enumerate_processes()</code> always returns an empty list.. Am I doing something wrong?</p>

<p>Test code:</p>

<pre><code>import pydbg

if __name__ == "__main__":
    print(pydbg.pydbg().enumerate_processes())
</code></pre>

<p>32-bit working:</p>

<pre><code>&gt;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
...
&gt;C:\Python27-32\python-32bit.exe pydbg_test.py
[(0L, '[System Process]'), (4L, 'System'), &lt;redacted for brevity&gt;]
</code></pre>

<p>64-bit gives an empty list:</p>

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

<p>Pydbg defines the PROCESSENTRY32 structure wrong.</p>

<p>Better use a maintained package such as <a href="https://pythonhosted.org/psutil/#psutil.process_iter" rel="nofollow">psutil</a> or use ctypes directly, e.g.:</p>

<pre><code>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)
</code></pre>

python pydbg