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

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

项目:Liljimbo-Chatbot    作者:chrisjim316    | 项目源码 | 文件源码
def _wait_for_handles(handles, timeout=-1):
    """
    Waits for multiple handles. (Similar to 'select') Returns the handle which is ready.
    Returns `None` on timeout.

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms687025(v=vs.85).aspx
    """
    arrtype = HANDLE * len(handles)
    handle_array = arrtype(*handles)

    ret = windll.kernel32.WaitForMultipleObjects(
        len(handle_array), handle_array, BOOL(False), DWORD(timeout))

    if ret == WAIT_TIMEOUT:
        return None
    else:
        h = handle_array[ret]
        return h
项目:depot_tools    作者:webrtc-uwp    | 项目源码 | 文件源码
def __init__(self, console_handle, fileno, stream_name, encoding):
    super(WinUnicodeConsoleOutput, self).__init__(
        fileno, '<Unicode console %s>' % stream_name, encoding)
    # Handle to use for WriteConsoleW
    self._console_handle = console_handle

    # Loads the necessary function.
    # These types are available on linux but not Mac.
    # pylint: disable=no-name-in-module,F0401
    from ctypes import byref, GetLastError, POINTER, windll, WINFUNCTYPE
    from ctypes.wintypes import BOOL, DWORD, HANDLE, LPWSTR
    from ctypes.wintypes import LPVOID  # pylint: disable=no-name-in-module

    self._DWORD = DWORD
    self._byref = byref

    # <http://msdn.microsoft.com/en-us/library/ms687401.aspx>
    self._WriteConsoleW = WINFUNCTYPE(
        BOOL, HANDLE, LPWSTR, DWORD, POINTER(DWORD), LPVOID)(
            ('WriteConsoleW', windll.kernel32))
    self._GetLastError = GetLastError
项目:leetcode    作者:thomasyimgit    | 项目源码 | 文件源码
def _wait_for_handles(handles, timeout=-1):
    """
    Waits for multiple handles. (Similar to 'select') Returns the handle which is ready.
    Returns `None` on timeout.

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms687025(v=vs.85).aspx
    """
    arrtype = HANDLE * len(handles)
    handle_array = arrtype(*handles)

    ret = windll.kernel32.WaitForMultipleObjects(
        len(handle_array), handle_array, BOOL(False), DWORD(timeout))

    if ret == WAIT_TIMEOUT:
        return None
    else:
        h = handle_array[ret]
        return h
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_CTRL_C_EVENT(self):
        from ctypes import wintypes
        import ctypes

        # Make a NULL value by creating a pointer with no argument.
        NULL = ctypes.POINTER(ctypes.c_int)()
        SetConsoleCtrlHandler = ctypes.windll.kernel32.SetConsoleCtrlHandler
        SetConsoleCtrlHandler.argtypes = (ctypes.POINTER(ctypes.c_int),
                                          wintypes.BOOL)
        SetConsoleCtrlHandler.restype = wintypes.BOOL

        # Calling this with NULL and FALSE causes the calling process to
        # handle CTRL+C, rather than ignore it. This property is inherited
        # by subprocesses.
        SetConsoleCtrlHandler(NULL, 0)

        self._kill_with_event(signal.CTRL_C_EVENT, "CTRL_C_EVENT")
项目:driverlib    作者:sam-b    | 项目源码 | 文件源码
def WriteFile(file, buffer, number_of_bytes_to_write, number_of_bytes_written, overlapped):
    """See: WriteFile function 
        https://msdn.microsoft.com/en-us/library/windows/desktop/aa365747(v=vs.85).aspx
    """
    WriteFile_Fn = windll.kernel32.WriteFile
    WriteFile_Fn.argtypes = [
        wintypes.HANDLE,    # _In_        HANDLE       hFile,
        wintypes.LPCVOID,   # _In_        LPCVOID      lpBuffer,
        wintypes.DWORD,     # _In_        DWORD        nNumberOfBytesToWrite,
        LPDWORD,            # _Out_opt_   LPDWORD      lpNumberOfBytesWritten,
        LPOVERLAPPED        # _Inout_opt_ LPOVERLAPPED lpOverlapped
    ]
    WriteFile_Fn.restype = wintypes.BOOL
    ret = wintypes.BOOL(WriteFile_Fn(
        file, 
        buffer, 
        number_of_bytes_to_write, 
        number_of_bytes_written, 
        overlapped
    ))
    return ret
项目:driverlib    作者:sam-b    | 项目源码 | 文件源码
def control_service(service_handle, control, service_status):
    """See: ControlService function
    https://msdn.microsoft.com/en-us/library/windows/desktop/ms682108(v=vs.85).aspx
    """
    ControlService_Fn = windll.Advapi32.ControlService      #BOOL WINAPI ControlService(
    ControlService_Fn.argtypes = [                          #
        wintypes.SC_HANDLE,                                 #   _In_  SC_HANDLE        hService,
        wintypes.DWORD,                                     #   _In_  DWORD            dwControl,
        wintypes.LPCVOID                                    #   _Out_ LPSERVICE_STATUS lpServiceStatus
    ]
    ControlService_Fn.restype = wintypes.BOOL
    bool = ControlService_Fn(
        service_handle,
        control,
        service_status
    )
    return bool
项目:driverlib    作者:sam-b    | 项目源码 | 文件源码
def start_service(service_handle, service_arg_count, service_arg_vectors):
    """See: StartService function
    https://msdn.microsoft.com/en-us/library/windows/desktop/ms686321(v=vs.85).aspx
    """

    StartService_Fn = windll.Advapi32.StartServiceA #BOOL WINAPI StartService(
    StartService_Fn.argtypes = [                    #
        wintypes.SC_HANDLE,                         #   _In_     SC_HANDLE hService,
        wintypes.DWORD,                             #   _In_     DWORD     dwNumServiceArgs,
        LPCTSTR                         #   _In_opt_ LPCTSTR   *lpServiceArgVectors
    ]
    StartService_Fn.restype = wintypes.BOOL
    bool = StartService_Fn(
        service_handle,
        service_arg_count, 
        service_arg_vectors
    )
    return bool
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_CTRL_C_EVENT(self):
        from ctypes import wintypes
        import ctypes

        # Make a NULL value by creating a pointer with no argument.
        NULL = ctypes.POINTER(ctypes.c_int)()
        SetConsoleCtrlHandler = ctypes.windll.kernel32.SetConsoleCtrlHandler
        SetConsoleCtrlHandler.argtypes = (ctypes.POINTER(ctypes.c_int),
                                          wintypes.BOOL)
        SetConsoleCtrlHandler.restype = wintypes.BOOL

        # Calling this with NULL and FALSE causes the calling process to
        # handle Ctrl+C, rather than ignore it. This property is inherited
        # by subprocesses.
        SetConsoleCtrlHandler(NULL, 0)

        self._kill_with_event(signal.CTRL_C_EVENT, "CTRL_C_EVENT")
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_CTRL_C_EVENT(self):
        from ctypes import wintypes
        import ctypes

        # Make a NULL value by creating a pointer with no argument.
        NULL = ctypes.POINTER(ctypes.c_int)()
        SetConsoleCtrlHandler = ctypes.windll.kernel32.SetConsoleCtrlHandler
        SetConsoleCtrlHandler.argtypes = (ctypes.POINTER(ctypes.c_int),
                                          wintypes.BOOL)
        SetConsoleCtrlHandler.restype = wintypes.BOOL

        # Calling this with NULL and FALSE causes the calling process to
        # handle Ctrl+C, rather than ignore it. This property is inherited
        # by subprocesses.
        SetConsoleCtrlHandler(NULL, 0)

        self._kill_with_event(signal.CTRL_C_EVENT, "CTRL_C_EVENT")
项目:rice    作者:randy3k    | 项目源码 | 文件源码
def wait_for_handles(handles, timeout=INFINITE):
    """
    Waits for multiple handles. (Similar to 'select') Returns the handle which is ready.
    Returns `None` on timeout.

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms687025(v=vs.85).aspx
    """
    assert isinstance(handles, list)
    assert isinstance(timeout, int)

    arrtype = HANDLE * len(handles)
    handle_array = arrtype(*handles)

    ret = windll.kernel32.WaitForMultipleObjects(
        len(handle_array), handle_array, BOOL(False), DWORD(timeout))

    if ret == WAIT_TIMEOUT:
        return None
    else:
        h = handle_array[ret]
        return h
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_CTRL_C_EVENT(self):
        from ctypes import wintypes
        import ctypes

        # Make a NULL value by creating a pointer with no argument.
        NULL = ctypes.POINTER(ctypes.c_int)()
        SetConsoleCtrlHandler = ctypes.windll.kernel32.SetConsoleCtrlHandler
        SetConsoleCtrlHandler.argtypes = (ctypes.POINTER(ctypes.c_int),
                                          wintypes.BOOL)
        SetConsoleCtrlHandler.restype = wintypes.BOOL

        # Calling this with NULL and FALSE causes the calling process to
        # handle CTRL+C, rather than ignore it. This property is inherited
        # by subprocesses.
        SetConsoleCtrlHandler(NULL, 0)

        self._kill_with_event(signal.CTRL_C_EVENT, "CTRL_C_EVENT")
项目:Repobot    作者:Desgard    | 项目源码 | 文件源码
def _wait_for_handles(handles, timeout=-1):
    """
    Waits for multiple handles. (Similar to 'select') Returns the handle which is ready.
    Returns `None` on timeout.

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms687025(v=vs.85).aspx
    """
    arrtype = HANDLE * len(handles)
    handle_array = arrtype(*handles)

    ret = windll.kernel32.WaitForMultipleObjects(
        len(handle_array), handle_array, BOOL(False), DWORD(timeout))

    if ret == WAIT_TIMEOUT:
        return None
    else:
        h = handle_array[ret]
        return h
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def test_CTRL_C_EVENT(self):
        from ctypes import wintypes
        import ctypes

        # Make a NULL value by creating a pointer with no argument.
        NULL = ctypes.POINTER(ctypes.c_int)()
        SetConsoleCtrlHandler = ctypes.windll.kernel32.SetConsoleCtrlHandler
        SetConsoleCtrlHandler.argtypes = (ctypes.POINTER(ctypes.c_int),
                                          wintypes.BOOL)
        SetConsoleCtrlHandler.restype = wintypes.BOOL

        # Calling this with NULL and FALSE causes the calling process to
        # handle CTRL+C, rather than ignore it. This property is inherited
        # by subprocesses.
        SetConsoleCtrlHandler(NULL, 0)

        self._kill_with_event(signal.CTRL_C_EVENT, "CTRL_C_EVENT")
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_CTRL_C_EVENT(self):
        from ctypes import wintypes
        import ctypes

        # Make a NULL value by creating a pointer with no argument.
        NULL = ctypes.POINTER(ctypes.c_int)()
        SetConsoleCtrlHandler = ctypes.windll.kernel32.SetConsoleCtrlHandler
        SetConsoleCtrlHandler.argtypes = (ctypes.POINTER(ctypes.c_int),
                                          wintypes.BOOL)
        SetConsoleCtrlHandler.restype = wintypes.BOOL

        # Calling this with NULL and FALSE causes the calling process to
        # handle Ctrl+C, rather than ignore it. This property is inherited
        # by subprocesses.
        SetConsoleCtrlHandler(NULL, 0)

        self._kill_with_event(signal.CTRL_C_EVENT, "CTRL_C_EVENT")
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def test_CTRL_C_EVENT(self):
        from ctypes import wintypes
        import ctypes

        # Make a NULL value by creating a pointer with no argument.
        NULL = ctypes.POINTER(ctypes.c_int)()
        SetConsoleCtrlHandler = ctypes.windll.kernel32.SetConsoleCtrlHandler
        SetConsoleCtrlHandler.argtypes = (ctypes.POINTER(ctypes.c_int),
                                          wintypes.BOOL)
        SetConsoleCtrlHandler.restype = wintypes.BOOL

        # Calling this with NULL and FALSE causes the calling process to
        # handle CTRL+C, rather than ignore it. This property is inherited
        # by subprocesses.
        SetConsoleCtrlHandler(NULL, 0)

        self._kill_with_event(signal.CTRL_C_EVENT, "CTRL_C_EVENT")
项目:Chromium_DepotTools    作者:p07r0457    | 项目源码 | 文件源码
def __init__(self, console_handle, fileno, stream_name, encoding):
    super(WinUnicodeConsoleOutput, self).__init__(
        fileno, '<Unicode console %s>' % stream_name, encoding)
    # Handle to use for WriteConsoleW
    self._console_handle = console_handle

    # Loads the necessary function.
    # These types are available on linux but not Mac.
    # pylint: disable=no-name-in-module,F0401
    from ctypes import byref, GetLastError, POINTER, windll, WINFUNCTYPE
    from ctypes.wintypes import BOOL, DWORD, HANDLE, LPWSTR
    from ctypes.wintypes import LPVOID  # pylint: disable=no-name-in-module

    self._DWORD = DWORD
    self._byref = byref

    # <http://msdn.microsoft.com/en-us/library/ms687401.aspx>
    self._WriteConsoleW = WINFUNCTYPE(
        BOOL, HANDLE, LPWSTR, DWORD, POINTER(DWORD), LPVOID)(
            ('WriteConsoleW', windll.kernel32))
    self._GetLastError = GetLastError
项目:Chromium_DepotTools    作者:p07r0457    | 项目源码 | 文件源码
def win_handle_is_a_console(handle):
  """Returns True if a Windows file handle is a handle to a console."""
  # These types are available on linux but not Mac.
  # pylint: disable=no-name-in-module,F0401
  from ctypes import byref, POINTER, windll, WINFUNCTYPE
  from ctypes.wintypes import BOOL, DWORD, HANDLE

  FILE_TYPE_CHAR   = 0x0002
  FILE_TYPE_REMOTE = 0x8000
  INVALID_HANDLE_VALUE = DWORD(-1).value

  # <http://msdn.microsoft.com/en-us/library/ms683167.aspx>
  GetConsoleMode = WINFUNCTYPE(BOOL, HANDLE, POINTER(DWORD))(
      ('GetConsoleMode', windll.kernel32))
  # <http://msdn.microsoft.com/en-us/library/aa364960.aspx>
  GetFileType = WINFUNCTYPE(DWORD, DWORD)(('GetFileType', windll.kernel32))

  # GetStdHandle returns INVALID_HANDLE_VALUE, NULL, or a valid handle.
  if handle == INVALID_HANDLE_VALUE or handle is None:
    return False
  return (
      (GetFileType(handle) & ~FILE_TYPE_REMOTE) == FILE_TYPE_CHAR and
       GetConsoleMode(handle, byref(DWORD())))
项目:node-gn    作者:Shouqun    | 项目源码 | 文件源码
def __init__(self, console_handle, fileno, stream_name, encoding):
    super(WinUnicodeConsoleOutput, self).__init__(
        fileno, '<Unicode console %s>' % stream_name, encoding)
    # Handle to use for WriteConsoleW
    self._console_handle = console_handle

    # Loads the necessary function.
    # These types are available on linux but not Mac.
    # pylint: disable=no-name-in-module,F0401
    from ctypes import byref, GetLastError, POINTER, windll, WINFUNCTYPE
    from ctypes.wintypes import BOOL, DWORD, HANDLE, LPWSTR
    from ctypes.wintypes import LPVOID  # pylint: disable=no-name-in-module

    self._DWORD = DWORD
    self._byref = byref

    # <http://msdn.microsoft.com/en-us/library/ms687401.aspx>
    self._WriteConsoleW = WINFUNCTYPE(
        BOOL, HANDLE, LPWSTR, DWORD, POINTER(DWORD), LPVOID)(
            ('WriteConsoleW', windll.kernel32))
    self._GetLastError = GetLastError
项目:node-gn    作者:Shouqun    | 项目源码 | 文件源码
def win_handle_is_a_console(handle):
  """Returns True if a Windows file handle is a handle to a console."""
  # These types are available on linux but not Mac.
  # pylint: disable=no-name-in-module,F0401
  from ctypes import byref, POINTER, windll, WINFUNCTYPE
  from ctypes.wintypes import BOOL, DWORD, HANDLE

  FILE_TYPE_CHAR   = 0x0002
  FILE_TYPE_REMOTE = 0x8000
  INVALID_HANDLE_VALUE = DWORD(-1).value

  # <http://msdn.microsoft.com/en-us/library/ms683167.aspx>
  GetConsoleMode = WINFUNCTYPE(BOOL, HANDLE, POINTER(DWORD))(
      ('GetConsoleMode', windll.kernel32))
  # <http://msdn.microsoft.com/en-us/library/aa364960.aspx>
  GetFileType = WINFUNCTYPE(DWORD, DWORD)(('GetFileType', windll.kernel32))

  # GetStdHandle returns INVALID_HANDLE_VALUE, NULL, or a valid handle.
  if handle == INVALID_HANDLE_VALUE or handle is None:
    return False
  return (
      (GetFileType(handle) & ~FILE_TYPE_REMOTE) == FILE_TYPE_CHAR and
       GetConsoleMode(handle, byref(DWORD())))
项目:win_driver_plugin    作者:mwrlabs    | 项目源码 | 文件源码
def control_service(service_handle, control, service_status):
    """See: ControlService function
    https://msdn.microsoft.com/en-us/library/windows/desktop/ms682108(v=vs.85).aspx
    """
    ControlService_Fn = windll.Advapi32.ControlService      #BOOL WINAPI ControlService(
    ControlService_Fn.argtypes = [                          #
        wintypes.SC_HANDLE,                                 #   _In_  SC_HANDLE        hService,
        wintypes.DWORD,                                     #   _In_  DWORD            dwControl,
        wintypes.LPCVOID                                    #   _Out_ LPSERVICE_STATUS lpServiceStatus
    ]
    ControlService_Fn.restype = wintypes.BOOL
    bool = ControlService_Fn(
        service_handle,
        control,
        service_status
    )
    return bool
项目:win_driver_plugin    作者:mwrlabs    | 项目源码 | 文件源码
def start_service(service_handle, service_arg_count, service_arg_vectors):
    """See: StartService function
    https://msdn.microsoft.com/en-us/library/windows/desktop/ms686321(v=vs.85).aspx
    """

    StartService_Fn = windll.Advapi32.StartServiceA #BOOL WINAPI StartService(
    StartService_Fn.argtypes = [                    #
        wintypes.SC_HANDLE,                         #   _In_     SC_HANDLE hService,
        wintypes.DWORD,                             #   _In_     DWORD     dwNumServiceArgs,
        LPCTSTR                         #   _In_opt_ LPCTSTR   *lpServiceArgVectors
    ]
    StartService_Fn.restype = wintypes.BOOL
    bool = StartService_Fn(
        service_handle,
        service_arg_count, 
        service_arg_vectors
    )
    return bool
项目:TC2017    作者:G4lB1t    | 项目源码 | 文件源码
def create_spora_mutex():
    """
    Creates a mutex just like the notorious Spora ransomware
    This prevents the execution of known Spora variants

    Based on Minerva's blog post:
    https://www.minerva-labs.com/post/vaccinating-against-spora-ransomware-a-proof-of-concept-tool-by-minerva
    """
    try:
        vol_serial = int(subprocess.check_output(['cmd', '/c', 'vol'])[-11:-2].replace("-", ""), 16)
        spora_mutex = 'm' + str(vol_serial)
        _CreateMutex = ctypes.windll.kernel32.CreateMutexA
        _CreateMutex.argtypes = [wintypes.LPCVOID, wintypes.BOOL, wintypes.LPCSTR]
        _CreateMutex.restype = wintypes.HANDLE

        ret = _CreateMutex(None, False, spora_mutex)
    except Exception as e:
        print "Got exception {0} while creating {1}".format(e, "Spora mutex")
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_CTRL_C_EVENT(self):
        from ctypes import wintypes
        import ctypes

        # Make a NULL value by creating a pointer with no argument.
        NULL = ctypes.POINTER(ctypes.c_int)()
        SetConsoleCtrlHandler = ctypes.windll.kernel32.SetConsoleCtrlHandler
        SetConsoleCtrlHandler.argtypes = (ctypes.POINTER(ctypes.c_int),
                                          wintypes.BOOL)
        SetConsoleCtrlHandler.restype = wintypes.BOOL

        # Calling this with NULL and FALSE causes the calling process to
        # handle CTRL+C, rather than ignore it. This property is inherited
        # by subprocesses.
        SetConsoleCtrlHandler(NULL, 0)

        self._kill_with_event(signal.CTRL_C_EVENT, "CTRL_C_EVENT")
项目:collection    作者:skywind3000    | 项目源码 | 文件源码
def __init__ (self):
        import ctypes.wintypes
        if sys.platform[:3] != 'win':
            raise SystemError('Windows is required')
        self.__winmm = ctypes.windll.LoadLibrary('winmm.dll')
        self.__mciSendStringW = self.__winmm.mciSendStringW
        self.__mciGetErrorStringW = self.__winmm.mciGetErrorStringW
        wintypes = ctypes.wintypes
        LPCWSTR, HANDLE = wintypes.LPCWSTR, wintypes.HANDLE
        args = [LPCWSTR, ctypes.c_char_p, wintypes.UINT, HANDLE]
        self.__mciSendStringW.argtypes = args
        self.__mciSendStringW.restype = wintypes.DWORD
        args = [wintypes.DWORD, ctypes.c_void_p, wintypes.UINT]
        self.__mciGetErrorStringW.argtypes = args
        self.__mciGetErrorStringW.restype = wintypes.BOOL
        self.__buffer = ctypes.create_string_buffer('?' * 4098)
        self.__alias_index = 0
项目:depot_tools    作者:webrtc-uwp    | 项目源码 | 文件源码
def win_handle_is_a_console(handle):
  """Returns True if a Windows file handle is a handle to a console."""
  # These types are available on linux but not Mac.
  # pylint: disable=no-name-in-module,F0401
  from ctypes import byref, POINTER, windll, WINFUNCTYPE
  from ctypes.wintypes import BOOL, DWORD, HANDLE

  FILE_TYPE_CHAR   = 0x0002
  FILE_TYPE_REMOTE = 0x8000
  INVALID_HANDLE_VALUE = DWORD(-1).value

  # <http://msdn.microsoft.com/en-us/library/ms683167.aspx>
  GetConsoleMode = WINFUNCTYPE(BOOL, HANDLE, POINTER(DWORD))(
      ('GetConsoleMode', windll.kernel32))
  # <http://msdn.microsoft.com/en-us/library/aa364960.aspx>
  GetFileType = WINFUNCTYPE(DWORD, DWORD)(('GetFileType', windll.kernel32))

  # GetStdHandle returns INVALID_HANDLE_VALUE, NULL, or a valid handle.
  if handle == INVALID_HANDLE_VALUE or handle is None:
    return False
  return (
      (GetFileType(handle) & ~FILE_TYPE_REMOTE) == FILE_TYPE_CHAR and
       GetConsoleMode(handle, byref(DWORD())))
项目:blender    作者:gastrodia    | 项目源码 | 文件源码
def _wait_for_handles(handles, timeout=-1):
    """
    Waits for multiple handles. (Similar to 'select') Returns the handle which is ready.
    Returns `None` on timeout.

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms687025(v=vs.85).aspx
    """
    arrtype = HANDLE * len(handles)
    handle_array = arrtype(*handles)

    ret = windll.kernel32.WaitForMultipleObjects(
        len(handle_array), handle_array, BOOL(False), DWORD(timeout))

    if ret == WAIT_TIMEOUT:
        return None
    else:
        h = handle_array[ret]
        return h
项目:puppet    作者:Raytone-D    | 项目源码 | 文件源码
def finder(register):
    ''' ???????broker??????? '''
    team = set()
    buff = buffer(32)
    @ctypes.WINFUNCTYPE(BOOL, HWND, LPARAM)
    def check(hwnd, extra):
        if op.IsWindowVisible(hwnd):
            op.GetWindowTextW(hwnd, buff, 32)
            if '????' in buff.value:
                team.add(hwnd)
        return 1
    op.EnumWindows(check, 0)

    def get_nickname(hwnd):
        account = hwnd
        for i in 59392, 0, 1711:
            account = op.GetDlgItem(account, i)
        op.SendMessageW(account, WM_GETTEXT, 32, buff)
        return register.get(buff.value[-3:])

    return {get_nickname(hwnd): unity(hwnd) for hwnd in team if hwnd}
项目:yatta_reader    作者:sound88    | 项目源码 | 文件源码
def _wait_for_handles(handles, timeout=-1):
    """
    Waits for multiple handles. (Similar to 'select') Returns the handle which is ready.
    Returns `None` on timeout.

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms687025(v=vs.85).aspx
    """
    arrtype = HANDLE * len(handles)
    handle_array = arrtype(*handles)

    ret = windll.kernel32.WaitForMultipleObjects(
        len(handle_array), handle_array, BOOL(False), DWORD(timeout))

    if ret == WAIT_TIMEOUT:
        return None
    else:
        h = handle_array[ret]
        return h
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def test_issue_8959_b(self):
        from ctypes.wintypes import BOOL, HWND, LPARAM
        global windowCount
        windowCount = 0

        @WINFUNCTYPE(BOOL, HWND, LPARAM)
        def EnumWindowsCallbackFunc(hwnd, lParam):
            global windowCount
            windowCount += 1
            return True #Allow windows to keep enumerating

        windll.user32.EnumWindows(EnumWindowsCallbackFunc, 0)
项目:Liljimbo-Chatbot    作者:chrisjim316    | 项目源码 | 文件源码
def _create_event():
    """
    Creates a Win32 unnamed Event .

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms682396(v=vs.85).aspx
    """
    return windll.kernel32.CreateEventA(pointer(SECURITY_ATTRIBUTES()), BOOL(True), BOOL(False), None)
项目:leetcode    作者:thomasyimgit    | 项目源码 | 文件源码
def _create_event():
    """
    Creates a Win32 unnamed Event .

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms682396(v=vs.85).aspx
    """
    return windll.kernel32.CreateEventA(pointer(SECURITY_ATTRIBUTES()), BOOL(True), BOOL(False), None)
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_issue_8959_b(self):
            from ctypes.wintypes import BOOL, HWND, LPARAM
            global windowCount
            windowCount = 0

            @WINFUNCTYPE(BOOL, HWND, LPARAM)
            def EnumWindowsCallbackFunc(hwnd, lParam):
                global windowCount
                windowCount += 1
                return True #Allow windows to keep enumerating

            windll.user32.EnumWindows(EnumWindowsCallbackFunc, 0)
项目:azmq    作者:ereOn    | 项目源码 | 文件源码
def allow_interruption(*callbacks):
    if sys.platform == 'win32':
        from ctypes import WINFUNCTYPE, windll
        from ctypes.wintypes import BOOL, DWORD
        kernel32 = windll.LoadLibrary('kernel32')
        phandler_routine = WINFUNCTYPE(BOOL, DWORD)
        setconsolectrlhandler = kernel32.SetConsoleCtrlHandler
        setconsolectrlhandler.argtypes = (phandler_routine, BOOL)
        setconsolectrlhandler.restype = BOOL

        @phandler_routine
        def shutdown(event):
            if event == 0:
                for loop, cb in callbacks:
                    loop.call_soon_threadsafe(cb)

                return 1

            return 0

        if setconsolectrlhandler(shutdown, 1) == 0:
            raise WindowsError()
    else:
        def handler(*args):
            for loop, cb in callbacks:
                loop.call_soon_threadsafe(cb)

        signal.signal(signal.SIGINT, handler)

    try:
        yield
    finally:
        if sys.platform == 'win32':
            if setconsolectrlhandler(shutdown, 0) == 0:
                    raise WindowsError()
        else:
            signal.signal(signal.SIGINT, signal.SIG_DFL)
项目:driverlib    作者:sam-b    | 项目源码 | 文件源码
def ConnectNamedPipe(named_pipe, overlapped):   
    """See: ConnectNamedPipe function 
       https://msdn.microsoft.com/en-us/library/windows/desktop/aa365146(v=vs.85).aspx
    """
    ConnectNamedPipe_Fn = windll.kernel32.ConnectNamedPipe
    ConnectNamedPipe_Fn.argtypes = [
        wintypes.HANDLE,    # _In_        HANDLE       hNamedPipe,
        LPOVERLAPPED        # _Inout_opt_ LPOVERLAPPED lpOverlapped
    ]
    ConnectNamedPipe_Fn.restype = wintypes.BOOL
    ret = wintypes.BOOL(ConnectNamedPipe_Fn(
        named_pipe,
        overlapped
    ))
    return ret
项目:driverlib    作者:sam-b    | 项目源码 | 文件源码
def ReadFile(file, buffer, number_of_bytes_to_read, number_of_bytes_read, overlapped):
    """See: ReadFile function
       https://msdn.microsoft.com/en-us/library/windows/desktop/aa365467(v=vs.85).aspx
    """
    ReadFile_Fn = windll.kernel32.ReadFile
    ReadFile_Fn.argtypes = [
    wintypes.HANDLE,    # _In_        HANDLE       hFile,
    LPVOID,             # _Out_       LPVOID       lpBuffer,
    wintypes.DWORD,     # _In_        DWORD        nNumberOfBytesToRead,
    LPDWORD,            # _Out_opt_   LPDWORD      lpNumberOfBytesRead,
    LPOVERLAPPED        # _Inout_opt_ LPOVERLAPPED lpOverlapped
    ]
    ReadFile_Fn.restype = wintypes.BOOL

    ret = wintypes.BOOL(ReadFile_Fn(
        file, 
        buffer, 
        number_of_bytes_to_read, 
        number_of_bytes_read, 
        overlapped
    ))
项目:driverlib    作者:sam-b    | 项目源码 | 文件源码
def send_ioctl(self, ioctl, inbuf, inbufsiz, outbuf, outbufsiz):
        """See: DeviceIoControl function
        http://msdn.microsoft.com/en-us/library/aa363216(v=vs.85).aspx
        """
        DeviceIoControl_Fn = windll.kernel32.DeviceIoControl
        DeviceIoControl_Fn.argtypes = [
                wintypes.HANDLE,                    # _In_          HANDLE hDevice
                wintypes.DWORD,                     # _In_          DWORD dwIoControlCode
                wintypes.LPVOID,                    # _In_opt_      LPVOID lpInBuffer
                wintypes.DWORD,                     # _In_          DWORD nInBufferSize
                wintypes.LPVOID,                    # _Out_opt_     LPVOID lpOutBuffer
                wintypes.DWORD,                     # _In_          DWORD nOutBufferSize
                LPDWORD,                            # _Out_opt_     LPDWORD lpBytesReturned
                LPOVERLAPPED]                       # _Inout_opt_   LPOVERLAPPED lpOverlapped
        DeviceIoControl_Fn.restype = wintypes.BOOL
        print ioctl
        # allocate a DWORD, and take its reference
        dwBytesReturned = wintypes.DWORD(0)
        lpBytesReturned = ctypes.byref(dwBytesReturned)
        status = DeviceIoControl_Fn(self.handle,
                      ioctl,
                      inbuf,
                      inbufsiz,
                      outbuf,
                      outbufsiz,
                      lpBytesReturned,
                      None)

        return status, dwBytesReturned
项目:driverlib    作者:sam-b    | 项目源码 | 文件源码
def delete_service(service_handle):
    """See: DeleteService function
    https://msdn.microsoft.com/en-us/library/windows/desktop/ms682562(v=vs.85).aspx
    """
    DeleteService_Fn = windll.Advapi32.DeleteService    #BOOL WINAPI DeleteService(
    DeleteService_Fn.argtypes = [                       #
        wintypes.SC_HANDLE                              #   _In_ SC_HANDLE hService
    ]
    DeleteService_Fn.restype = wintypes.BOOL
    bool = DeleteService_Fn(
        service_handle
    )
    return bool
项目:constructor    作者:conda    | 项目源码 | 文件源码
def _link(src, dst, linktype=LINK_HARD):
    if linktype == LINK_HARD:
        if on_win:
            from ctypes import windll, wintypes
            CreateHardLink = windll.kernel32.CreateHardLinkW
            CreateHardLink.restype = wintypes.BOOL
            CreateHardLink.argtypes = [wintypes.LPCWSTR, wintypes.LPCWSTR,
                                       wintypes.LPVOID]
            if not CreateHardLink(dst, src, None):
                raise OSError('win32 hard link failed')
        else:
            os.link(src, dst)
    elif linktype == LINK_COPY:
        # copy relative symlinks as symlinks
        if islink(src) and not os.readlink(src).startswith(os.path.sep):
            os.symlink(os.readlink(src), dst)
        else:
            shutil.copy2(src, dst)
    else:
        raise Exception("Did not expect linktype=%r" % linktype)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_issue_8959_b(self):
        from ctypes.wintypes import BOOL, HWND, LPARAM
        global windowCount
        windowCount = 0

        @WINFUNCTYPE(BOOL, HWND, LPARAM)
        def EnumWindowsCallbackFunc(hwnd, lParam):
            global windowCount
            windowCount += 1
            return True #Allow windows to keep enumerating

        windll.user32.EnumWindows(EnumWindowsCallbackFunc, 0)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_issue_8959_b(self):
        from ctypes.wintypes import BOOL, HWND, LPARAM
        global windowCount
        windowCount = 0

        @WINFUNCTYPE(BOOL, HWND, LPARAM)
        def EnumWindowsCallbackFunc(hwnd, lParam):
            global windowCount
            windowCount += 1
            return True #Allow windows to keep enumerating

        windll.user32.EnumWindows(EnumWindowsCallbackFunc, 0)
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def test_issue_8959_b(self):
        from ctypes.wintypes import BOOL, HWND, LPARAM
        global windowCount
        windowCount = 0

        @WINFUNCTYPE(BOOL, HWND, LPARAM)
        def EnumWindowsCallbackFunc(hwnd, lParam):
            global windowCount
            windowCount += 1
            return True #Allow windows to keep enumerating

        windll.user32.EnumWindows(EnumWindowsCallbackFunc, 0)
项目:rice    作者:randy3k    | 项目源码 | 文件源码
def _create_event():
    """
    Creates a Win32 unnamed Event .

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms682396(v=vs.85).aspx
    """
    return windll.kernel32.CreateEventA(
        pointer(SECURITY_ATTRIBUTES()), BOOL(True), BOOL(False), None)
项目:Repobot    作者:Desgard    | 项目源码 | 文件源码
def _create_event():
    """
    Creates a Win32 unnamed Event .

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms682396(v=vs.85).aspx
    """
    return windll.kernel32.CreateEventA(pointer(SECURITY_ATTRIBUTES()), BOOL(True), BOOL(False), None)
项目:jupyter-powershell    作者:vors    | 项目源码 | 文件源码
def ErrCheckBool(result, func, args):
    """errcheck function for Windows functions that return a BOOL True
    on success"""
    if not result:
        raise WinError()
    return args


# AutoHANDLE
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_issue_8959_b(self):
        from ctypes.wintypes import BOOL, HWND, LPARAM
        global windowCount
        windowCount = 0

        @WINFUNCTYPE(BOOL, HWND, LPARAM)
        def EnumWindowsCallbackFunc(hwnd, lParam):
            global windowCount
            windowCount += 1
            return True #Allow windows to keep enumerating

        windll.user32.EnumWindows(EnumWindowsCallbackFunc, 0)
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def test_issue_8959_b(self):
            from ctypes.wintypes import BOOL, HWND, LPARAM
            global windowCount
            windowCount = 0

            @WINFUNCTYPE(BOOL, HWND, LPARAM)
            def EnumWindowsCallbackFunc(hwnd, lParam):
                global windowCount
                windowCount += 1
                return True #Allow windows to keep enumerating

            windll.user32.EnumWindows(EnumWindowsCallbackFunc, 0)
项目:win_driver_plugin    作者:mwrlabs    | 项目源码 | 文件源码
def send_ioctl(self, ioctl, inbuf, inbufsiz, outbuf, outbufsiz):
        """See: DeviceIoControl function
        http://msdn.microsoft.com/en-us/library/aa363216(v=vs.85).aspx
        """
        DeviceIoControl_Fn = windll.kernel32.DeviceIoControl
        DeviceIoControl_Fn.argtypes = [
                wintypes.HANDLE,                    # _In_          HANDLE hDevice
                wintypes.DWORD,                     # _In_          DWORD dwIoControlCode
                wintypes.LPVOID,                    # _In_opt_      LPVOID lpInBuffer
                wintypes.DWORD,                     # _In_          DWORD nInBufferSize
                wintypes.LPVOID,                    # _Out_opt_     LPVOID lpOutBuffer
                wintypes.DWORD,                     # _In_          DWORD nOutBufferSize
                LPDWORD,                            # _Out_opt_     LPDWORD lpBytesReturned
                LPOVERLAPPED]                       # _Inout_opt_   LPOVERLAPPED lpOverlapped
        DeviceIoControl_Fn.restype = wintypes.BOOL
        # allocate a DWORD, and take its reference
        dwBytesReturned = wintypes.DWORD(0)
        lpBytesReturned = ctypes.byref(dwBytesReturned)
        status = DeviceIoControl_Fn(self.handle,
                      ioctl,
                      inbuf,
                      inbufsiz,
                      outbuf,
                      outbufsiz,
                      lpBytesReturned,
                      None)

        return status, dwBytesReturned
项目:win_driver_plugin    作者:mwrlabs    | 项目源码 | 文件源码
def close_service_handle(service_handle):
    """See: CloseServiceHandle function 
    https://msdn.microsoft.com/en-us/library/windows/desktop/ms682028(v=vs.85).aspx
    """
    CloseServiceHandle_Fn = windll.Advapi32.CloseServiceHandle  #BOOL WINAPI CloseServiceHandle(
    CloseServiceHandle_Fn.argtypes = [
        wintypes.SC_HANDLE                                      #   _In_ SC_HANDLE hSCObject
    ]
    CloseServiceHandle_Fn.restype = wintypes.BOOL
    bool = CloseServiceHandle_Fn(
        service_handle
    )
    return bool
项目:win_driver_plugin    作者:mwrlabs    | 项目源码 | 文件源码
def delete_service(service_handle):
    """See: DeleteService function
    https://msdn.microsoft.com/en-us/library/windows/desktop/ms682562(v=vs.85).aspx
    """
    DeleteService_Fn = windll.Advapi32.DeleteService    #BOOL WINAPI DeleteService(
    DeleteService_Fn.argtypes = [                       #
        wintypes.SC_HANDLE                              #   _In_ SC_HANDLE hService
    ]
    DeleteService_Fn.restype = wintypes.BOOL
    bool = DeleteService_Fn(
        service_handle
    )
    return bool
项目:servoshell    作者:paulrouget    | 项目源码 | 文件源码
def notify_win(title, text):
    try:
        from servo.win32_toast import WindowsToast
        w = WindowsToast()
        w.balloon_tip(title, text)
    except:
        from ctypes import Structure, windll, POINTER, sizeof
        from ctypes.wintypes import DWORD, HANDLE, WINFUNCTYPE, BOOL, UINT

        class FLASHWINDOW(Structure):
            _fields_ = [("cbSize", UINT),
                        ("hwnd", HANDLE),
                        ("dwFlags", DWORD),
                        ("uCount", UINT),
                        ("dwTimeout", DWORD)]

        FlashWindowExProto = WINFUNCTYPE(BOOL, POINTER(FLASHWINDOW))
        FlashWindowEx = FlashWindowExProto(("FlashWindowEx", windll.user32))
        FLASHW_CAPTION = 0x01
        FLASHW_TRAY = 0x02
        FLASHW_TIMERNOFG = 0x0C

        params = FLASHWINDOW(sizeof(FLASHWINDOW),
                             windll.kernel32.GetConsoleWindow(),
                             FLASHW_CAPTION | FLASHW_TRAY | FLASHW_TIMERNOFG, 3, 0)
        FlashWindowEx(params)