How to use the pypsrp.complex_objects.ObjectMeta function in pypsrp

To help you get started, we’ve selected a few pypsrp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jborean93 / pypsrp / tests / test_messages.py View on Github external
System.Object
                            
                            System.Timers.ElapsedEventArgs
                            
                                <dt>2009-06-17T10:57:23.1568275-07:00</dt>
                            
                        
                    
                
                
                
                
            
        '''
        serializer = Serializer()
        meta = ObjectMeta("Obj", object=UserEvent)
        actual = serializer.deserialize(xml, meta)

        assert str(actual.args[0]) == "System.Timers.Timer"
        assert actual.args[0].adapted_properties['Interval'] == 5000.0
        assert str(actual.args[1]) == "System.Timers.ElapsedEventArgs"
        assert actual.args[1].adapted_properties['SignalTime'] == \
            "2009-06-17T10:57:23.1568275-07:00"
        assert actual.computer is None
        assert actual.data is None
        assert actual.event_id == 1
        assert actual.runspace_id == \
            uuid.UUID("fb9c87e8-1190-40a7-a681-6fc9b9f84a17")
        assert str(actual.sender) == "System.Timers.Timer"
        assert actual.sender.adapted_properties['Interval'] == 5000.0
        assert actual.source_id == "ae6245f2-c179-4a9a-a039-47b60fc44500"
        assert actual.time == "2009-06-17T10:57:23.1578277-07:00"
github jborean93 / pypsrp / pypsrp / serializer.py View on Github external
# None: ObjectMeta("TS"), # duration timespan
                "System.Byte": ObjectMeta("By"),
                "System.SByte": ObjectMeta("SB"),
                "System.UInt16": ObjectMeta("U16"),
                "System.Int16": ObjectMeta("I16"),
                "System.UInt32": ObjectMeta("U32"),
                "System.Int32": ObjectMeta("I32"),
                "System.UInt64": ObjectMeta("U64"),
                "System.Int64": ObjectMeta("I64"),
                "System.Single": ObjectMeta("Sg"),
                "System.Double": ObjectMeta("Db"),
                "System.Decimal": ObjectMeta("D"),
                # None: ObjectMeta("BA"), # Byte array base64e ncoded
                "System.Guid": ObjectMeta("G"),
                "System.Uri": ObjectMeta("URI"),
                "System.Version": ObjectMeta("Version"),
                "System.Xml.XmlDocument": ObjectMeta("XD"),
                "System.Management.Automation.ScriptBlock": ObjectMeta("SBK"),
                "System.Security.SecureString": ObjectMeta("SS"),
            }
            metadata = None
            for obj_type in obj_types:
                is_list = False
                if obj_type.endswith("[]"):
                    obj_type = obj_type[0:-2]
                    is_list = True

                obj_meta = structures.get(obj_type)
                if obj_meta is not None:
                    metadata = obj_meta
                    if is_list:
                        metadata = ListMeta(list_value_meta=metadata)
github jborean93 / pypsrp / pypsrp / messages.py View on Github external
def __init__(self, names=None, command_type=None, namespace=None,
                 argument_list=None):
        """
        [MS-PSRP] 2.2.2.14 GET_COMMAND_METADATA Message
        https://msdn.microsoft.com/en-us/library/ee175985.aspx

        :param names:
        :param command_type:
        :param namespace:
        :param argument_list:
        """
        super(GetCommandMetadata, self).__init__()
        self._extended_properties = (
            ('names', ListMeta(
                name="Name", list_value_meta=ObjectMeta("S"),
                list_types=[
                    "System.String[]",
                    "System.Array",
                    "System.Object"
                ])
             ),
            ('command_type', ObjectMeta(name="CommandType",
                                        object=CommandType)),
            ('namespace', ObjectMeta(name="Namespace")),
            ('argument_list', ListMeta(name="ArgumentList"))
        )
        self.names = names
        self.command_type = command_type
        self.namespace = namespace
        self.argument_list = argument_list
github jborean93 / pypsrp / pypsrp / messages.py View on Github external
def __init__(self, ci=None, mi=None, mr=None, me=None):
        """
        [MS-PSRP] 2.2.2.16 RUNSPACEPOOL_HOST_RESPONSE Message
        https://msdn.microsoft.com/en-us/library/dd358453.aspx

        :param ci:
        :param mi:
        :param mr:
        :param me:
        """
        super(RunspacePoolHostResponse, self).__init__()
        self._extended_properties = (
            ('ci', ObjectMeta("I64", name="ci")),
            ('mi', ObjectMeta("Obj", name="mi", object=HostMethodIdentifier)),
            ('mr', ObjectMeta(name="mr")),
            ('me', ObjectMeta("Obj", name="me", object=ErrorRecord,
                              optional=True)),
        )
        self.ci = ci
        self.mi = mi
        self.mr = mr
        self.me = me
github jborean93 / pypsrp / pypsrp / serializer.py View on Github external
"System.Boolean": ObjectMeta("B"),
                "System.DateTime": ObjectMeta("DT"),
                # None: ObjectMeta("TS"), # duration timespan
                "System.Byte": ObjectMeta("By"),
                "System.SByte": ObjectMeta("SB"),
                "System.UInt16": ObjectMeta("U16"),
                "System.Int16": ObjectMeta("I16"),
                "System.UInt32": ObjectMeta("U32"),
                "System.Int32": ObjectMeta("I32"),
                "System.UInt64": ObjectMeta("U64"),
                "System.Int64": ObjectMeta("I64"),
                "System.Single": ObjectMeta("Sg"),
                "System.Double": ObjectMeta("Db"),
                "System.Decimal": ObjectMeta("D"),
                # None: ObjectMeta("BA"), # Byte array base64e ncoded
                "System.Guid": ObjectMeta("G"),
                "System.Uri": ObjectMeta("URI"),
                "System.Version": ObjectMeta("Version"),
                "System.Xml.XmlDocument": ObjectMeta("XD"),
                "System.Management.Automation.ScriptBlock": ObjectMeta("SBK"),
                "System.Security.SecureString": ObjectMeta("SS"),
            }
            metadata = None
            for obj_type in obj_types:
                is_list = False
                if obj_type.endswith("[]"):
                    obj_type = obj_type[0:-2]
                    is_list = True

                obj_meta = structures.get(obj_type)
                if obj_meta is not None:
                    metadata = obj_meta
github jborean93 / pypsrp / pypsrp / complex_objects.py View on Github external
Represents a username and a password. As the password is a secure
        string, the RunspacePool must have already exchanged keys with
        .exchange_keys() method.

        :param username: The username (including the domain if required)
        :param password: The password for the user, this should be a unicode
            string in order to make sure the encoding is correct
        """
        super(PSCredential, self).__init__()
        self._types = [
            "System.Management.Automation.PSCredential",
            "System.Object"
        ]
        self._adapted_properties = (
            ('username', ObjectMeta("S", name="UserName")),
            ('password', ObjectMeta("SS", name="Password")),
        )
        self._to_string = "System.Management.Automation.PSCredential"

        self.username = kwargs.get('username')
        self.password = kwargs.get('password')
github jborean93 / pypsrp / pypsrp / serializer.py View on Github external
"System.SByte": ObjectMeta("SB"),
                "System.UInt16": ObjectMeta("U16"),
                "System.Int16": ObjectMeta("I16"),
                "System.UInt32": ObjectMeta("U32"),
                "System.Int32": ObjectMeta("I32"),
                "System.UInt64": ObjectMeta("U64"),
                "System.Int64": ObjectMeta("I64"),
                "System.Single": ObjectMeta("Sg"),
                "System.Double": ObjectMeta("Db"),
                "System.Decimal": ObjectMeta("D"),
                # None: ObjectMeta("BA"), # Byte array base64e ncoded
                "System.Guid": ObjectMeta("G"),
                "System.Uri": ObjectMeta("URI"),
                "System.Version": ObjectMeta("Version"),
                "System.Xml.XmlDocument": ObjectMeta("XD"),
                "System.Management.Automation.ScriptBlock": ObjectMeta("SBK"),
                "System.Security.SecureString": ObjectMeta("SS"),
            }
            metadata = None
            for obj_type in obj_types:
                is_list = False
                if obj_type.endswith("[]"):
                    obj_type = obj_type[0:-2]
                    is_list = True

                obj_meta = structures.get(obj_type)
                if obj_meta is not None:
                    metadata = obj_meta
                    if is_list:
                        metadata = ListMeta(list_value_meta=metadata)
                    break
github jborean93 / pypsrp / pypsrp / serializer.py View on Github external
"System.UInt16": ObjectMeta("U16"),
                "System.Int16": ObjectMeta("I16"),
                "System.UInt32": ObjectMeta("U32"),
                "System.Int32": ObjectMeta("I32"),
                "System.UInt64": ObjectMeta("U64"),
                "System.Int64": ObjectMeta("I64"),
                "System.Single": ObjectMeta("Sg"),
                "System.Double": ObjectMeta("Db"),
                "System.Decimal": ObjectMeta("D"),
                # None: ObjectMeta("BA"), # Byte array base64e ncoded
                "System.Guid": ObjectMeta("G"),
                "System.Uri": ObjectMeta("URI"),
                "System.Version": ObjectMeta("Version"),
                "System.Xml.XmlDocument": ObjectMeta("XD"),
                "System.Management.Automation.ScriptBlock": ObjectMeta("SBK"),
                "System.Security.SecureString": ObjectMeta("SS"),
            }
            metadata = None
            for obj_type in obj_types:
                is_list = False
                if obj_type.endswith("[]"):
                    obj_type = obj_type[0:-2]
                    is_list = True

                obj_meta = structures.get(obj_type)
                if obj_meta is not None:
                    metadata = obj_meta
                    if is_list:
                        metadata = ListMeta(list_value_meta=metadata)
                    break

        # we were unable to find the complex object type so just return the
github jborean93 / pypsrp / pypsrp / complex_objects.py View on Github external
list_types)


class QueueMeta(ListMeta):
    def __init__(self, name=None, optional=False, list_value_meta=None,
                 list_types=None):
        if list_types is None:
            list_types = [
                "System.Collections.Queue",
                "System.Object"
            ]
        super(QueueMeta, self).__init__("QUE", name, optional, list_value_meta,
                                        list_types)


class DictionaryMeta(ObjectMeta):

    def __init__(self, name=None, optional=False, dict_key_meta=None,
                 dict_value_meta=None, dict_types=None):
        super(DictionaryMeta, self).__init__("DCT", name, optional)
        if dict_key_meta is None:
            self.dict_key_meta = ObjectMeta(name="Key")
        else:
            self.dict_key_meta = dict_key_meta

        if dict_value_meta is None:
            self.dict_value_meta = ObjectMeta(name="Value")
        else:
            self.dict_value_meta = dict_value_meta

        if dict_types is None:
            self.dict_types = [
github jborean93 / pypsrp / pypsrp / messages.py View on Github external
def __init__(self, activity=None, activity_id=None, description=None,
                 current_operation=None, parent_activity_id=None,
                 percent_complete=None, progress_type=None,
                 seconds_remaining=None):
        """
        [MS-PSRP] 2.2.2.25 PROGRESS_RECORD Message
        https://msdn.microsoft.com/en-us/library/dd340751.aspx

        :param kwargs:
        """
        super(ProgressRecord, self).__init__()
        self._extended_properties = (
            ('activity', ObjectMeta("S", name="Activity")),
            ('activity_id', ObjectMeta("I32", name="ActivityId")),
            ('description', ObjectMeta("S", name="StatusDescription")),
            ('current_operation', ObjectMeta("S", name="CurrentOperation")),
            ('parent_activity_id', ObjectMeta("I32", name="ParentActivityId")),
            ('percent_complete', ObjectMeta("I32", name="PercentComplete")),
            ('progress_type', ObjectMeta("Obj", name="Type",
                                         object=ProgressRecordType)),
            ('seconds_remaining', ObjectMeta("I32", name="SecondsRemaining")),
        )
        self.activity = activity
        self.activity_id = activity_id
        self.description = description
        self.current_operation = current_operation
        self.parent_activity_id = parent_activity_id
        self.percent_complete = percent_complete
        self.progress_type = progress_type
        self.seconds_remaining = seconds_remaining