mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-07-03 16:23:19 +02:00
SMB1: Improved FindInformation / QueryFSInformation implementations
This commit is contained in:
parent
a3017c1b50
commit
a8ccae65ad
11 changed files with 120 additions and 17 deletions
|
@ -98,5 +98,13 @@ namespace SMBLibrary.SMB1
|
||||||
}
|
}
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override FindInformationLevel InformationLevel
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return FindInformationLevel.SMB_FIND_FILE_BOTH_DIRECTORY_INFO;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,5 +80,13 @@ namespace SMBLibrary.SMB1
|
||||||
}
|
}
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override FindInformationLevel InformationLevel
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return FindInformationLevel.SMB_FIND_FILE_DIRECTORY_INFO;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,5 +83,13 @@ namespace SMBLibrary.SMB1
|
||||||
}
|
}
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override FindInformationLevel InformationLevel
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return FindInformationLevel.SMB_FIND_FILE_FULL_DIRECTORY_INFO;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 2014 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
/* 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
|
* 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,
|
* the GNU Lesser Public License as published by the Free Software Foundation,
|
||||||
|
@ -59,5 +59,13 @@ namespace SMBLibrary.SMB1
|
||||||
}
|
}
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override FindInformationLevel InformationLevel
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return FindInformationLevel.SMB_FIND_FILE_NAMES_INFO;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 2014 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
/* 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
|
* 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,
|
* the GNU Lesser Public License as published by the Free Software Foundation,
|
||||||
|
@ -31,6 +31,11 @@ namespace SMBLibrary.SMB1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract FindInformationLevel InformationLevel
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
}
|
||||||
|
|
||||||
public static FindInformation ReadEntry(byte[] buffer, ref int offset, FindInformationLevel informationLevel, bool isUnicode, bool returnResumeKeys)
|
public static FindInformation ReadEntry(byte[] buffer, ref int offset, FindInformationLevel informationLevel, bool isUnicode, bool returnResumeKeys)
|
||||||
{
|
{
|
||||||
switch (informationLevel)
|
switch (informationLevel)
|
||||||
|
@ -44,7 +49,7 @@ namespace SMBLibrary.SMB1
|
||||||
case FindInformationLevel.SMB_FIND_FILE_BOTH_DIRECTORY_INFO:
|
case FindInformationLevel.SMB_FIND_FILE_BOTH_DIRECTORY_INFO:
|
||||||
return new FindFileBothDirectoryInfo(buffer, ref offset, isUnicode);
|
return new FindFileBothDirectoryInfo(buffer, ref offset, isUnicode);
|
||||||
default:
|
default:
|
||||||
throw new InvalidRequestException();;
|
throw new UnsupportedInformationLevelException();;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 2014 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
/* 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
|
* 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,
|
* the GNU Lesser Public License as published by the Free Software Foundation,
|
||||||
|
@ -46,12 +46,20 @@ namespace SMBLibrary.SMB1
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Length
|
public override int Length
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return FixedLength + FileSystemName.Length * 2;
|
return FixedLength + FileSystemName.Length * 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override QueryFSInformationLevel InformationLevel
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return QueryFSInformationLevel.SMB_QUERY_FS_ATTRIBUTE_INFO;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 2014 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
/* 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
|
* 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,
|
* the GNU Lesser Public License as published by the Free Software Foundation,
|
||||||
|
@ -16,7 +16,7 @@ namespace SMBLibrary.SMB1
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class QueryFSDeviceInfo : QueryFSInformation
|
public class QueryFSDeviceInfo : QueryFSInformation
|
||||||
{
|
{
|
||||||
public const int Length = 8;
|
public const int FixedLength = 8;
|
||||||
|
|
||||||
public DeviceType DeviceType;
|
public DeviceType DeviceType;
|
||||||
public DeviceCharacteristics DeviceCharacteristics;
|
public DeviceCharacteristics DeviceCharacteristics;
|
||||||
|
@ -38,5 +38,21 @@ namespace SMBLibrary.SMB1
|
||||||
LittleEndianWriter.WriteUInt32(buffer, 4, (uint)DeviceCharacteristics);
|
LittleEndianWriter.WriteUInt32(buffer, 4, (uint)DeviceCharacteristics);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override int Length
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return FixedLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override QueryFSInformationLevel InformationLevel
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return QueryFSInformationLevel.SMB_QUERY_FS_DEVICE_INFO;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 2014 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
/* 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
|
* 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,
|
* the GNU Lesser Public License as published by the Free Software Foundation,
|
||||||
|
@ -15,6 +15,16 @@ namespace SMBLibrary.SMB1
|
||||||
{
|
{
|
||||||
public abstract byte[] GetBytes(bool isUnicode);
|
public abstract byte[] GetBytes(bool isUnicode);
|
||||||
|
|
||||||
|
public abstract int Length
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract QueryFSInformationLevel InformationLevel
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
}
|
||||||
|
|
||||||
public static QueryFSInformation GetQueryFSInformation(byte[] buffer, QueryFSInformationLevel informationLevel, bool isUnicode)
|
public static QueryFSInformation GetQueryFSInformation(byte[] buffer, QueryFSInformationLevel informationLevel, bool isUnicode)
|
||||||
{
|
{
|
||||||
switch (informationLevel)
|
switch (informationLevel)
|
||||||
|
@ -28,7 +38,7 @@ namespace SMBLibrary.SMB1
|
||||||
case QueryFSInformationLevel.SMB_QUERY_FS_ATTRIBUTE_INFO:
|
case QueryFSInformationLevel.SMB_QUERY_FS_ATTRIBUTE_INFO:
|
||||||
return new QueryFSAttibuteInfo(buffer, 0);
|
return new QueryFSAttibuteInfo(buffer, 0);
|
||||||
default:
|
default:
|
||||||
throw new InvalidRequestException();
|
throw new UnsupportedInformationLevelException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace SMBLibrary.SMB1
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class QueryFSSizeInfo : QueryFSInformation
|
public class QueryFSSizeInfo : QueryFSInformation
|
||||||
{
|
{
|
||||||
public const int Length = 24;
|
public const int FixedLength = 24;
|
||||||
|
|
||||||
public long TotalAllocationUnits;
|
public long TotalAllocationUnits;
|
||||||
public long TotalFreeAllocationUnits;
|
public long TotalFreeAllocationUnits;
|
||||||
|
@ -44,5 +44,21 @@ namespace SMBLibrary.SMB1
|
||||||
LittleEndianWriter.WriteUInt32(buffer, 20, BytesPerSector);
|
LittleEndianWriter.WriteUInt32(buffer, 20, BytesPerSector);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override int Length
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return FixedLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override QueryFSInformationLevel InformationLevel
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return QueryFSInformationLevel.SMB_QUERY_FS_SIZE_INFO;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace SMBLibrary.SMB1
|
||||||
|
|
||||||
public DateTime? VolumeCreationTime;
|
public DateTime? VolumeCreationTime;
|
||||||
public uint SerialNumber;
|
public uint SerialNumber;
|
||||||
//uint VolumeLabelSize;
|
private uint VolumeLabelSize;
|
||||||
public ushort Reserved;
|
public ushort Reserved;
|
||||||
public string VolumeLabel; // Unicode
|
public string VolumeLabel; // Unicode
|
||||||
|
|
||||||
|
@ -33,22 +33,38 @@ namespace SMBLibrary.SMB1
|
||||||
{
|
{
|
||||||
VolumeCreationTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 0);
|
VolumeCreationTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 0);
|
||||||
SerialNumber = LittleEndianConverter.ToUInt32(buffer, offset + 8);
|
SerialNumber = LittleEndianConverter.ToUInt32(buffer, offset + 8);
|
||||||
uint volumeLabelSize = LittleEndianConverter.ToUInt32(buffer, offset + 12);
|
VolumeLabelSize = LittleEndianConverter.ToUInt32(buffer, offset + 12);
|
||||||
Reserved = LittleEndianConverter.ToUInt16(buffer, offset + 16);
|
Reserved = LittleEndianConverter.ToUInt16(buffer, offset + 16);
|
||||||
VolumeLabel = ByteReader.ReadUTF16String(buffer, offset + 18, (int)volumeLabelSize);
|
VolumeLabel = ByteReader.ReadUTF16String(buffer, offset + 18, (int)VolumeLabelSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetBytes(bool isUnicode)
|
public override byte[] GetBytes(bool isUnicode)
|
||||||
{
|
{
|
||||||
uint volumeLabelSize = (uint)(VolumeLabel.Length * 2);
|
VolumeLabelSize = (uint)(VolumeLabel.Length * 2);
|
||||||
|
|
||||||
byte[] buffer = new byte[FixedLength + volumeLabelSize];
|
byte[] buffer = new byte[this.Length];
|
||||||
FileTimeHelper.WriteFileTime(buffer, 0, VolumeCreationTime);
|
FileTimeHelper.WriteFileTime(buffer, 0, VolumeCreationTime);
|
||||||
LittleEndianWriter.WriteUInt32(buffer, 8, SerialNumber);
|
LittleEndianWriter.WriteUInt32(buffer, 8, SerialNumber);
|
||||||
LittleEndianWriter.WriteUInt32(buffer, 12, volumeLabelSize);
|
LittleEndianWriter.WriteUInt32(buffer, 12, VolumeLabelSize);
|
||||||
LittleEndianWriter.WriteUInt16(buffer, 16, Reserved);
|
LittleEndianWriter.WriteUInt16(buffer, 16, Reserved);
|
||||||
ByteWriter.WriteUTF16String(buffer, 18, VolumeLabel);
|
ByteWriter.WriteUTF16String(buffer, 18, VolumeLabel);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override int Length
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return FixedLength + VolumeLabel.Length * 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override QueryFSInformationLevel InformationLevel
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return QueryFSInformationLevel.SMB_QUERY_FS_VOLUME_INFO;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace SMBLibrary.SMB1
|
||||||
case QueryInformationLevel.SMB_QUERY_FILE_COMPRESSION_INFO:
|
case QueryInformationLevel.SMB_QUERY_FILE_COMPRESSION_INFO:
|
||||||
return new QueryFileCompressionInfo(buffer, 0);
|
return new QueryFileCompressionInfo(buffer, 0);
|
||||||
default:
|
default:
|
||||||
throw new InvalidRequestException();
|
throw new UnsupportedInformationLevelException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue