MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / decode

Method decode

pager_lib/smb/smb_structs.py:787–819  ·  view source on GitHub ↗
(self, message)

Source from the content-addressed store, hash-verified

785 PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
786
787 def decode(self, message):
788 assert message.command == SMB_COM_TRANSACTION
789
790 if not message.status.hasError:
791 if len(message.parameters_data) < self.PAYLOAD_STRUCT_SIZE:
792 raise ProtocolError('Not enough data to decode SMB_COM_TRANSACTION parameters', message.raw_data, message)
793
794 self.total_params_count, self.total_data_count, _, \
795 params_bytes_len, params_bytes_offset, params_bytes_displ, \
796 data_bytes_len, data_bytes_offset, data_bytes_displ, \
797 setup_count = struct.unpack(self.PAYLOAD_STRUCT_FORMAT, message.parameters_data[:self.PAYLOAD_STRUCT_SIZE])
798
799 if setup_count > 0:
800 setup_bytes_len = setup_count * 2
801
802 if len(message.parameters_data) < self.PAYLOAD_STRUCT_SIZE + setup_bytes_len:
803 raise ProtocolError('Not enough data to decode SMB_COM_TRANSACTION parameters', message.raw_data, message)
804
805 self.setup_bytes = message.parameters_data[self.PAYLOAD_STRUCT_SIZE:self.PAYLOAD_STRUCT_SIZE+setup_bytes_len]
806 else:
807 self.setup_bytes = ''
808
809 offset = message.HEADER_STRUCT_SIZE + self.PAYLOAD_STRUCT_SIZE + setup_count * 2 + 2 # constant 2 is for the ByteCount field in the SMB header (i.e. field which indicates number of data bytes after the SMB parameters)
810
811 if params_bytes_len > 0:
812 self.params_bytes = message.data[params_bytes_offset-offset:params_bytes_offset-offset+params_bytes_len]
813 else:
814 self.params_bytes = ''
815
816 if data_bytes_len > 0:
817 self.data_bytes = message.data[data_bytes_offset-offset:data_bytes_offset-offset+data_bytes_len]
818 else:
819 self.data_bytes = ''
820
821
822class ComTransaction2Request(Payload):

Callers

nothing calls this directly

Calls 1

ProtocolErrorClass · 0.85

Tested by

no test coverage detected