SMBAndXCommand.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* Copyright (C) 2014 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. using Utilities;
  11. namespace SMBLibrary.SMB1
  12. {
  13. public abstract class SMBAndXCommand : SMB1Command
  14. {
  15. public CommandName AndXCommand;
  16. public byte AndXReserved;
  17. public ushort AndXOffset;
  18. public SMBAndXCommand() : base()
  19. {
  20. }
  21. public SMBAndXCommand(byte[] buffer, int offset, bool isUnicode) : base(buffer, offset, isUnicode)
  22. {
  23. AndXCommand = (CommandName)ByteReader.ReadByte(this.SMBParameters, 0);
  24. AndXReserved = ByteReader.ReadByte(this.SMBParameters, 1);
  25. AndXOffset = LittleEndianConverter.ToUInt16(this.SMBParameters, 2);
  26. }
  27. public override byte[] GetBytes(bool isUnicode)
  28. {
  29. ByteWriter.WriteByte(this.SMBParameters, 0, (byte)AndXCommand);
  30. ByteWriter.WriteByte(this.SMBParameters, 1, AndXReserved);
  31. LittleEndianWriter.WriteUInt16(this.SMBParameters, 2, AndXOffset);
  32. return base.GetBytes(isUnicode);
  33. }
  34. public static void WriteAndXOffset(byte[] buffer, int commandOffset, ushort AndXOffset)
  35. {
  36. // 3 preceding bytes: WordCount, AndXCommand and AndXReserved
  37. LittleEndianWriter.WriteUInt16(buffer, commandOffset + 3, AndXOffset);
  38. }
  39. }
  40. }