MCPcopy Create free account
hub / github.com/ELMERIKH/PyinMemoryPE / create_port

Method create_port

windows/alpc.py:459–501  ·  view source on GitHub ↗

Create the ALPC port ``port_name``. Most of the parameters have defauls value is ``None`` is passed. :param str port_name: The port's name to create. :param int msglen: ``ALPC_PORT_ATTRIBUTES.MaxMessageLength`` used if ``port_attr`` is ``None`` (MUTUALY EXCLUSINVE WITH ``por

(self, port_name, msglen=None, port_attr_flags=0, obj_attr=None, port_attr=None)

Source from the content-addressed store, hash-verified

457 return gdef.UNICODE_STRING.from_string(name)
458
459 def create_port(self, port_name, msglen=None, port_attr_flags=0, obj_attr=None, port_attr=None):
460 """Create the ALPC port ``port_name``. Most of the parameters have defauls value is ``None`` is passed.
461
462 :param str port_name: The port's name to create.
463 :param int msglen: ``ALPC_PORT_ATTRIBUTES.MaxMessageLength`` used if ``port_attr`` is ``None`` (MUTUALY EXCLUSINVE WITH ``port_attr``)
464 :param int port_attr_flags: ``ALPC_PORT_ATTRIBUTES.Flags`` used if ``port_attr`` is ``None`` (MUTUALY EXCLUSINVE WITH ``port_attr``)
465 :param OBJECT_ATTRIBUTES obj_attr: The attributes of the port, one with default value will be used if this parameter is ``None``
466 :param ALPC_PORT_ATTRIBUTES port_attr: The port attributes, one with default value will be used if this parameter is ``None``
467 """
468 # TODO raise on mutual exclusive parameter (port_attr + port_attr_flags | obj_attr + msglen)
469 handle = gdef.HANDLE()
470 raw_name = port_name
471 if not raw_name.startswith("\\"):
472 raw_name = "\\" + port_name
473 port_name = self._alpc_port_to_unicode_string(raw_name)
474
475 if msglen is None:
476 msglen = DEFAULT_MESSAGE_SIZE
477 if obj_attr is None:
478 obj_attr = gdef.OBJECT_ATTRIBUTES()
479 obj_attr.Length = ctypes.sizeof(obj_attr)
480 obj_attr.RootDirectory = None
481 obj_attr.ObjectName = ctypes.pointer(port_name)
482 obj_attr.Attributes = 0
483 obj_attr.SecurityDescriptor = None
484 obj_attr.SecurityQualityOfService = None
485 if port_attr is None:
486 port_attr = gdef.ALPC_PORT_ATTRIBUTES()
487 port_attr.Flags = port_attr_flags
488 # port_attr.Flags = 0x2080000
489 # port_attr.Flags = 0x90000
490 port_attr.MaxMessageLength = msglen
491 port_attr.MemoryBandwidth = 0
492 port_attr.MaxPoolUsage = 0xffffffff
493 port_attr.MaxSectionSize = 0xffffffff
494 port_attr.MaxViewSize = 0xffffffff
495 port_attr.MaxTotalSectionSize = 0xffffffff
496 port_attr.DupObjectTypes = 0xffffffff
497 # windows.utils.print_ctypes_struct(port_attr, " - PORT_ATTR", hexa=True)
498
499 winproxy.NtAlpcCreatePort(handle, obj_attr, port_attr)
500 self.port_name = raw_name
501 self.handle = handle.value
502
503 def accept_connection(self, msg, port_attr=None, port_context=None):
504 """Accept the connection for a ``LPC_CONNECTION_REQUEST`` message.

Callers 1

__init__Method · 0.95

Calls 2

sizeofMethod · 0.45

Tested by

no test coverage detected