/* Copyright (C) 2017 Tal Aloni . 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 { /// /// [MS-FSCC] 2.4.40 - FileStreamInformation /// public class FileStreamInformation : FileInformation { List m_entries = new List(); 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 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; } } } }