當前位置: 首頁>>代碼示例>>Python>>正文


Python ctypes.GetLastError方法代碼示例

本文整理匯總了Python中ctypes.GetLastError方法的典型用法代碼示例。如果您正苦於以下問題:Python ctypes.GetLastError方法的具體用法?Python ctypes.GetLastError怎麽用?Python ctypes.GetLastError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ctypes的用法示例。


在下文中一共展示了ctypes.GetLastError方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: win32_path_short

# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import GetLastError [as 別名]
def win32_path_short (self, path):
		if not path:
			return ''
		path = os.path.abspath(path)
		if self.unix:
			return path
		self._win32_load_kernel()
		if not self.GetShortPathName:
			try:
				import ctypes
				self.GetShortPathName = self.kernel32.GetShortPathNameA
				args = [ ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int32 ]
				self.GetShortPathName.argtypes = args
				self.GetShortPathName.restype = ctypes.c_uint32
			except: pass
		if not self.GetShortPathName:
			return path
		retval = self.GetShortPathName(path, self.textdata, 2048)
		shortpath = self.textdata.value
		if retval <= 0:
			import ctypes
			print 'ERROR(%d): %s'%(ctypes.GetLastError(), path)
			return ''
		return shortpath 
開發者ID:skywind3000,項目名稱:terminal,代碼行數:26,代碼來源:terminal.py

示例2: get_volumes

# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import GetLastError [as 別名]
def get_volumes(self):
        """Retrieve a list with all the volumes found on all disks."""
        volumes = []
        volume = ctypes.create_unicode_buffer(chr(0) * self.MAX_PATH)

        handle_volumes = kernel32.FindFirstVolumeW(volume, self.MAX_PATH)
        if handle_volumes == self.INVALID_HANDLE_VALUE:
            raise exception.WindowsCloudbaseInitException(
                "FindFirstVolumeW failed: %r")
        try:
            while True:
                volumes.append(volume.value)
                found = kernel32.FindNextVolumeW(handle_volumes, volume,
                                                 self.MAX_PATH)
                if not found:
                    errno = ctypes.GetLastError()
                    if errno == self.ERROR_NO_MORE_FILES:
                        break
                    else:
                        raise exception.WindowsCloudbaseInitException(
                            "FindNextVolumeW failed: %r")
        finally:
            kernel32.FindVolumeClose(handle_volumes)

        return volumes 
開發者ID:cloudbase,項目名稱:cloudbase-init,代碼行數:27,代碼來源:windows.py

示例3: get_user_name

# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import GetLastError [as 別名]
def get_user_name():
    global os_encoding

    DWORD = c_uint32
    nSize = DWORD(0)
    windll.advapi32.GetUserNameA(None, byref(nSize))
    error = GetLastError()

    ERROR_INSUFFICIENT_BUFFER = 122
    if error != ERROR_INSUFFICIENT_BUFFER:
        raise WinError(error)

    lpBuffer = create_string_buffer('', nSize.value + 1)
    success = windll.advapi32.GetUserNameA(lpBuffer, byref(nSize))

    if not success:
        raise WinError()

    return lpBuffer.value.decode(encoding = os_encoding).encode("utf8") 
開發者ID:turingsec,項目名稱:marsnake,代碼行數:21,代碼來源:lib_win32.py

示例4: get_process_image_filename

# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import GetLastError [as 別名]
def get_process_image_filename(self, pid):

        process_name = None

        if pid == 4:
            # Skip the inevitable errno 87, invalid parameter
            process_name = 'System'
        elif pid:
            hProcess = windll.kernel32.OpenProcess(
                PROCESS_QUERY_LIMITED_INFORMATION, False, pid)
            if hProcess:

                lpImageFileName = create_string_buffer(MAX_PATH)

                if windll.psapi.GetProcessImageFileNameA(hProcess, lpImageFileName, MAX_PATH) > 0:
                    process_name = os.path.basename(lpImageFileName.value)
                else:
                    self.logger.error('Failed to call GetProcessImageFileNameA, %d' %
                                      (ctypes.GetLastError()))

                windll.kernel32.CloseHandle(hProcess)

        return process_name 
開發者ID:fireeye,項目名稱:flare-fakenet-ng,代碼行數:25,代碼來源:winutil.py

示例5: checkFirmwareType

# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import GetLastError [as 別名]
def checkFirmwareType(self):
        # Load in kernel32.dll
        kernel32_dll = ctypes.WinDLL("C:\\Windows\\System32\\kernel32.dll")

        # Because we're using bogus parameters in the function call, it
        # should always fail (return 0).
        if kernel32_dll.GetFirmwareEnvironmentVariableW(ctypes.c_wchar_p(""),
            ctypes.c_wchar_p("{00000000-0000-0000-0000-000000000000}"), None,
            ctypes.c_int(0)) == 0:
            # Check the last error returned to determine firmware type.
            # If the error is anything other than ERROR_INVALID_FUNCTION
            # or ERROR_NOACCESS, raise an exception.
            last_error = ctypes.GetLastError()
            if last_error == self._ERROR_INVALID_FUNCTION:
                return "Legacy"
            elif last_error == self._ERROR_NOACCESS:
                return "UEFI"
            else:
                raise ctypes.WinError()
        else:
            return "Unknown"

    # Check for PAE, SMEP, SMAP, and NX hardware support using CPUID. 
開發者ID:nsacyber,項目名稱:Splunk-Assessment-of-Mitigation-Implementations,代碼行數:25,代碼來源:ae.py

示例6: fcntl

# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import GetLastError [as 別名]
def fcntl(fd, op, arg=0):
    if op == F_GETFD or op == F_GETFL:
        return 0
    elif op == F_SETFD:
        # Check that the flag is CLOEXEC and translate
        if arg == FD_CLOEXEC:
            success = SetHandleInformation(fd, HANDLE_FLAG_INHERIT, arg)
            if not success:
                raise ctypes.GetLastError()
        else:
            raise ValueError("Unsupported arg")
    #elif op == F_SETFL:
        ## Check that the flag is NONBLOCK and translate
        #if arg == os.O_NONBLOCK:
            ##pass
            #result = ioctlsocket(fd, FIONBIO, 1)
            #if result != 0:
                #raise ctypes.GetLastError()
        #else:
            #raise ValueError("Unsupported arg")
    else:
        raise ValueError("Unsupported op") 
開發者ID:omererdem,項目名稱:honeything,代碼行數:24,代碼來源:win32_support.py

示例7: QueryDosDevice

# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import GetLastError [as 別名]
def QueryDosDevice(drive_letter):
    """Returns the Windows 'native' path for a DOS drive letter."""
    assert re.match(r'^[a-zA-Z]:$', drive_letter), drive_letter
    assert isinstance(drive_letter, six.text_type)
    # Guesswork. QueryDosDeviceW never returns the required number of bytes.
    chars = 1024
    drive_letter = drive_letter
    p = wintypes.create_unicode_buffer(chars)
    if not windll.kernel32.QueryDosDeviceW(drive_letter, p, chars):
      err = ctypes.GetLastError()
      if err:
        # pylint: disable=undefined-variable
        msg = u'QueryDosDevice(%s): %s (%d)' % (
              drive_letter, FormatError(err), err)
        raise WindowsError(err, msg.encode('utf-8'))
    return p.value 
開發者ID:luci,項目名稱:luci-py,代碼行數:18,代碼來源:file_path.py

示例8: GetShortPathName

# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import GetLastError [as 別名]
def GetShortPathName(long_path):
    """Returns the Windows short path equivalent for a 'long' path."""
    path = fs.extend(long_path)
    chars = windll.kernel32.GetShortPathNameW(path, None, 0)
    if chars:
      p = wintypes.create_unicode_buffer(chars)
      if windll.kernel32.GetShortPathNameW(path, p, chars):
        return fs.trim(p.value)

    err = ctypes.GetLastError()
    if err:
      # pylint: disable=undefined-variable
      msg = u'GetShortPathName(%s): %s (%d)' % (
            long_path, FormatError(err), err)
      raise WindowsError(err, msg.encode('utf-8'))
    return None 
開發者ID:luci,項目名稱:luci-py,代碼行數:18,代碼來源:file_path.py

示例9: enable_privilege

# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import GetLastError [as 別名]
def enable_privilege(name):
    """Enables the privilege for the current process token.

    Returns:
    - True if the assignment is successful.
    """
    SE_PRIVILEGE_ENABLED = 2
    ERROR_NOT_ALL_ASSIGNED = 1300

    size = ctypes.sizeof(TOKEN_PRIVILEGES) + ctypes.sizeof(LUID_AND_ATTRIBUTES)
    buf = ctypes.create_string_buffer(size)
    tp = ctypes.cast(buf, ctypes.POINTER(TOKEN_PRIVILEGES)).contents
    tp.count = 1
    tp.get_array()[0].LUID = get_luid(name)
    tp.get_array()[0].Attributes = SE_PRIVILEGE_ENABLED
    token = get_process_token()
    try:
      if not AdjustTokenPrivileges(token, False, tp, 0, None, None):
        # pylint: disable=undefined-variable
        raise WindowsError(
            u'AdjustTokenPrivileges(%r): failed: %s' %
              (name, ctypes.GetLastError()))
    finally:
      windll.kernel32.CloseHandle(token)
    return ctypes.GetLastError() != ERROR_NOT_ALL_ASSIGNED 
開發者ID:luci,項目名稱:luci-py,代碼行數:27,代碼來源:file_path.py

示例10: _monitor

# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import GetLastError [as 別名]
def _monitor(self):
    buff = ctypes.create_string_buffer(_BUFF_SIZE)
    while not self._stop.isSet():
      size_returned = ctypes.c_ulong(0)
      result = ctypes.windll.kernel32.ReadDirectoryChangesW(
          self._directory_handle,
          buff,
          ctypes.c_ulong(_BUFF_SIZE),
          True,  # recursive.
          ctypes.c_ulong(_FILE_NOTIFY_CHANGE_ANY),
          ctypes.byref(size_returned),
          None,
          None)  # this is a blocking call.
      if result == 0 and ctypes.GetLastError() == _ERROR_NOTIFY_ENUM_DIR:
        logging.warning('Buffer overflow while monitoring for file changes.')
        # we need to notify that something changed anyway
        with self._lock:
          self._change_set |= {'Unknown file'}
      if result != 0 and size_returned.value != 0:
        additional_changes = _parse_buffer(buff)
        with self._lock:
          self._change_set |= additional_changes
          self._change_event.set() 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:25,代碼來源:win32_file_watcher.py

示例11: Register

# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import GetLastError [as 別名]
def Register(self):
        success = WTSRegisterSessionNotification(
            eg.messageReceiver.hwnd,
            NOTIFY_FOR_ALL_SESSIONS
        )
        if success:
            self.inited = True
            return
        errorNum = GetLastError()
        # if we get the error RPC_S_INVALID_BINDING (1702), the system
        # hasn't started all needed services. For this reason we wait some
        # time and try it again.
        if errorNum == 1702:
            self.retryCount += 1
            if self.retryCount > 60:
                # if we tried it to often, give up
                eg.PrintError("WTSRegisterSessionNotification timeout")
                return
            eg.scheduler.AddTask(2.0, self.Register)
            return
        # some other error has happened
        raise SystemError("WTSRegisterSessionNotification", errorNum) 
開發者ID:EventGhost,項目名稱:EventGhost,代碼行數:24,代碼來源:SessionChangeNotifier.py

示例12: load_pdb

# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import GetLastError [as 別名]
def load_pdb(self, pdb_filename):
        size = os.path.getsize(pdb_filename)
        module_base = 0x10000000
        module_base = SymLoadModuleEx(
                        self.process,
                        0,
                        ctypes.c_char_p(pdb_filename.encode('utf-8')),
                        None,
                        module_base,
                        size,
                        None,
                        0
                    )
        if not module_base:
            raise Exception('Failed SymLoadModuleEx last error:  %d' % ctypes.GetLastError())

        print('module_base: %x' % module_base)
        return module_base 
開發者ID:ohjeongwook,項目名稱:windbgtool,代碼行數:20,代碼來源:symbol_tool.py

示例13: FindNextVolume

# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import GetLastError [as 別名]
def FindNextVolume(hSearch):
    volume_name = ctypes.create_unicode_buffer(" " * 255)
    if kernel32.FindNextVolumeW(hSearch, volume_name, 255) != 0:
        return volume_name.value
    else:
        errno = ctypes.GetLastError()
        if errno == winerror.ERROR_NO_MORE_FILES:
            FindVolumeClose(hSearch)
            return None
        raise RuntimeError("FindNextVolume failed (%s)" % errno) 
開發者ID:mbusb,項目名稱:multibootusb,代碼行數:12,代碼來源:win32.py

示例14: get_error

# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import GetLastError [as 別名]
def get_error():
    error = ctypes.GetLastError()
    return (error, ctypes.FormatError(error)) 
開發者ID:wbond,項目名稱:oscrypto,代碼行數:5,代碼來源:_crypt32_ctypes.py

示例15: _connect_raw

# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import GetLastError [as 別名]
def _connect_raw(self):
    # This is a similar procedure to the one in
    #   https://github.com/microsoft/go-winio/blob/master/pipe.go (tryDialPipe)
    while True:
      try:
        return open(self._name, 'wb+', buffering=0)
      except (OSError, IOError):
        if GetLastError() != self.ERROR_PIPE_BUSY:
          raise
      time.sleep(0.001)  # 1ms 
開發者ID:luci,項目名稱:recipes-py,代碼行數:12,代碼來源:stream.py


注:本文中的ctypes.GetLastError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。