Пример #1
0
 def __bytes__(self) -> bytes:
     return b''.join([
         self.key_handle,
         ndr_pad(bytes(RRPUnicodeString(representation=self.sub_key_name))),
         ndr_pad(bytes(RRPUnicodeString(representation=self.class_name))),
         self._OPTIONS_STRUCT.pack(int(self.options)),
         self._SAM_DESIRED_STRUCT.pack(int(self.sam_desired)),
         ndr_pad(
             bytes(
                 Pointer(representation=bytes(self.security_attributes)))),
         bytes(
             Pointer(representation=self._DISPOSITION_STRUCT.pack(
                 self.disposition)))
     ])
Пример #2
0
 def __bytes__(self) -> bytes:
     return b''.join([
         self.key_handle,
         ndr_pad(bytes(RRPUnicodeString(representation=self.sub_key_name))),
         self._OPTIONS_STRUCT.pack(int(self.options)),
         self._SAM_DESIRED_STRUCT.pack(int(self.sam_desired))
     ])
Пример #3
0
    def from_bytes(cls,
                   data: ByteString,
                   base_offset: int = 0) -> BaseRegOpenKeyRequest:
        data = memoryview(data)[base_offset:]
        offset = 0

        key_handle: bytes = cls._KEY_HANDLE_STRUCT.unpack_from(
            buffer=data, offset=offset)[0]
        offset += cls._KEY_HANDLE_STRUCT.size

        ndr_sub_key_name = RRPUnicodeString.from_bytes(data=data,
                                                       base_offset=offset)
        offset += calculate_pad_length(len(ndr_sub_key_name))

        options = RegOptions.from_int(value=cls._OPTIONS_STRUCT.unpack_from(
            buffer=data, offset=offset)[0])
        offset += cls._OPTIONS_STRUCT.size

        sam_desired = Regsam.from_int(
            value=cls._SAM_DESIRED_STRUCT.unpack_from(buffer=data,
                                                      offset=offset)[0])

        return cls(key_handle=key_handle,
                   sub_key_name=ndr_sub_key_name.representation,
                   options=options,
                   sam_desired=sam_desired)
Пример #4
0
    def from_bytes(cls,
                   data: ByteString,
                   base_offset: int = 0,
                   strict: bool = False) -> BaseRegSetValueRequest:

        data = memoryview(data)[base_offset:]
        offset = 0

        key_handle: bytes = cls._KEY_HANDLE_STRUCT.unpack_from(
            buffer=data, offset=offset)[0]
        offset += cls._KEY_HANDLE_STRUCT.size

        ndr_sub_key_name = RRPUnicodeString.from_bytes(data[offset:])
        offset += calculate_pad_length(length_unpadded=len(ndr_sub_key_name))

        value_type = RegValueType(
            cls._VALUE_TYPE_STRUCT.unpack_from(buffer=data, offset=offset)[0])
        offset += cls._VALUE_TYPE_STRUCT.size

        ndr_value = UnidimensionalConformantArray.from_bytes(data=bytes(
            data[offset:offset + UnidimensionalConformantArray.STRUCTURE_SIZE +
                 calcsize(REG_VALUE_TYPE_TO_STRUCT_FORMAT[value_type])]))
        offset += len(ndr_value)

        value_len: int = cls._VALUE_LEN_STRUCT.unpack_from(buffer=data,
                                                           offset=offset)[0]
        # TODO: Check if correct?

        return cls(key_handle=key_handle,
                   sub_key_name=ndr_sub_key_name.representation,
                   value_type=value_type,
                   value=b''.join(ndr_value.representation))
Пример #5
0
    def from_bytes(cls,
                   data: ByteString,
                   base_offset: int = 0,
                   strict: bool = False) -> BaseRegCreateKeyRequest:

        data = memoryview(data)[base_offset:]
        offset = 0

        key_handle: bytes = cls._KEY_HANDLE_STRUCT.unpack_from(
            buffer=data, offset=offset)[0]
        offset += cls._KEY_HANDLE_STRUCT.size

        ndr_sub_key_name = RRPUnicodeString.from_bytes(data=data[offset:])
        offset += calculate_pad_length(len(ndr_sub_key_name))

        ndr_class_name = RRPUnicodeString.from_bytes(data=data[offset:])
        offset += calculate_pad_length(len(ndr_class_name))

        options = RegOptions.from_int(value=cls._OPTIONS_STRUCT.unpack_from(
            buffer=data, offset=offset)[0])
        offset += cls._OPTIONS_STRUCT.size

        sam_desired = Regsam.from_int(
            value=cls._SAM_DESIRED_STRUCT.unpack_from(buffer=data,
                                                      offset=offset)[0])
        offset += cls._SAM_DESIRED_STRUCT.size

        security_attributes_pointer = Pointer.from_bytes(data=data,
                                                         base_offset=offset)
        offset += Pointer.structure_size
        security_attributes = RPCSecurityAttributes.from_bytes(
            data=security_attributes_pointer.representation)
        offset += calculate_pad_length(len(security_attributes))

        disposition_pointer = Pointer.from_bytes(data=data, base_offset=offset)
        offset += Pointer.structure_size
        disposition = Disposition(
            cls._DISPOSITION_STRUCT.unpack_from(
                buffer=disposition_pointer.representation)[0])

        return cls(key_handle=key_handle,
                   sub_key_name=ndr_sub_key_name.representation,
                   class_name=ndr_class_name.representation,
                   options=options,
                   sam_desired=sam_desired,
                   security_attributes=security_attributes,
                   disposition=disposition)
Пример #6
0
 def __bytes__(self) -> bytes:
     return b''.join([
         self.key_handle,
         ndr_pad(bytes(RRPUnicodeString(representation=self.sub_key_name))),
         self._VALUE_TYPE_STRUCT.pack(self.value_type.value),
         bytes(UnidimensionalConformantArray(tuple(self.value))),
         self._VALUE_LEN_STRUCT.pack(len(self.value))
     ])
Пример #7
0
    def from_bytes(cls, data: ByteString, base_offset: int = 0) -> BaseRegSaveKeyRequest:
        data = memoryview(data)[base_offset:]
        offset = 0

        key_handle: bytes = cls._KEY_HANDLE_STRUCT.unpack_from(buffer=data, offset=base_offset)[0]
        offset += cls._KEY_HANDLE_STRUCT.size

        ndr_save_path = RRPUnicodeString.from_bytes(data=data, base_offset=offset)
        offset += calculate_pad_length(length_unpadded=len(ndr_save_path))

        security_attributes_ndr_pointer = Pointer.from_bytes(data=data, base_offset=offset)
        offset += Pointer.structure_size
        security_attributes = RPCSecurityAttributes.from_bytes(data=security_attributes_ndr_pointer.representation)
        offset += calculate_pad_length(length_unpadded=len(security_attributes))

        return cls(
            key_handle=key_handle,
            save_path=ndr_save_path.representation,
            security_attributes=security_attributes
        )
Пример #8
0
 def __bytes__(self) -> bytes:
     return b''.join([
         self.key_handle,
         ndr_pad(bytes(RRPUnicodeString(representation=str(self.save_path)))),
         bytes(Pointer(representation=bytes(self.security_attributes)))
     ])