FindInfoStandard.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_STANDARD
  15. /// </summary>
  16. public class FindInfoStandard : FindInformation
  17. {
  18. public const int FixedLength = 23;
  19. public uint ResumeKey; // Optional
  20. public DateTime CreationDateTime;
  21. public DateTime LastAccessDateTime;
  22. public DateTime LastWriteDateTime;
  23. public uint FileDataSize;
  24. public uint AllocationSize;
  25. public SMBFileAttributes Attributes;
  26. //byte FileNameLength;
  27. public string FileName; // SMB_STRING
  28. public FindInfoStandard(bool returnResumeKeys) : base(returnResumeKeys)
  29. {
  30. }
  31. public FindInfoStandard(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. byte fileNameLength = ByteReader.ReadByte(buffer, ref offset);
  44. FileName = SMB1Helper.ReadSMBString(buffer, ref offset, isUnicode);
  45. }
  46. public override void WriteBytes(byte[] buffer, ref int offset, bool isUnicode)
  47. {
  48. byte fileNameLength = (byte)(isUnicode ? FileName.Length * 2 : FileName.Length);
  49. if (ReturnResumeKeys)
  50. {
  51. LittleEndianWriter.WriteUInt32(buffer, ref offset, ResumeKey);
  52. }
  53. SMB1Helper.WriteSMBDateTime(buffer, ref offset, CreationDateTime);
  54. SMB1Helper.WriteSMBDateTime(buffer, ref offset, LastAccessDateTime);
  55. SMB1Helper.WriteSMBDateTime(buffer, ref offset, LastWriteDateTime);
  56. LittleEndianWriter.WriteUInt32(buffer, ref offset, FileDataSize);
  57. LittleEndianWriter.WriteUInt32(buffer, ref offset, AllocationSize);
  58. LittleEndianWriter.WriteUInt16(buffer, ref offset, (ushort)Attributes);
  59. ByteWriter.WriteByte(buffer, ref offset, fileNameLength);
  60. SMB1Helper.WriteSMBString(buffer, ref offset, isUnicode, FileName);
  61. }
  62. public override int GetLength(bool isUnicode)
  63. {
  64. int length = FixedLength;
  65. if (ReturnResumeKeys)
  66. {
  67. length += 4;
  68. }
  69. if (isUnicode)
  70. {
  71. length += FileName.Length * 2 + 2;
  72. }
  73. else
  74. {
  75. length += FileName.Length + 1;
  76. }
  77. return length;
  78. }
  79. }
  80. }