Minor code refactoring

This commit is contained in:
Tal Aloni 2017-12-08 14:20:04 +02:00
parent 74b4a83635
commit 387b3b6709
4 changed files with 26 additions and 18 deletions

View file

@ -37,6 +37,8 @@ namespace SMBLibrary.SMB1
/// </summary>
public struct NamedPipeStatus // ushort
{
public const int Length = 2;
public byte ICount;
public ReadMode ReadMode;
public NamedPipeType NamedPipeType;
@ -45,7 +47,7 @@ namespace SMBLibrary.SMB1
public NamedPipeStatus(byte[] buffer, int offset)
{
ICount = buffer[offset];
ICount = buffer[offset + 0];
ReadMode = (ReadMode)(buffer[offset + 1] & 0x03);
NamedPipeType = (NamedPipeType)((buffer[offset + 1] & 0x0C) >> 2);
Endpoint = (Endpoint)((buffer[offset + 1] & 0x40) >> 6);
@ -73,7 +75,7 @@ namespace SMBLibrary.SMB1
public void WriteBytes(byte[] buffer, ref int offset)
{
WriteBytes(buffer, offset);
offset += 2;
offset += Length;
}
public ushort ToUInt16()
@ -88,7 +90,7 @@ namespace SMBLibrary.SMB1
public static NamedPipeStatus Read(byte[] buffer, ref int offset)
{
offset += 2;
offset += Length;
return new NamedPipeStatus(buffer, offset - 2);
}
}

View file

@ -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
* the GNU Lesser Public License as published by the Free Software Foundation,
@ -13,12 +13,14 @@ namespace SMBLibrary.SMB1
{
public struct OpenResults // 2 bytes
{
public const int Length = 2;
public OpenResult OpenResult;
public bool OpLockGranted;
public OpenResults(byte[] buffer, int offset)
{
OpenResult = (OpenResult)(buffer[offset] & 0x3);
OpenResult = (OpenResult)(buffer[offset + 0] & 0x3);
OpLockGranted = (buffer[offset + 1] & 0x80) > 0;
}
@ -38,13 +40,13 @@ namespace SMBLibrary.SMB1
public void WriteBytes(byte[] buffer, ref int offset)
{
WriteBytes(buffer, offset);
offset += 2;
offset += Length;
}
public static OpenResults Read(byte[] buffer, ref int offset)
{
offset += 2;
return new OpenResults(buffer, offset - 2);
offset += Length;
return new OpenResults(buffer, offset - Length);
}
}
}

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2014-2016 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
* the GNU Lesser Public License as published by the Free Software Foundation,
@ -56,6 +56,8 @@ namespace SMBLibrary.SMB1
public struct AccessModeOptions // 2 bytes
{
public const int Length = 2;
public AccessMode AccessMode;
public SharingMode SharingMode;
public ReferenceLocality ReferenceLocality;
@ -64,8 +66,8 @@ namespace SMBLibrary.SMB1
public AccessModeOptions(byte[] buffer, int offset)
{
AccessMode = (AccessMode)(buffer[offset] & 0x07);
SharingMode = (SharingMode)((buffer[offset] & 0x70) >> 4);
AccessMode = (AccessMode)(buffer[offset + 0] & 0x07);
SharingMode = (SharingMode)((buffer[offset + 0] & 0x70) >> 4);
ReferenceLocality = (ReferenceLocality)(buffer[offset + 1] & 0x07);
CachedMode = (CachedMode)((buffer[offset + 1] & 0x10) >> 4);
WriteThroughMode = (WriteThroughMode)((buffer[offset + 1] & 0x40) >> 6);
@ -82,8 +84,8 @@ namespace SMBLibrary.SMB1
public static AccessModeOptions Read(byte[] buffer, ref int offset)
{
offset += 2;
return new AccessModeOptions(buffer, offset - 2);
offset += Length;
return new AccessModeOptions(buffer, offset - Length);
}
}
}

View file

@ -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
* the GNU Lesser Public License as published by the Free Software Foundation,
@ -25,13 +25,15 @@ namespace SMBLibrary.SMB1
public struct OpenMode // 2 bytes
{
public const int Length = 2;
public FileExistsOpts FileExistsOpts;
public CreateFile CreateFile;
public OpenMode(byte[] buffer, int offset)
{
FileExistsOpts = (FileExistsOpts)(buffer[offset] & 0x3);
CreateFile = (CreateFile)((buffer[offset] & 0x10) >> 4);
FileExistsOpts = (FileExistsOpts)(buffer[offset + 0] & 0x3);
CreateFile = (CreateFile)((buffer[offset + 0] & 0x10) >> 4);
}
public void WriteBytes(byte[] buffer, int offset)
@ -42,8 +44,8 @@ namespace SMBLibrary.SMB1
public static OpenMode Read(byte[] buffer, ref int offset)
{
offset += 2;
return new OpenMode(buffer, offset - 2);
offset += Length;
return new OpenMode(buffer, offset - Length);
}
}
}