FileFullEAEntry.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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.Text;
  10. using Utilities;
  11. namespace SMBLibrary
  12. {
  13. /// <summary>
  14. /// [MS-FSCC] 2.4.15 - FileFullEaInformation data element
  15. /// </summary>
  16. public class FileFullEAEntry
  17. {
  18. public const int FixedLength = 8;
  19. public uint NextEntryOffset;
  20. public ExtendedAttributeFlags Flags;
  21. private byte EaNameLength;
  22. private ushort EaValueLength;
  23. public string EaName; // 8-bit ASCII followed by a single terminating null character byte
  24. public string EaValue; // 8-bit ASCII
  25. public FileFullEAEntry()
  26. {
  27. }
  28. public FileFullEAEntry(byte[] buffer, int offset)
  29. {
  30. NextEntryOffset = LittleEndianReader.ReadUInt32(buffer, ref offset);
  31. Flags = (ExtendedAttributeFlags)ByteReader.ReadByte(buffer, ref offset);
  32. EaNameLength = ByteReader.ReadByte(buffer, ref offset);
  33. EaValueLength = LittleEndianReader.ReadUInt16(buffer, ref offset);
  34. EaName = ByteReader.ReadAnsiString(buffer, ref offset, EaNameLength);
  35. offset++; // terminating null
  36. EaValue = ByteReader.ReadAnsiString(buffer, ref offset, EaValueLength);
  37. }
  38. public void WriteBytes(byte[] buffer, int offset)
  39. {
  40. EaNameLength = (byte)EaName.Length;
  41. EaValueLength = (ushort)EaValue.Length;
  42. LittleEndianWriter.WriteUInt32(buffer, ref offset, NextEntryOffset);
  43. ByteWriter.WriteByte(buffer, ref offset, (byte)Flags);
  44. ByteWriter.WriteByte(buffer, ref offset, EaNameLength);
  45. LittleEndianWriter.WriteUInt16(buffer, ref offset, EaValueLength);
  46. ByteWriter.WriteAnsiString(buffer, ref offset, EaName);
  47. ByteWriter.WriteByte(buffer, ref offset, 0); // terminating null
  48. ByteWriter.WriteAnsiString(buffer, ref offset, EaValue);
  49. }
  50. public int Length
  51. {
  52. get
  53. {
  54. return FixedLength + EaName.Length + 1 + EaValue.Length;
  55. }
  56. }
  57. }
  58. }