53 lines · python
1# DExTer : Debugging Experience Tester2# ~~~~~~ ~ ~~ ~ ~~3#4# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5# See https://llvm.org/LICENSE.txt for license information.6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7 8from ctypes import *9 10# Error codes are negative when received by python, but are typically11# represented by unsigned hex elsewhere. Subtract 2^32 from the unsigned12# hex to produce negative error codes.13E_NOINTERFACE = 0x80004002 - 0x10000000014E_FAIL = 0x80004005 - 0x10000000015E_EINVAL = 0x80070057 - 0x10000000016E_INTERNALEXCEPTION = 0x80040205 - 0x10000000017S_FALSE = 118 19# This doesn't fit into any convenient category20DEBUG_ANY_ID = 0xFFFFFFFF21 22 23class WinError(Exception):24 def __init__(self, msg, hstatus):25 self.hstatus = hstatus26 super(WinError, self).__init__(msg)27 28 29def aborter(res, msg, ignore=[]):30 if res != 0 and res not in ignore:31 # Convert a negative error code to a positive unsigned one, which is32 # now NTSTATUSes appear in documentation.33 if res < 0:34 res += 0x10000000035 msg = "{:08X} : {}".format(res, msg)36 raise WinError(msg, res)37 38 39IID_Data4_Type = c_ubyte * 840 41 42class IID(Structure):43 _fields_ = [44 ("Data1", c_uint),45 ("Data2", c_ushort),46 ("Data3", c_ushort),47 ("Data4", IID_Data4_Type),48 ]49 50 51c_ulong_p = POINTER(c_ulong)52c_ulong64_p = POINTER(c_ulonglong)53