mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-04-30 10:47:48 +02:00
Client: Improved handling of invalid FILETIME
This commit is contained in:
parent
2c4e42d956
commit
1172dfb043
6 changed files with 41 additions and 32 deletions
|
@ -1,11 +1,10 @@
|
||||||
/* Copyright (C) 2014-2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
/* Copyright (C) 2014-2025 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,
|
||||||
* either version 3 of the License, or (at your option) any later version.
|
* either version 3 of the License, or (at your option) any later version.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using Utilities;
|
using Utilities;
|
||||||
|
|
||||||
namespace SMBLibrary
|
namespace SMBLibrary
|
||||||
|
@ -14,6 +13,21 @@ namespace SMBLibrary
|
||||||
{
|
{
|
||||||
public static readonly DateTime MinFileTimeValue = new DateTime(1601, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
public static readonly DateTime MinFileTimeValue = new DateTime(1601, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||||
|
|
||||||
|
private static readonly long MaxFileTimeIntegerValue = DateTime.MaxValue.ToFileTimeUtc();
|
||||||
|
|
||||||
|
public static DateTime ReadFileTimeSafe(byte[] buffer, int offset)
|
||||||
|
{
|
||||||
|
long span = LittleEndianConverter.ToInt64(buffer, offset);
|
||||||
|
if (span >= 0 && span <= MaxFileTimeIntegerValue)
|
||||||
|
{
|
||||||
|
return DateTime.FromFileTimeUtc(span);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return DateTime.MaxValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static DateTime ReadFileTime(byte[] buffer, int offset)
|
public static DateTime ReadFileTime(byte[] buffer, int offset)
|
||||||
{
|
{
|
||||||
long span = LittleEndianConverter.ToInt64(buffer, offset);
|
long span = LittleEndianConverter.ToInt64(buffer, offset);
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
/* Copyright (C) 2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
/* Copyright (C) 2017-2025 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,
|
||||||
* either version 3 of the License, or (at your option) any later version.
|
* either version 3 of the License, or (at your option) any later version.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using Utilities;
|
using Utilities;
|
||||||
|
|
||||||
namespace SMBLibrary
|
namespace SMBLibrary
|
||||||
|
@ -37,10 +36,10 @@ namespace SMBLibrary
|
||||||
|
|
||||||
public FileBothDirectoryInformation(byte[] buffer, int offset) : base(buffer, offset)
|
public FileBothDirectoryInformation(byte[] buffer, int offset) : base(buffer, offset)
|
||||||
{
|
{
|
||||||
CreationTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 8));
|
CreationTime = FileTimeHelper.ReadFileTimeSafe(buffer, offset + 8);
|
||||||
LastAccessTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 16));
|
LastAccessTime = FileTimeHelper.ReadFileTimeSafe(buffer, offset + 16);
|
||||||
LastWriteTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 24));
|
LastWriteTime = FileTimeHelper.ReadFileTimeSafe(buffer, offset + 24);
|
||||||
ChangeTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 32));
|
ChangeTime = FileTimeHelper.ReadFileTimeSafe(buffer, offset + 32);
|
||||||
EndOfFile = LittleEndianConverter.ToInt64(buffer, offset + 40);
|
EndOfFile = LittleEndianConverter.ToInt64(buffer, offset + 40);
|
||||||
AllocationSize = LittleEndianConverter.ToInt64(buffer, offset + 48);
|
AllocationSize = LittleEndianConverter.ToInt64(buffer, offset + 48);
|
||||||
FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 56);
|
FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 56);
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
/* Copyright (C) 2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
/* Copyright (C) 2017-2025 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,
|
||||||
* either version 3 of the License, or (at your option) any later version.
|
* either version 3 of the License, or (at your option) any later version.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using Utilities;
|
using Utilities;
|
||||||
|
|
||||||
namespace SMBLibrary
|
namespace SMBLibrary
|
||||||
|
@ -33,10 +32,10 @@ namespace SMBLibrary
|
||||||
|
|
||||||
public FileDirectoryInformation(byte[] buffer, int offset) : base(buffer, offset)
|
public FileDirectoryInformation(byte[] buffer, int offset) : base(buffer, offset)
|
||||||
{
|
{
|
||||||
CreationTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 8));
|
CreationTime = FileTimeHelper.ReadFileTimeSafe(buffer, offset + 8);
|
||||||
LastAccessTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 16));
|
LastAccessTime = FileTimeHelper.ReadFileTimeSafe(buffer, offset + 16);
|
||||||
LastWriteTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 24));
|
LastWriteTime = FileTimeHelper.ReadFileTimeSafe(buffer, offset + 24);
|
||||||
ChangeTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 32));
|
ChangeTime = FileTimeHelper.ReadFileTimeSafe(buffer, offset + 32);
|
||||||
EndOfFile = LittleEndianConverter.ToInt64(buffer, offset + 40);
|
EndOfFile = LittleEndianConverter.ToInt64(buffer, offset + 40);
|
||||||
AllocationSize = LittleEndianConverter.ToInt64(buffer, offset + 48);
|
AllocationSize = LittleEndianConverter.ToInt64(buffer, offset + 48);
|
||||||
FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 56);
|
FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 56);
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
/* Copyright (C) 2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
/* Copyright (C) 2017-2025 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,
|
||||||
* either version 3 of the License, or (at your option) any later version.
|
* either version 3 of the License, or (at your option) any later version.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using Utilities;
|
using Utilities;
|
||||||
|
|
||||||
namespace SMBLibrary
|
namespace SMBLibrary
|
||||||
|
@ -34,10 +33,10 @@ namespace SMBLibrary
|
||||||
|
|
||||||
public FileFullDirectoryInformation(byte[] buffer, int offset) : base(buffer, offset)
|
public FileFullDirectoryInformation(byte[] buffer, int offset) : base(buffer, offset)
|
||||||
{
|
{
|
||||||
CreationTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 8));
|
CreationTime = FileTimeHelper.ReadFileTimeSafe(buffer, offset + 8);
|
||||||
LastAccessTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 16));
|
LastAccessTime = FileTimeHelper.ReadFileTimeSafe(buffer, offset + 16);
|
||||||
LastWriteTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 24));
|
LastWriteTime = FileTimeHelper.ReadFileTimeSafe(buffer, offset + 24);
|
||||||
ChangeTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 32));
|
ChangeTime = FileTimeHelper.ReadFileTimeSafe(buffer, offset + 32);
|
||||||
EndOfFile = LittleEndianConverter.ToInt64(buffer, offset + 40);
|
EndOfFile = LittleEndianConverter.ToInt64(buffer, offset + 40);
|
||||||
AllocationSize = LittleEndianConverter.ToInt64(buffer, offset + 48);
|
AllocationSize = LittleEndianConverter.ToInt64(buffer, offset + 48);
|
||||||
FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 56);
|
FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 56);
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
/* Copyright (C) 2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
/* Copyright (C) 2017-2025 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,
|
||||||
* either version 3 of the License, or (at your option) any later version.
|
* either version 3 of the License, or (at your option) any later version.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using Utilities;
|
using Utilities;
|
||||||
|
|
||||||
namespace SMBLibrary
|
namespace SMBLibrary
|
||||||
|
@ -39,10 +38,10 @@ namespace SMBLibrary
|
||||||
|
|
||||||
public FileIdBothDirectoryInformation(byte[] buffer, int offset) : base(buffer, offset)
|
public FileIdBothDirectoryInformation(byte[] buffer, int offset) : base(buffer, offset)
|
||||||
{
|
{
|
||||||
CreationTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 8));
|
CreationTime = FileTimeHelper.ReadFileTimeSafe(buffer, offset + 8);
|
||||||
LastAccessTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 16));
|
LastAccessTime = FileTimeHelper.ReadFileTimeSafe(buffer, offset + 16);
|
||||||
LastWriteTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 24));
|
LastWriteTime = FileTimeHelper.ReadFileTimeSafe(buffer, offset + 24);
|
||||||
ChangeTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 32));
|
ChangeTime = FileTimeHelper.ReadFileTimeSafe(buffer, offset + 32);
|
||||||
EndOfFile = LittleEndianConverter.ToInt64(buffer, offset + 40);
|
EndOfFile = LittleEndianConverter.ToInt64(buffer, offset + 40);
|
||||||
AllocationSize = LittleEndianConverter.ToInt64(buffer, offset + 48);
|
AllocationSize = LittleEndianConverter.ToInt64(buffer, offset + 48);
|
||||||
FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 56);
|
FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 56);
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
/* Copyright (C) 2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
/* Copyright (C) 2017-2025 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,
|
||||||
* either version 3 of the License, or (at your option) any later version.
|
* either version 3 of the License, or (at your option) any later version.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using Utilities;
|
using Utilities;
|
||||||
|
|
||||||
namespace SMBLibrary
|
namespace SMBLibrary
|
||||||
|
@ -36,10 +35,10 @@ namespace SMBLibrary
|
||||||
|
|
||||||
public FileIdFullDirectoryInformation(byte[] buffer, int offset) : base(buffer, offset)
|
public FileIdFullDirectoryInformation(byte[] buffer, int offset) : base(buffer, offset)
|
||||||
{
|
{
|
||||||
CreationTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 8));
|
CreationTime = FileTimeHelper.ReadFileTimeSafe(buffer, offset + 8);
|
||||||
LastAccessTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 16));
|
LastAccessTime = FileTimeHelper.ReadFileTimeSafe(buffer, offset + 16);
|
||||||
LastWriteTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 24));
|
LastWriteTime = FileTimeHelper.ReadFileTimeSafe(buffer, offset + 24);
|
||||||
ChangeTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 32));
|
ChangeTime = FileTimeHelper.ReadFileTimeSafe(buffer, offset + 32);
|
||||||
EndOfFile = LittleEndianConverter.ToInt64(buffer, offset + 40);
|
EndOfFile = LittleEndianConverter.ToInt64(buffer, offset + 40);
|
||||||
AllocationSize = LittleEndianConverter.ToInt64(buffer, offset + 48);
|
AllocationSize = LittleEndianConverter.ToInt64(buffer, offset + 48);
|
||||||
FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 56);
|
FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 56);
|
||||||
|
|
Loading…
Add table
Reference in a new issue