From 71e2e4096f893b624e6cbdb05cbc402c8ef1923d Mon Sep 17 00:00:00 2001 From: Tal Aloni Date: Fri, 31 Jan 2020 09:39:36 +0200 Subject: [PATCH] NetBIOS: Minor code refactoring --- SMBLibrary/NetBios/NBTConnectionReceiveBuffer.cs | 6 ++---- SMBLibrary/NetBios/SessionPackets/SessionPacket.cs | 7 +++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/SMBLibrary/NetBios/NBTConnectionReceiveBuffer.cs b/SMBLibrary/NetBios/NBTConnectionReceiveBuffer.cs index d1ceb65..9ac32a8 100644 --- a/SMBLibrary/NetBios/NBTConnectionReceiveBuffer.cs +++ b/SMBLibrary/NetBios/NBTConnectionReceiveBuffer.cs @@ -1,4 +1,4 @@ -/* Copyright (C) 2014-2017 Tal Aloni . All rights reserved. +/* Copyright (C) 2014-2020 Tal Aloni . 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, @@ -43,9 +43,7 @@ namespace SMBLibrary.NetBios { if (!m_packetLength.HasValue) { - byte flags = ByteReader.ReadByte(m_buffer, m_readOffset + 1); - int trailerLength = (flags & 0x01) << 16 | BigEndianConverter.ToUInt16(m_buffer, m_readOffset + 2); - m_packetLength = 4 + trailerLength; + m_packetLength = SessionPacket.GetSessionPacketLength(m_buffer, m_readOffset); } return m_bytesInBuffer >= m_packetLength.Value; } diff --git a/SMBLibrary/NetBios/SessionPackets/SessionPacket.cs b/SMBLibrary/NetBios/SessionPackets/SessionPacket.cs index d3c8fe3..d8bea44 100644 --- a/SMBLibrary/NetBios/SessionPackets/SessionPacket.cs +++ b/SMBLibrary/NetBios/SessionPackets/SessionPacket.cs @@ -63,6 +63,13 @@ namespace SMBLibrary.NetBios } } + public static int GetSessionPacketLength(byte[] buffer, int offset) + { + byte flags = ByteReader.ReadByte(buffer, offset + 1); + int trailerLength = (flags & 0x01) << 16 | BigEndianConverter.ToUInt16(buffer, offset + 2); + return 4 + trailerLength; + } + public static SessionPacket GetSessionPacket(byte[] buffer, int offset) { SessionPacketTypeName type = (SessionPacketTypeName)ByteReader.ReadByte(buffer, offset);