123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using Utilities;
- namespace SMBLibrary.SMB1
- {
-
-
-
- public class RenameRequest : SMB1Command
- {
- public const int SupportedBufferFormat = 0x04;
- public const int ParametersLength = 2;
-
- public SMBFileAttributes SearchAttributes;
-
- public byte BufferFormat1;
- public string OldFileName;
- public byte BufferFormat2;
- public string NewFileName;
- public RenameRequest() : base()
- {
- BufferFormat1 = SupportedBufferFormat;
- BufferFormat2 = SupportedBufferFormat;
- }
- public RenameRequest(byte[] buffer, int offset, bool isUnicode) : base(buffer, offset, isUnicode)
- {
- SearchAttributes = (SMBFileAttributes)LittleEndianConverter.ToUInt16(this.SMBParameters, 0);
- int dataOffset = 0;
- BufferFormat1 = ByteReader.ReadByte(this.SMBData, ref dataOffset);
- if (BufferFormat1 != SupportedBufferFormat)
- {
- throw new InvalidRequestException("Unsupported Buffer Format");
- }
- OldFileName = SMB1Helper.ReadSMBString(this.SMBData, ref dataOffset, isUnicode);
- BufferFormat2 = ByteReader.ReadByte(this.SMBData, ref dataOffset);
- if (BufferFormat2 != SupportedBufferFormat)
- {
- throw new InvalidRequestException("Unsupported Buffer Format");
- }
- if (isUnicode)
- {
- dataOffset++;
- }
- NewFileName = SMB1Helper.ReadSMBString(this.SMBData, ref dataOffset, isUnicode);
- }
- public override byte[] GetBytes(bool isUnicode)
- {
- this.SMBParameters = new byte[ParametersLength];
- LittleEndianWriter.WriteUInt16(this.SMBParameters, 0, (ushort)SearchAttributes);
- if (isUnicode)
- {
- int padding = 1;
- this.SMBData = new byte[2 + OldFileName.Length * 2 + NewFileName.Length * 2 + 4 + padding];
- }
- else
- {
- this.SMBData = new byte[2 + OldFileName.Length + NewFileName.Length + 2];
- }
- int dataOffset = 0;
- ByteWriter.WriteByte(this.SMBData, ref dataOffset, BufferFormat1);
- SMB1Helper.WriteSMBString(this.SMBData, ref dataOffset, isUnicode, OldFileName);
- ByteWriter.WriteByte(this.SMBData, ref dataOffset, BufferFormat2);
- if (isUnicode)
- {
- dataOffset++;
- }
- SMB1Helper.WriteSMBString(this.SMBData, ref dataOffset, isUnicode, NewFileName);
- return base.GetBytes(isUnicode);
- }
- public override CommandName CommandName
- {
- get
- {
- return CommandName.SMB_COM_RENAME;
- }
- }
- }
- }
|