FindInfoQueryEASize.cs 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. /// <summary>
  14. /// SMB_INFO_QUERY_EA_SIZE
  15. /// </summary>
  16. public class FindInfoQueryEASize : FindInformation
  17. {
  18. public uint ResumeKey; // Optional
  19. public DateTime CreationDateTime;
  20. public DateTime LastAccessDateTime;
  21. public DateTime LastWriteDateTime;
  22. public uint FileDataSize;
  23. public uint AllocationSize;
  24. public SMBFileAttributes Attributes;
  25. public uint EASize;
  26. //byte FileNameLength; // In bytes, MUST exclude the null termination.
  27. public string FileName; // OEM / Unicode character array. MUST be written as SMB_STRING, and read as fixed length string.
  28. public FindInfoQueryEASize(bool returnResumeKeys) : base(returnResumeKeys)
  29. {
  30. }
  31. public FindInfoQueryEASize(byte[] buffer, ref int offset, bool isUnicode, bool returnResumeKeys) : base(returnResumeKeys)
  32. {
  33. if (returnResumeKeys)
  34. {
  35. ResumeKey = LittleEndianReader.ReadUInt32(buffer, ref offset);
  36. }
  37. CreationDateTime = SMB1Helper.ReadSMBDateTime(buffer, ref offset);
  38. LastAccessDateTime = SMB1Helper.ReadSMBDateTime(buffer, ref offset);
  39. LastWriteDateTime = SMB1Helper.ReadSMBDateTime(buffer, ref offset);
  40. FileDataSize = LittleEndianReader.ReadUInt32(buffer, ref offset);
  41. AllocationSize = LittleEndianReader.ReadUInt32(buffer, ref offset);
  42. Attributes = (SMBFileAttributes)LittleEndianReader.ReadUInt16(buffer, ref offset);
  43. EASize = LittleEndianReader.ReadUInt32(buffer, ref offset);
  44. byte fileNameLength = ByteReader.ReadByte(buffer, ref offset);
  45. FileName = SMB1Helper.ReadFixedLengthString(buffer, ref offset, isUnicode, fileNameLength);
  46. }
  47. public override void WriteBytes(byte[] buffer, ref int offset, bool isUnicode)
  48. {
  49. byte fileNameLength = (byte)(isUnicode ? FileName.Length * 2 : FileName.Length);
  50. if (ReturnResumeKeys)
  51. {
  52. LittleEndianWriter.WriteUInt32(buffer, ref offset, ResumeKey);
  53. }
  54. SMB1Helper.WriteSMBDateTime(buffer, ref offset, CreationDateTime);
  55. SMB1Helper.WriteSMBDateTime(buffer, ref offset, LastAccessDateTime);
  56. SMB1Helper.WriteSMBDateTime(buffer, ref offset, LastWriteDateTime);
  57. LittleEndianWriter.WriteUInt32(buffer, ref offset, FileDataSize);
  58. LittleEndianWriter.WriteUInt32(buffer, ref offset, AllocationSize);
  59. LittleEndianWriter.WriteUInt16(buffer, ref offset, (ushort)Attributes);
  60. LittleEndianWriter.WriteUInt32(buffer, ref offset, EASize);
  61. ByteWriter.WriteByte(buffer, ref offset, fileNameLength);
  62. SMB1Helper.WriteSMBString(buffer, ref offset, isUnicode, FileName);
  63. }
  64. public override int GetLength(bool isUnicode)
  65. {
  66. int length = 31;
  67. if (ReturnResumeKeys)
  68. {
  69. length += 4;
  70. }
  71. if (isUnicode)
  72. {
  73. length += FileName.Length * 2 + 2;
  74. }
  75. else
  76. {
  77. length += FileName.Length + 1;
  78. }
  79. return length;
  80. }
  81. }
  82. }