diff --git a/windows/alpc.py b/windows/alpc.py index 8d36291..15cd2ed 100644 --- a/windows/alpc.py +++ b/windows/alpc.py @@ -292,7 +292,7 @@ class MessageAttribute(gdef.ALPC_MESSAGE_ATTRIBUTES): AlpcSection = namedtuple("AlpcSection", ["handle", "size"]) class AlpcTransportBase(object): - def send_receive(self, alpc_message, receive_msg=None, flags=gdef.ALPC_MSGFLG_SYNC_REQUEST): + def send_receive(self, alpc_message, receive_msg=None, flags=gdef.ALPC_MSGFLG_SYNC_REQUEST, timeout=None): """Send and receive a message with ``flags``. :param alpc_message: The message to send. If ``alpc_message`` is a :class:`str` it build an AlpcMessage with the message as data. @@ -309,7 +309,7 @@ class AlpcTransportBase(object): if receive_msg is None: receive_msg = AlpcMessage(0x1000) receive_size = gdef.SIZE_T(receive_msg.port_message_buffer_size) - winproxy.NtAlpcSendWaitReceivePort(self.handle, flags, alpc_message.port_message, alpc_message.attributes, receive_msg.port_message, receive_size, receive_msg.attributes, None) + winproxy.NtAlpcSendWaitReceivePort(self.handle, flags, alpc_message.port_message, alpc_message.attributes, receive_msg.port_message, receive_size, receive_msg.attributes, timeout) return receive_msg def send(self, alpc_message, flags=0): @@ -408,7 +408,6 @@ class AlpcClient(AlpcTransportBase): else: raise ValueError("Don't know how to send <{0!r}> as connect message".format(connect_message)) - # windows.utils.print_ctypes_struct(port_attr, "port_attr_connect", hexa=True) receive_attr = MessageAttribute.with_all_attributes() winproxy.NtAlpcConnectPort(handle, port_name_unicode, obj_attr, port_attr, flags, None, send_msg, buffersize, send_msg_attr, receive_attr, timeout) # If send_msg is not None, it contains the ClientId.UniqueProcess : PID of the server :) @@ -433,7 +432,8 @@ class AlpcClient(AlpcTransportBase): return view_attributes def disconnect(self): - self._close_port(self.handle) + if self.handle: + self._close_port(self.handle) def __del__(self): if sys.path is not None: @@ -447,6 +447,7 @@ class AlpcServer(AlpcTransportBase): def __init__(self, port_name=None): self.port_name = None self.communication_port_list = [] + self.handle = None if port_name is not None: self.create_port(port_name) @@ -526,7 +527,8 @@ class AlpcServer(AlpcTransportBase): return msg def disconnect(self): - self._close_port(self.handle) + if self.handle: + self._close_port(self.handle) for com_port_handle in self.communication_port_list: self._close_port(com_port_handle) diff --git a/windows/com.py b/windows/com.py index 10a0f47..ba67de7 100644 --- a/windows/com.py +++ b/windows/com.py @@ -12,6 +12,9 @@ from windows.generated_def import RPC_C_IMP_LEVEL_IMPERSONATE, CLSCTX_INPROC_SER from windows.generated_def import interfaces from windows.generated_def.interfaces import generate_IID, IID +# We have windows.com.COMImplementation +# So we need windows.com.COMInterface +COMInterface = interfaces.COMInterface # Simple raw -> UUID # "-".join("{:02X}".format(c) for c in struct.unpack("``""" if custom_iid is None: custom_iid = targetinterface.IID - return winproxy.CoCreateInstance(byref(clsiid), None, context, byref(custom_iid), byref(targetinterface)) + if isinstance(clsiid, basestring): + clsiid = IID.from_string(clsiid) + winproxy.CoCreateInstance(byref(clsiid), None, context, byref(custom_iid), byref(targetinterface)) + return targetinterface def resolve_progid(progid): diff --git a/windows/winobject/process.py b/windows/winobject/process.py index 0ce793b..3cb271c 100644 --- a/windows/winobject/process.py +++ b/windows/winobject/process.py @@ -471,6 +471,11 @@ class Process(utils.AutoHandle): token = property(open_token, doc="The process :class:`~windows.winobject.token.Token`") + @property # Document ? + def handles(self): + pid = self.pid + return [h for h in windows.system.handles if h.dwProcessId == pid] + def __del__(self): super(Process, self).__del__() # Same logic that AutoHandle.__del__ for Process.limited_handle