mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-08-16 20:23:47 +02:00
FileBasicInformation, SMB_SET_FILE_BASIC_INFO: Added support for FILETIME value of -1
This commit is contained in:
parent
c3a88d59ab
commit
0098cc78f5
5 changed files with 127 additions and 30 deletions
|
@ -12,7 +12,7 @@ namespace SMBLibrary
|
||||||
{
|
{
|
||||||
public class FileTimeHelper
|
public class FileTimeHelper
|
||||||
{
|
{
|
||||||
public static readonly DateTime MinFileTimeValue = new DateTime(1601, 1, 1);
|
public static readonly DateTime MinFileTimeValue = new DateTime(1601, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||||
|
|
||||||
public static DateTime ReadFileTime(byte[] buffer, int offset)
|
public static DateTime ReadFileTime(byte[] buffer, int offset)
|
||||||
{
|
{
|
||||||
|
@ -87,21 +87,19 @@ namespace SMBLibrary
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// When setting file attributes, a value of -1 indicates to the server that it MUST NOT change this attribute for all subsequent operations on the same file handle.
|
/// When setting file attributes, a value of -1 indicates to the server that it MUST NOT change this attribute for all subsequent operations on the same file handle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static DateTime? ReadSetFileTime(byte[] buffer, int offset)
|
public static SetFileTime ReadSetFileTime(byte[] buffer, int offset)
|
||||||
{
|
{
|
||||||
long span = LittleEndianConverter.ToInt64(buffer, offset);
|
long span = LittleEndianConverter.ToInt64(buffer, offset);
|
||||||
if (span > 0)
|
return SetFileTime.FromFileTimeUtc(span);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// When setting file attributes, a value of -1 indicates to the server that it MUST NOT change this attribute for all subsequent operations on the same file handle.
|
||||||
|
/// </summary>
|
||||||
|
public static void WriteSetFileTime(byte[] buffer, int offset, SetFileTime time)
|
||||||
{
|
{
|
||||||
return DateTime.FromFileTimeUtc(span);
|
long span = time.ToFileTimeUtc();
|
||||||
}
|
LittleEndianWriter.WriteInt64(buffer, offset, span);
|
||||||
else if (span == 0 || span == -1)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new System.IO.InvalidDataException("Set FILETIME cannot be set to a value less than -1");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,10 +17,10 @@ namespace SMBLibrary
|
||||||
{
|
{
|
||||||
public const int FixedLength = 40;
|
public const int FixedLength = 40;
|
||||||
|
|
||||||
public DateTime? CreationTime;
|
public SetFileTime CreationTime;
|
||||||
public DateTime? LastAccessTime;
|
public SetFileTime LastAccessTime;
|
||||||
public DateTime? LastWriteTime;
|
public SetFileTime LastWriteTime;
|
||||||
public DateTime? ChangeTime;
|
public SetFileTime ChangeTime;
|
||||||
public FileAttributes FileAttributes;
|
public FileAttributes FileAttributes;
|
||||||
public uint Reserved;
|
public uint Reserved;
|
||||||
|
|
||||||
|
@ -40,10 +40,10 @@ namespace SMBLibrary
|
||||||
|
|
||||||
public override void WriteBytes(byte[] buffer, int offset)
|
public override void WriteBytes(byte[] buffer, int offset)
|
||||||
{
|
{
|
||||||
FileTimeHelper.WriteFileTime(buffer, offset + 0, CreationTime);
|
FileTimeHelper.WriteSetFileTime(buffer, offset + 0, CreationTime);
|
||||||
FileTimeHelper.WriteFileTime(buffer, offset + 8, LastAccessTime);
|
FileTimeHelper.WriteSetFileTime(buffer, offset + 8, LastAccessTime);
|
||||||
FileTimeHelper.WriteFileTime(buffer, offset + 16, LastWriteTime);
|
FileTimeHelper.WriteSetFileTime(buffer, offset + 16, LastWriteTime);
|
||||||
FileTimeHelper.WriteFileTime(buffer, offset + 24, ChangeTime);
|
FileTimeHelper.WriteSetFileTime(buffer, offset + 24, ChangeTime);
|
||||||
LittleEndianWriter.WriteUInt32(buffer, offset + 32, (uint)FileAttributes);
|
LittleEndianWriter.WriteUInt32(buffer, offset + 32, (uint)FileAttributes);
|
||||||
LittleEndianWriter.WriteUInt32(buffer, offset + 36, Reserved);
|
LittleEndianWriter.WriteUInt32(buffer, offset + 36, Reserved);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,98 @@
|
||||||
|
/* 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;
|
||||||
|
|
||||||
|
namespace SMBLibrary
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// [MS-FSCC] When setting file attributes, a value of -1 indicates to the server that it MUST NOT change this attribute for all subsequent operations on the same file handle.
|
||||||
|
/// </summary>
|
||||||
|
public struct SetFileTime
|
||||||
|
{
|
||||||
|
public bool MustNotChange;
|
||||||
|
private DateTime? m_time;
|
||||||
|
|
||||||
|
public SetFileTime(bool mustNotChange)
|
||||||
|
{
|
||||||
|
MustNotChange = mustNotChange;
|
||||||
|
m_time = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SetFileTime(DateTime? time)
|
||||||
|
{
|
||||||
|
MustNotChange = false;
|
||||||
|
m_time = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long ToFileTimeUtc()
|
||||||
|
{
|
||||||
|
if (MustNotChange)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else if (!m_time.HasValue)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Time.Value.ToFileTimeUtc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public DateTime? Time
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (MustNotChange)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return m_time;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
MustNotChange = false;
|
||||||
|
m_time = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SetFileTime FromFileTimeUtc(long span)
|
||||||
|
{
|
||||||
|
if (span > 0)
|
||||||
|
{
|
||||||
|
DateTime value = DateTime.FromFileTimeUtc(span);
|
||||||
|
return new SetFileTime(value);
|
||||||
|
}
|
||||||
|
else if (span == 0)
|
||||||
|
{
|
||||||
|
return new SetFileTime(false);
|
||||||
|
}
|
||||||
|
else if (span == -1)
|
||||||
|
{
|
||||||
|
return new SetFileTime(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new System.IO.InvalidDataException("Set FILETIME cannot be less than -1");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator DateTime?(SetFileTime setTime)
|
||||||
|
{
|
||||||
|
return setTime.Time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator SetFileTime(DateTime? time)
|
||||||
|
{
|
||||||
|
return new SetFileTime(time);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,10 +17,10 @@ namespace SMBLibrary.SMB1
|
||||||
{
|
{
|
||||||
public const int Length = 40;
|
public const int Length = 40;
|
||||||
|
|
||||||
public DateTime? CreationTime;
|
public SetFileTime CreationTime;
|
||||||
public DateTime? LastAccessTime;
|
public SetFileTime LastAccessTime;
|
||||||
public DateTime? LastWriteTime;
|
public SetFileTime LastWriteTime;
|
||||||
public DateTime? LastChangeTime;
|
public SetFileTime LastChangeTime;
|
||||||
public ExtendedFileAttributes ExtFileAttributes;
|
public ExtendedFileAttributes ExtFileAttributes;
|
||||||
public uint Reserved;
|
public uint Reserved;
|
||||||
|
|
||||||
|
@ -45,10 +45,10 @@ namespace SMBLibrary.SMB1
|
||||||
public override byte[] GetBytes()
|
public override byte[] GetBytes()
|
||||||
{
|
{
|
||||||
byte[] buffer = new byte[Length];
|
byte[] buffer = new byte[Length];
|
||||||
FileTimeHelper.WriteFileTime(buffer, 0, CreationTime);
|
FileTimeHelper.WriteSetFileTime(buffer, 0, CreationTime);
|
||||||
FileTimeHelper.WriteFileTime(buffer, 8, LastAccessTime);
|
FileTimeHelper.WriteSetFileTime(buffer, 8, LastAccessTime);
|
||||||
FileTimeHelper.WriteFileTime(buffer, 16, LastWriteTime);
|
FileTimeHelper.WriteSetFileTime(buffer, 16, LastWriteTime);
|
||||||
FileTimeHelper.WriteFileTime(buffer, 24, LastChangeTime);
|
FileTimeHelper.WriteSetFileTime(buffer, 24, LastChangeTime);
|
||||||
LittleEndianWriter.WriteUInt32(buffer, 32, (uint)ExtFileAttributes);
|
LittleEndianWriter.WriteUInt32(buffer, 32, (uint)ExtFileAttributes);
|
||||||
LittleEndianWriter.WriteUInt32(buffer, 36, Reserved);
|
LittleEndianWriter.WriteUInt32(buffer, 36, Reserved);
|
||||||
return buffer;
|
return buffer;
|
||||||
|
|
|
@ -159,6 +159,7 @@
|
||||||
<Compile Include="NTFileStore\Structures\FileInformation\Set\FileRenameInformationType1.cs" />
|
<Compile Include="NTFileStore\Structures\FileInformation\Set\FileRenameInformationType1.cs" />
|
||||||
<Compile Include="NTFileStore\Structures\FileInformation\Set\FileRenameInformationType2.cs" />
|
<Compile Include="NTFileStore\Structures\FileInformation\Set\FileRenameInformationType2.cs" />
|
||||||
<Compile Include="NTFileStore\Structures\FileInformation\Set\FileValidDataLengthInformation.cs" />
|
<Compile Include="NTFileStore\Structures\FileInformation\Set\FileValidDataLengthInformation.cs" />
|
||||||
|
<Compile Include="NTFileStore\Structures\FileInformation\Set\SetFileTime.cs" />
|
||||||
<Compile Include="NTFileStore\Structures\FileNotifyInformation.cs" />
|
<Compile Include="NTFileStore\Structures\FileNotifyInformation.cs" />
|
||||||
<Compile Include="NTFileStore\Structures\FileSystemInformation\FileFsAttributeInformation.cs" />
|
<Compile Include="NTFileStore\Structures\FileSystemInformation\FileFsAttributeInformation.cs" />
|
||||||
<Compile Include="NTFileStore\Structures\FileSystemInformation\FileFsControlInformation.cs" />
|
<Compile Include="NTFileStore\Structures\FileSystemInformation\FileFsControlInformation.cs" />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue