|
| 1 | +# |
| 2 | +# PyDBG |
| 3 | +# Copyright (C) 2006 Pedram Amini <[email protected]> |
| 4 | +# |
| 5 | +# $Id: defines.py 224 2007-10-12 19:51:45Z aportnoy $ |
| 6 | +# |
| 7 | +# This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public |
| 8 | +# License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later |
| 9 | +# version. |
| 10 | +# |
| 11 | +# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
| 12 | +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 13 | +# |
| 14 | +# You should have received a copy of the GNU General Public License along with this program; if not, write to the Free |
| 15 | +# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 16 | +# |
| 17 | +# |
| 18 | +# windows_h.py was generated with: |
| 19 | +# |
| 20 | +# c:\Python\Lib\site-packages\ctypes\wrap |
| 21 | +# c:\python\python h2xml.py windows.h -o windows.xml -q -c |
| 22 | +# c:\python\python xml2py.py windows.xml -s DEBUG_EVENT -s CONTEXT -s MEMORY_BASIC_INFORMATION -s LDT_ENTRY \ |
| 23 | +# -s PROCESS_INFORMATION -s STARTUPINFO -s SYSTEM_INFO -o windows_h.py |
| 24 | +# |
| 25 | +# Then the import of ctypes was changed at the top of the file to utilize my_ctypes, which adds the necessary changes |
| 26 | +# to support the pickle-ing of our defined data structures and ctype primitives. |
| 27 | +# |
| 28 | + |
| 29 | +''' |
| 30 | +@author: Pedram Amini |
| 31 | +@license: GNU General Public License 2.0 or later |
| 32 | + |
| 33 | +@organization: www.openrce.org |
| 34 | +''' |
| 35 | + |
| 36 | +from my_ctypes import * |
| 37 | +from windows_h import * |
| 38 | + |
| 39 | +### |
| 40 | +### manually declare entities from Tlhelp32.h since i was unable to import using h2xml.py. |
| 41 | +### |
| 42 | + |
| 43 | +TH32CS_SNAPHEAPLIST = 0x00000001 |
| 44 | +TH32CS_SNAPPROCESS = 0x00000002 |
| 45 | +TH32CS_SNAPTHREAD = 0x00000004 |
| 46 | +TH32CS_SNAPMODULE = 0x00000008 |
| 47 | +TH32CS_INHERIT = 0x80000000 |
| 48 | +TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST | TH32CS_SNAPPROCESS | TH32CS_SNAPTHREAD | TH32CS_SNAPMODULE) |
| 49 | + |
| 50 | +class THREADENTRY32(Structure): |
| 51 | + _fields_ = [ |
| 52 | + ('dwSize', DWORD), |
| 53 | + ('cntUsage', DWORD), |
| 54 | + ('th32ThreadID', DWORD), |
| 55 | + ('th32OwnerProcessID', DWORD), |
| 56 | + ('tpBasePri', DWORD), |
| 57 | + ('tpDeltaPri', DWORD), |
| 58 | + ('dwFlags', DWORD), |
| 59 | + ] |
| 60 | + |
| 61 | +class PROCESSENTRY32(Structure): |
| 62 | + _fields_ = [ |
| 63 | + ('dwSize', DWORD), |
| 64 | + ('cntUsage', DWORD), |
| 65 | + ('th32ProcessID', DWORD), |
| 66 | + ('th32DefaultHeapID', DWORD), |
| 67 | + ('th32ModuleID', DWORD), |
| 68 | + ('cntThreads', DWORD), |
| 69 | + ('th32ParentProcessID', DWORD), |
| 70 | + ('pcPriClassBase', DWORD), |
| 71 | + ('dwFlags', DWORD), |
| 72 | + ('szExeFile', CHAR * 260), |
| 73 | + ] |
| 74 | + |
| 75 | +class MODULEENTRY32(Structure): |
| 76 | + _fields_ = [ |
| 77 | + ("dwSize", DWORD), |
| 78 | + ("th32ModuleID", DWORD), |
| 79 | + ("th32ProcessID", DWORD), |
| 80 | + ("GlblcntUsage", DWORD), |
| 81 | + ("ProccntUsage", DWORD), |
| 82 | + ("modBaseAddr", DWORD), |
| 83 | + ("modBaseSize", DWORD), |
| 84 | + ("hModule", DWORD), |
| 85 | + ("szModule", CHAR * 256), |
| 86 | + ("szExePath", CHAR * 260), |
| 87 | + ] |
| 88 | + |
| 89 | +class _MIB_TCPROW_OWNER_PID(Structure): |
| 90 | + _fields_ = [ |
| 91 | + ("dwState", DWORD), |
| 92 | + ("dwLocalAddr", DWORD), |
| 93 | + ("dwLocalPort", DWORD), |
| 94 | + ("dwRemoteAddr", DWORD), |
| 95 | + ("dwRemotePort", DWORD), |
| 96 | + ("dwOwningPid", DWORD), |
| 97 | + ] |
| 98 | + |
| 99 | +class MIB_TCPTABLE_OWNER_PID(Structure): |
| 100 | + _fields_ = [ |
| 101 | + ("dwNumEntries", DWORD), |
| 102 | + ("table", _MIB_TCPROW_OWNER_PID * 512) |
| 103 | + ] |
| 104 | + |
| 105 | + |
| 106 | +class _MIB_UDPROW_OWNER_PID(Structure): |
| 107 | + _fields_ = [ |
| 108 | + ("dwLocalAddr", DWORD), |
| 109 | + ("dwLocalPort", DWORD), |
| 110 | + ("dwOwningPid", DWORD) |
| 111 | + ] |
| 112 | + |
| 113 | +class MIB_UDPTABLE_OWNER_PID(Structure): |
| 114 | + _fields_ = [ |
| 115 | + ("dwNumEntries", DWORD), |
| 116 | + ("table", _MIB_UDPROW_OWNER_PID * 512) |
| 117 | + ] |
| 118 | + |
| 119 | + |
| 120 | +### |
| 121 | +### manually declare various structures as needed. |
| 122 | +### |
| 123 | + |
| 124 | +class SYSDBG_MSR(Structure): |
| 125 | + _fields_ = [ |
| 126 | + ("Address", c_ulong), |
| 127 | + ("Data", c_ulonglong), |
| 128 | + ] |
| 129 | + |
| 130 | +### |
| 131 | +### manually declare various #define's as needed. |
| 132 | +### |
| 133 | + |
| 134 | +# debug event codes. |
| 135 | +EXCEPTION_DEBUG_EVENT = 0x00000001 |
| 136 | +CREATE_THREAD_DEBUG_EVENT = 0x00000002 |
| 137 | +CREATE_PROCESS_DEBUG_EVENT = 0x00000003 |
| 138 | +EXIT_THREAD_DEBUG_EVENT = 0x00000004 |
| 139 | +EXIT_PROCESS_DEBUG_EVENT = 0x00000005 |
| 140 | +LOAD_DLL_DEBUG_EVENT = 0x00000006 |
| 141 | +UNLOAD_DLL_DEBUG_EVENT = 0x00000007 |
| 142 | +OUTPUT_DEBUG_STRING_EVENT = 0x00000008 |
| 143 | +RIP_EVENT = 0x00000009 |
| 144 | +USER_CALLBACK_DEBUG_EVENT = 0xDEADBEEF # added for callback support in debug event loop. |
| 145 | + |
| 146 | +# debug exception codes. |
| 147 | +EXCEPTION_ACCESS_VIOLATION = 0xC0000005 |
| 148 | +EXCEPTION_BREAKPOINT = 0x80000003 |
| 149 | +EXCEPTION_GUARD_PAGE = 0x80000001 |
| 150 | +EXCEPTION_SINGLE_STEP = 0x80000004 |
| 151 | + |
| 152 | +# hw breakpoint conditions |
| 153 | +HW_ACCESS = 0x00000003 |
| 154 | +HW_EXECUTE = 0x00000000 |
| 155 | +HW_WRITE = 0x00000001 |
| 156 | + |
| 157 | +CONTEXT_CONTROL = 0x00010001 |
| 158 | +CONTEXT_FULL = 0x00010007 |
| 159 | +CONTEXT_DEBUG_REGISTERS = 0x00010010 |
| 160 | +CREATE_NEW_CONSOLE = 0x00000010 |
| 161 | +DBG_CONTINUE = 0x00010002 |
| 162 | +DBG_EXCEPTION_NOT_HANDLED = 0x80010001 |
| 163 | +DBG_EXCEPTION_HANDLED = 0x00010001 |
| 164 | +DEBUG_PROCESS = 0x00000001 |
| 165 | +DEBUG_ONLY_THIS_PROCESS = 0x00000002 |
| 166 | +EFLAGS_RF = 0x00010000 |
| 167 | +EFLAGS_TRAP = 0x00000100 |
| 168 | +ERROR_NO_MORE_FILES = 0x00000012 |
| 169 | +FILE_MAP_READ = 0x00000004 |
| 170 | +FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100 |
| 171 | +FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000 |
| 172 | +INVALID_HANDLE_VALUE = 0xFFFFFFFF |
| 173 | +MEM_COMMIT = 0x00001000 |
| 174 | +MEM_DECOMMIT = 0x00004000 |
| 175 | +MEM_IMAGE = 0x01000000 |
| 176 | +MEM_RELEASE = 0x00008000 |
| 177 | +PAGE_NOACCESS = 0x00000001 |
| 178 | +PAGE_READONLY = 0x00000002 |
| 179 | +PAGE_READWRITE = 0x00000004 |
| 180 | +PAGE_WRITECOPY = 0x00000008 |
| 181 | +PAGE_EXECUTE = 0x00000010 |
| 182 | +PAGE_EXECUTE_READ = 0x00000020 |
| 183 | +PAGE_EXECUTE_READWRITE = 0x00000040 |
| 184 | +PAGE_EXECUTE_WRITECOPY = 0x00000080 |
| 185 | +PAGE_GUARD = 0x00000100 |
| 186 | +PAGE_NOCACHE = 0x00000200 |
| 187 | +PAGE_WRITECOMBINE = 0x00000400 |
| 188 | +PROCESS_ALL_ACCESS = 0x001F0FFF |
| 189 | +SE_PRIVILEGE_ENABLED = 0x00000002 |
| 190 | +SW_SHOW = 0x00000005 |
| 191 | +THREAD_ALL_ACCESS = 0x001F03FF |
| 192 | +TOKEN_ADJUST_PRIVILEGES = 0x00000020 |
| 193 | +UDP_TABLE_OWNER_PID = 0x00000001 |
| 194 | +VIRTUAL_MEM = 0x00003000 |
| 195 | + |
| 196 | +# for NtSystemDebugControl() |
| 197 | +SysDbgReadMsr = 16 |
| 198 | +SysDbgWriteMsr = 17 |
| 199 | + |
| 200 | +# for mapping TCP ports and PIDs |
| 201 | +AF_INET = 0x00000002 |
| 202 | +AF_INET6 = 0x00000017 |
| 203 | +MIB_TCP_STATE_LISTEN = 0x00000002 |
| 204 | +TCP_TABLE_OWNER_PID_ALL = 0x00000005 |
0 commit comments