Python ctypes.wintypes 模块,ULONG 实例源码

我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用ctypes.wintypes.ULONG

项目:pyUVVIS    作者:ddietze    | 项目源码 | 文件源码
def create_camera_list(dwCount):
    """Returns an instance of the UC480_CAMERA_LIST structure having the properly scaled UC480_CAMERA_INFO array.

    :param ULONG dwCount: Number of camera info structures requested.
    :returns: UC480_CAMERA_LIST

    :var ULONG dwCount: Size of uci.
    :var UC480_CAMERA_INFO[dwCount] uci: List of camera info structures.
    """
    class UC480_CAMERA_LIST(ctypes.Structure):
        _fields_ = [("dwCount", wt.ULONG),
                    ("uci", UC480_CAMERA_INFO * dwCount)]
    a_list = UC480_CAMERA_LIST()
    a_list.dwCount = dwCount
    return a_list

#  ----------------------------------------------------------------------------
#  the  following defines are the status bits of the dwStatus member of
#  the UC480_CAMERA_INFO structure
项目:pyUVVIS    作者:ddietze    | 项目源码 | 文件源码
def create_image_format_list(nNumListElements):
    """Returns an instance of the IMAGE_FORMAT_LIST structure having the properly scaled *FormatInfo* array.

    :param ULONG nNumListElements: Number of format info structures requested.
    :returns: IMAGE_FORMAT_LIST

    :var UINT nSizeOfListEntry:
    :var UINT nNumListElements:
    :var UINT[4] nReserved:
    :var IMAGE_FORMAT_INFO[nNumListElements] FormatInfo:
    """
    class IMAGE_FORMAT_LIST(ctypes.Structure):
        _fields_ = [("nSizeOfListEntry", wt.UINT),
                    ("nNumListElements", wt.UINT),
                    ("nReserved", wt.UINT * 4),
                    ("FormatInfo", IMAGE_FORMAT_INFO * nNumListElements)]
    a_list = IMAGE_FORMAT_LIST()
    a_list.nNumListElements = nNumListElements
    return a_list
项目:pyUVVIS    作者:ddietze    | 项目源码 | 文件源码
def create_fdt_info_list(nNumListElements):
    """Returns an instance of the FDT_INFO_LIST structure having the properly scaled *FaceEntry* array.

    :param ULONG nNumListElements: Number of face entry structures requested.
    :returns: FDT_INFO_LIST

    :var UINT nSizeOfListEntry:
    :var UINT nNumDetectedFaces:
    :var UINT nNumListElements:
    :var UINT[4] nReserved:
    :var FDT_INFO_EL[nNumListElements] FaceEntry:
    """
    class FDT_INFO_LIST(ctypes.Structure):
        _fields_ = [("nSizeOfListEntry", wt.UINT),
                    ("nNumDetectedFaces", wt.UINT),
                    ("nNumListElements", wt.UINT),
                    ("nReserved", wt.UINT * 4),
                    ("FaceEntry", FDT_INFO_EL * nNumListElements)]
    a_list = FDT_INFO_LIST()
    a_list.nNumListElements = nNumListElements
    return a_list
项目:pyUVVIS    作者:ddietze    | 项目源码 | 文件源码
def create_bootboost_idlist(numberOfEntries):
    """Returns an instance of the IS_BOOTBOOST_IDLIST structure having the properly scaled *aList* array.

    :param ULONG numberOfEntries: Number of aList structures requested.
    :returns: IS_BOOTBOOST_IDLIST

    :var DWORD u32NumberOfEntries:
    :var IS_BOOTBOOST_ID[numberOfEntries] aList:
    """
    class IS_BOOTBOOST_IDLIST(ctypes.Structure):
        _fields_ = [("u32NumberOfEntries", wt.DWORD),
                    ("aList", IS_BOOTBOOST_ID * numberOfEntries)]
    a_list = IS_BOOTBOOST_IDLIST()
    a_list.u32NumberOfEntries = numberOfEntries
    return a_list
项目:processtap    作者:firodj    | 项目源码 | 文件源码
def definitions( self ):
        definitions_len = ULONG(0)        
        definitions_ids = pointer( IDEF() )

        if not BSCGetDefArray( self.__bsc, self.inst_id, byref( definitions_ids ), byref( definitions_len ) ):
            raise RuntimeError( "Unable to call BSCGetDefArray" )

        definitions = map( lambda i: definition_t( definitions_ids[i], self.__bsc )
                           , range( definitions_len.value ) )

        BSCDisposeArray( self.__bsc, definitions_ids )        
        return definitions
项目:processtap    作者:firodj    | 项目源码 | 文件源码
def members( self ):
        instances_len = ULONG(0)        
        instances_ids = pointer( IINST() )

        if not BSCGetMembersArray( self.__bsc, self.inst_id, enums.MBF.ALL, byref( instances_ids ), byref( instances_len ) ):
            raise RuntimeError( "Unable to call BSCGetMembersArray" )

        instances = map( lambda i: self.__bsc.create_instance( instances_ids[i] )
                         , range( instances_len.value ) )

        BSCDisposeArray( self.__bsc, instances_ids )        
        return instances
项目:processtap    作者:firodj    | 项目源码 | 文件源码
def used_symbols(self):
        instances_len = ULONG(0)        
        instances_ids = pointer( IINST() )

        if not BSCGetUsesArray( self.__bsc, self.inst_id, enums.MBF.ALL, byref( instances_ids ), byref( instances_len ) ):
            raise RuntimeError( "Unable to call BSCGetUsesArray" )

        instances = map( lambda i: self.__bsc.create_instance( instances_ids[i] )
                         , range( instances_len.value ) )

        BSCDisposeArray( self.__bsc, instances_ids )        
        return instances
项目:processtap    作者:firodj    | 项目源码 | 文件源码
def base_classes(self):
        instances_len = ULONG(0)        
        instances_ids = pointer( IINST() )

        if not BSCGetBaseArray( self.__bsc, self.inst_id, byref( instances_ids ), byref( instances_len ) ):
            raise RuntimeError( "Unable to call BSCGetBaseArray" )

        instances = map( lambda i: self.__bsc.create_instance( instances_ids[i] )
                         , range( instances_len.value ) )

        BSCDisposeArray( self.__bsc, instances_ids )        
        return instances
项目:processtap    作者:firodj    | 项目源码 | 文件源码
def derived_classes(self):
        instances_len = ULONG(0)        
        instances_ids = pointer( IINST() )

        if not BSCGetDervArray( self.__bsc, self.inst_id, byref( instances_ids ), byref( instances_len ) ):
            raise RuntimeError( "Unable to call BSCGetDervArray" )

        instances = map( lambda i: self.__bsc.create_instance( instances_ids[i] )
                         , range( instances_len.value ) )

        BSCDisposeArray( self.__bsc, instances_ids )        
        return instances
项目:processtap    作者:firodj    | 项目源码 | 文件源码
def query_all_instances( self ):
        instances_len = ULONG(0)        
        instances = pointer( IINST() )

        if not BSCGetAllGlobalsArray( self.__bsc, enums.MBF.ALL, byref( instances ), byref( instances_len ) ):
            raise RuntimeError( "Unable to load all globals symbols" )
        for i in range( instances_len.value ):
            self.__instances.append( instances[i] )  
        BSCDisposeArray( self.__bsc, instances )
项目:processtap    作者:firodj    | 项目源码 | 文件源码
def files(self):
        module_ids = pointer( IMOD() ) 
        module_len = ULONG()
        bs = BSC_STAT()

        if not BSCGetAllModulesArray( self.__bsc, module_ids, byref(module_len) ):
            raise RuntimeError( "Unable to load all modules" )            

        modules = map( lambda i: module_t( module_ids[i], self.__bsc )
                       , range( module_len.value ) )

        BSCDisposeArray( self.__bsc, module_ids )

        return modules
项目:fibratus    作者:rabbitstack    | 项目源码 | 文件源码
def _query_handle(self, handle, klass, object_info_type):
        """Gets the object handle info.

        Parameters
        ----------


        handle: HANDLE
            handle object
        klass: int
            the class of information to query
        object_info_type: Structure
            structure type which holds the handle info
        """
        buff = malloc(self._object_buff_size)
        rlen = ULONG()
        status = nt_query_object(handle,
                                 klass,
                                 buff,
                                 self._object_buff_size,
                                 byref(rlen))
        if status >= 0:
            info = cast(buff, POINTER(object_info_type))
            self._buffers.append(buff)
            return info
        else:
            # reallocate the buffer size
            # and try again
            buff = realloc(buff, rlen.value)
            status = nt_query_object(handle,
                                     klass,
                                     buff,
                                     self._object_buff_size,
                                     None)
            if status >= 0:
                info = cast(buff, POINTER(object_info_type))
                self._buffers.append(buff)
                return info
            else:
                free(buff)
                return None
项目:kerberom    作者:Synacktiv    | 项目源码 | 文件源码
def ConnectToLDAP(pConnectionInformation):

    dwRes = ULONG(LDAP_SUCCESS)
    version = ULONG(LDAP_VERSION3)
    size = ULONG(LDAP_NO_LIMIT)
    time = ULONG(LDAP_NO_LIMIT)

    hLDAPConnection = ldap_init(pConnectionInformation, LDAP_PORT)

    if hLDAPConnection == 0:
        print "Impossible to connect to LDAP\n"
        return 0

    dwRes = ldap_set_option(hLDAPConnection, LDAP_OPT_PROTOCOL_VERSION, byref(version))

    if dwRes != LDAP_SUCCESS:
        print "Unable to set LDAP protocol option (ErrorCode: %d).\r\n" % dwRes
        if hLDAPConnection != 0:
            ldap_unbind(hLDAPConnection)
            return 0

    dwRes = ldap_set_option(hLDAPConnection, LDAP_OPT_SIZELIMIT, byref(size))

    if dwRes != LDAP_SUCCESS:
        print "Unable to set LDAP size limit option (ErrorCode: %d).\r\n" % dwRes
        if hLDAPConnection != 0:
            ldap_unbind(hLDAPConnection)
            return 0

    dwRes = ldap_set_option(hLDAPConnection, LDAP_OPT_TIMELIMIT, byref(time))

    if dwRes != LDAP_SUCCESS:
        print "Unable to set LDAP time limit option (ErrorCode: %d).\r\n" % dwRes
        if hLDAPConnection != 0:
            ldap_unbind(hLDAPConnection)
            return 0

    dwRes = ldap_connect(hLDAPConnection, 0);

    if dwRes != LDAP_SUCCESS:
        print "Unable to connect to LDAP server\n"
        if hLDAPConnection != 0:
            ldap_unbind(hLDAPConnection)
            return 0

    dwRes = ldap_bind_s(hLDAPConnection, 0, 0, LDAP_AUTH_NEGOTIATE);

    if dwRes != LDAP_SUCCESS:
        print "Unable to bind to LDAP server\n"
        if hLDAPConnection != 0:
            ldap_unbind(hLDAPConnection)
            return 0

    return cast(hLDAPConnection, PLDAP)
项目:kerberom    作者:Synacktiv    | 项目源码 | 文件源码
def Get_TGS(hLsaConnection, dwKerberosAuthenticationPackageId, SPNentry):
    LPTR = (0x0000 | 0x0040)

    list_of_target = SPNentry["serviceprincipalname"].split(";")

    for target in list_of_target:
        szSPN = create_unicode_buffer(target.lower())
        dwSPNSize = USHORT((len(target)) * sizeof(wchar_t))

        dwTicketPayloadSize = DWORD(sizeof(KERB_RETRIEVE_TKT_REQUEST) + dwSPNSize.value)

        KerbRetrieveEncodedTicketMessage = 8
        KERB_ETYPE_RC4_HMAC_NT = 23
        KERB_RETRIEVE_TICKET_DONT_USE_CACHE = (0x1)

        dwKerbRetrieveTicketRequestAddress = windll.kernel32.LocalAlloc(LPTR, dwTicketPayloadSize.value)
        pKerbRetrieveTicketRequest = cast(dwKerbRetrieveTicketRequestAddress, PKERB_RETRIEVE_TKT_REQUEST)

        pKerbRetrieveTicketRequest.contents.MessageType = KerbRetrieveEncodedTicketMessage
        # current logon session context
        pKerbRetrieveTicketRequest.contents.LogonID = 0
        # TargetName
        pKerbRetrieveTicketRequest.contents.TargetName.Length = USHORT(dwSPNSize.value)
        pKerbRetrieveTicketRequest.contents.TargetName.MaximumLength = USHORT(dwSPNSize.value + sizeof(wchar_t))

        dwKerbRetrieveTicketRequestBufferAddress = dwKerbRetrieveTicketRequestAddress + sizeof(KERB_RETRIEVE_TKT_REQUEST)
        memmove(dwKerbRetrieveTicketRequestBufferAddress, szSPN, pKerbRetrieveTicketRequest.contents.TargetName.Length)
        pKerbRetrieveTicketRequest.contents.TargetName.Buffer = cast(dwKerbRetrieveTicketRequestBufferAddress, PWSTR)

        pKerbRetrieveTicketRequest.contents.TicketFlags = ULONG(0)
        pKerbRetrieveTicketRequest.contents.CacheOptions = KERB_RETRIEVE_TICKET_DONT_USE_CACHE
        pKerbRetrieveTicketRequest.contents.EncryptionType = KERB_ETYPE_RC4_HMAC_NT
        pKerbRetrieveTicketRequest.contents.CredentialsHandle = SecHandle()

        pKerbRetrieveTicketResponse = PVOID()
        pKerbRetrieveTicketResponse = cast(pKerbRetrieveTicketResponse, PKERB_RETRIEVE_TKT_RESPONSE)
        dwProtocolStatus = DWORD(0)

        status = LsaCallAuthenticationPackage(hLsaConnection, dwKerberosAuthenticationPackageId, pKerbRetrieveTicketRequest, dwTicketPayloadSize, byref(pKerbRetrieveTicketResponse), byref(dwTicketPayloadSize), byref(dwProtocolStatus))

        windll.kernel32.LocalFree(pKerbRetrieveTicketRequest)

        if status == STATUS_SUCCESS and dwProtocolStatus.value == STATUS_SUCCESS and dwTicketPayloadSize.value != 0:
            pKerbRetrieveTicketResponse = cast(pKerbRetrieveTicketResponse, PKERB_RETRIEVE_TKT_RESPONSE)
            pEncodedTicket = pKerbRetrieveTicketResponse.contents.Ticket.EncodedTicket
            dwEncodedTicketSize = pKerbRetrieveTicketResponse.contents.Ticket.EncodedTicketSize

            Ticket = ""
            for i in range(dwEncodedTicketSize):
                Ticket += hex(pEncodedTicket[i]).replace("0x",'').zfill(2)

            LsaFreeReturnBuffer(pKerbRetrieveTicketResponse)

            return Ticket
        else:
            print " [-] Cannot retrieve ticket for account '%s' and SPN '%s', status: %s ; protocolstatus: %s" % (SPNentry["samaccountname"], target, hex(status), hex(dwProtocolStatus.value))
            print " [+] Trying the next one."
    print "[-] Could not retrieve any ticket for account '%s' and the list of SPN: '%s'" % (SPNentry["samaccountname"], SPNentry["serviceprincipalname"])
    return 0