References: =========== - [MS-CIFS]: 2.2.4.43.1 - [MS-SMB]: 2.2.4.3.1
| 1059 | |
| 1060 | |
| 1061 | class ComWriteAndxRequest(Payload): |
| 1062 | """ |
| 1063 | References: |
| 1064 | =========== |
| 1065 | - [MS-CIFS]: 2.2.4.43.1 |
| 1066 | - [MS-SMB]: 2.2.4.3.1 |
| 1067 | """ |
| 1068 | |
| 1069 | PAYLOAD_STRUCT_FORMAT = '<HIIHHHHHI' |
| 1070 | PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT) |
| 1071 | |
| 1072 | def __init__(self, fid, data_bytes, offset, write_mode = 0, timeout = 0): |
| 1073 | """ |
| 1074 | @param timeout: Number of milliseconds to wait for blocked write request before failing. Must be zero for writing to regular file |
| 1075 | @type timeout: int |
| 1076 | """ |
| 1077 | self.fid = fid |
| 1078 | self.offset = offset |
| 1079 | self.data_bytes = data_bytes |
| 1080 | self.timeout = timeout |
| 1081 | self.write_mode = write_mode |
| 1082 | |
| 1083 | def initMessage(self, message): |
| 1084 | Payload.initMessage(self, message) |
| 1085 | message.command = SMB_COM_WRITE_ANDX |
| 1086 | |
| 1087 | def prepare(self, message): |
| 1088 | # constant 1 is to account for the pad byte in the message.data |
| 1089 | # constant 2 is for the ByteCount field in the SMB header (i.e. field which indicates number of data bytes after the SMB parameters) |
| 1090 | data_offset = message.HEADER_STRUCT_SIZE + self.DEFAULT_ANDX_PARAM_SIZE + self.PAYLOAD_STRUCT_SIZE + 1 + 2 |
| 1091 | data_len = len(self.data_bytes) |
| 1092 | |
| 1093 | message.parameters_data = \ |
| 1094 | self.DEFAULT_ANDX_PARAM_HEADER + \ |
| 1095 | struct.pack(self.PAYLOAD_STRUCT_FORMAT, |
| 1096 | self.fid, |
| 1097 | self.offset & 0xFFFFFFFF, |
| 1098 | self.timeout, |
| 1099 | self.write_mode, |
| 1100 | data_len, # Remaining |
| 1101 | 0x0000, # Reserved |
| 1102 | len(self.data_bytes), # DataLength |
| 1103 | data_offset, # DataOffset |
| 1104 | self.offset >> 32) # OffsetHigh field defined in [MS-SMB]: 2.2.4.3.1 |
| 1105 | |
| 1106 | message.data = b'\0' + self.data_bytes |
| 1107 | |
| 1108 | |
| 1109 | class ComWriteAndxResponse(Payload): |