123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- /* Copyright (C) 2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
- *
- * You can redistribute this program and/or modify it under the terms of
- * the GNU Lesser Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- */
- using System;
- using System.Collections.Generic;
- using Utilities;
- namespace SMBLibrary
- {
- /// <summary>
- /// [MS-FSCC] 2.4.40 - FileStreamInformation
- /// </summary>
- public class FileStreamInformation : FileInformation
- {
- List<FileStreamEntry> m_entries = new List<FileStreamEntry>();
- public FileStreamInformation()
- {
- }
- public FileStreamInformation(byte[] buffer, int offset)
- {
- if (offset < buffer.Length)
- {
- FileStreamEntry entry;
- do
- {
- entry = new FileStreamEntry(buffer, offset);
- m_entries.Add(entry);
- offset += (int)entry.NextEntryOffset;
- }
- while (entry.NextEntryOffset != 0);
- }
- }
- public override void WriteBytes(byte[] buffer, int offset)
- {
- for (int index = 0; index < m_entries.Count; index++)
- {
- FileStreamEntry entry = m_entries[index];
- entry.WriteBytes(buffer, offset);
- int entryLength = entry.Length;
- offset += entryLength;
- if (index < m_entries.Count - 1)
- {
- // [MS-FSCC] When multiple FILE_STREAM_INFORMATION data elements are present in the buffer, each MUST be aligned on an 8-byte boundary
- int padding = (8 - (entryLength % 8)) % 8;
- offset += padding;
- }
- }
- }
- public List<FileStreamEntry> Entries
- {
- get
- {
- return m_entries;
- }
- }
- public override FileInformationClass FileInformationClass
- {
- get
- {
- return FileInformationClass.FileStreamInformation;
- }
- }
- public override int Length
- {
- get
- {
- int length = 0;
- for (int index = 0; index < m_entries.Count; index++)
- {
- FileStreamEntry entry = m_entries[index];
- int entryLength = entry.Length;
- length += entryLength;
- if (index < m_entries.Count - 1)
- {
- // [MS-FSCC] When multiple FILE_STREAM_INFORMATION data elements are present in the buffer, each MUST be aligned on an 8-byte boundary
- int padding = (8 - (entryLength % 8)) % 8;
- length += padding;
- }
- }
- return length;
- }
- }
- }
- }
|