QueryFileStreamInfo.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.SMB1
  12. {
  13. /// <summary>
  14. /// SMB_QUERY_FILE_STREAM_INFO
  15. /// </summary>
  16. public class QueryFileStreamInfo : QueryInformation
  17. {
  18. private List<FileStreamEntry> m_entries = new List<FileStreamEntry>();
  19. public QueryFileStreamInfo()
  20. {
  21. }
  22. public QueryFileStreamInfo(byte[] buffer, int offset)
  23. {
  24. if (offset < buffer.Length)
  25. {
  26. FileStreamEntry entry;
  27. do
  28. {
  29. entry = new FileStreamEntry(buffer, offset);
  30. m_entries.Add(entry);
  31. offset += (int)entry.NextEntryOffset;
  32. }
  33. while (entry.NextEntryOffset != 0);
  34. }
  35. }
  36. public override byte[] GetBytes()
  37. {
  38. byte[] buffer = new byte[Length];
  39. int offset = 0;
  40. for (int index = 0; index < m_entries.Count; index++)
  41. {
  42. FileStreamEntry entry = m_entries[index];
  43. entry.WriteBytes(buffer, offset);
  44. int entryLength = entry.Length;
  45. offset += entryLength;
  46. if (index < m_entries.Count - 1)
  47. {
  48. // [MS-FSCC] When multiple FILE_STREAM_INFORMATION data elements are present in the buffer, each MUST be aligned on an 8-byte boundary
  49. int padding = (8 - (entryLength % 8)) % 8;
  50. offset += padding;
  51. }
  52. }
  53. return buffer;
  54. }
  55. public List<FileStreamEntry> Entries
  56. {
  57. get
  58. {
  59. return m_entries;
  60. }
  61. }
  62. public override QueryInformationLevel InformationLevel
  63. {
  64. get
  65. {
  66. return QueryInformationLevel.SMB_QUERY_FILE_STREAM_INFO;
  67. }
  68. }
  69. public int Length
  70. {
  71. get
  72. {
  73. int length = 0;
  74. for (int index = 0; index < m_entries.Count; index++)
  75. {
  76. FileStreamEntry entry = m_entries[index];
  77. int entryLength = entry.Length;
  78. length += entryLength;
  79. if (index < m_entries.Count - 1)
  80. {
  81. // [MS-FSCC] When multiple FILE_STREAM_INFORMATION data elements are present in the buffer, each MUST be aligned on an 8-byte boundary
  82. int padding = (8 - (entryLength % 8)) % 8;
  83. length += padding;
  84. }
  85. }
  86. return length;
  87. }
  88. }
  89. }
  90. }