QueryInformationRequest.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Copyright (C) 2014-2017 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.IO;
  10. using Utilities;
  11. namespace SMBLibrary.SMB1
  12. {
  13. /// <summary>
  14. /// SMB_COM_QUERY_INFORMATION Request.
  15. /// This command is deprecated.
  16. /// This command is used by Windows NT4 SP6.
  17. /// </summary>
  18. public class QueryInformationRequest : SMB1Command
  19. {
  20. public const byte SupportedBufferFormat = 0x04;
  21. // Data:
  22. public byte BufferFormat;
  23. public string FileName; // SMB_STRING
  24. public QueryInformationRequest() : base()
  25. {
  26. BufferFormat = SupportedBufferFormat;
  27. FileName = String.Empty;
  28. }
  29. public QueryInformationRequest(byte[] buffer, int offset, bool isUnicode) : base(buffer, offset, isUnicode)
  30. {
  31. BufferFormat = ByteReader.ReadByte(this.SMBData, 0);
  32. if (BufferFormat != SupportedBufferFormat)
  33. {
  34. throw new InvalidDataException("Unsupported Buffer Format");
  35. }
  36. FileName = SMB1Helper.ReadSMBString(this.SMBData, 1, isUnicode);
  37. }
  38. public override byte[] GetBytes(bool isUnicode)
  39. {
  40. int length = 1;
  41. if (isUnicode)
  42. {
  43. length += FileName.Length * 2 + 2;
  44. }
  45. else
  46. {
  47. length += FileName.Length + 1;
  48. }
  49. this.SMBData = new byte[1 + length];
  50. ByteWriter.WriteByte(this.SMBData, 0, BufferFormat);
  51. SMB1Helper.WriteSMBString(this.SMBData, 1, isUnicode, FileName);
  52. return base.GetBytes(isUnicode);
  53. }
  54. public override CommandName CommandName
  55. {
  56. get
  57. {
  58. return CommandName.SMB_COM_QUERY_INFORMATION;
  59. }
  60. }
  61. }
  62. }