mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-08-12 02:19:17 +02:00
NetBios: ResourceRecord: Improved implementation
This commit is contained in:
parent
3c67594c73
commit
f48763f049
6 changed files with 32 additions and 12 deletions
|
@ -0,0 +1,8 @@
|
||||||
|
|
||||||
|
namespace SMBLibrary.NetBios
|
||||||
|
{
|
||||||
|
public enum ResourceRecordClass : ushort
|
||||||
|
{
|
||||||
|
In = 0x0001,
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 2014-2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
/* Copyright (C) 2014-2020 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,
|
||||||
|
@ -34,7 +34,7 @@ namespace SMBLibrary.NetBios
|
||||||
Header.ARCount = 1;
|
Header.ARCount = 1;
|
||||||
Header.Flags = OperationFlags.Broadcast | OperationFlags.RecursionDesired;
|
Header.Flags = OperationFlags.Broadcast | OperationFlags.RecursionDesired;
|
||||||
Question = new QuestionSection();
|
Question = new QuestionSection();
|
||||||
Resource = new ResourceRecord();
|
Resource = new ResourceRecord(NameRecordType.NB);
|
||||||
Address = new byte[4];
|
Address = new byte[4];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 2014-2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
/* Copyright (C) 2014-2020 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,
|
||||||
|
@ -29,8 +29,7 @@ namespace SMBLibrary.NetBios
|
||||||
Header.OpCode = NameServiceOperation.QueryResponse;
|
Header.OpCode = NameServiceOperation.QueryResponse;
|
||||||
Header.Flags = OperationFlags.AuthoritativeAnswer | OperationFlags.RecursionAvailable;
|
Header.Flags = OperationFlags.AuthoritativeAnswer | OperationFlags.RecursionAvailable;
|
||||||
Header.ANCount = 1;
|
Header.ANCount = 1;
|
||||||
Resource = new ResourceRecord();
|
Resource = new ResourceRecord(NameRecordType.NBStat);
|
||||||
Resource.Type = NameRecordType.NBStat;
|
|
||||||
Statistics = new NodeStatistics();
|
Statistics = new NodeStatistics();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 2014-2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
/* Copyright (C) 2014-2020 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,
|
||||||
|
@ -29,7 +29,7 @@ namespace SMBLibrary.NetBios
|
||||||
Header.Flags = OperationFlags.AuthoritativeAnswer | OperationFlags.RecursionDesired;
|
Header.Flags = OperationFlags.AuthoritativeAnswer | OperationFlags.RecursionDesired;
|
||||||
Header.OpCode = NameServiceOperation.QueryResponse;
|
Header.OpCode = NameServiceOperation.QueryResponse;
|
||||||
Header.ANCount = 1;
|
Header.ANCount = 1;
|
||||||
Resource = new ResourceRecord();
|
Resource = new ResourceRecord(NameRecordType.NB);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] GetBytes()
|
public byte[] GetBytes()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 2014 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
/* Copyright (C) 2014-2020 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,
|
||||||
|
@ -18,19 +18,31 @@ namespace SMBLibrary.NetBios
|
||||||
public class ResourceRecord
|
public class ResourceRecord
|
||||||
{
|
{
|
||||||
public string Name;
|
public string Name;
|
||||||
public NameRecordType Type = NameRecordType.NB; // NB
|
public NameRecordType Type;
|
||||||
public ushort Class = 0x0001; // IN
|
public ResourceRecordClass Class;
|
||||||
public uint TTL;
|
public uint TTL;
|
||||||
// ushort DataLength
|
// ushort DataLength
|
||||||
public byte[] Data;
|
public byte[] Data;
|
||||||
|
|
||||||
public ResourceRecord()
|
public ResourceRecord(NameRecordType type)
|
||||||
{
|
{
|
||||||
Name = String.Empty;
|
Name = String.Empty;
|
||||||
|
Type = type;
|
||||||
|
Class = ResourceRecordClass.In;
|
||||||
TTL = (uint)new TimeSpan(7, 0, 0, 0).TotalSeconds;
|
TTL = (uint)new TimeSpan(7, 0, 0, 0).TotalSeconds;
|
||||||
Data = new byte[0];
|
Data = new byte[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ResourceRecord(byte[] buffer, ref int offset)
|
||||||
|
{
|
||||||
|
Name = NetBiosUtils.DecodeName(buffer, ref offset);
|
||||||
|
Type = (NameRecordType)BigEndianReader.ReadUInt16(buffer, ref offset);
|
||||||
|
Class = (ResourceRecordClass)BigEndianReader.ReadUInt16(buffer, ref offset);
|
||||||
|
TTL = BigEndianReader.ReadUInt32(buffer, ref offset);
|
||||||
|
ushort dataLength = BigEndianReader.ReadUInt16(buffer, ref offset);
|
||||||
|
Data = ByteReader.ReadBytes(buffer, ref offset, dataLength);
|
||||||
|
}
|
||||||
|
|
||||||
public void WriteBytes(Stream stream)
|
public void WriteBytes(Stream stream)
|
||||||
{
|
{
|
||||||
WriteBytes(stream, null);
|
WriteBytes(stream, null);
|
||||||
|
@ -48,7 +60,7 @@ namespace SMBLibrary.NetBios
|
||||||
ByteWriter.WriteBytes(stream, encodedName);
|
ByteWriter.WriteBytes(stream, encodedName);
|
||||||
}
|
}
|
||||||
BigEndianWriter.WriteUInt16(stream, (ushort)Type);
|
BigEndianWriter.WriteUInt16(stream, (ushort)Type);
|
||||||
BigEndianWriter.WriteUInt16(stream, Class);
|
BigEndianWriter.WriteUInt16(stream, (ushort)Class);
|
||||||
BigEndianWriter.WriteUInt32(stream, TTL);
|
BigEndianWriter.WriteUInt32(stream, TTL);
|
||||||
BigEndianWriter.WriteUInt16(stream, (ushort)Data.Length);
|
BigEndianWriter.WriteUInt16(stream, (ushort)Data.Length);
|
||||||
ByteWriter.WriteBytes(stream, Data);
|
ByteWriter.WriteBytes(stream, Data);
|
||||||
|
|
|
@ -73,6 +73,7 @@
|
||||||
<Compile Include="Enums\Win32Error.cs" />
|
<Compile Include="Enums\Win32Error.cs" />
|
||||||
<Compile Include="Exceptions\UnsupportedInformationLevelException.cs" />
|
<Compile Include="Exceptions\UnsupportedInformationLevelException.cs" />
|
||||||
<Compile Include="Helpers\FileTimeHelper.cs" />
|
<Compile Include="Helpers\FileTimeHelper.cs" />
|
||||||
|
<Compile Include="NetBios\NameServicePackets\Enums\ResourceRecordClass.cs" />
|
||||||
<Compile Include="NetBios\NameServicePackets\Enums\NameRecordType.cs" />
|
<Compile Include="NetBios\NameServicePackets\Enums\NameRecordType.cs" />
|
||||||
<Compile Include="NetBios\NameServicePackets\Enums\NameServiceOperation.cs" />
|
<Compile Include="NetBios\NameServicePackets\Enums\NameServiceOperation.cs" />
|
||||||
<Compile Include="NetBios\NameServicePackets\Enums\NetBiosSuffix.cs" />
|
<Compile Include="NetBios\NameServicePackets\Enums\NetBiosSuffix.cs" />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue