Added MS-FSCC enums and structures required for SMB2

This commit is contained in:
Tal Aloni 2017-01-20 17:24:37 +02:00
parent cbe4160675
commit d5b73a8f9d
37 changed files with 2184 additions and 4 deletions

View file

@ -0,0 +1,32 @@
using System;
namespace SMBLibrary
{
/// <summary>
/// [MS-FSCC] 2.6 - FileAttributes
/// </summary>
[Flags]
public enum FileAttributes : uint
{
ReadOnly = 0x00000001, // FILE_ATTRIBUTE_READONLY
Hidden = 0x00000002, // FILE_ATTRIBUTE_HIDDEN
System = 0x00000004, // FILE_ATTRIBUTE_SYSTEM
Directory = 0x00000010, // FILE_ATTRIBUTE_DIRECTORY
Archive = 0x00000020, // FILE_ATTRIBUTE_ARCHIVE
/// <summary>
/// A file that does not have other attributes set.
/// This attribute is valid only when used alone.
/// </summary>
Normal = 0x00000080, // FILE_ATTRIBUTE_NORMAL
Temporary = 0x00000100, // FILE_ATTRIBUTE_TEMPORARY
SparseFile = 0x00000200, // FILE_ATTRIBUTE_SPARSE_FILE
ReparsePoint = 0x00000400, // FILE_ATTRIBUTE_REPARSE_POINT
Compressed = 0x00000800, // FILE_ATTRIBUTE_COMPRESSED
Offline = 0x00001000, // FILE_ATTRIBUTE_OFFLINE
NotContentIndexed = 0x00002000, // FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
Encrypted = 0x00004000, // FILE_ATTRIBUTE_ENCRYPTED
IntegrityStream = 0x00008000, // FILE_ATTRIBUTE_INTEGRITY_STREAM
NoScrubData = 0x00020000, // FILE_ATTRIBUTE_NO_SCRUB_DATA
}
}

View file

@ -0,0 +1,40 @@
namespace SMBLibrary
{
/// <summary>
/// [MS-FSCC] 2.4 - File Information Classes
/// </summary>
public enum FileInformationClass : byte
{
FileDirectoryInformation = 0x01, // Uses: Query
FileFullDirectoryInformation = 0x02, // Uses: Query
FileBothDirectoryInformation = 0x03, // Uses: Query
FileBasicInformation = 0x04, // Uses: Query, Set
FileStandardInformation = 0x05, // Uses: Query
FileInternalInformation = 0x06, // Uses: Query
FileEaInformation = 0x07, // Uses: Query
FileRenameInformation = 0x0A, // Uses: Set
FileLinkInformation = 0x0B, // Uses: Set
FileNamesInformation = 0x0C, // Uses: Query
FileDispositionInformation = 0x0D, // Uses: Set
FilePositionInformation = 0x0E, // Uses: Query, Set
FileFullEaInformation = 0x0F, // Uses: Query, Set
FileModeInformation = 0x10, // Uses: Query, Set
FileAlignmentInformation = 0x11, // Uses: Query
FileAllInformation = 0x12, // Uses: Query
FileAllocationInformation = 0x13, // Uses: Set
FileEndOfFileInformation = 0x14, // Uses: Set
FileAlternateNameInformation = 0x15, // Uses: Query
FileStreamInformation = 0x16, // Uses: Query
FilePipeInformation = 0x17, // Uses: Query, Set
FilePipeLocalInformation = 0x18, // Uses: Query
FilePipeRemoteInformation = 0x19, // Uses: Query
FileCompressionInformation = 0x1C, // Uses: Query
FileNetworkOpenInformation = 0x22, // Uses: Query
FileAttributeTagInformation = 0x23, // Uses: Query
FileIdBothDirectoryInformation = 0x25, // Uses: Query
FileIdFullDirectoryInformation = 0x26, // Uses: Query
FileValidDataLengthInformation = 0x27, // Uses: Set
FileShortNameInformation = 0x28, // Uses: Set
}
}

View file

@ -0,0 +1,16 @@
namespace SMBLibrary
{
public enum FileSystemControlFlags : uint
{
QuotaTrack = 0x00000001, // FILE_VC_QUOTA_TRACK
QuotaEnforce = 0x00000002, // FILE_VC_QUOTA_ENFORCE
ContentIndexingDisabled = 0x00000008, // FILE_VC_CONTENT_INDEX_DISABLED
LogQuotaThreshold = 0x00000010, // FILE_VC_LOG_QUOTA_THRESHOLD
LogQuotaLimit = 0x00000020, // FILE_VC_LOG_QUOTA_LIMIT
LogVolumeThreshold = 0x00000040, // FILE_VC_LOG_VOLUME_THRESHOLD
LogVolumeLimit = 0x00000080, // FILE_VC_LOG_VOLUME_LIMIT
QuotasIncomplete = 0x00000100, // FILE_VC_QUOTAS_INCOMPLETE
QuotasRebuilding = 0x00000200, // FILE_VC_QUOTAS_REBUILDING
}
}

View file

@ -0,0 +1,21 @@
namespace SMBLibrary
{
/// <summary>
/// [MS-FSCC] 2.5 - File System Information Classes
/// </summary>
public enum FileSystemInformationClass : byte
{
FileFsVolumeInformation = 0x01, // Uses: Query
FileFsLabelInformation = 0x02,
FileFsSizeInformation = 0x03, // Uses: Query
FileFsDeviceInformation = 0x04, // Uses: Query
FileFsAttributeInformation = 0x05, // Uses: Query
FileFsControlInformation = 0x06, // Uses: Query, Set
FileFsFullSizeInformation = 0x07, // Uses: Query
FileFsObjectIdInformation = 0x08, // Uses: Query, Set
FileFsDriverPathInformation = 0x09,
FileFsVolumeFlagsInformation = 0x0A,
FileFsSectorSizeInformation = 0x0B, // Uses: Query
}
}

View file

@ -0,0 +1,13 @@
using System;
namespace SMBLibrary
{
[Flags]
public enum SectorSizeInformationFlags : uint
{
AlignedDevice = 0x00000001, // SSINFO_FLAGS_ALIGNED_DEVICE
PartitionAlignedOnDevice = 0x00000002, // SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE
NoSeekPenalty = 0x0000004, // SSINFO_FLAGS_NO_SEEK_PENALTY
TrimEnabled = 0x00000008, // SSINFO_FLAGS_TRIM_ENABLED
}
}

View file

@ -49,9 +49,14 @@
<Compile Include="Authentication\MD4.cs" />
<Compile Include="Authentication\NTAuthentication.cs" />
<Compile Include="Client\SMBClient.cs" />
<Compile Include="Enums\FileAttributes.cs" />
<Compile Include="Enums\FileInformationClass.cs" />
<Compile Include="Enums\FileSystemInformation\DeviceCharacteristics.cs" />
<Compile Include="Enums\FileSystemInformation\DeviceType.cs" />
<Compile Include="Enums\FileSystemInformation\FileSystemAttributes.cs" />
<Compile Include="Enums\FileSystemInformation\FileSystemControlFlags.cs" />
<Compile Include="Enums\FileSystemInformation\FileSystemInformationClass.cs" />
<Compile Include="Enums\FileSystemInformation\SectorSizeInformationFlags.cs" />
<Compile Include="Enums\NtCreateFile\CreateDisposition.cs" />
<Compile Include="Enums\NtCreateFile\CreateOptions.cs" />
<Compile Include="Enums\NtCreateFile\ShareAccess.cs" />
@ -399,7 +404,37 @@
<Compile Include="Structures\ACE\Enums\AceFlags.cs" />
<Compile Include="Structures\ACE\Enums\AceType.cs" />
<Compile Include="Structures\ACL.cs" />
<Compile Include="Structures\FileInformation\FileInformation.cs" />
<Compile Include="Structures\FileInformation\Query\FileBasicInformation.cs" />
<Compile Include="Structures\FileInformation\Query\FileEaInformation.cs" />
<Compile Include="Structures\FileInformation\Query\FileInternalInformation.cs" />
<Compile Include="Structures\FileInformation\Query\FileModeInformation.cs" />
<Compile Include="Structures\FileInformation\Query\FileNetworkOpenInformation.cs" />
<Compile Include="Structures\FileInformation\Query\FileStandardInformation.cs" />
<Compile Include="Structures\FileInformation\Query\FileStreamInformation.cs" />
<Compile Include="Structures\FileInformation\QueryDirectory\FileBothDirectoryInformation.cs" />
<Compile Include="Structures\FileInformation\QueryDirectory\FileDirectoryInformation.cs" />
<Compile Include="Structures\FileInformation\QueryDirectory\FileFullDirectoryInformation.cs" />
<Compile Include="Structures\FileInformation\QueryDirectory\FileIdBothDirectoryInformation.cs" />
<Compile Include="Structures\FileInformation\QueryDirectory\FileIdFullDirectoryInformation.cs" />
<Compile Include="Structures\FileInformation\QueryDirectory\FileNamesInformation.cs" />
<Compile Include="Structures\FileInformation\QueryDirectory\QueryDirectoryFileInformation.cs" />
<Compile Include="Structures\FileInformation\Set\FileAllocationInformation.cs" />
<Compile Include="Structures\FileInformation\Set\FileDispositionInformation.cs" />
<Compile Include="Structures\FileInformation\Set\FileEndOfFileInformation.cs" />
<Compile Include="Structures\FileInformation\Set\FileFullEAInformation.cs" />
<Compile Include="Structures\FileInformation\Set\FileLinkInformationType2.cs" />
<Compile Include="Structures\FileInformation\Set\FileRenameInformationType2.cs" />
<Compile Include="Structures\FileInformation\Set\FileValidDataLengthInformation.cs" />
<Compile Include="Structures\FileSystemInformation\FileFsAttributeInformation.cs" />
<Compile Include="Structures\FileSystemInformation\FileFsControlInformation.cs" />
<Compile Include="Structures\FileSystemInformation\FileFsDeviceInformation.cs" />
<Compile Include="Structures\FileSystemInformation\FileFsFullSizeInformation.cs" />
<Compile Include="Structures\FileSystemInformation\FileFsObjectIdInformation.cs" />
<Compile Include="Structures\FileSystemInformation\FileFsSectorSizeInformation.cs" />
<Compile Include="Structures\FileSystemInformation\FileFsSizeInformation.cs" />
<Compile Include="Structures\FileSystemInformation\FileFsVolumeInformation.cs" />
<Compile Include="Structures\FileSystemInformation\FileSystemInformation.cs" />
<Compile Include="Structures\ObjectIDBufferType1.cs" />
<Compile Include="Structures\SecurityDescriptor.cs" />
<Compile Include="Structures\SID.cs" />

View file

@ -0,0 +1,93 @@
/* 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
{
public abstract class FileInformation
{
public abstract void WriteBytes(byte[] buffer, int offset);
public byte[] GetBytes()
{
byte[] buffer = new byte[this.Length];
WriteBytes(buffer, 0);
return buffer;
}
public abstract FileInformationClass FileInformationClass
{
get;
}
public abstract int Length
{
get;
}
public static FileInformation GetFileInformation(byte[] buffer, int offset, FileInformationClass informationClass)
{
switch (informationClass)
{
case FileInformationClass.FileBasicInformation:
return new FileBasicInformation(buffer, offset);
case FileInformationClass.FileStandardInformation:
return new FileStandardInformation(buffer, offset);
case FileInformationClass.FileInternalInformation:
return new FileInternalInformation(buffer, offset);
case FileInformationClass.FileEaInformation:
return new FileEaInformation(buffer, offset);
case FileInformationClass.FileRenameInformation:
return new FileRenameInformationType2(buffer, offset);
case FileInformationClass.FileLinkInformation:
return new FileLinkInformationType2(buffer, offset);
case FileInformationClass.FileNamesInformation:
throw new NotImplementedException();
case FileInformationClass.FileDispositionInformation:
return new FileDispositionInformation(buffer, offset);
case FileInformationClass.FilePositionInformation:
throw new NotImplementedException();
case FileInformationClass.FileFullEaInformation:
return new FileFullEAInformation(buffer, offset);
case FileInformationClass.FileModeInformation:
return new FileModeInformation(buffer, offset);
case FileInformationClass.FileAlignmentInformation:
throw new NotImplementedException();
case FileInformationClass.FileAllInformation:
throw new NotImplementedException();
case FileInformationClass.FileAllocationInformation:
return new FileAllocationInformation(buffer, offset);
case FileInformationClass.FileEndOfFileInformation:
return new FileEndOfFileInformation(buffer, offset);
case FileInformationClass.FileAlternateNameInformation:
throw new NotImplementedException();
case FileInformationClass.FileStreamInformation:
throw new NotImplementedException();
case FileInformationClass.FilePipeInformation:
throw new NotImplementedException();
case FileInformationClass.FilePipeLocalInformation:
throw new NotImplementedException();
case FileInformationClass.FilePipeRemoteInformation:
throw new NotImplementedException();
case FileInformationClass.FileCompressionInformation:
throw new NotImplementedException();
case FileInformationClass.FileNetworkOpenInformation:
return new FileNetworkOpenInformation(buffer, offset);
case FileInformationClass.FileAttributeTagInformation:
throw new NotImplementedException();
case FileInformationClass.FileValidDataLengthInformation:
return new FileValidDataLengthInformation(buffer, offset);
case FileInformationClass.FileShortNameInformation:
throw new NotImplementedException();
default:
throw new UnsupportedInformationLevelException();
}
}
}
}

View file

@ -0,0 +1,67 @@
/* 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.7 - FileBasicInformation
/// </summary>
public class FileBasicInformation : FileInformation
{
public const int FixedLength = 40;
public DateTime? CreationTime;
public DateTime? LastAccessTime;
public DateTime? LastWriteTime;
public DateTime? ChangeTime;
public FileAttributes FileAttributes;
public uint Reserved;
public FileBasicInformation()
{
}
public FileBasicInformation(byte[] buffer, int offset)
{
CreationTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 0);
LastAccessTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 8);
LastWriteTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 16);
ChangeTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 24);
FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 32);
Reserved = LittleEndianConverter.ToUInt32(buffer, offset + 36);
}
public override void WriteBytes(byte[] buffer, int offset)
{
FileTimeHelper.WriteFileTime(buffer, offset + 0, CreationTime);
FileTimeHelper.WriteFileTime(buffer, offset + 8, LastAccessTime);
FileTimeHelper.WriteFileTime(buffer, offset + 16, LastWriteTime);
FileTimeHelper.WriteFileTime(buffer, offset + 24, ChangeTime);
LittleEndianWriter.WriteUInt32(buffer, offset + 32, (uint)FileAttributes);
LittleEndianWriter.WriteUInt32(buffer, offset + 36, Reserved);
}
public override FileInformationClass FileInformationClass
{
get
{
return FileInformationClass.FileBasicInformation;
}
}
public override int Length
{
get
{
return FixedLength;
}
}
}
}

View file

@ -0,0 +1,52 @@
/* 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.12 - FileEaInformation
/// </summary>
public class FileEaInformation : FileInformation
{
public const int FixedLength = 4;
public uint EaSize;
public FileEaInformation()
{
}
public FileEaInformation(byte[] buffer, int offset)
{
EaSize = LittleEndianConverter.ToUInt32(buffer, offset + 0);
}
public override void WriteBytes(byte[] buffer, int offset)
{
LittleEndianWriter.WriteUInt32(buffer, offset + 0, EaSize);
}
public override FileInformationClass FileInformationClass
{
get
{
return FileInformationClass.FileEaInformation;
}
}
public override int Length
{
get
{
return FixedLength;
}
}
}
}

View file

@ -0,0 +1,52 @@
/* 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.20 - FileInternalInformation
/// </summary>
public class FileInternalInformation : FileInformation
{
public const int FixedLength = 8;
public long IndexNumber;
public FileInternalInformation()
{
}
public FileInternalInformation(byte[] buffer, int offset)
{
IndexNumber = LittleEndianConverter.ToInt64(buffer, offset + 0);
}
public override void WriteBytes(byte[] buffer, int offset)
{
LittleEndianWriter.WriteInt64(buffer, offset + 0, IndexNumber);
}
public override FileInformationClass FileInformationClass
{
get
{
return FileInformationClass.FileInternalInformation;
}
}
public override int Length
{
get
{
return FixedLength;
}
}
}
}

View file

@ -0,0 +1,52 @@
/* 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.24 - FileModeInformation
/// </summary>
public class FileModeInformation : FileInformation
{
public const int FixedSize = 4;
public CreateOptions FileMode;
public FileModeInformation()
{
}
public FileModeInformation(byte[] buffer, int offset)
{
FileMode = (CreateOptions)LittleEndianConverter.ToUInt32(buffer, offset + 0);
}
public override void WriteBytes(byte[] buffer, int offset)
{
LittleEndianWriter.WriteUInt32(buffer, offset, (uint)FileMode);
}
public override FileInformationClass FileInformationClass
{
get
{
return FileInformationClass.FileModeInformation;
}
}
public override int Length
{
get
{
return FixedSize;
}
}
}
}

View file

@ -0,0 +1,73 @@
/* 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.12 - FileNetworkOpenInformation
/// </summary>
public class FileNetworkOpenInformation : FileInformation
{
public const int FixedLength = 56;
public DateTime? CreationTime;
public DateTime? LastAccessTime;
public DateTime? LastWriteTime;
public DateTime? ChangeTime;
public ulong AllocationSize;
public ulong EndOfFile;
public FileAttributes FileAttributes;
public uint Reserved;
public FileNetworkOpenInformation()
{
}
public FileNetworkOpenInformation(byte[] buffer, int offset)
{
CreationTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 0);
LastAccessTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 8);
LastWriteTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 16);
ChangeTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 24);
AllocationSize = LittleEndianConverter.ToUInt64(buffer, offset + 32);
EndOfFile = LittleEndianConverter.ToUInt64(buffer, offset + 40);
FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 48);
Reserved = LittleEndianConverter.ToUInt32(buffer, offset + 52);
}
public override void WriteBytes(byte[] buffer, int offset)
{
FileTimeHelper.WriteFileTime(buffer, offset + 0, CreationTime);
FileTimeHelper.WriteFileTime(buffer, offset + 8, LastAccessTime);
FileTimeHelper.WriteFileTime(buffer, offset + 16, LastWriteTime);
FileTimeHelper.WriteFileTime(buffer, offset + 24, ChangeTime);
LittleEndianWriter.WriteUInt64(buffer, offset + 32, AllocationSize);
LittleEndianWriter.WriteUInt64(buffer, offset + 40, EndOfFile);
LittleEndianWriter.WriteUInt32(buffer, offset + 48, (uint)FileAttributes);
LittleEndianWriter.WriteUInt32(buffer, offset + 52, Reserved);
}
public override FileInformationClass FileInformationClass
{
get
{
return FileInformationClass.FileNetworkOpenInformation;
}
}
public override int Length
{
get
{
return FixedLength;
}
}
}
}

View file

@ -0,0 +1,67 @@
/* 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.38 - FileStandardInformation
/// </summary>
public class FileStandardInformation : FileInformation
{
public const int FixedLength = 24;
public ulong AllocationSize;
public ulong EndOfFile;
public uint NumberOfLinks;
public bool DeletePending;
public bool Directory;
public ushort Reserved;
public FileStandardInformation()
{
}
public FileStandardInformation(byte[] buffer, int offset)
{
AllocationSize = LittleEndianConverter.ToUInt64(buffer, offset + 0);
EndOfFile = LittleEndianConverter.ToUInt64(buffer, offset + 8);
NumberOfLinks = LittleEndianConverter.ToUInt32(buffer, offset + 16);
DeletePending = (ByteReader.ReadByte(buffer, offset + 20) > 0);
Directory = (ByteReader.ReadByte(buffer, offset + 21) > 0);
Reserved = LittleEndianConverter.ToUInt16(buffer, offset + 22);
}
public override void WriteBytes(byte[] buffer, int offset)
{
LittleEndianWriter.WriteUInt64(buffer, offset + 0, AllocationSize);
LittleEndianWriter.WriteUInt64(buffer, offset + 8, EndOfFile);
LittleEndianWriter.WriteUInt32(buffer, offset + 16, NumberOfLinks);
ByteWriter.WriteByte(buffer, offset + 20, Convert.ToByte(DeletePending));
ByteWriter.WriteByte(buffer, offset + 21, Convert.ToByte(Directory));
LittleEndianWriter.WriteUInt16(buffer, offset + 22, Reserved);
}
public override FileInformationClass FileInformationClass
{
get
{
return FileInformationClass.FileStandardInformation;
}
}
public override int Length
{
get
{
return FixedLength;
}
}
}
}

View file

@ -0,0 +1,66 @@
/* 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
{
public const int FixedLength = 24;
public uint NextEntryOffset;
private uint StreamNameLength;
public ulong StreamSize;
public ulong StreamAllocationSize;
public string StreamName = String.Empty;
public FileStreamInformation()
{
}
public FileStreamInformation(byte[] buffer, int offset)
{
NextEntryOffset = LittleEndianConverter.ToUInt32(buffer, offset + 0);
StreamNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 4);
StreamSize = LittleEndianConverter.ToUInt64(buffer, offset + 8);
StreamAllocationSize = LittleEndianConverter.ToUInt64(buffer, offset + 16);
ByteReader.ReadUTF16String(buffer, offset + 24, (int)StreamNameLength / 2);
}
public override void WriteBytes(byte[] buffer, int offset)
{
StreamNameLength = (uint)(StreamName.Length * 2);
LittleEndianWriter.WriteUInt32(buffer, offset + 0, NextEntryOffset);
LittleEndianWriter.WriteUInt32(buffer, offset + 4, StreamNameLength);
LittleEndianWriter.WriteUInt64(buffer, offset + 8, StreamSize);
LittleEndianWriter.WriteUInt64(buffer, offset + 16, StreamAllocationSize);
ByteWriter.WriteUTF16String(buffer, offset + 24, StreamName);
}
public override FileInformationClass FileInformationClass
{
get
{
return FileInformationClass.FileStreamInformation;
}
}
public override int Length
{
get
{
return FixedLength + StreamName.Length * 2;
}
}
}
}

View file

@ -0,0 +1,91 @@
/* 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.8 - FileBothDirectoryInformation
/// </summary>
public class FileBothDirectoryInformation : QueryDirectoryFileInformation
{
public const int FixedLength = 94;
public DateTime CreationTime;
public DateTime LastAccessTime;
public DateTime LastWriteTime;
public DateTime ChangeTime;
public ulong EndOfFile;
public ulong AllocationSize;
public FileAttributes FileAttributes;
private uint FileNameLength;
public uint EaSize;
private byte ShortNameLength;
public byte Reserved;
public string ShortName = String.Empty; // Short (8.3) file name in UTF16 (24 bytes)
public string FileName = String.Empty;
public FileBothDirectoryInformation()
{
}
public FileBothDirectoryInformation(byte[] buffer, int offset) : base(buffer, offset)
{
CreationTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 8));
LastAccessTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 16));
LastWriteTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 24));
ChangeTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 32));
EndOfFile = LittleEndianConverter.ToUInt64(buffer, offset + 40);
AllocationSize = LittleEndianConverter.ToUInt64(buffer, offset + 48);
FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 56);
FileNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 60);
EaSize = LittleEndianConverter.ToUInt32(buffer, offset + 64);
ShortNameLength = ByteReader.ReadByte(buffer, offset + 68);
Reserved = ByteReader.ReadByte(buffer, offset + 69);
ShortName = ByteReader.ReadUTF16String(buffer, offset + 70, ShortNameLength / 2);
FileName = ByteReader.ReadUTF16String(buffer, offset + 94, (int)FileNameLength / 2);
}
public override void WriteBytes(byte[] buffer, int offset)
{
base.WriteBytes(buffer, offset);
ShortNameLength = (byte)(ShortName.Length * 2);
FileNameLength = (uint)(FileName.Length * 2);
LittleEndianWriter.WriteInt64(buffer, offset + 8, CreationTime.ToFileTimeUtc());
LittleEndianWriter.WriteInt64(buffer, offset + 16, LastAccessTime.ToFileTimeUtc());
LittleEndianWriter.WriteInt64(buffer, offset + 24, LastWriteTime.ToFileTimeUtc());
LittleEndianWriter.WriteInt64(buffer, offset + 32, ChangeTime.ToFileTimeUtc());
LittleEndianWriter.WriteUInt64(buffer, offset + 40, EndOfFile);
LittleEndianWriter.WriteUInt64(buffer, offset + 48, AllocationSize);
LittleEndianWriter.WriteUInt32(buffer, offset + 56, (uint)FileAttributes);
LittleEndianWriter.WriteUInt32(buffer, offset + 60, FileNameLength);
LittleEndianWriter.WriteUInt32(buffer, offset + 64, EaSize);
ByteWriter.WriteByte(buffer, offset + 68, ShortNameLength);
ByteWriter.WriteByte(buffer, offset + 69, Reserved);
ByteWriter.WriteUTF16String(buffer, offset + 70, ShortName);
ByteWriter.WriteUTF16String(buffer, offset + 94, FileName);
}
public override FileInformationClass FileInformationClass
{
get
{
return FileInformationClass.FileBothDirectoryInformation;
}
}
public override int Length
{
get
{
return FixedLength + FileName.Length * 2;
}
}
}
}

View file

@ -0,0 +1,78 @@
/* 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.10 - FileDirectoryInformation
/// </summary>
public class FileDirectoryInformation : QueryDirectoryFileInformation
{
public const int FixedLength = 64;
public DateTime CreationTime;
public DateTime LastAccessTime;
public DateTime LastWriteTime;
public DateTime ChangeTime;
public ulong EndOfFile;
public ulong AllocationSize;
public FileAttributes FileAttributes;
private uint FileNameLength;
public string FileName = String.Empty;
public FileDirectoryInformation()
{
}
public FileDirectoryInformation(byte[] buffer, int offset) : base(buffer, offset)
{
CreationTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 8));
LastAccessTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 16));
LastWriteTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 24));
ChangeTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 32));
EndOfFile = LittleEndianConverter.ToUInt64(buffer, offset + 40);
AllocationSize = LittleEndianConverter.ToUInt64(buffer, offset + 48);
FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 56);
FileNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 60);
FileName = ByteReader.ReadUTF16String(buffer, offset + 64, (int)FileNameLength / 2);
}
public override void WriteBytes(byte[] buffer, int offset)
{
base.WriteBytes(buffer, offset);
FileNameLength = (uint)(FileName.Length * 2);
LittleEndianWriter.WriteInt64(buffer, offset + 8, CreationTime.ToFileTimeUtc());
LittleEndianWriter.WriteInt64(buffer, offset + 16, LastAccessTime.ToFileTimeUtc());
LittleEndianWriter.WriteInt64(buffer, offset + 24, LastWriteTime.ToFileTimeUtc());
LittleEndianWriter.WriteInt64(buffer, offset + 32, ChangeTime.ToFileTimeUtc());
LittleEndianWriter.WriteUInt64(buffer, offset + 40, EndOfFile);
LittleEndianWriter.WriteUInt64(buffer, offset + 48, AllocationSize);
LittleEndianWriter.WriteUInt32(buffer, offset + 56, (uint)FileAttributes);
LittleEndianWriter.WriteUInt32(buffer, offset + 60, FileNameLength);
ByteWriter.WriteUTF16String(buffer, offset + 64, FileName);
}
public override FileInformationClass FileInformationClass
{
get
{
return FileInformationClass.FileDirectoryInformation;
}
}
public override int Length
{
get
{
return FixedLength + FileName.Length * 2;
}
}
}
}

View file

@ -0,0 +1,81 @@
/* 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.14 - FileFullDirectoryInformation
/// </summary>
public class FileFullDirectoryInformation : QueryDirectoryFileInformation
{
public const int FixedLength = 68;
public DateTime CreationTime;
public DateTime LastAccessTime;
public DateTime LastWriteTime;
public DateTime ChangeTime;
public ulong EndOfFile;
public ulong AllocationSize;
public FileAttributes FileAttributes;
private uint FileNameLength;
public uint EaSize;
public string FileName = String.Empty;
public FileFullDirectoryInformation()
{
}
public FileFullDirectoryInformation(byte[] buffer, int offset) : base(buffer, offset)
{
CreationTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 8));
LastAccessTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 16));
LastWriteTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 24));
ChangeTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 32));
EndOfFile = LittleEndianConverter.ToUInt64(buffer, offset + 40);
AllocationSize = LittleEndianConverter.ToUInt64(buffer, offset + 48);
FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 56);
FileNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 60);
EaSize = LittleEndianConverter.ToUInt32(buffer, offset + 64);
FileName = ByteReader.ReadUTF16String(buffer, offset + 68, (int)FileNameLength / 2);
}
public override void WriteBytes(byte[] buffer, int offset)
{
base.WriteBytes(buffer, offset);
FileNameLength = (uint)(FileName.Length * 2);
LittleEndianWriter.WriteInt64(buffer, offset + 8, CreationTime.ToFileTimeUtc());
LittleEndianWriter.WriteInt64(buffer, offset + 16, LastAccessTime.ToFileTimeUtc());
LittleEndianWriter.WriteInt64(buffer, offset + 24, LastWriteTime.ToFileTimeUtc());
LittleEndianWriter.WriteInt64(buffer, offset + 32, ChangeTime.ToFileTimeUtc());
LittleEndianWriter.WriteUInt64(buffer, offset + 40, EndOfFile);
LittleEndianWriter.WriteUInt64(buffer, offset + 48, AllocationSize);
LittleEndianWriter.WriteUInt32(buffer, offset + 56, (uint)FileAttributes);
LittleEndianWriter.WriteUInt32(buffer, offset + 60, FileNameLength);
LittleEndianWriter.WriteUInt32(buffer, offset + 64, EaSize);
ByteWriter.WriteUTF16String(buffer, offset + 68, FileName);
}
public override FileInformationClass FileInformationClass
{
get
{
return FileInformationClass.FileFullDirectoryInformation;
}
}
public override int Length
{
get
{
return FixedLength + FileName.Length * 2;
}
}
}
}

View file

@ -0,0 +1,97 @@
/* 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.17 - FileIdBothDirectoryInformation
/// </summary>
public class FileIdBothDirectoryInformation : QueryDirectoryFileInformation
{
public const int FixedLength = 104;
public DateTime CreationTime;
public DateTime LastAccessTime;
public DateTime LastWriteTime;
public DateTime ChangeTime;
public ulong EndOfFile;
public ulong AllocationSize;
public FileAttributes FileAttributes;
private uint FileNameLength;
public uint EaSize;
private byte ShortNameLength;
public byte Reserved1;
public string ShortName = String.Empty; // Short (8.3) file name in UTF16 (24 bytes)
public ushort Reserved2;
public ulong FileId;
public string FileName = String.Empty;
public FileIdBothDirectoryInformation()
{
}
public FileIdBothDirectoryInformation(byte[] buffer, int offset) : base(buffer, offset)
{
CreationTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 8));
LastAccessTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 16));
LastWriteTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 24));
ChangeTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 32));
EndOfFile = LittleEndianConverter.ToUInt64(buffer, offset + 40);
AllocationSize = LittleEndianConverter.ToUInt64(buffer, offset + 48);
FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 56);
FileNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 60);
EaSize = LittleEndianConverter.ToUInt32(buffer, offset + 64);
ShortNameLength = ByteReader.ReadByte(buffer, offset + 68);
Reserved1 = ByteReader.ReadByte(buffer, offset + 69);
ShortName = ByteReader.ReadUTF16String(buffer, offset + 70, ShortNameLength / 2);
Reserved2 = LittleEndianConverter.ToUInt16(buffer, offset + 94);
FileId = LittleEndianConverter.ToUInt64(buffer, offset + 96);
FileName = ByteReader.ReadUTF16String(buffer, offset + 104, (int)FileNameLength / 2);
}
public override void WriteBytes(byte[] buffer, int offset)
{
base.WriteBytes(buffer, offset);
ShortNameLength = (byte)(ShortName.Length * 2);
FileNameLength = (uint)(FileName.Length * 2);
LittleEndianWriter.WriteInt64(buffer, offset + 8, CreationTime.ToFileTimeUtc());
LittleEndianWriter.WriteInt64(buffer, offset + 16, LastAccessTime.ToFileTimeUtc());
LittleEndianWriter.WriteInt64(buffer, offset + 24, LastWriteTime.ToFileTimeUtc());
LittleEndianWriter.WriteInt64(buffer, offset + 32, ChangeTime.ToFileTimeUtc());
LittleEndianWriter.WriteUInt64(buffer, offset + 40, EndOfFile);
LittleEndianWriter.WriteUInt64(buffer, offset + 48, AllocationSize);
LittleEndianWriter.WriteUInt32(buffer, offset + 56, (uint)FileAttributes);
LittleEndianWriter.WriteUInt32(buffer, offset + 60, FileNameLength);
LittleEndianWriter.WriteUInt32(buffer, offset + 64, EaSize);
ByteWriter.WriteByte(buffer, offset + 68, ShortNameLength);
ByteWriter.WriteByte(buffer, offset + 69, Reserved1);
ByteWriter.WriteUTF16String(buffer, offset + 70, ShortName);
LittleEndianWriter.WriteUInt16(buffer, offset + 94, Reserved2);
LittleEndianWriter.WriteUInt64(buffer, offset + 96, FileId);
ByteWriter.WriteUTF16String(buffer, offset + 104, FileName);
}
public override FileInformationClass FileInformationClass
{
get
{
return FileInformationClass.FileIdBothDirectoryInformation;
}
}
public override int Length
{
get
{
return FixedLength + FileName.Length * 2;
}
}
}
}

View file

@ -0,0 +1,87 @@
/* 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.18 - FileIdFullDirectoryInformation
/// </summary>
public class FileIdFullDirectoryInformation : QueryDirectoryFileInformation
{
public const int FixedLength = 80;
public DateTime CreationTime;
public DateTime LastAccessTime;
public DateTime LastWriteTime;
public DateTime ChangeTime;
public ulong EndOfFile;
public ulong AllocationSize;
public FileAttributes FileAttributes;
private uint FileNameLength;
public uint EaSize;
public uint Reserved;
public ulong FileId;
public string FileName = String.Empty;
public FileIdFullDirectoryInformation()
{
}
public FileIdFullDirectoryInformation(byte[] buffer, int offset) : base(buffer, offset)
{
CreationTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 8));
LastAccessTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 16));
LastWriteTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 24));
ChangeTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 32));
EndOfFile = LittleEndianConverter.ToUInt64(buffer, offset + 40);
AllocationSize = LittleEndianConverter.ToUInt64(buffer, offset + 48);
FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 56);
FileNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 60);
EaSize = LittleEndianConverter.ToUInt32(buffer, offset + 64);
Reserved = LittleEndianConverter.ToUInt32(buffer, offset + 68);
FileId = LittleEndianConverter.ToUInt64(buffer, offset + 72);
FileName = ByteReader.ReadUTF16String(buffer, offset + 80, (int)FileNameLength / 2);
}
public override void WriteBytes(byte[] buffer, int offset)
{
base.WriteBytes(buffer, offset);
FileNameLength = (uint)(FileName.Length * 2);
LittleEndianWriter.WriteInt64(buffer, offset + 8, CreationTime.ToFileTimeUtc());
LittleEndianWriter.WriteInt64(buffer, offset + 16, LastAccessTime.ToFileTimeUtc());
LittleEndianWriter.WriteInt64(buffer, offset + 24, LastWriteTime.ToFileTimeUtc());
LittleEndianWriter.WriteInt64(buffer, offset + 32, ChangeTime.ToFileTimeUtc());
LittleEndianWriter.WriteUInt64(buffer, offset + 40, EndOfFile);
LittleEndianWriter.WriteUInt64(buffer, offset + 48, AllocationSize);
LittleEndianWriter.WriteUInt32(buffer, offset + 56, (uint)FileAttributes);
LittleEndianWriter.WriteUInt32(buffer, offset + 60, FileNameLength);
LittleEndianWriter.WriteUInt32(buffer, offset + 64, EaSize);
LittleEndianWriter.WriteUInt32(buffer, offset + 68, Reserved);
LittleEndianWriter.WriteUInt64(buffer, offset + 72, FileId);
ByteWriter.WriteUTF16String(buffer, offset + 80, FileName);
}
public override FileInformationClass FileInformationClass
{
get
{
return FileInformationClass.FileIdFullDirectoryInformation;
}
}
public override int Length
{
get
{
return FixedLength + FileName.Length * 2;
}
}
}
}

View file

@ -0,0 +1,57 @@
/* 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.26 - FileNamesInformation
/// </summary>
public class FileNamesInformation : QueryDirectoryFileInformation
{
public const int FixedLength = 12;
private uint FileNameLength;
public string FileName = String.Empty;
public FileNamesInformation()
{
}
public FileNamesInformation(byte[] buffer, int offset) : base(buffer, offset)
{
FileNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 8);
FileName = ByteReader.ReadUTF16String(buffer, offset + 12, (int)FileNameLength / 2);
}
public override void WriteBytes(byte[] buffer, int offset)
{
base.WriteBytes(buffer, offset);
FileNameLength = (uint)(FileName.Length * 2);
LittleEndianWriter.WriteUInt32(buffer, offset + 8, FileNameLength);
ByteWriter.WriteUTF16String(buffer, offset + 12, FileName);
}
public override FileInformationClass FileInformationClass
{
get
{
return FileInformationClass.FileNamesInformation;
}
}
public override int Length
{
get
{
return FixedLength + FileName.Length * 2;
}
}
}
}

View file

@ -0,0 +1,115 @@
/* 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
{
public abstract class QueryDirectoryFileInformation : FileInformation
{
public uint NextEntryOffset;
public uint FileIndex;
public QueryDirectoryFileInformation()
{
}
public QueryDirectoryFileInformation(byte[] buffer, int offset)
{
NextEntryOffset = LittleEndianConverter.ToUInt32(buffer, offset + 0);
FileIndex = LittleEndianConverter.ToUInt32(buffer, offset + 4);
}
public override void WriteBytes(byte[] buffer, int offset)
{
LittleEndianWriter.WriteUInt32(buffer, offset + 0, NextEntryOffset);
LittleEndianWriter.WriteUInt32(buffer, offset + 4, FileIndex);
}
public static QueryDirectoryFileInformation ReadFileInformation(byte[] buffer, int offset, FileInformationClass fileInformationClass)
{
switch (fileInformationClass)
{
case FileInformationClass.FileDirectoryInformation:
return new FileDirectoryInformation(buffer, offset);
case FileInformationClass.FileFullDirectoryInformation:
return new FileFullDirectoryInformation(buffer, offset);
case FileInformationClass.FileBothDirectoryInformation:
return new FileBothDirectoryInformation(buffer, offset);
case FileInformationClass.FileNamesInformation:
return new FileNamesInformation(buffer, offset);
case FileInformationClass.FileIdBothDirectoryInformation:
return new FileIdBothDirectoryInformation(buffer, offset);
case FileInformationClass.FileIdFullDirectoryInformation:
return new FileIdFullDirectoryInformation(buffer, offset);
default:
throw new NotImplementedException(String.Format("File information class {0} is not supported.", (int)fileInformationClass));
}
}
public static List<QueryDirectoryFileInformation> ReadFileInformationList(byte[] buffer, int offset, FileInformationClass fileInformationClass)
{
List<QueryDirectoryFileInformation> result = new List<QueryDirectoryFileInformation>();
QueryDirectoryFileInformation entry;
do
{
entry = ReadFileInformation(buffer, offset, fileInformationClass);
result.Add(entry);
offset += (int)entry.NextEntryOffset;
}
while (entry.NextEntryOffset != 0);
return result;
}
public static byte[] GetBytes(List<QueryDirectoryFileInformation> fileInformationList)
{
int listLength = GetListLength(fileInformationList);
byte[] buffer = new byte[listLength];
int offset = 0;
for (int index = 0; index < fileInformationList.Count; index++)
{
QueryDirectoryFileInformation entry = fileInformationList[index];
int length = entry.Length;
int paddedLength = (int)Math.Ceiling((double)length / 8) * 8;
if (index < fileInformationList.Count - 1)
{
entry.NextEntryOffset = (uint)paddedLength;
}
else
{
entry.NextEntryOffset = 0;
}
entry.WriteBytes(buffer, offset);
offset += paddedLength;
}
return buffer;
}
public static int GetListLength(List<QueryDirectoryFileInformation> fileInformationList)
{
int result = 0;
for(int index = 0; index < fileInformationList.Count; index++)
{
QueryDirectoryFileInformation entry = fileInformationList[index];
int length = entry.Length;
// [MS-FSCC] each [entry] MUST be aligned on an 8-byte boundary.
if (index < fileInformationList.Count - 1)
{
// No padding is required following the last data element.
int paddedLength = (int)Math.Ceiling((double)length / 8) * 8;
result += paddedLength;
}
else
{
result += length;
}
}
return result;
}
}
}

View file

@ -0,0 +1,53 @@
/* Copyright (C) 2014-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 System.Text;
using Utilities;
namespace SMBLibrary
{
/// <summary>
/// [MS-FSCC] 2.4.4 - FileAllocationInformation
/// </summary>
public class FileAllocationInformation : FileInformation
{
public const int FixedLength = 8;
public ulong AllocationSize;
public FileAllocationInformation()
{
}
public FileAllocationInformation(byte[] buffer, int offset)
{
AllocationSize = LittleEndianConverter.ToUInt64(buffer, offset);
}
public override void WriteBytes(byte[] buffer, int offset)
{
LittleEndianWriter.WriteUInt64(buffer, offset, AllocationSize);
}
public override FileInformationClass FileInformationClass
{
get
{
return FileInformationClass.FileAllocationInformation;
}
}
public override int Length
{
get
{
return FixedLength;
}
}
}
}

View file

@ -0,0 +1,53 @@
/* Copyright (C) 2014-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 System.Text;
using Utilities;
namespace SMBLibrary
{
/// <summary>
/// [MS-FSCC] 2.4.11 - FileDispositionInformation
/// </summary>
public class FileDispositionInformation : FileInformation
{
public const int FixedLength = 1;
public bool DeletePending;
public FileDispositionInformation()
{
}
public FileDispositionInformation(byte[] buffer, int offset)
{
DeletePending = Convert.ToBoolean(ByteReader.ReadByte(buffer, offset + 0));
}
public override void WriteBytes(byte[] buffer, int offset)
{
ByteWriter.WriteByte(buffer, offset + 0, Convert.ToByte(DeletePending));
}
public override FileInformationClass FileInformationClass
{
get
{
return FileInformationClass.FileDispositionInformation;
}
}
public override int Length
{
get
{
return FixedLength;
}
}
}
}

View file

@ -0,0 +1,53 @@
/* Copyright (C) 2014-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 System.Text;
using Utilities;
namespace SMBLibrary
{
/// <summary>
/// [MS-FSCC] 2.4.13 - FileEndOfFileInformation
/// </summary>
public class FileEndOfFileInformation : FileInformation
{
public const int FixedLength = 8;
public ulong EndOfFile;
public FileEndOfFileInformation()
{
}
public FileEndOfFileInformation(byte[] buffer, int offset)
{
EndOfFile = LittleEndianConverter.ToUInt64(buffer, offset);
}
public override void WriteBytes(byte[] buffer, int offset)
{
LittleEndianWriter.WriteUInt64(buffer, offset, EndOfFile);
}
public override FileInformationClass FileInformationClass
{
get
{
return FileInformationClass.FileEndOfFileInformation;
}
}
public override int Length
{
get
{
return FixedLength;
}
}
}
}

View file

@ -12,9 +12,9 @@ using Utilities;
namespace SMBLibrary
{
/// <summary>
/// [MS-FSCC] 2.4.15 - FILE_FULL_EA_INFORMATION
/// [MS-FSCC] 2.4.15 - FileFullEaInformation
/// </summary>
public class FileFullEAInformation
public class FileFullEAInformation : FileInformation
{
public const int FixedLength = 8;
@ -39,7 +39,7 @@ namespace SMBLibrary
EaValue = ByteReader.ReadAnsiString(buffer, ref offset, EaValueLength);
}
public void WriteBytes(byte[] buffer, int offset)
public override void WriteBytes(byte[] buffer, int offset)
{
EaNameLength = (byte)EaName.Length;
EaValueLength = (ushort)EaValue.Length;
@ -51,7 +51,15 @@ namespace SMBLibrary
ByteWriter.WriteAnsiString(buffer, ref offset, EaValue);
}
public int Length
public override FileInformationClass FileInformationClass
{
get
{
return FileInformationClass.FileFullEaInformation;
}
}
public override int Length
{
get
{

View file

@ -0,0 +1,64 @@
/* Copyright (C) 2014-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 System.Text;
using Utilities;
namespace SMBLibrary
{
/// <summary>
/// [MS-FSCC] 2.4.21.2 - FileLinkInformation Type 2
/// </summary>
public class FileLinkInformationType2 : FileInformation
{
public const int FixedLength = 20;
public bool ReplaceIfExists;
// 7 reserved bytes
public ulong RootDirectory;
private uint FileNameLength;
public string FileName = String.Empty;
public FileLinkInformationType2()
{
}
public FileLinkInformationType2(byte[] buffer, int offset)
{
ReplaceIfExists = Conversion.ToBoolean(ByteReader.ReadByte(buffer, offset + 0));
RootDirectory = LittleEndianConverter.ToUInt64(buffer, offset + 8);
FileNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 16);
FileName = ByteReader.ReadUTF16String(buffer, offset + 20, (int)FileNameLength / 2);
}
public override void WriteBytes(byte[] buffer, int offset)
{
FileNameLength = (uint)(FileName.Length * 2);
ByteWriter.WriteByte(buffer, offset + 0, Convert.ToByte(ReplaceIfExists));
LittleEndianWriter.WriteUInt64(buffer, offset + 8, RootDirectory);
LittleEndianWriter.WriteUInt32(buffer, offset + 16, FileNameLength);
ByteWriter.WriteUTF16String(buffer, offset + 20, FileName);
}
public override FileInformationClass FileInformationClass
{
get
{
return FileInformationClass.FileLinkInformation;
}
}
public override int Length
{
get
{
return FixedLength + FileName.Length * 2;
}
}
}
}

View file

@ -0,0 +1,64 @@
/* Copyright (C) 2014-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 System.Text;
using Utilities;
namespace SMBLibrary
{
/// <summary>
/// [MS-FSCC] 2.4.34.2 - FileRenameInformation Type 2
/// </summary>
public class FileRenameInformationType2 : FileInformation
{
public const int FixedLength = 20;
public bool ReplaceIfExists;
// 7 reserved bytes
public ulong RootDirectory;
private uint FileNameLength;
public string FileName = String.Empty;
public FileRenameInformationType2()
{
}
public FileRenameInformationType2(byte[] buffer, int offset)
{
ReplaceIfExists = Conversion.ToBoolean(ByteReader.ReadByte(buffer, offset + 0));
RootDirectory = LittleEndianConverter.ToUInt64(buffer, offset + 8);
FileNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 16);
FileName = ByteReader.ReadUTF16String(buffer, offset + 20, (int)FileNameLength / 2);
}
public override void WriteBytes(byte[] buffer, int offset)
{
FileNameLength = (uint)(FileName.Length * 2);
ByteWriter.WriteByte(buffer, offset + 0, Convert.ToByte(ReplaceIfExists));
LittleEndianWriter.WriteUInt64(buffer, offset + 8, RootDirectory);
LittleEndianWriter.WriteUInt32(buffer, offset + 16, FileNameLength);
ByteWriter.WriteUTF16String(buffer, offset + 20, FileName);
}
public override FileInformationClass FileInformationClass
{
get
{
return FileInformationClass.FileRenameInformation;
}
}
public override int Length
{
get
{
return FixedLength + FileName.Length * 2;
}
}
}
}

View file

@ -0,0 +1,53 @@
/* Copyright (C) 2014-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 System.Text;
using Utilities;
namespace SMBLibrary
{
/// <summary>
/// [MS-FSCC] 2.4.41 - FileValidDataLengthInformation
/// </summary>
public class FileValidDataLengthInformation : FileInformation
{
public const int FixedLength = 8;
public long ValidDataLength;
public FileValidDataLengthInformation()
{
}
public FileValidDataLengthInformation(byte[] buffer, int offset)
{
ValidDataLength = LittleEndianConverter.ToInt64(buffer, offset);
}
public override void WriteBytes(byte[] buffer, int offset)
{
LittleEndianWriter.WriteInt64(buffer, offset, ValidDataLength);
}
public override FileInformationClass FileInformationClass
{
get
{
return FileInformationClass.FileValidDataLengthInformation;
}
}
public override int Length
{
get
{
return FixedLength;
}
}
}
}

View file

@ -0,0 +1,66 @@
/* 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.5.1 - FileFsAttributeInformation
/// </summary>
public class FileFsAttributeInformation : FileSystemInformation
{
public const int FixedLength = 12;
public FileSystemAttributes FileSystemAttributes;
/// <summary>
/// Maximum file name component length, in bytes, supported by the specified file system.
/// The value of this field MUST be greater than zero and MUST be no more than 510.
/// </summary>
public uint MaximumComponentNameLength;
private uint FileSystemNameLength;
public string FileSystemName = String.Empty;
public FileFsAttributeInformation()
{
}
public FileFsAttributeInformation(byte[] buffer, int offset)
{
FileSystemAttributes = (FileSystemAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 0);
MaximumComponentNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 4);
FileSystemNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 8);
FileSystemName = ByteReader.ReadUTF16String(buffer, offset + 12, (int)FileSystemNameLength / 2);
}
public override void WriteBytes(byte[] buffer, int offset)
{
FileSystemNameLength = (uint)(FileSystemName.Length * 2);
LittleEndianWriter.WriteUInt32(buffer, offset + 0, (uint)FileSystemAttributes);
LittleEndianWriter.WriteUInt32(buffer, offset + 4, MaximumComponentNameLength);
LittleEndianWriter.WriteUInt32(buffer, offset + 8, FileSystemNameLength);
ByteWriter.WriteUTF16String(buffer, offset + 12, FileSystemName);
}
public override FileSystemInformationClass FileSystemInformationClass
{
get
{
return FileSystemInformationClass.FileFsAttributeInformation;
}
}
public override int Length
{
get
{
return FixedLength + FileSystemName.Length * 2;
}
}
}
}

View file

@ -0,0 +1,70 @@
/* 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.5.2 - FileFsControlInformation
/// </summary>
public class FileFsControlInformation : FileSystemInformation
{
public const int FixedLength = 48;
public long FreeSpaceStartFiltering;
public long FreeSpaceThreshold;
public long FreeSpaceStopFiltering;
public ulong DefaultQuotaThreshold;
public ulong DefaultQuotaLimit;
public FileSystemControlFlags FileSystemControlFlags;
public uint Padding;
public FileFsControlInformation()
{
}
public FileFsControlInformation(byte[] buffer, int offset)
{
FreeSpaceStartFiltering = LittleEndianConverter.ToInt64(buffer, offset + 0);
FreeSpaceThreshold = LittleEndianConverter.ToInt64(buffer, offset + 8);
FreeSpaceStopFiltering = LittleEndianConverter.ToInt64(buffer, offset + 16);
DefaultQuotaThreshold = LittleEndianConverter.ToUInt64(buffer, offset + 24);
DefaultQuotaLimit = LittleEndianConverter.ToUInt64(buffer, offset + 32);
FileSystemControlFlags = (FileSystemControlFlags)LittleEndianConverter.ToUInt32(buffer, offset + 40);
Padding = LittleEndianConverter.ToUInt32(buffer, offset + 44);
}
public override void WriteBytes(byte[] buffer, int offset)
{
LittleEndianWriter.WriteInt64(buffer, offset + 0, FreeSpaceStartFiltering);
LittleEndianWriter.WriteInt64(buffer, offset + 8, FreeSpaceThreshold);
LittleEndianWriter.WriteInt64(buffer, offset + 16, FreeSpaceStopFiltering);
LittleEndianWriter.WriteUInt64(buffer, offset + 24, DefaultQuotaThreshold);
LittleEndianWriter.WriteUInt64(buffer, offset + 32, DefaultQuotaLimit);
LittleEndianWriter.WriteUInt32(buffer, offset + 40, (uint)FileSystemControlFlags);
LittleEndianWriter.WriteUInt32(buffer, offset + 44, Padding);
}
public override FileSystemInformationClass FileSystemInformationClass
{
get
{
return FileSystemInformationClass.FileFsControlInformation;
}
}
public override int Length
{
get
{
return FixedLength;
}
}
}
}

View file

@ -0,0 +1,55 @@
/* 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.5.10 - FileFsDeviceInformation
/// </summary>
public class FileFsDeviceInformation : FileSystemInformation
{
public const int FixedLength = 8;
public DeviceType DeviceType;
public DeviceCharacteristics Characteristics;
public FileFsDeviceInformation()
{
}
public FileFsDeviceInformation(byte[] buffer, int offset)
{
DeviceType = (DeviceType)LittleEndianConverter.ToUInt32(buffer, offset + 0);
Characteristics = (DeviceCharacteristics)LittleEndianConverter.ToUInt32(buffer, offset + 4);
}
public override void WriteBytes(byte[] buffer, int offset)
{
LittleEndianWriter.WriteUInt32(buffer, offset + 0, (uint)DeviceType);
LittleEndianWriter.WriteUInt32(buffer, offset + 4, (uint)Characteristics);
}
public override FileSystemInformationClass FileSystemInformationClass
{
get
{
return FileSystemInformationClass.FileFsDeviceInformation;
}
}
public override int Length
{
get
{
return FixedLength;
}
}
}
}

View file

@ -0,0 +1,64 @@
/* 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.5.4 - FileFsFullSizeInformation
/// </summary>
public class FileFsFullSizeInformation : FileSystemInformation
{
public const int FixedLength = 32;
public long TotalAllocationUnits;
public long CallerAvailableAllocationUnits;
public long ActualAvailableAllocationUnits;
public uint SectorsPerAllocationUnit;
public uint BytesPerSector;
public FileFsFullSizeInformation()
{
}
public FileFsFullSizeInformation(byte[] buffer, int offset)
{
TotalAllocationUnits = LittleEndianConverter.ToInt64(buffer, offset + 0);
CallerAvailableAllocationUnits = LittleEndianConverter.ToInt64(buffer, offset + 8);
ActualAvailableAllocationUnits = LittleEndianConverter.ToInt64(buffer, offset + 16);
SectorsPerAllocationUnit = LittleEndianConverter.ToUInt32(buffer, offset + 24);
BytesPerSector = LittleEndianConverter.ToUInt32(buffer, offset + 28);
}
public override void WriteBytes(byte[] buffer, int offset)
{
LittleEndianWriter.WriteInt64(buffer, offset + 0, TotalAllocationUnits);
LittleEndianWriter.WriteInt64(buffer, offset + 8, CallerAvailableAllocationUnits);
LittleEndianWriter.WriteInt64(buffer, offset + 16, ActualAvailableAllocationUnits);
LittleEndianWriter.WriteUInt32(buffer, offset + 24, SectorsPerAllocationUnit);
LittleEndianWriter.WriteUInt32(buffer, offset + 28, BytesPerSector);
}
public override FileSystemInformationClass FileSystemInformationClass
{
get
{
return FileSystemInformationClass.FileFsFullSizeInformation;
}
}
public override int Length
{
get
{
return FixedLength;
}
}
}
}

View file

@ -0,0 +1,56 @@
/* 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.5.6 - FileFsObjectIdInformation
/// </summary>
public class FileFsObjectIdInformation : FileSystemInformation
{
public const int FixedLength = 64;
public Guid ObjectID;
public byte[] ExtendedInfo; //48 bytes
public FileFsObjectIdInformation()
{
ExtendedInfo = new byte[48];
}
public FileFsObjectIdInformation(byte[] buffer, int offset)
{
LittleEndianConverter.ToGuid(buffer, offset + 0);
ExtendedInfo = ByteReader.ReadBytes(buffer, offset + 16, 48);
}
public override void WriteBytes(byte[] buffer, int offset)
{
LittleEndianWriter.WriteGuidBytes(buffer, offset + 0, ObjectID);
ByteWriter.WriteBytes(buffer, offset + 16, ExtendedInfo);
}
public override FileSystemInformationClass FileSystemInformationClass
{
get
{
return FileSystemInformationClass.FileFsObjectIdInformation;
}
}
public override int Length
{
get
{
return FixedLength;
}
}
}
}

View file

@ -0,0 +1,70 @@
/* 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.5.4 - FileFsSectorSizeInformation
/// </summary>
public class FileFsSectorSizeInformation : FileSystemInformation
{
public const int FixedLength = 28;
public uint LogicalBytesPerSector;
public uint PhysicalBytesPerSectorForAtomicity;
public uint PhysicalBytesPerSectorForPerformance;
public uint FileSystemEffectivePhysicalBytesPerSectorForAtomicity;
public SectorSizeInformationFlags Flags;
public uint ByteOffsetForSectorAlignment;
public uint ByteOffsetForPartitionAlignment;
public FileFsSectorSizeInformation()
{
}
public FileFsSectorSizeInformation(byte[] buffer, int offset)
{
LogicalBytesPerSector = LittleEndianConverter.ToUInt32(buffer, offset + 0);
PhysicalBytesPerSectorForAtomicity = LittleEndianConverter.ToUInt32(buffer, offset + 4);
PhysicalBytesPerSectorForPerformance = LittleEndianConverter.ToUInt32(buffer, offset + 8);
FileSystemEffectivePhysicalBytesPerSectorForAtomicity = LittleEndianConverter.ToUInt32(buffer, offset + 12);
Flags = (SectorSizeInformationFlags)LittleEndianConverter.ToUInt32(buffer, offset + 16);
ByteOffsetForSectorAlignment = LittleEndianConverter.ToUInt32(buffer, offset + 20);
ByteOffsetForPartitionAlignment = LittleEndianConverter.ToUInt32(buffer, offset + 24);
}
public override void WriteBytes(byte[] buffer, int offset)
{
LittleEndianWriter.WriteUInt32(buffer, offset + 0, LogicalBytesPerSector);
LittleEndianWriter.WriteUInt32(buffer, offset + 4, PhysicalBytesPerSectorForAtomicity);
LittleEndianWriter.WriteUInt32(buffer, offset + 8, PhysicalBytesPerSectorForPerformance);
LittleEndianWriter.WriteUInt32(buffer, offset + 12, FileSystemEffectivePhysicalBytesPerSectorForAtomicity);
LittleEndianWriter.WriteUInt32(buffer, offset + 16, (uint)Flags);
LittleEndianWriter.WriteUInt32(buffer, offset + 20, ByteOffsetForSectorAlignment);
LittleEndianWriter.WriteUInt32(buffer, offset + 24, ByteOffsetForPartitionAlignment);
}
public override FileSystemInformationClass FileSystemInformationClass
{
get
{
return FileSystemInformationClass.FileFsSectorSizeInformation;
}
}
public override int Length
{
get
{
return FixedLength;
}
}
}
}

View file

@ -0,0 +1,61 @@
/* 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.5.8 - FileFsSizeInformation
/// </summary>
public class FileFsSizeInformation : FileSystemInformation
{
public const int FixedLength = 24;
public long TotalAllocationUnits;
public long AvailableAllocationUnits;
public uint SectorsPerAllocationUnit;
public uint BytesPerSector;
public FileFsSizeInformation()
{
}
public FileFsSizeInformation(byte[] buffer, int offset)
{
TotalAllocationUnits = LittleEndianConverter.ToInt64(buffer, offset + 0);
AvailableAllocationUnits = LittleEndianConverter.ToInt64(buffer, offset + 8);
SectorsPerAllocationUnit = LittleEndianConverter.ToUInt32(buffer, offset + 16);
BytesPerSector = LittleEndianConverter.ToUInt32(buffer, offset + 20);
}
public override void WriteBytes(byte[] buffer, int offset)
{
LittleEndianWriter.WriteInt64(buffer, offset + 0, TotalAllocationUnits);
LittleEndianWriter.WriteInt64(buffer, offset + 8, AvailableAllocationUnits);
LittleEndianWriter.WriteUInt32(buffer, offset + 16, SectorsPerAllocationUnit);
LittleEndianWriter.WriteUInt32(buffer, offset + 20, BytesPerSector);
}
public override FileSystemInformationClass FileSystemInformationClass
{
get
{
return FileSystemInformationClass.FileFsSizeInformation;
}
}
public override int Length
{
get
{
return FixedLength;
}
}
}
}

View file

@ -0,0 +1,71 @@
/* 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.5.9 - FileFsVolumeInformation
/// </summary>
public class FileFsVolumeInformation : FileSystemInformation
{
public const int FixedLength = 18;
public DateTime? VolumeCreationTime;
public uint VolumeSerialNumber;
private uint VolumeLabelLength;
public bool SupportsObjects;
public byte Reserved;
public string VolumeLabel = String.Empty;
public FileFsVolumeInformation()
{
}
public FileFsVolumeInformation(byte[] buffer, int offset)
{
VolumeCreationTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 0);
VolumeSerialNumber = LittleEndianConverter.ToUInt32(buffer, offset + 8);
VolumeLabelLength = LittleEndianConverter.ToUInt32(buffer, offset + 12);
SupportsObjects = Convert.ToBoolean(ByteReader.ReadByte(buffer, offset + 16));
Reserved = ByteReader.ReadByte(buffer, offset + 17);
if (VolumeLabelLength > 0)
{
VolumeLabel = ByteReader.ReadUTF16String(buffer, offset + 18, (int)VolumeLabelLength / 2);
}
}
public override void WriteBytes(byte[] buffer, int offset)
{
VolumeLabelLength = (uint)(VolumeLabel.Length * 2);
FileTimeHelper.WriteFileTime(buffer, offset + 0, VolumeCreationTime);
LittleEndianWriter.WriteUInt32(buffer, offset + 8, VolumeSerialNumber);
LittleEndianWriter.WriteUInt32(buffer, offset + 12, VolumeLabelLength);
ByteWriter.WriteByte(buffer, offset + 16, Convert.ToByte(SupportsObjects));
ByteWriter.WriteByte(buffer, offset + 17, Reserved);
ByteWriter.WriteUTF16String(buffer, offset + 18, VolumeLabel);
}
public override FileSystemInformationClass FileSystemInformationClass
{
get
{
return FileSystemInformationClass.FileFsVolumeInformation;
}
}
public override int Length
{
get
{
return FixedLength + VolumeLabel.Length * 2;
}
}
}
}

View file

@ -0,0 +1,34 @@
/* 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
{
public abstract class FileSystemInformation
{
public abstract void WriteBytes(byte[] buffer, int offset);
public byte[] GetBytes()
{
byte[] buffer = new byte[this.Length];
WriteBytes(buffer, 0);
return buffer;
}
public abstract FileSystemInformationClass FileSystemInformationClass
{
get;
}
public abstract int Length
{
get;
}
}
}