12. windows.alpc – Advanced Local Procedure Call¶
The windows.alpc module regroups the classes that permits to send and receive
ALPC messages over an ALPC port and the classes representing these messages.
12.1. ALPC Message¶
-
class
windows.alpc.AlpcMessage(msg_or_size=4096, attributes=None)[source]¶ Represent a full ALPC Message: a
AlpcMessagePortand aMessageAttribute-
context_attribute¶ The
ALPC_MESSAGE_CONTEXT_ATTRIBUTEof the message:Type: ALPC_CONTEXT_ATTR
-
context_is_valid¶ True if
ALPC_MESSAGE_CONTEXT_ATTRIBUTEis a ValidAttributes
-
data¶ The data of the message (located after the PORT_MESSAGE header)
-
handle_attribute¶ The
ALPC_MESSAGE_HANDLE_ATTRIBUTEof the message:Type: ALPC_HANDLE_ATTR
-
handle_is_valid¶ True if
ALPC_MESSAGE_HANDLE_ATTRIBUTEis a ValidAttributes
-
security_attribute¶ The
ALPC_MESSAGE_SECURITY_ATTRIBUTEof the messageType: ALPC_SECURITY_ATTR
-
security_is_valid¶ True if
ALPC_MESSAGE_SECURITY_ATTRIBUTEis a ValidAttributes
-
type¶ The type of the message (
PORT_MESSAGE.u2.s2.Type)
-
view_attribute¶ The
ALPC_MESSAGE_VIEW_ATTRIBUTEof the message:Type: ALPC_DATA_VIEW_ATTR
-
view_is_valid¶ True if
ALPC_MESSAGE_VIEW_ATTRIBUTEis a ValidAttributes
-
-
class
windows.alpc.AlpcMessagePort[source]¶ The effective ALPC Message composed of a
PORT_MESSAGEstructure followed by the data-
data¶ The data of the message (located after the header)
-
datalen¶ The length of the data
-
-
class
windows.alpc.MessageAttribute[source]¶ The attributes of an ALPC message
-
classmethod
with_all_attributes()[source]¶ Create a new
MessageAttributewith the following attributes allocated:ALPC_MESSAGE_SECURITY_ATTRIBUTEALPC_MESSAGE_VIEW_ATTRIBUTEALPC_MESSAGE_CONTEXT_ATTRIBUTEALPC_MESSAGE_HANDLE_ATTRIBUTEALPC_MESSAGE_TOKEN_ATTRIBUTEALPC_MESSAGE_DIRECT_ATTRIBUTEALPC_MESSAGE_WORK_ON_BEHALF_ATTRIBUTE
Returns: MessageAttribute
-
classmethod
with_attributes(attributes)[source]¶ Create a new
MessageAttributewithattributesallocatedReturns: MessageAttribute
-
classmethod
12.2. ALPC client¶
-
class
windows.alpc.AlpcClient(port_name=None)[source]¶ An ALPC client able to connect to a port and send/receive messages
-
connect_to_port(port_name, connect_message=None, port_attr=None, port_attr_flags=65536, obj_attr=None, flags=ALPC_MSGFLG_SYNC_REQUEST(0x20000), timeout=None)[source]¶ Connect to the ALPC port
port_name. Most of the parameters have defauls value isNoneis passed.Parameters: - connect_message (AlpcMessage) – The message send with the connection request, if not
Nonethe function will return anAlpcMessage - port_attr (ALPC_PORT_ATTRIBUTES) – The port attributes, one with default value will be used if this parameter is
None - port_attr_flags (int) –
ALPC_PORT_ATTRIBUTES.Flagsused ifport_attrisNone(MUTUALY EXCLUSINVE WITHport_attr) - obj_attr (OBJECT_ATTRIBUTES) – The attributes of the port (can be None)
- flags (int) – The flags for
NtAlpcConnectPort() - timeout (int) – The timeout of the request
- connect_message (AlpcMessage) – The message send with the connection request, if not
-
port_name= None¶ The name of the ALPC port the client is connect to.
-
recv(receive_msg=None, flags=0)¶ Receive a message into
alpc_messagewithflags.Parameters: - receive_msg (AlpcMessage or None) – The message to send. If
receive_msgis aNoneit create and return a simpleAlpcMessage - flags (int) – The flags for
NtAlpcSendWaitReceivePort()
- receive_msg (AlpcMessage or None) – The message to send. If
-
send(alpc_message, flags=0)¶ Send the
alpc_messagewithflagsParameters: - alpc_message (AlpcMessage or str) – The message to send. If
alpc_messageis astrit build an AlpcMessage with the message as data. - flags (int) – The flags for
NtAlpcSendWaitReceivePort()
- alpc_message (AlpcMessage or str) – The message to send. If
-
send_receive(alpc_message, receive_msg=None, flags=ALPC_MSGFLG_SYNC_REQUEST(0x20000), timeout=None)¶ Send and receive a message with
flags.Parameters: - alpc_message (AlpcMessage or str) – The message to send. If
alpc_messageis astrit build an AlpcMessage with the message as data. - receive_msg (AlpcMessage or None) – The message to send. If
receive_msgis aNoneit create and return a simpleAlpcMessage - flags (int) – The flags for
NtAlpcSendWaitReceivePort()
- alpc_message (AlpcMessage or str) – The message to send. If
-
12.3. ALPC Server¶
-
class
windows.alpc.AlpcServer(port_name=None)[source]¶ An ALPC server able to create a port, accept connections and send/receive messages
-
accept_connection(msg, port_attr=None, port_context=None)[source]¶ Accept the connection for a
LPC_CONNECTION_REQUESTmessage.msg.MessageIdmust be the same as the connection requesting message.Parameters: - msg (AlpcMessage) – The response message.
- port_attr (ALPC_PORT_ATTRIBUTES) – The attributes of the port, one with default value will be used if this parameter is
None - port_context (PVOID) – A value that will be copied in
ALPC_CONTEXT_ATTR.PortContextof every message on this connection.
-
create_port(port_name, msglen=None, port_attr_flags=0, obj_attr=None, port_attr=None)[source]¶ Create the ALPC port
port_name. Most of the parameters have defauls value isNoneis passed.Parameters: - port_name (str) – The port’s name to create.
- msglen (int) –
ALPC_PORT_ATTRIBUTES.MaxMessageLengthused ifport_attrisNone(MUTUALY EXCLUSINVE WITHport_attr) - port_attr_flags (int) –
ALPC_PORT_ATTRIBUTES.Flagsused ifport_attrisNone(MUTUALY EXCLUSINVE WITHport_attr) - obj_attr (OBJECT_ATTRIBUTES) – The attributes of the port, one with default value will be used if this parameter is
None - port_attr (ALPC_PORT_ATTRIBUTES) – The port attributes, one with default value will be used if this parameter is
None
-
recv(receive_msg=None, flags=0)¶ Receive a message into
alpc_messagewithflags.Parameters: - receive_msg (AlpcMessage or None) – The message to send. If
receive_msgis aNoneit create and return a simpleAlpcMessage - flags (int) – The flags for
NtAlpcSendWaitReceivePort()
- receive_msg (AlpcMessage or None) – The message to send. If
-
send(alpc_message, flags=0)¶ Send the
alpc_messagewithflagsParameters: - alpc_message (AlpcMessage or str) – The message to send. If
alpc_messageis astrit build an AlpcMessage with the message as data. - flags (int) – The flags for
NtAlpcSendWaitReceivePort()
- alpc_message (AlpcMessage or str) – The message to send. If
-
send_receive(alpc_message, receive_msg=None, flags=ALPC_MSGFLG_SYNC_REQUEST(0x20000), timeout=None)¶ Send and receive a message with
flags.Parameters: - alpc_message (AlpcMessage or str) – The message to send. If
alpc_messageis astrit build an AlpcMessage with the message as data. - receive_msg (AlpcMessage or None) – The message to send. If
receive_msgis aNoneit create and return a simpleAlpcMessage - flags (int) – The flags for
NtAlpcSendWaitReceivePort()
- alpc_message (AlpcMessage or str) – The message to send. If
-