FindInformation was renamed to FindInformationList, FindInformationEntry was renamed to FindInformation

This commit is contained in:
Tal Aloni 2017-01-06 22:28:01 +02:00
parent e0c0bc6ae6
commit b892bd9018
15 changed files with 125 additions and 125 deletions

View file

@ -14,7 +14,7 @@ namespace SMBLibrary.SMB1
/// <summary> /// <summary>
/// SMB_FIND_FILE_BOTH_DIRECTORY_INFO /// SMB_FIND_FILE_BOTH_DIRECTORY_INFO
/// </summary> /// </summary>
public class FindFileBothDirectoryInfo : FindInformationEntry public class FindFileBothDirectoryInfo : FindInformation
{ {
public const int FixedLength = 94; public const int FixedLength = 94;

View file

@ -14,7 +14,7 @@ namespace SMBLibrary.SMB1
/// <summary> /// <summary>
/// SMB_FIND_FILE_DIRECTORY_INFO /// SMB_FIND_FILE_DIRECTORY_INFO
/// </summary> /// </summary>
public class FindFileDirectoryInfo : FindInformationEntry public class FindFileDirectoryInfo : FindInformation
{ {
public const int FixedLength = 64; public const int FixedLength = 64;

View file

@ -14,7 +14,7 @@ namespace SMBLibrary.SMB1
/// <summary> /// <summary>
/// SMB_FIND_FILE_FULL_DIRECTORY_INFO /// SMB_FIND_FILE_FULL_DIRECTORY_INFO
/// </summary> /// </summary>
public class FindFileFullDirectoryInfo : FindInformationEntry public class FindFileFullDirectoryInfo : FindInformation
{ {
public const int FixedLength = 68; public const int FixedLength = 68;

View file

@ -14,7 +14,7 @@ namespace SMBLibrary.SMB1
/// <summary> /// <summary>
/// SMB_FIND_FILE_NAMES_INFO /// SMB_FIND_FILE_NAMES_INFO
/// </summary> /// </summary>
public class FindFileNamesInfo : FindInformationEntry public class FindFileNamesInfo : FindInformation
{ {
public const int FixedLength = 12; public const int FixedLength = 12;

View file

@ -14,7 +14,7 @@ namespace SMBLibrary.SMB1
/// <summary> /// <summary>
/// SMB_INFO_QUERY_EA_SIZE /// SMB_INFO_QUERY_EA_SIZE
/// </summary> /// </summary>
public class FindInfoQueryEASize : FindInformationEntry public class FindInfoQueryEASize : FindInformation
{ {
public uint ResumeKey; // Optional public uint ResumeKey; // Optional
public DateTime CreationDateTime; public DateTime CreationDateTime;

View file

@ -14,7 +14,7 @@ namespace SMBLibrary.SMB1
/// <summary> /// <summary>
/// SMB_INFO_QUERY_EAS_FROM_LIST /// SMB_INFO_QUERY_EAS_FROM_LIST
/// </summary> /// </summary>
public class FindInfoQueryExtendedAttributesFromList : FindInformationEntry public class FindInfoQueryExtendedAttributesFromList : FindInformation
{ {
public uint ResumeKey; // Optional public uint ResumeKey; // Optional
public DateTime CreationDateTime; public DateTime CreationDateTime;

View file

@ -14,7 +14,7 @@ namespace SMBLibrary.SMB1
/// <summary> /// <summary>
/// SMB_INFO_STANDARD /// SMB_INFO_STANDARD
/// </summary> /// </summary>
public class FindInfoStandard : FindInformationEntry public class FindInfoStandard : FindInformation
{ {
public const int FixedLength = 23; public const int FixedLength = 23;

View file

@ -7,72 +7,51 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using Utilities;
namespace SMBLibrary.SMB1 namespace SMBLibrary.SMB1
{ {
public class FindInformation : List<FindInformationEntry> public abstract class FindInformation
{ {
public FindInformation() private bool m_returnResumeKeys;
public FindInformation(bool returnResumeKeys)
{ {
m_returnResumeKeys = returnResumeKeys;
} }
public FindInformation(byte[] buffer, FindInformationLevel informationLevel, bool isUnicode, bool returnResumeKeys) public abstract void WriteBytes(byte[] buffer, ref int offset, bool isUnicode);
public abstract int GetLength(bool isUnicode);
public bool ReturnResumeKeys
{ {
int offset = 0; get
while (offset < buffer.Length)
{ {
FindInformationEntry entry = FindInformationEntry.ReadEntry(buffer, ref offset, informationLevel, isUnicode, returnResumeKeys); return m_returnResumeKeys;
this.Add(entry);
} }
} }
public byte[] GetBytes(bool isUnicode) public static FindInformation ReadEntry(byte[] buffer, ref int offset, FindInformationLevel informationLevel, bool isUnicode, bool returnResumeKeys)
{ {
for(int index = 0; index < this.Count; index++) switch (informationLevel)
{ {
if (index < this.Count - 1) case FindInformationLevel.SMB_INFO_STANDARD:
{ return new FindInfoStandard(buffer, ref offset, isUnicode, returnResumeKeys);
FindInformationEntry entry = this[index]; case FindInformationLevel.SMB_INFO_QUERY_EA_SIZE:
int entryLength = entry.GetLength(isUnicode); return new FindInfoQueryEASize(buffer, ref offset, isUnicode, returnResumeKeys);
if (entry is FindFileBothDirectoryInfo) case FindInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST:
{ return new FindInfoQueryExtendedAttributesFromList(buffer, ref offset, isUnicode, returnResumeKeys);
((FindFileBothDirectoryInfo)entry).NextEntryOffset = (uint)entryLength; case FindInformationLevel.SMB_FIND_FILE_DIRECTORY_INFO:
} return new FindFileDirectoryInfo(buffer, ref offset, isUnicode);
else if (entry is FindFileDirectoryInfo) case FindInformationLevel.SMB_FIND_FILE_FULL_DIRECTORY_INFO:
{ return new FindFileFullDirectoryInfo(buffer, ref offset, isUnicode);
((FindFileDirectoryInfo)entry).NextEntryOffset = (uint)entryLength; case FindInformationLevel.SMB_FIND_FILE_NAMES_INFO:
} return new FindFileNamesInfo(buffer, ref offset, isUnicode);
else if (entry is FindFileFullDirectoryInfo) case FindInformationLevel.SMB_FIND_FILE_BOTH_DIRECTORY_INFO:
{ return new FindFileBothDirectoryInfo(buffer, ref offset, isUnicode);
((FindFileFullDirectoryInfo)entry).NextEntryOffset = (uint)entryLength; default:
} throw new InvalidRequestException();;
else if (entry is FindFileNamesInfo)
{
((FindFileNamesInfo)entry).NextEntryOffset = (uint)entryLength;
} }
} }
} }
int length = GetLength(isUnicode);
byte[] buffer = new byte[length];
int offset = 0;
foreach (FindInformationEntry entry in this)
{
entry.WriteBytes(buffer, ref offset, isUnicode);
}
return buffer;
}
public int GetLength(bool isUnicode)
{
int length = 0;
for (int index = 0; index < this.Count; index++)
{
FindInformationEntry entry = this[index];
int entryLength = entry.GetLength(isUnicode);
length += entryLength;
}
return length;
}
}
} }

View file

@ -1,57 +0,0 @@
/* Copyright (C) 2014 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;
namespace SMBLibrary.SMB1
{
public abstract class FindInformationEntry
{
private bool m_returnResumeKeys;
public FindInformationEntry(bool returnResumeKeys)
{
m_returnResumeKeys = returnResumeKeys;
}
public abstract void WriteBytes(byte[] buffer, ref int offset, bool isUnicode);
public abstract int GetLength(bool isUnicode);
public bool ReturnResumeKeys
{
get
{
return m_returnResumeKeys;
}
}
public static FindInformationEntry ReadEntry(byte[] buffer, ref int offset, FindInformationLevel informationLevel, bool isUnicode, bool returnResumeKeys)
{
switch (informationLevel)
{
case FindInformationLevel.SMB_INFO_STANDARD:
return new FindInfoStandard(buffer, ref offset, isUnicode, returnResumeKeys);
case FindInformationLevel.SMB_INFO_QUERY_EA_SIZE:
return new FindInfoQueryEASize(buffer, ref offset, isUnicode, returnResumeKeys);
case FindInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST:
return new FindInfoQueryExtendedAttributesFromList(buffer, ref offset, isUnicode, returnResumeKeys);
case FindInformationLevel.SMB_FIND_FILE_DIRECTORY_INFO:
return new FindFileDirectoryInfo(buffer, ref offset, isUnicode);
case FindInformationLevel.SMB_FIND_FILE_FULL_DIRECTORY_INFO:
return new FindFileFullDirectoryInfo(buffer, ref offset, isUnicode);
case FindInformationLevel.SMB_FIND_FILE_NAMES_INFO:
return new FindFileNamesInfo(buffer, ref offset, isUnicode);
case FindInformationLevel.SMB_FIND_FILE_BOTH_DIRECTORY_INFO:
return new FindFileBothDirectoryInfo(buffer, ref offset, isUnicode);
default:
throw new InvalidRequestException();;
}
}
}
}

View file

@ -0,0 +1,78 @@
/* Copyright (C) 2014 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.SMB1
{
public class FindInformationList : List<FindInformation>
{
public FindInformationList()
{
}
public FindInformationList(byte[] buffer, FindInformationLevel informationLevel, bool isUnicode, bool returnResumeKeys)
{
int offset = 0;
while (offset < buffer.Length)
{
FindInformation entry = FindInformation.ReadEntry(buffer, ref offset, informationLevel, isUnicode, returnResumeKeys);
this.Add(entry);
}
}
public byte[] GetBytes(bool isUnicode)
{
for(int index = 0; index < this.Count; index++)
{
if (index < this.Count - 1)
{
FindInformation entry = this[index];
int entryLength = entry.GetLength(isUnicode);
if (entry is FindFileBothDirectoryInfo)
{
((FindFileBothDirectoryInfo)entry).NextEntryOffset = (uint)entryLength;
}
else if (entry is FindFileDirectoryInfo)
{
((FindFileDirectoryInfo)entry).NextEntryOffset = (uint)entryLength;
}
else if (entry is FindFileFullDirectoryInfo)
{
((FindFileFullDirectoryInfo)entry).NextEntryOffset = (uint)entryLength;
}
else if (entry is FindFileNamesInfo)
{
((FindFileNamesInfo)entry).NextEntryOffset = (uint)entryLength;
}
}
}
int length = GetLength(isUnicode);
byte[] buffer = new byte[length];
int offset = 0;
foreach (FindInformation entry in this)
{
entry.WriteBytes(buffer, ref offset, isUnicode);
}
return buffer;
}
public int GetLength(bool isUnicode)
{
int length = 0;
for (int index = 0; index < this.Count; index++)
{
FindInformation entry = this[index];
int entryLength = entry.GetLength(isUnicode);
length += entryLength;
}
return length;
}
}
}

View file

@ -24,11 +24,11 @@ namespace SMBLibrary.SMB1
public ushort EaErrorOffset; public ushort EaErrorOffset;
public ushort LastNameOffset; public ushort LastNameOffset;
// Data: // Data:
public FindInformation FindInfoList; public FindInformationList FindInfoList;
public Transaction2FindFirst2Response() : base() public Transaction2FindFirst2Response() : base()
{ {
FindInfoList = new FindInformation(); FindInfoList = new FindInformationList();
} }
public Transaction2FindFirst2Response(byte[] parameters, byte[] data, FindInformationLevel informationLevel, bool isUnicode, bool returnResumeKeys) : base() public Transaction2FindFirst2Response(byte[] parameters, byte[] data, FindInformationLevel informationLevel, bool isUnicode, bool returnResumeKeys) : base()
@ -39,7 +39,7 @@ namespace SMBLibrary.SMB1
EaErrorOffset = LittleEndianConverter.ToUInt16(parameters, 6); EaErrorOffset = LittleEndianConverter.ToUInt16(parameters, 6);
LastNameOffset = LittleEndianConverter.ToUInt16(parameters, 8); LastNameOffset = LittleEndianConverter.ToUInt16(parameters, 8);
FindInfoList = new FindInformation(data, informationLevel, isUnicode, returnResumeKeys); FindInfoList = new FindInformationList(data, informationLevel, isUnicode, returnResumeKeys);
} }
public override byte[] GetParameters(bool isUnicode) public override byte[] GetParameters(bool isUnicode)

View file

@ -23,11 +23,11 @@ namespace SMBLibrary.SMB1
public ushort EaErrorOffset; public ushort EaErrorOffset;
public ushort LastNameOffset; public ushort LastNameOffset;
// Data: // Data:
public FindInformation FindInfoList; public FindInformationList FindInfoList;
public Transaction2FindNext2Response() : base() public Transaction2FindNext2Response() : base()
{ {
FindInfoList = new FindInformation(); FindInfoList = new FindInformationList();
} }
public Transaction2FindNext2Response(byte[] parameters, byte[] data, FindInformationLevel informationLevel, bool isUnicode, bool returnResumeKeys) : base() public Transaction2FindNext2Response(byte[] parameters, byte[] data, FindInformationLevel informationLevel, bool isUnicode, bool returnResumeKeys) : base()
@ -37,7 +37,7 @@ namespace SMBLibrary.SMB1
EaErrorOffset = LittleEndianConverter.ToUInt16(parameters, 4); EaErrorOffset = LittleEndianConverter.ToUInt16(parameters, 4);
LastNameOffset = LittleEndianConverter.ToUInt16(parameters, 6); LastNameOffset = LittleEndianConverter.ToUInt16(parameters, 6);
FindInfoList = new FindInformation(data, informationLevel, isUnicode, returnResumeKeys); FindInfoList = new FindInformationList(data, informationLevel, isUnicode, returnResumeKeys);
} }
public override byte[] GetParameters(bool isUnicode) public override byte[] GetParameters(bool isUnicode)

View file

@ -296,7 +296,7 @@
<Compile Include="SMB1\Transaction2Subcommands\Structures\FindInformation\FindInfoQueryEASize.cs" /> <Compile Include="SMB1\Transaction2Subcommands\Structures\FindInformation\FindInfoQueryEASize.cs" />
<Compile Include="SMB1\Transaction2Subcommands\Structures\FindInformation\FindInfoQueryExtendedAttributesFromList.cs" /> <Compile Include="SMB1\Transaction2Subcommands\Structures\FindInformation\FindInfoQueryExtendedAttributesFromList.cs" />
<Compile Include="SMB1\Transaction2Subcommands\Structures\FindInformation\FindInformation.cs" /> <Compile Include="SMB1\Transaction2Subcommands\Structures\FindInformation\FindInformation.cs" />
<Compile Include="SMB1\Transaction2Subcommands\Structures\FindInformation\FindInformationEntry.cs" /> <Compile Include="SMB1\Transaction2Subcommands\Structures\FindInformation\FindInformationList.cs" />
<Compile Include="SMB1\Transaction2Subcommands\Structures\FindInformation\FindInfoStandard.cs" /> <Compile Include="SMB1\Transaction2Subcommands\Structures\FindInformation\FindInfoStandard.cs" />
<Compile Include="SMB1\Transaction2Subcommands\Structures\FullExtendedAttribute.cs" /> <Compile Include="SMB1\Transaction2Subcommands\Structures\FullExtendedAttribute.cs" />
<Compile Include="SMB1\Transaction2Subcommands\Structures\FullExtendedAttributeList.cs" /> <Compile Include="SMB1\Transaction2Subcommands\Structures\FullExtendedAttributeList.cs" />

View file

@ -17,7 +17,7 @@ namespace SMBLibrary.Server
public const int BytesPerSector = 512; public const int BytesPerSector = 512;
public const int ClusterSize = 4096; public const int ClusterSize = 4096;
internal static FindInformationEntry FromFileSystemEntry(FileSystemEntry entry, FindInformationLevel informationLevel, bool isUnicode, bool returnResumeKeys) internal static FindInformation FromFileSystemEntry(FileSystemEntry entry, FindInformationLevel informationLevel, bool isUnicode, bool returnResumeKeys)
{ {
switch (informationLevel) switch (informationLevel)
{ {

View file

@ -104,7 +104,7 @@ namespace SMBLibrary.Server
Transaction2FindFirst2Response response = new Transaction2FindFirst2Response(); Transaction2FindFirst2Response response = new Transaction2FindFirst2Response();
for (int index = 0; index < entriesToReturn; index++) for (int index = 0; index < entriesToReturn; index++)
{ {
FindInformationEntry infoEntry = InfoHelper.FromFileSystemEntry(entries[index], subcommand.InformationLevel, header.UnicodeFlag, returnResumeKeys); FindInformation infoEntry = InfoHelper.FromFileSystemEntry(entries[index], subcommand.InformationLevel, header.UnicodeFlag, returnResumeKeys);
response.FindInfoList.Add(infoEntry); response.FindInfoList.Add(infoEntry);
if (response.FindInfoList.GetLength(header.UnicodeFlag) > state.GetMaxDataCount(header.PID)) if (response.FindInfoList.GetLength(header.UnicodeFlag) > state.GetMaxDataCount(header.PID))
{ {
@ -204,7 +204,7 @@ namespace SMBLibrary.Server
List<FileSystemEntry> entries = state.OpenSearches[subcommand.SID]; List<FileSystemEntry> entries = state.OpenSearches[subcommand.SID];
for (int index = 0; index < entries.Count; index++) for (int index = 0; index < entries.Count; index++)
{ {
FindInformationEntry infoEntry = InfoHelper.FromFileSystemEntry(entries[index], subcommand.InformationLevel, header.UnicodeFlag, returnResumeKeys); FindInformation infoEntry = InfoHelper.FromFileSystemEntry(entries[index], subcommand.InformationLevel, header.UnicodeFlag, returnResumeKeys);
response.FindInfoList.Add(infoEntry); response.FindInfoList.Add(infoEntry);
if (response.FindInfoList.GetLength(header.UnicodeFlag) > state.GetMaxDataCount(header.PID)) if (response.FindInfoList.GetLength(header.UnicodeFlag) > state.GetMaxDataCount(header.PID))
{ {