Package winappdbg :: Package win32 :: Module dbghelp
[hide private]
[frames] | no frames]

Source Code for Module winappdbg.win32.dbghelp

  1  # Copyright (c) 2009, Mario Vilas 
  2  # All rights reserved. 
  3  # 
  4  # Redistribution and use in source and binary forms, with or without 
  5  # modification, are permitted provided that the following conditions are met: 
  6  # 
  7  #     * Redistributions of source code must retain the above copyright notice, 
  8  #       this list of conditions and the following disclaimer. 
  9  #     * Redistributions in binary form must reproduce the above copyright 
 10  #       notice,this list of conditions and the following disclaimer in the 
 11  #       documentation and/or other materials provided with the distribution. 
 12  #     * Neither the name of the copyright holder nor the names of its 
 13  #       contributors may be used to endorse or promote products derived from 
 14  #       this software without specific prior written permission. 
 15  # 
 16  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 17  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 18  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 19  # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 20  # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 21  # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 22  # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 23  # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 24  # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 25  # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 26  # POSSIBILITY OF SUCH DAMAGE. 
 27   
 28  """ 
 29  Debugging API wrappers in ctypes. 
 30   
 31  @see: U{http://apps.sourceforge.net/trac/winappdbg/wiki/Win32APIWrappers} 
 32  """ 
 33   
 34  __revision__ = "$Id: dbghelp.py 343 2009-08-03 22:58:22Z QvasiModo $" 
 35   
 36  from defines import * 
 37  from kernel32 import * 
 38   
 39  UNDNAME_32_BIT_DECODE           = 0x0800 
 40  UNDNAME_COMPLETE                = 0x0000 
 41  UNDNAME_NAME_ONLY               = 0x1000 
 42  UNDNAME_NO_ACCESS_SPECIFIERS    = 0x0080 
 43  UNDNAME_NO_ALLOCATION_LANGUAGE  = 0x0010 
 44  UNDNAME_NO_ALLOCATION_MODEL     = 0x0008 
 45  UNDNAME_NO_ARGUMENTS            = 0x2000 
 46  UNDNAME_NO_CV_THISTYPE          = 0x0040 
 47  UNDNAME_NO_FUNCTION_RETURNS     = 0x0004 
 48  UNDNAME_NO_LEADING_UNDERSCORES  = 0x0001 
 49  UNDNAME_NO_MEMBER_TYPE          = 0x0200 
 50  UNDNAME_NO_MS_KEYWORDS          = 0x0002 
 51  UNDNAME_NO_MS_THISTYPE          = 0x0020 
 52  UNDNAME_NO_RETURN_UDT_MODEL     = 0x0400 
 53  UNDNAME_NO_SPECIAL_SYMS         = 0x4000 
 54  UNDNAME_NO_THISTYPE             = 0x0060 
 55  UNDNAME_NO_THROW_SIGNATURES     = 0x0100 
 56   
 57  #--- IMAGEHLP_MODULE structure and related ------------------------------------ 
 58   
 59  SYMOPT_ALLOW_ABSOLUTE_SYMBOLS       = 0x00000800 
 60  SYMOPT_ALLOW_ZERO_ADDRESS           = 0x01000000 
 61  SYMOPT_AUTO_PUBLICS                 = 0x00010000 
 62  SYMOPT_CASE_INSENSITIVE             = 0x00000001 
 63  SYMOPT_DEBUG                        = 0x80000000 
 64  SYMOPT_DEFERRED_LOADS               = 0x00000004 
 65  SYMOPT_DISABLE_SYMSRV_AUTODETECT    = 0x02000000 
 66  SYMOPT_EXACT_SYMBOLS                = 0x00000400 
 67  SYMOPT_FAIL_CRITICAL_ERRORS         = 0x00000200 
 68  SYMOPT_FAVOR_COMPRESSED             = 0x00800000 
 69  SYMOPT_FLAT_DIRECTORY               = 0x00400000 
 70  SYMOPT_IGNORE_CVREC                 = 0x00000080 
 71  SYMOPT_IGNORE_IMAGEDIR              = 0x00200000 
 72  SYMOPT_IGNORE_NT_SYMPATH            = 0x00001000 
 73  SYMOPT_INCLUDE_32BIT_MODULES        = 0x00002000 
 74  SYMOPT_LOAD_ANYTHING                = 0x00000040 
 75  SYMOPT_LOAD_LINES                   = 0x00000010 
 76  SYMOPT_NO_CPP                       = 0x00000008 
 77  SYMOPT_NO_IMAGE_SEARCH              = 0x00020000 
 78  SYMOPT_NO_PROMPTS                   = 0x00080000 
 79  SYMOPT_NO_PUBLICS                   = 0x00008000 
 80  SYMOPT_NO_UNQUALIFIED_LOADS         = 0x00000100 
 81  SYMOPT_OVERWRITE                    = 0x00100000 
 82  SYMOPT_PUBLICS_ONLY                 = 0x00004000 
 83  SYMOPT_SECURE                       = 0x00040000 
 84  SYMOPT_UNDNAME                      = 0x00000002 
 85   
 86  ##SSRVOPT_DWORD 
 87  ##SSRVOPT_DWORDPTR 
 88  ##SSRVOPT_GUIDPTR 
 89  ## 
 90  ##SSRVOPT_CALLBACK 
 91  ##SSRVOPT_DOWNSTREAM_STORE 
 92  ##SSRVOPT_FLAT_DEFAULT_STORE 
 93  ##SSRVOPT_FAVOR_COMPRESSED 
 94  ##SSRVOPT_NOCOPY 
 95  ##SSRVOPT_OVERWRITE 
 96  ##SSRVOPT_PARAMTYPE 
 97  ##SSRVOPT_PARENTWIN 
 98  ##SSRVOPT_PROXY 
 99  ##SSRVOPT_RESET 
100  ##SSRVOPT_SECURE 
101  ##SSRVOPT_SETCONTEXT 
102  ##SSRVOPT_TRACE 
103  ##SSRVOPT_UNATTENDED 
104   
105  #    typedef enum 
106  #    { 
107  #        SymNone = 0, 
108  #        SymCoff, 
109  #        SymCv, 
110  #        SymPdb, 
111  #        SymExport, 
112  #        SymDeferred, 
113  #        SymSym, 
114  #        SymDia, 
115  #        SymVirtual, 
116  #        NumSymTypes 
117  #    } SYM_TYPE; 
118  SymNone     = 0 
119  SymCoff     = 1 
120  SymCv       = 2 
121  SymPdb      = 3 
122  SymExport   = 4 
123  SymDeferred = 5 
124  SymSym      = 6 
125  SymDia      = 7 
126  SymVirtual  = 8 
127  NumSymTypes = 9 
128   
129  #    typedef struct _IMAGEHLP_MODULE64 { 
130  #      DWORD    SizeOfStruct; 
131  #      DWORD64  BaseOfImage; 
132  #      DWORD    ImageSize; 
133  #      DWORD    TimeDateStamp; 
134  #      DWORD    CheckSum; 
135  #      DWORD    NumSyms; 
136  #      SYM_TYPE SymType; 
137  #      TCHAR    ModuleName[32]; 
138  #      TCHAR    ImageName[256]; 
139  #      TCHAR    LoadedImageName[256]; 
140  #      TCHAR    LoadedPdbName[256]; 
141  #      DWORD    CVSig; 
142  #      TCHAR    CVData[MAX_PATH*3]; 
143  #      DWORD    PdbSig; 
144  #      GUID     PdbSig70; 
145  #      DWORD    PdbAge; 
146  #      BOOL     PdbUnmatched; 
147  #      BOOL     DbgUnmatched; 
148  #      BOOL     LineNumbers; 
149  #      BOOL     GlobalSymbols; 
150  #      BOOL     TypeInfo; 
151  #      BOOL     SourceIndexed; 
152  #      BOOL     Publics; 
153  #    } IMAGEHLP_MODULE64, *PIMAGEHLP_MODULE64; 
154   
155 -class IMAGEHLP_MODULE (Structure):
156 _fields_ = [ 157 ("SizeOfStruct", DWORD), 158 ("BaseOfImage", DWORD), 159 ("ImageSize", DWORD), 160 ("TimeDateStamp", DWORD), 161 ("CheckSum", DWORD), 162 ("NumSyms", DWORD), 163 ("SymType", DWORD), # SYM_TYPE 164 ("ModuleName", CHAR * 32), 165 ("ImageName", CHAR * 256), 166 ("LoadedImageName", CHAR * 256), 167 ]
168 PIMAGEHLP_MODULE = POINTER(IMAGEHLP_MODULE) 169
170 -class IMAGEHLP_MODULE64 (Structure):
171 _fields_ = [ 172 ("SizeOfStruct", DWORD), 173 ("BaseOfImage", DWORD64), 174 ("ImageSize", DWORD), 175 ("TimeDateStamp", DWORD), 176 ("CheckSum", DWORD), 177 ("NumSyms", DWORD), 178 ("SymType", DWORD), # SYM_TYPE 179 ("ModuleName", CHAR * 32), 180 ("ImageName", CHAR * 256), 181 ("LoadedImageName", CHAR * 256), 182 ("LoadedPdbName", CHAR * 256), 183 ("CVSig", DWORD), 184 ("CVData", CHAR * (MAX_PATH * 3)), 185 ("PdbSig", DWORD), 186 ("PdbSig70", GUID), 187 ("PdbAge", DWORD), 188 ("PdbUnmatched", BOOL), 189 ("DbgUnmatched", BOOL), 190 ("LineNumbers", BOOL), 191 ("GlobalSymbols", BOOL), 192 ("TypeInfo", BOOL), 193 ("SourceIndexed", BOOL), 194 ("Publics", BOOL), 195 ]
196 PIMAGEHLP_MODULE64 = POINTER(IMAGEHLP_MODULE64) 197
198 -class IMAGEHLP_MODULEW (Structure):
199 _fields_ = [ 200 ("SizeOfStruct", DWORD), 201 ("BaseOfImage", DWORD), 202 ("ImageSize", DWORD), 203 ("TimeDateStamp", DWORD), 204 ("CheckSum", DWORD), 205 ("NumSyms", DWORD), 206 ("SymType", DWORD), # SYM_TYPE 207 ("ModuleName", WCHAR * 32), 208 ("ImageName", WCHAR * 256), 209 ("LoadedImageName", WCHAR * 256), 210 ]
211 PIMAGEHLP_MODULEW = POINTER(IMAGEHLP_MODULEW) 212
213 -class IMAGEHLP_MODULEW64 (Structure):
214 _fields_ = [ 215 ("SizeOfStruct", DWORD), 216 ("BaseOfImage", DWORD64), 217 ("ImageSize", DWORD), 218 ("TimeDateStamp", DWORD), 219 ("CheckSum", DWORD), 220 ("NumSyms", DWORD), 221 ("SymType", DWORD), # SYM_TYPE 222 ("ModuleName", WCHAR * 32), 223 ("ImageName", WCHAR * 256), 224 ("LoadedImageName", WCHAR * 256), 225 ("LoadedPdbName", WCHAR * 256), 226 ("CVSig", DWORD), 227 ("CVData", WCHAR * (MAX_PATH * 3)), 228 ("PdbSig", DWORD), 229 ("PdbSig70", GUID), 230 ("PdbAge", DWORD), 231 ("PdbUnmatched", BOOL), 232 ("DbgUnmatched", BOOL), 233 ("LineNumbers", BOOL), 234 ("GlobalSymbols", BOOL), 235 ("TypeInfo", BOOL), 236 ("SourceIndexed", BOOL), 237 ("Publics", BOOL), 238 ]
239 PIMAGEHLP_MODULEW64 = POINTER(IMAGEHLP_MODULEW64) 240 241 #--- dbghelp.dll -------------------------------------------------------------- 242 243 # XXX the ANSI versions of these functions don't end in "A" as expected! 244 245 # BOOL WINAPI SymInitialize( 246 # __in HANDLE hProcess, 247 # __in_opt PCTSTR UserSearchPath, 248 # __in BOOL fInvadeProcess 249 # );
250 -def SymInitialize(hProcess, UserSearchPath = None, fInvadeProcess = False):
251 _SymInitialize = windll.dbghelp.SymInitialize 252 _SymInitialize.argtypes = [HANDLE, LPSTR, BOOL] 253 _SymInitialize.restype = bool 254 _SymInitialize.errcheck = RaiseIfZero 255 if not UserSearchPath: 256 UserSearchPath = None 257 _SymInitialize(hProcess, UserSearchPath, fInvadeProcess)
258 259 # BOOL WINAPI SymCleanup( 260 # __in HANDLE hProcess 261 # );
262 -def SymCleanup(hProcess):
263 _SymCleanup = windll.dbghelp.SymCleanup 264 _SymCleanup.argtypes = [HANDLE] 265 _SymCleanup.restype = bool 266 _SymCleanup.errcheck = RaiseIfZero 267 _SymCleanup(hProcess)
268 269 # BOOL WINAPI SymRefreshModuleList( 270 # __in HANDLE hProcess 271 # );
272 -def SymRefreshModuleList(hProcess):
273 _SymRefreshModuleList = windll.dbghelp.SymRefreshModuleList 274 _SymRefreshModuleList.argtypes = [HANDLE] 275 _SymRefreshModuleList.restype = bool 276 _SymRefreshModuleList.errcheck = RaiseIfZero 277 _SymRefreshModuleList(hProcess)
278 279 # BOOL WINAPI SymSetParentWindow( 280 # __in HWND hwnd 281 # );
282 -def SymSetParentWindow(hwnd):
283 _SymSetParentWindow = windll.dbghelp.SymSetParentWindow 284 _SymSetParentWindow.argtypes = [HWND] 285 _SymSetParentWindow.restype = bool 286 _SymSetParentWindow.errcheck = RaiseIfZero 287 _SymSetParentWindow(hwnd)
288 289 # DWORD WINAPI SymSetOptions( 290 # __in DWORD SymOptions 291 # );
292 -def SymSetOptions(SymOptions):
293 _SymSetOptions = windll.dbghelp.SymSetOptions 294 _SymSetOptions.argtypes = [DWORD] 295 _SymSetOptions.restype = DWORD 296 _SymSetOptions.errcheck = RaiseIfZero 297 _SymSetOptions(SymOptions)
298 299 # DWORD WINAPI SymGetOptions(void);
300 -def SymGetOptions():
301 _SymGetOptions = windll.dbghelp.SymGetOptions 302 _SymGetOptions.argtypes = [] 303 _SymGetOptions.restype = DWORD 304 return _SymGetOptions()
305 306 # DWORD WINAPI SymLoadModule( 307 # __in HANDLE hProcess, 308 # __in_opt HANDLE hFile, 309 # __in_opt PCSTR ImageName, 310 # __in_opt PCSTR ModuleName, 311 # __in DWORD BaseOfDll, 312 # __in DWORD SizeOfDll 313 # );
314 -def SymLoadModule(hProcess, hFile = None, ImageName = None, ModuleName = None, BaseOfDll = None, SizeOfDll = None):
315 _SymLoadModule = windll.dbghelp.SymLoadModule 316 _SymLoadModule.argtypes = [HANDLE, HANDLE, LPSTR, LPSTR, DWORD, DWORD] 317 _SymLoadModule.restype = DWORD 318 319 if not ImageName: 320 ImageName = None 321 if not ModuleName: 322 ModuleName = None 323 if not BaseOfDll: 324 BaseOfDll = 0 325 if not SizeOfDll: 326 SizeOfDll = 0 327 lpBaseAddress = _SymLoadModule(hProcess, hFile, ImageName, ModuleName, BaseOfDll, SizeOfDll) 328 if lpBaseAddress == NULL: 329 dwErrorCode = GetLastError() 330 if dwErrorCode != ERROR_SUCCESS: 331 raise ctypes.WinError(dwErrorCode) 332 return lpBaseAddress
333 334 # DWORD64 WINAPI SymLoadModule64( 335 # __in HANDLE hProcess, 336 # __in_opt HANDLE hFile, 337 # __in_opt PCSTR ImageName, 338 # __in_opt PCSTR ModuleName, 339 # __in DWORD64 BaseOfDll, 340 # __in DWORD SizeOfDll 341 # );
342 -def SymLoadModule64(hProcess, hFile = None, ImageName = None, ModuleName = None, BaseOfDll = None, SizeOfDll = None):
343 _SymLoadModule64 = windll.dbghelp.SymLoadModule64 344 _SymLoadModule64.argtypes = [HANDLE, HANDLE, LPSTR, LPSTR, DWORD64, DWORD] 345 _SymLoadModule64.restype = DWORD64 346 347 if not ImageName: 348 ImageName = None 349 if not ModuleName: 350 ModuleName = None 351 if not BaseOfDll: 352 BaseOfDll = 0 353 if not SizeOfDll: 354 SizeOfDll = 0 355 lpBaseAddress = _SymLoadModule64(hProcess, hFile, ImageName, ModuleName, BaseOfDll, SizeOfDll) 356 if lpBaseAddress == NULL: 357 dwErrorCode = GetLastError() 358 if dwErrorCode != ERROR_SUCCESS: 359 raise ctypes.WinError(dwErrorCode) 360 return lpBaseAddress
361 362 # BOOL WINAPI SymUnloadModule( 363 # __in HANDLE hProcess, 364 # __in DWORD BaseOfDll 365 # );
366 -def SymUnloadModule(hProcess, BaseOfDll):
367 _SymUnloadModule = windll.dbghelp.SymUnloadModule 368 _SymUnloadModule.argtypes = [HANDLE, DWORD] 369 _SymUnloadModule.restype = bool 370 _SymUnloadModule.errcheck = RaiseIfZero 371 _SymUnloadModule(hProcess, BaseOfDll)
372 373 # BOOL WINAPI SymUnloadModule64( 374 # __in HANDLE hProcess, 375 # __in DWORD64 BaseOfDll 376 # );
377 -def SymUnloadModule64(hProcess, BaseOfDll):
378 _SymUnloadModule64 = windll.dbghelp.SymUnloadModule64 379 _SymUnloadModule64.argtypes = [HANDLE, DWORD64] 380 _SymUnloadModule64.restype = bool 381 _SymUnloadModule64.errcheck = RaiseIfZero 382 _SymUnloadModule64(hProcess, BaseOfDll)
383 384 # BOOL WINAPI SymGetModuleInfo( 385 # __in HANDLE hProcess, 386 # __in DWORD dwAddr, 387 # __out PIMAGEHLP_MODULE ModuleInfo 388 # );
389 -def SymGetModuleInfoA(hProcess, dwAddr):
390 _SymGetModuleInfo = windll.dbghelp.SymGetModuleInfo 391 _SymGetModuleInfo.argtypes = [HANDLE, DWORD, PIMAGEHLP_MODULE] 392 _SymGetModuleInfo.restype = bool 393 _SymGetModuleInfo.errcheck = RaiseIfZero 394 395 ModuleInfo = IMAGEHLP_MODULE() 396 ModuleInfo.SizeOfStruct = sizeof(ModuleInfo) 397 _SymGetModuleInfo(hProcess, dwAddr, ctypes.byref(ModuleInfo)) 398 return ModuleInfo
399
400 -def SymGetModuleInfoW(hProcess, dwAddr):
401 _SymGetModuleInfoW = windll.dbghelp.SymGetModuleInfoW 402 _SymGetModuleInfoW.argtypes = [HANDLE, DWORD, PIMAGEHLP_MODULEW] 403 _SymGetModuleInfoW.restype = bool 404 _SymGetModuleInfoW.errcheck = RaiseIfZero 405 406 ModuleInfo = IMAGEHLP_MODULEW() 407 ModuleInfo.SizeOfStruct = sizeof(ModuleInfo) 408 _SymGetModuleInfoW(hProcess, dwAddr, ctypes.byref(ModuleInfo)) 409 return ModuleInfo
410 411 SymGetModuleInfo = GuessStringType(SymGetModuleInfoA, SymGetModuleInfoW) 412 413 # BOOL WINAPI SymGetModuleInfo64( 414 # __in HANDLE hProcess, 415 # __in DWORD64 dwAddr, 416 # __out PIMAGEHLP_MODULE64 ModuleInfo 417 # );
418 -def SymGetModuleInfo64A(hProcess, dwAddr):
419 _SymGetModuleInfo64 = windll.dbghelp.SymGetModuleInfo64 420 _SymGetModuleInfo64.argtypes = [HANDLE, DWORD64, PIMAGEHLP_MODULE64] 421 _SymGetModuleInfo64.restype = bool 422 _SymGetModuleInfo64.errcheck = RaiseIfZero 423 424 ModuleInfo = IMAGEHLP_MODULE64() 425 ModuleInfo.SizeOfStruct = sizeof(ModuleInfo) 426 _SymGetModuleInfo64(hProcess, dwAddr, ctypes.byref(ModuleInfo)) 427 return ModuleInfo
428
429 -def SymGetModuleInfo64W(hProcess, dwAddr):
430 _SymGetModuleInfo64W = windll.dbghelp.SymGetModuleInfo64W 431 _SymGetModuleInfo64W.argtypes = [HANDLE, DWORD64, PIMAGEHLP_MODULE64W] 432 _SymGetModuleInfo64W.restype = bool 433 _SymGetModuleInfo64W.errcheck = RaiseIfZero 434 435 ModuleInfo = IMAGEHLP_MODULE64W() 436 ModuleInfo.SizeOfStruct = sizeof(ModuleInfo) 437 _SymGetModuleInfo64W(hProcess, dwAddr, ctypes.byref(ModuleInfo)) 438 return ModuleInfo
439 440 SymGetModuleInfo64 = GuessStringType(SymGetModuleInfo64A, SymGetModuleInfo64W) 441 442 # BOOL CALLBACK SymEnumerateModulesProc( 443 # __in PCTSTR ModuleName, 444 # __in DWORD BaseOfDll, 445 # __in_opt PVOID UserContext 446 # ); 447 PSYM_ENUMMODULES_CALLBACK = WINFUNCTYPE(BOOL, LPSTR, DWORD, PVOID) 448 PSYM_ENUMMODULES_CALLBACKW = WINFUNCTYPE(BOOL, LPWSTR, DWORD, PVOID) 449 450 # BOOL CALLBACK SymEnumerateModulesProc64( 451 # __in PCTSTR ModuleName, 452 # __in DWORD64 BaseOfDll, 453 # __in_opt PVOID UserContext 454 # ); 455 PSYM_ENUMMODULES_CALLBACK64 = WINFUNCTYPE(BOOL, LPSTR, DWORD64, PVOID) 456 PSYM_ENUMMODULES_CALLBACKW64 = WINFUNCTYPE(BOOL, LPWSTR, DWORD64, PVOID) 457 458 # BOOL WINAPI SymEnumerateModules( 459 # __in HANDLE hProcess, 460 # __in PSYM_ENUMMODULES_CALLBACK EnumModulesCallback, 461 # __in_opt PVOID UserContext 462 # );
463 -def SymEnumerateModulesA(hProcess, EnumModulesCallback, UserContext = None):
464 _SymEnumerateModules = windll.dbghelp.SymEnumerateModules 465 _SymEnumerateModules.argtypes = [HANDLE, PSYM_ENUMMODULES_CALLBACK, PVOID] 466 _SymEnumerateModules.restype = bool 467 _SymEnumerateModules.errcheck = RaiseIfZero 468 469 EnumModulesCallback = PSYM_ENUMMODULES_CALLBACK(EnumModulesCallback) 470 if UserContext: 471 UserContext = ctypes.pointer(UserContext) 472 else: 473 UserContext = LPVOID(NULL) 474 _SymEnumerateModules(hProcess, EnumModulesCallback, UserContext)
475
476 -def SymEnumerateModulesW(hProcess, EnumModulesCallback, UserContext = None):
477 _SymEnumerateModulesW = windll.dbghelp.SymEnumerateModulesW 478 _SymEnumerateModulesW.argtypes = [HANDLE, PSYM_ENUMMODULES_CALLBACKW, PVOID] 479 _SymEnumerateModulesW.restype = bool 480 _SymEnumerateModulesW.errcheck = RaiseIfZero 481 482 EnumModulesCallback = PSYM_ENUMMODULES_CALLBACKW(EnumModulesCallback) 483 if UserContext: 484 UserContext = ctypes.pointer(UserContext) 485 else: 486 UserContext = LPVOID(NULL) 487 _SymEnumerateModulesW(hProcess, EnumModulesCallback, UserContext)
488 489 SymEnumerateModules = GuessStringType(SymEnumerateModulesA, SymEnumerateModulesW) 490 491 # BOOL WINAPI SymEnumerateModules64( 492 # __in HANDLE hProcess, 493 # __in PSYM_ENUMMODULES_CALLBACK64 EnumModulesCallback, 494 # __in_opt PVOID UserContext 495 # );
496 -def SymEnumerateModules64A(hProcess, EnumModulesCallback, UserContext = None):
497 _SymEnumerateModules64 = windll.dbghelp.SymEnumerateModules64 498 _SymEnumerateModules64.argtypes = [HANDLE, PSYM_ENUMMODULES_CALLBACK64, PVOID] 499 _SymEnumerateModules64.restype = bool 500 _SymEnumerateModules64.errcheck = RaiseIfZero 501 502 EnumModulesCallback = PSYM_ENUMMODULES_CALLBACK64(EnumModulesCallback) 503 if UserContext: 504 UserContext = ctypes.pointer(UserContext) 505 else: 506 UserContext = LPVOID(NULL) 507 _SymEnumerateModules64(hProcess, EnumModulesCallback, UserContext)
508
509 -def SymEnumerateModules64W(hProcess, EnumModulesCallback, UserContext = None):
510 _SymEnumerateModules64W = windll.dbghelp.SymEnumerateModules64W 511 _SymEnumerateModules64W.argtypes = [HANDLE, PSYM_ENUMMODULES_CALLBACK64W, PVOID] 512 _SymEnumerateModules64W.restype = bool 513 _SymEnumerateModules64W.errcheck = RaiseIfZero 514 515 EnumModulesCallback = PSYM_ENUMMODULES_CALLBACK64W(EnumModulesCallback) 516 if UserContext: 517 UserContext = ctypes.pointer(UserContext) 518 else: 519 UserContext = LPVOID(NULL) 520 _SymEnumerateModules64W(hProcess, EnumModulesCallback, UserContext)
521 522 SymEnumerateModules64 = GuessStringType(SymEnumerateModules64A, SymEnumerateModules64W) 523 524 # BOOL CALLBACK SymEnumerateSymbolsProc( 525 # __in PCTSTR SymbolName, 526 # __in DWORD SymbolAddress, 527 # __in ULONG SymbolSize, 528 # __in_opt PVOID UserContext 529 # ); 530 PSYM_ENUMSYMBOLS_CALLBACK = WINFUNCTYPE(BOOL, LPSTR, DWORD, ULONG, PVOID) 531 PSYM_ENUMSYMBOLS_CALLBACKW = WINFUNCTYPE(BOOL, LPWSTR, DWORD, ULONG, PVOID) 532 533 # BOOL CALLBACK SymEnumerateSymbolsProc64( 534 # __in PCTSTR SymbolName, 535 # __in DWORD64 SymbolAddress, 536 # __in ULONG SymbolSize, 537 # __in_opt PVOID UserContext 538 # ); 539 PSYM_ENUMSYMBOLS_CALLBACK64 = WINFUNCTYPE(BOOL, LPSTR, DWORD64, ULONG, PVOID) 540 PSYM_ENUMSYMBOLS_CALLBACKW64 = WINFUNCTYPE(BOOL, LPWSTR, DWORD64, ULONG, PVOID) 541 542 # BOOL WINAPI SymEnumerateSymbols( 543 # __in HANDLE hProcess, 544 # __in ULONG BaseOfDll, 545 # __in PSYM_ENUMSYMBOLS_CALLBACK EnumSymbolsCallback, 546 # __in_opt PVOID UserContext 547 # );
548 -def SymEnumerateSymbolsA(hProcess, BaseOfDll, EnumSymbolsCallback, UserContext = None):
549 _SymEnumerateSymbols = windll.dbghelp.SymEnumerateSymbols 550 _SymEnumerateSymbols.argtypes = [HANDLE, ULONG, PSYM_ENUMSYMBOLS_CALLBACK, PVOID] 551 _SymEnumerateSymbols.restype = bool 552 _SymEnumerateSymbols.errcheck = RaiseIfZero 553 554 EnumSymbolsCallback = PSYM_ENUMSYMBOLS_CALLBACK(EnumSymbolsCallback) 555 if UserContext: 556 UserContext = ctypes.pointer(UserContext) 557 else: 558 UserContext = LPVOID(NULL) 559 _SymEnumerateSymbols(hProcess, BaseOfDll, EnumSymbolsCallback, UserContext)
560
561 -def SymEnumerateSymbolsW(hProcess, BaseOfDll, EnumSymbolsCallback, UserContext = None):
562 _SymEnumerateSymbolsW = windll.dbghelp.SymEnumerateSymbolsW 563 _SymEnumerateSymbolsW.argtypes = [HANDLE, ULONG, PSYM_ENUMSYMBOLS_CALLBACKW, PVOID] 564 _SymEnumerateSymbolsW.restype = bool 565 _SymEnumerateSymbolsW.errcheck = RaiseIfZero 566 567 EnumSymbolsCallback = PSYM_ENUMSYMBOLS_CALLBACKW(EnumSymbolsCallback) 568 if UserContext: 569 UserContext = ctypes.pointer(UserContext) 570 else: 571 UserContext = LPVOID(NULL) 572 _SymEnumerateSymbolsW(hProcess, BaseOfDll, EnumSymbolsCallback, UserContext)
573 574 SymEnumerateSymbols = GuessStringType(SymEnumerateSymbolsA, SymEnumerateSymbolsW) 575 576 # BOOL WINAPI SymEnumerateSymbols64( 577 # __in HANDLE hProcess, 578 # __in ULONG64 BaseOfDll, 579 # __in PSYM_ENUMSYMBOLS_CALLBACK64 EnumSymbolsCallback, 580 # __in_opt PVOID UserContext 581 # );
582 -def SymEnumerateSymbols64A(hProcess, BaseOfDll, EnumSymbolsCallback, UserContext = None):
583 _SymEnumerateSymbols64 = windll.dbghelp.SymEnumerateSymbols64 584 _SymEnumerateSymbols64.argtypes = [HANDLE, ULONG64, PSYM_ENUMSYMBOLS_CALLBACK64, PVOID] 585 _SymEnumerateSymbols64.restype = bool 586 _SymEnumerateSymbols64.errcheck = RaiseIfZero 587 588 EnumSymbolsCallback = PSYM_ENUMSYMBOLS_CALLBACK64(EnumSymbolsCallback) 589 if UserContext: 590 UserContext = ctypes.pointer(UserContext) 591 else: 592 UserContext = LPVOID(NULL) 593 _SymEnumerateSymbols64(hProcess, BaseOfDll, EnumSymbolsCallback, UserContext)
594
595 -def SymEnumerateSymbols64W(hProcess, BaseOfDll, EnumSymbolsCallback, UserContext = None):
596 _SymEnumerateSymbols64W = windll.dbghelp.SymEnumerateSymbols64W 597 _SymEnumerateSymbols64W.argtypes = [HANDLE, ULONG64, PSYM_ENUMSYMBOLS_CALLBACK64W, PVOID] 598 _SymEnumerateSymbols64W.restype = bool 599 _SymEnumerateSymbols64W.errcheck = RaiseIfZero 600 601 EnumSymbolsCallback = PSYM_ENUMSYMBOLS_CALLBACK64W(EnumSymbolsCallback) 602 if UserContext: 603 UserContext = ctypes.pointer(UserContext) 604 else: 605 UserContext = LPVOID(NULL) 606 _SymEnumerateSymbols64W(hProcess, BaseOfDll, EnumSymbolsCallback, UserContext)
607 608 SymEnumerateSymbols64 = GuessStringType(SymEnumerateSymbols64A, SymEnumerateSymbols64W) 609 610 # DWORD WINAPI UnDecorateSymbolName( 611 # __in PCTSTR DecoratedName, 612 # __out PTSTR UnDecoratedName, 613 # __in DWORD UndecoratedLength, 614 # __in DWORD Flags 615 # );
616 -def UnDecorateSymbolNameA(DecoratedName, Flags = UNDNAME_COMPLETE):
617 _UnDecorateSymbolNameA = windll.dbghelp.UnDecorateSymbolName 618 _UnDecorateSymbolNameA.argtypes = [LPSTR, LPSTR, DWORD, DWORD] 619 _UnDecorateSymbolNameA.restype = DWORD 620 _UnDecorateSymbolNameA.errcheck = RaiseIfZero 621 622 UndecoratedLength = _UnDecorateSymbolNameA(DecoratedName, None, 0, Flags) 623 UnDecoratedName = ctypes.create_string_buffer('', UndecoratedLength + 1) 624 _UnDecorateSymbolNameA(DecoratedName, UnDecoratedName, UndecoratedLength, Flags) 625 return UnDecoratedName.value
626
627 -def UnDecorateSymbolNameW(DecoratedName, Flags = UNDNAME_COMPLETE):
628 _UnDecorateSymbolNameW = windll.dbghelp.UnDecorateSymbolNameW 629 _UnDecorateSymbolNameW.argtypes = [LPWSTR, LPWSTR, DWORD, DWORD] 630 _UnDecorateSymbolNameW.restype = DWORD 631 _UnDecorateSymbolNameW.errcheck = RaiseIfZero 632 633 UndecoratedLength = _UnDecorateSymbolNameW(DecoratedName, None, 0, Flags) 634 UnDecoratedName = ctypes.create_unicode_buffer(u'', UndecoratedLength + 1) 635 _UnDecorateSymbolNameW(DecoratedName, UnDecoratedName, UndecoratedLength, Flags) 636 return UnDecoratedName.value
637 638 UnDecorateSymbolName = GuessStringType(UnDecorateSymbolNameA, UnDecorateSymbolNameW) 639 640 # BOOL WINAPI SymGetSearchPath( 641 # __in HANDLE hProcess, 642 # __out PTSTR SearchPath, 643 # __in DWORD SearchPathLength 644 # );
645 -def SymGetSearchPathA(hProcess):
646 _SymGetSearchPath = windll.dbghelp.SymGetSearchPath 647 _SymGetSearchPath.argtypes = [HANDLE, LPSTR, DWORD] 648 _SymGetSearchPath.restype = bool 649 _SymGetSearchPath.errcheck = RaiseIfZero 650 651 SearchPathLength = MAX_PATH 652 SearchPath = ctypes.create_string_buffer("", SearchPathLength) 653 _SymGetSearchPath(hProcess, ctypes.byref(SearchPath), SearchPathLength) 654 return SearchPath.value
655
656 -def SymGetSearchPathW(hProcess):
657 _SymGetSearchPathW = windll.dbghelp.SymGetSearchPathW 658 _SymGetSearchPathW.argtypes = [HANDLE, LPWSTR, DWORD] 659 _SymGetSearchPathW.restype = bool 660 _SymGetSearchPathW.errcheck = RaiseIfZero 661 662 SearchPathLength = MAX_PATH 663 SearchPath = ctypes.create_unicode_buffer("", SearchPathLength) 664 _SymGetSearchPathW(hProcess, ctypes.byref(SearchPath), SearchPathLength) 665 return SearchPath.value
666 667 SymGetSearchPath = GuessStringType(SymGetSearchPathA, SymGetSearchPathW) 668 669 # BOOL WINAPI SymSetSearchPath( 670 # __in HANDLE hProcess, 671 # __in_opt PCTSTR SearchPath 672 # );
673 -def SymSetSearchPathA(hProcess, SearchPath = None):
674 _SymSetSearchPath = windll.dbghelp.SymSetSearchPath 675 _SymSetSearchPath.argtypes = [HANDLE, LPSTR] 676 _SymSetSearchPath.restype = bool 677 _SymSetSearchPath.errcheck = RaiseIfZero 678 if not SearchPath: 679 SearchPath = None 680 _SymSetSearchPath(hProcess, SearchPath)
681
682 -def SymSetSearchPathW(hProcess, SearchPath = None):
683 _SymSetSearchPathW = windll.dbghelp.SymSetSearchPathW 684 _SymSetSearchPathW.argtypes = [HANDLE, LPWSTR] 685 _SymSetSearchPathW.restype = bool 686 _SymSetSearchPathW.errcheck = RaiseIfZero 687 if not SearchPath: 688 SearchPath = None 689 _SymSetSearchPathW(hProcess, SearchPath)
690 691 SymSetSearchPath = GuessStringType(SymSetSearchPathA, SymSetSearchPathW) 692