Exemplo n.º 1
0
def set_clipboard_text(content):
        try:
            cb.OpenClipboard()
            cb.EmptyClipboard()
        except:
            print ("open failed, exception=%s"%FormatMessage(GetLastError()))
        else: 
            try:
                cb.SetClipboardText(content, cb.CF_UNICODETEXT)
            except:
                print ("set failed, exception = %s"%FormatMessage(GetLastError()))
            finally:
                cb.CloseClipboard()
Exemplo n.º 2
0
    def test_fromEnvironment(self):
        """
        L{_ErrorFormatter.fromEnvironment} should create an L{_ErrorFormatter}
        instance with attributes populated from available modules.
        """
        formatter = _ErrorFormatter.fromEnvironment()

        if formatter.winError is not None:
            from ctypes import WinError
            self.assertEqual(
                formatter.formatError(self.probeErrorCode),
                WinError(self.probeErrorCode).strerror)
            formatter.winError = None

        if formatter.formatMessage is not None:
            from win32api import FormatMessage
            self.assertEqual(
                formatter.formatError(self.probeErrorCode),
                FormatMessage(self.probeErrorCode))
            formatter.formatMessage = None

        if formatter.errorTab is not None:
            from socket import errorTab
            self.assertEqual(
                formatter.formatError(self.probeErrorCode),
                errorTab[self.probeErrorCode])
Exemplo n.º 3
0
def get_clipboard_text():
    data = ""
    try:
        cb.OpenClipboard()
        data = cb.GetClipboardData()
        cb.CloseClipboard()
        data = data[:data.find("\0")]
    except:
        print ("failed to get clipboard data, exception=%s"%FormatMessage(GetLastError()))
    return data
Exemplo n.º 4
0
def set_clipboard_file_old(content):
    ret_stg = pythoncom.STGMEDIUM()
    fname_buf=str2bytes(content)

    fname_ba=bytearray(fname_buf)
    fname_ba.append('\0')
    fname_ba.append('\0')
    fmt="lllll%ss" %len(fname_ba)
    df=struct.pack(fmt, 20, 0, 0, 0, 0, str(fname_ba))
    ret_stg.set(pythoncom.TYMED_HGLOBAL, df)
    try:
        cb.OpenClipboard()
        cb.EmptyClipboard()
    except:
        print ("open failed, exception=%s"%FormatMessage(GetLastError()))
    else: 
        try:
            cb.SetClipboardData(cb.CF_HDROP, ret_stg.data)
        except:
            print ("set failed, exception = %s"%FormatMessage(GetLastError()))
        finally:
            cb.CloseClipboard()
Exemplo n.º 5
0
def GetProcessId(handle):
    """Get the process id, given the process handle.
    """

    from win32api import GetLastError, FormatMessage
    from pywintypes import error, HANDLE
    from ctypes import windll, c_uint
    
    handle = c_uint(handle)
    _GetProcessId = windll.kernel32.GetProcessId
    pid = _GetProcessId(handle)

    if not pid:
        err = GetLastError()
        errmsg = FormatMessage(err)
        raise error(err, "GetProcessId", errmsg)

    return pid
Exemplo n.º 6
0
    def test_correctLookups(self):
        """
        Given an known-good errno, make sure that formatMessage gives results
        matching either C{socket.errorTab}, C{ctypes.WinError}, or
        C{win32api.FormatMessage}.
        """
        acceptable = [socket.errorTab[ECONNABORTED]]
        try:
            from ctypes import WinError
            acceptable.append(WinError(ECONNABORTED).strerror)
        except ImportError:
            pass
        try:
            from win32api import FormatMessage
            acceptable.append(FormatMessage(ECONNABORTED))
        except ImportError:
            pass

        self.assertIn(formatError(ECONNABORTED), acceptable)
Exemplo n.º 7
0
def CreateRemoteThread(hProcess, pfn, param):
    from win32api import GetLastError, FormatMessage
    from pywintypes import error, HANDLE
    from ctypes import windll, c_uint, c_void_p
    
    
    _CreateRemoteThread = windll.kernel32.CreateRemoteThread
    hProcess = c_uint(hProcess.handle) # XXX
    param = c_void_p(param)
    pfn = c_void_p(pfn) # XXX

    hThread = _CreateRemoteThread(hProcess, c_void_p(), c_uint(0),
                                  pfn, param, c_uint(0), c_void_p())

    if not hThread:
        err = GetLastError()
        errmsg = FormatMessage(err)
        raise error(err, "CreateRemoteThread", errmsg)

    return HANDLE(hThread)
Exemplo n.º 8
0
    def errcheck(result, func, args):
        """
        Kernel32 hook, if an error occurred, we rise an exception explaining
        what has happened, the exception will later be caught be the Sndbox cuckoo module.

        returns the argument tuple it receives unchanged,
        ctypes continues the normal processing it does on the output parameters.

        :param result: result is what the foreign function returns
        :param func: func is the foreign function object itself
        :param args: a tuple containing the parameters originally passed to the function call
        :return: function arguments
        """
        if not result:
            error_code = KERNEL32.GetLastError()
            error_message = "error: ({}, '{}', '{}')".format(error_code,
                                                             func.__name__,  # for example, CreateProcessW
                                                             FormatMessage(error_code).strip())
            log.error(error_message)
            raise Exception(error_message)
        return args
Exemplo n.º 9
0
def _error(routine):
    # internal helper
    err = GetLastError()
    errmsg = FormatMessage(err)
    raise error(err, routine, errmsg)