mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-08-05 23:34:56 +02:00
SMBServer v1.0.5
This commit is contained in:
parent
b75820452d
commit
bd1006cb81
400 changed files with 28062 additions and 0 deletions
101
Utilities/ByteUtils/BigEndianReader.cs
Normal file
101
Utilities/ByteUtils/BigEndianReader.cs
Normal file
|
@ -0,0 +1,101 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Utilities
|
||||
{
|
||||
public class BigEndianReader
|
||||
{
|
||||
public static short ReadInt16(byte[] buffer, ref int offset)
|
||||
{
|
||||
offset += 2;
|
||||
return BigEndianConverter.ToInt16(buffer, offset - 2);
|
||||
}
|
||||
|
||||
public static ushort ReadUInt16(byte[] buffer, ref int offset)
|
||||
{
|
||||
offset += 2;
|
||||
return BigEndianConverter.ToUInt16(buffer, offset - 2);
|
||||
}
|
||||
|
||||
public static int ReadInt32(byte[] buffer, ref int offset)
|
||||
{
|
||||
offset += 4;
|
||||
return BigEndianConverter.ToInt32(buffer, offset - 4);
|
||||
}
|
||||
|
||||
public static uint ReadUInt32(byte[] buffer, ref int offset)
|
||||
{
|
||||
offset += 4;
|
||||
return BigEndianConverter.ToUInt32(buffer, offset - 4);
|
||||
}
|
||||
|
||||
public static long ReadInt64(byte[] buffer, ref int offset)
|
||||
{
|
||||
offset += 8;
|
||||
return BigEndianConverter.ToInt64(buffer, offset - 8);
|
||||
}
|
||||
|
||||
public static ulong ReadUInt64(byte[] buffer, ref int offset)
|
||||
{
|
||||
offset += 8;
|
||||
return BigEndianConverter.ToUInt64(buffer, offset - 8);
|
||||
}
|
||||
|
||||
public static Guid ReadGuidBytes(byte[] buffer, ref int offset)
|
||||
{
|
||||
offset += 16;
|
||||
return BigEndianConverter.ToGuid(buffer, offset - 16);
|
||||
}
|
||||
|
||||
public static short ReadInt16(Stream stream)
|
||||
{
|
||||
byte[] buffer = new byte[2];
|
||||
stream.Read(buffer, 0, 2);
|
||||
return BigEndianConverter.ToInt16(buffer, 0);
|
||||
}
|
||||
|
||||
public static ushort ReadUInt16(Stream stream)
|
||||
{
|
||||
byte[] buffer = new byte[2];
|
||||
stream.Read(buffer, 0, 2);
|
||||
return BigEndianConverter.ToUInt16(buffer, 0);
|
||||
}
|
||||
|
||||
public static int ReadInt32(Stream stream)
|
||||
{
|
||||
byte[] buffer = new byte[4];
|
||||
stream.Read(buffer, 0, 4);
|
||||
return BigEndianConverter.ToInt32(buffer, 0);
|
||||
}
|
||||
|
||||
public static uint ReadUInt32(Stream stream)
|
||||
{
|
||||
byte[] buffer = new byte[4];
|
||||
stream.Read(buffer, 0, 4);
|
||||
return BigEndianConverter.ToUInt32(buffer, 0);
|
||||
}
|
||||
|
||||
public static long ReadInt64(Stream stream)
|
||||
{
|
||||
byte[] buffer = new byte[8];
|
||||
stream.Read(buffer, 0, 8);
|
||||
return BigEndianConverter.ToInt64(buffer, 0);
|
||||
}
|
||||
|
||||
public static ulong ReadUInt64(Stream stream)
|
||||
{
|
||||
byte[] buffer = new byte[8];
|
||||
stream.Read(buffer, 0, 8);
|
||||
return BigEndianConverter.ToUInt64(buffer, 0);
|
||||
}
|
||||
|
||||
public static Guid ReadGuidBytes(Stream stream)
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
stream.Read(buffer, 0, 16);
|
||||
return BigEndianConverter.ToGuid(buffer, 0);
|
||||
}
|
||||
}
|
||||
}
|
136
Utilities/ByteUtils/BigEndianWriter.cs
Normal file
136
Utilities/ByteUtils/BigEndianWriter.cs
Normal file
|
@ -0,0 +1,136 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Utilities
|
||||
{
|
||||
public class BigEndianWriter
|
||||
{
|
||||
public static void WriteInt16(byte[] buffer, int offset, short value)
|
||||
{
|
||||
byte[] bytes = BigEndianConverter.GetBytes(value);
|
||||
Array.Copy(bytes, 0, buffer, offset, bytes.Length);
|
||||
}
|
||||
|
||||
public static void WriteInt16(byte[] buffer, ref int offset, short value)
|
||||
{
|
||||
WriteInt16(buffer, offset, value);
|
||||
offset += 2;
|
||||
}
|
||||
|
||||
public static void WriteUInt16(byte[] buffer, int offset, ushort value)
|
||||
{
|
||||
byte[] bytes = BigEndianConverter.GetBytes(value);
|
||||
Array.Copy(bytes, 0, buffer, offset, bytes.Length);
|
||||
}
|
||||
|
||||
public static void WriteUInt16(byte[] buffer, ref int offset, ushort value)
|
||||
{
|
||||
WriteUInt16(buffer, offset, value);
|
||||
offset += 2;
|
||||
}
|
||||
|
||||
public static void WriteInt32(byte[] buffer, int offset, int value)
|
||||
{
|
||||
byte[] bytes = BigEndianConverter.GetBytes(value);
|
||||
Array.Copy(bytes, 0, buffer, offset, bytes.Length);
|
||||
}
|
||||
|
||||
public static void WriteInt32(byte[] buffer, ref int offset, int value)
|
||||
{
|
||||
WriteInt32(buffer, offset, value);
|
||||
offset += 4;
|
||||
}
|
||||
|
||||
public static void WriteUInt32(byte[] buffer, int offset, uint value)
|
||||
{
|
||||
byte[] bytes = BigEndianConverter.GetBytes(value);
|
||||
Array.Copy(bytes, 0, buffer, offset, bytes.Length);
|
||||
}
|
||||
|
||||
public static void WriteUInt32(byte[] buffer, ref int offset, uint value)
|
||||
{
|
||||
WriteUInt32(buffer, offset, value);
|
||||
offset += 4;
|
||||
}
|
||||
|
||||
public static void WriteInt64(byte[] buffer, int offset, long value)
|
||||
{
|
||||
byte[] bytes = BigEndianConverter.GetBytes(value);
|
||||
Array.Copy(bytes, 0, buffer, offset, bytes.Length);
|
||||
}
|
||||
|
||||
public static void WriteInt64(byte[] buffer, ref int offset, long value)
|
||||
{
|
||||
WriteInt64(buffer, offset, value);
|
||||
offset += 8;
|
||||
}
|
||||
|
||||
public static void WriteUInt64(byte[] buffer, int offset, ulong value)
|
||||
{
|
||||
byte[] bytes = BigEndianConverter.GetBytes(value);
|
||||
Array.Copy(bytes, 0, buffer, offset, bytes.Length);
|
||||
}
|
||||
|
||||
public static void WriteUInt64(byte[] buffer, ref int offset, ulong value)
|
||||
{
|
||||
WriteUInt64(buffer, offset, value);
|
||||
offset += 8;
|
||||
}
|
||||
|
||||
public static void WriteGuidBytes(byte[] buffer, int offset, Guid value)
|
||||
{
|
||||
byte[] bytes = BigEndianConverter.GetBytes(value);
|
||||
Array.Copy(bytes, 0, buffer, offset, bytes.Length);
|
||||
}
|
||||
|
||||
public static void WriteGuidBytes(byte[] buffer, ref int offset, Guid value)
|
||||
{
|
||||
WriteGuidBytes(buffer, offset, value);
|
||||
offset += 16;
|
||||
}
|
||||
|
||||
public static void WriteInt16(Stream stream, short value)
|
||||
{
|
||||
byte[] bytes = BigEndianConverter.GetBytes(value);
|
||||
stream.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
public static void WriteUInt16(Stream stream, ushort value)
|
||||
{
|
||||
byte[] bytes = BigEndianConverter.GetBytes(value);
|
||||
stream.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
public static void WriteInt32(Stream stream, int value)
|
||||
{
|
||||
byte[] bytes = BigEndianConverter.GetBytes(value);
|
||||
stream.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
public static void WriteUInt32(Stream stream, uint value)
|
||||
{
|
||||
byte[] bytes = BigEndianConverter.GetBytes(value);
|
||||
stream.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
public static void WriteInt64(Stream stream, long value)
|
||||
{
|
||||
byte[] bytes = BigEndianConverter.GetBytes(value);
|
||||
stream.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
public static void WriteUInt64(Stream stream, ulong value)
|
||||
{
|
||||
byte[] bytes = BigEndianConverter.GetBytes(value);
|
||||
stream.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
public static void WriteGuidBytes(Stream stream, Guid value)
|
||||
{
|
||||
byte[] bytes = BigEndianConverter.GetBytes(value);
|
||||
stream.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
}
|
||||
}
|
120
Utilities/ByteUtils/ByteReader.cs
Normal file
120
Utilities/ByteUtils/ByteReader.cs
Normal file
|
@ -0,0 +1,120 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Utilities
|
||||
{
|
||||
public class ByteReader
|
||||
{
|
||||
public static byte ReadByte(byte[] buffer, int offset)
|
||||
{
|
||||
return buffer[offset];
|
||||
}
|
||||
|
||||
public static byte ReadByte(byte[] buffer, ref int offset)
|
||||
{
|
||||
offset++;
|
||||
return buffer[offset - 1];
|
||||
}
|
||||
|
||||
public static byte[] ReadBytes(byte[] buffer, int offset, int length)
|
||||
{
|
||||
byte[] result = new byte[length];
|
||||
Array.Copy(buffer, offset, result, 0, length);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static byte[] ReadBytes(byte[] buffer, ref int offset, int length)
|
||||
{
|
||||
offset += length;
|
||||
return ReadBytes(buffer, offset - length, length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Will return the ANSI string stored in the buffer
|
||||
/// </summary>
|
||||
public static string ReadAnsiString(byte[] buffer, int offset, int count)
|
||||
{
|
||||
// ASCIIEncoding.ASCII.GetString will convert some values to '?' (byte value of 63)
|
||||
// Any codepage will do, but the only one that Mono supports is 28591.
|
||||
return ASCIIEncoding.GetEncoding(28591).GetString(buffer, offset, count);
|
||||
}
|
||||
|
||||
public static string ReadAnsiString(byte[] buffer, ref int offset, int count)
|
||||
{
|
||||
offset += count;
|
||||
return ReadAnsiString(buffer, offset - count, count);
|
||||
}
|
||||
|
||||
public static string ReadUTF16String(byte[] buffer, int offset, int numberOfCharacters)
|
||||
{
|
||||
int numberOfBytes = numberOfCharacters * 2;
|
||||
return Encoding.Unicode.GetString(buffer, offset, numberOfBytes);
|
||||
}
|
||||
|
||||
public static string ReadUTF16String(byte[] buffer, ref int offset, int numberOfCharacters)
|
||||
{
|
||||
int numberOfBytes = numberOfCharacters * 2;
|
||||
offset += numberOfBytes;
|
||||
return ReadUTF16String(buffer, offset - numberOfBytes, numberOfCharacters);
|
||||
}
|
||||
|
||||
public static string ReadNullTerminatedAnsiString(byte[] buffer, int offset)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
char c = (char)ByteReader.ReadByte(buffer, offset);
|
||||
while (c != '\0')
|
||||
{
|
||||
builder.Append(c);
|
||||
offset++;
|
||||
c = (char)ByteReader.ReadByte(buffer, offset);
|
||||
}
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
public static string ReadNullTerminatedUTF16String(byte[] buffer, int offset)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
char c = (char)LittleEndianConverter.ToUInt16(buffer, offset);
|
||||
while (c != 0)
|
||||
{
|
||||
builder.Append(c);
|
||||
offset += 2;
|
||||
c = (char)LittleEndianConverter.ToUInt16(buffer, offset);
|
||||
}
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
public static string ReadNullTerminatedAnsiString(byte[] buffer, ref int offset)
|
||||
{
|
||||
string result = ReadNullTerminatedAnsiString(buffer, offset);
|
||||
offset += result.Length + 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string ReadNullTerminatedUTF16String(byte[] buffer, ref int offset)
|
||||
{
|
||||
string result = ReadNullTerminatedUTF16String(buffer, offset);
|
||||
offset += result.Length * 2 + 2;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static byte[] ReadBytes(Stream stream, int count)
|
||||
{
|
||||
MemoryStream temp = new MemoryStream();
|
||||
ByteUtils.CopyStream(stream, temp, count);
|
||||
return temp.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return all bytes from current stream position to the end of the stream
|
||||
/// </summary>
|
||||
public static byte[] ReadAllBytes(Stream stream)
|
||||
{
|
||||
MemoryStream temp = new MemoryStream();
|
||||
ByteUtils.CopyStream(stream, temp);
|
||||
return temp.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
62
Utilities/ByteUtils/ByteUtils.cs
Normal file
62
Utilities/ByteUtils/ByteUtils.cs
Normal file
|
@ -0,0 +1,62 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Utilities
|
||||
{
|
||||
public class ByteUtils
|
||||
{
|
||||
public static byte[] Concatenate(byte[] a, byte[] b)
|
||||
{
|
||||
byte[] result = new byte[a.Length + b.Length];
|
||||
Array.Copy(a, 0, result, 0, a.Length);
|
||||
Array.Copy(b, 0, result, a.Length, b.Length);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool AreByteArraysEqual(byte[] array1, byte[] array2)
|
||||
{
|
||||
if (array1.Length != array2.Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int index = 0; index < array1.Length; index++)
|
||||
{
|
||||
if (array1[index] != array2[index])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static long CopyStream(Stream input, Stream output)
|
||||
{
|
||||
// input may not support seeking, so don't use input.Position
|
||||
return CopyStream(input, output, Int64.MaxValue);
|
||||
}
|
||||
|
||||
public static long CopyStream(Stream input, Stream output, long count)
|
||||
{
|
||||
const int MaxBufferSize = 4194304; // 4 MB
|
||||
int bufferSize = (int)Math.Min(MaxBufferSize, count);
|
||||
byte[] buffer = new byte[bufferSize];
|
||||
long totalBytesRead = 0;
|
||||
while (totalBytesRead < count)
|
||||
{
|
||||
int numberOfBytesToRead = (int)Math.Min(bufferSize, count - totalBytesRead);
|
||||
int bytesRead = input.Read(buffer, 0, numberOfBytesToRead);
|
||||
totalBytesRead += bytesRead;
|
||||
output.Write(buffer, 0, bytesRead);
|
||||
if (bytesRead == 0) // no more bytes to read from input stream
|
||||
{
|
||||
return totalBytesRead;
|
||||
}
|
||||
}
|
||||
return totalBytesRead;
|
||||
}
|
||||
}
|
||||
}
|
144
Utilities/ByteUtils/ByteWriter.cs
Normal file
144
Utilities/ByteUtils/ByteWriter.cs
Normal file
|
@ -0,0 +1,144 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Utilities
|
||||
{
|
||||
public class ByteWriter
|
||||
{
|
||||
public static void WriteByte(byte[] buffer, int offset, byte value)
|
||||
{
|
||||
buffer[offset] = value;
|
||||
}
|
||||
|
||||
public static void WriteByte(byte[] buffer, ref int offset, byte value)
|
||||
{
|
||||
buffer[offset] = value;
|
||||
offset += 1;
|
||||
}
|
||||
|
||||
public static void WriteBytes(byte[] buffer, int offset, byte[] bytes)
|
||||
{
|
||||
WriteBytes(buffer, offset, bytes, bytes.Length);
|
||||
}
|
||||
|
||||
public static void WriteBytes(byte[] buffer, ref int offset, byte[] bytes)
|
||||
{
|
||||
WriteBytes(buffer, offset, bytes);
|
||||
offset += bytes.Length;
|
||||
}
|
||||
|
||||
public static void WriteBytes(byte[] buffer, int offset, byte[] bytes, int length)
|
||||
{
|
||||
Array.Copy(bytes, 0, buffer, offset, length);
|
||||
}
|
||||
|
||||
public static void WriteBytes(byte[] buffer, ref int offset, byte[] bytes, int length)
|
||||
{
|
||||
Array.Copy(bytes, 0, buffer, offset, length);
|
||||
offset += length;
|
||||
}
|
||||
|
||||
public static void WriteAnsiString(byte[] buffer, int offset, string value)
|
||||
{
|
||||
WriteAnsiString(buffer, offset, value, value.Length);
|
||||
}
|
||||
|
||||
public static void WriteAnsiString(byte[] buffer, ref int offset, string value)
|
||||
{
|
||||
WriteAnsiString(buffer, ref offset, value, value.Length);
|
||||
}
|
||||
|
||||
public static void WriteAnsiString(byte[] buffer, int offset, string value, int maximumLength)
|
||||
{
|
||||
byte[] bytes = ASCIIEncoding.GetEncoding(28591).GetBytes(value);
|
||||
Array.Copy(bytes, 0, buffer, offset, Math.Min(value.Length, maximumLength));
|
||||
}
|
||||
|
||||
public static void WriteAnsiString(byte[] buffer, ref int offset, string value, int fieldLength)
|
||||
{
|
||||
WriteAnsiString(buffer, offset, value, fieldLength);
|
||||
offset += fieldLength;
|
||||
}
|
||||
|
||||
public static void WriteUTF16String(byte[] buffer, int offset, string value)
|
||||
{
|
||||
WriteUTF16String(buffer, offset, value, value.Length);
|
||||
}
|
||||
|
||||
public static void WriteUTF16String(byte[] buffer, ref int offset, string value)
|
||||
{
|
||||
WriteUTF16String(buffer, ref offset, value, value.Length);
|
||||
}
|
||||
|
||||
public static void WriteUTF16String(byte[] buffer, int offset, string value, int maximumNumberOfCharacters)
|
||||
{
|
||||
byte[] bytes = UnicodeEncoding.Unicode.GetBytes(value);
|
||||
int maximumNumberOfBytes = Math.Min(value.Length, maximumNumberOfCharacters) * 2;
|
||||
Array.Copy(bytes, 0, buffer, offset, maximumNumberOfBytes);
|
||||
}
|
||||
|
||||
public static void WriteUTF16String(byte[] buffer, ref int offset, string value, int numberOfCharacters)
|
||||
{
|
||||
WriteUTF16String(buffer, offset, value, numberOfCharacters);
|
||||
offset += numberOfCharacters * 2;
|
||||
}
|
||||
|
||||
public static void WriteNullTerminatedAnsiString(byte[] buffer, int offset, string value)
|
||||
{
|
||||
WriteAnsiString(buffer, offset, value);
|
||||
WriteByte(buffer, offset + value.Length, 0x00);
|
||||
}
|
||||
|
||||
public static void WriteNullTerminatedAnsiString(byte[] buffer, ref int offset, string value)
|
||||
{
|
||||
WriteNullTerminatedAnsiString(buffer, offset, value);
|
||||
offset += value.Length + 1;
|
||||
}
|
||||
|
||||
public static void WriteNullTerminatedUTF16String(byte[] buffer, int offset, string value)
|
||||
{
|
||||
WriteUTF16String(buffer, offset, value);
|
||||
WriteBytes(buffer, offset + value.Length * 2, new byte[] { 0x00, 0x00 });
|
||||
}
|
||||
|
||||
public static void WriteNullTerminatedUTF16String(byte[] buffer, ref int offset, string value)
|
||||
{
|
||||
WriteNullTerminatedUTF16String(buffer, offset, value);
|
||||
offset += value.Length * 2 + 2;
|
||||
}
|
||||
|
||||
public static void WriteBytes(Stream stream, byte[] bytes)
|
||||
{
|
||||
stream.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
public static void WriteBytes(Stream stream, byte[] bytes, int count)
|
||||
{
|
||||
stream.Write(bytes, 0, count);
|
||||
}
|
||||
|
||||
public static void WriteAnsiString(Stream stream, string value)
|
||||
{
|
||||
WriteAnsiString(stream, value, value.Length);
|
||||
}
|
||||
|
||||
public static void WriteAnsiString(Stream stream, string value, int fieldLength)
|
||||
{
|
||||
byte[] bytes = ASCIIEncoding.GetEncoding(28591).GetBytes(value);
|
||||
stream.Write(bytes, 0, Math.Min(bytes.Length, fieldLength));
|
||||
if (bytes.Length < fieldLength)
|
||||
{
|
||||
byte[] zeroFill = new byte[fieldLength - bytes.Length];
|
||||
stream.Write(zeroFill, 0, zeroFill.Length);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteUTF16String(Stream stream, string value)
|
||||
{
|
||||
byte[] bytes = UnicodeEncoding.Unicode.GetBytes(value);
|
||||
stream.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
}
|
||||
}
|
33
Utilities/ByteUtils/LittleEndianReader.cs
Normal file
33
Utilities/ByteUtils/LittleEndianReader.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Utilities
|
||||
{
|
||||
public class LittleEndianReader
|
||||
{
|
||||
public static ushort ReadUInt16(byte[] buffer, ref int offset)
|
||||
{
|
||||
offset += 2;
|
||||
return LittleEndianConverter.ToUInt16(buffer, offset - 2);
|
||||
}
|
||||
|
||||
public static uint ReadUInt32(byte[] buffer, ref int offset)
|
||||
{
|
||||
offset += 4;
|
||||
return LittleEndianConverter.ToUInt32(buffer, offset - 4);
|
||||
}
|
||||
|
||||
public static ulong ReadUInt64(byte[] buffer, ref int offset)
|
||||
{
|
||||
offset += 8;
|
||||
return LittleEndianConverter.ToUInt64(buffer, offset - 8);
|
||||
}
|
||||
|
||||
public static Guid ReadGuid(byte[] buffer, ref int offset)
|
||||
{
|
||||
offset += 16;
|
||||
return LittleEndianConverter.ToGuid(buffer, offset - 16);
|
||||
}
|
||||
}
|
||||
}
|
100
Utilities/ByteUtils/LittleEndianWriter.cs
Normal file
100
Utilities/ByteUtils/LittleEndianWriter.cs
Normal file
|
@ -0,0 +1,100 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Utilities
|
||||
{
|
||||
public class LittleEndianWriter
|
||||
{
|
||||
public static void WriteUInt16(byte[] buffer, int offset, ushort value)
|
||||
{
|
||||
byte[] bytes = LittleEndianConverter.GetBytes(value);
|
||||
Array.Copy(bytes, 0, buffer, offset, bytes.Length);
|
||||
}
|
||||
|
||||
public static void WriteUInt16(byte[] buffer, ref int offset, ushort value)
|
||||
{
|
||||
WriteUInt16(buffer, offset, value);
|
||||
offset += 2;
|
||||
}
|
||||
|
||||
public static void WriteInt16(byte[] buffer, int offset, short value)
|
||||
{
|
||||
byte[] bytes = LittleEndianConverter.GetBytes(value);
|
||||
Array.Copy(bytes, 0, buffer, offset, bytes.Length);
|
||||
}
|
||||
|
||||
public static void WriteUInt32(byte[] buffer, int offset, uint value)
|
||||
{
|
||||
byte[] bytes = LittleEndianConverter.GetBytes(value);
|
||||
Array.Copy(bytes, 0, buffer, offset, bytes.Length);
|
||||
}
|
||||
|
||||
public static void WriteUInt32(byte[] buffer, ref int offset, uint value)
|
||||
{
|
||||
WriteUInt32(buffer, offset, value);
|
||||
offset += 4;
|
||||
}
|
||||
|
||||
public static void WriteInt32(byte[] buffer, int offset, int value)
|
||||
{
|
||||
byte[] bytes = LittleEndianConverter.GetBytes(value);
|
||||
Array.Copy(bytes, 0, buffer, offset, bytes.Length);
|
||||
}
|
||||
|
||||
public static void WriteInt32(byte[] buffer, ref int offset, int value)
|
||||
{
|
||||
WriteInt32(buffer, offset, value);
|
||||
offset += 4;
|
||||
}
|
||||
|
||||
public static void WriteUInt64(byte[] buffer, int offset, ulong value)
|
||||
{
|
||||
byte[] bytes = LittleEndianConverter.GetBytes(value);
|
||||
Array.Copy(bytes, 0, buffer, offset, bytes.Length);
|
||||
}
|
||||
|
||||
public static void WriteUInt64(byte[] buffer, ref int offset, ulong value)
|
||||
{
|
||||
WriteUInt64(buffer, offset, value);
|
||||
offset += 8;
|
||||
}
|
||||
|
||||
public static void WriteInt64(byte[] buffer, int offset, long value)
|
||||
{
|
||||
byte[] bytes = LittleEndianConverter.GetBytes(value);
|
||||
Array.Copy(bytes, 0, buffer, offset, bytes.Length);
|
||||
}
|
||||
|
||||
public static void WriteGuidBytes(byte[] buffer, int offset, Guid value)
|
||||
{
|
||||
byte[] bytes = LittleEndianConverter.GetBytes(value);
|
||||
Array.Copy(bytes, 0, buffer, offset, bytes.Length);
|
||||
}
|
||||
|
||||
public static void WriteGuidBytes(byte[] buffer, ref int offset, Guid value)
|
||||
{
|
||||
WriteGuidBytes(buffer, offset, value);
|
||||
offset += 16;
|
||||
}
|
||||
|
||||
public static void WriteUInt16(Stream stream, ushort value)
|
||||
{
|
||||
byte[] bytes = LittleEndianConverter.GetBytes(value);
|
||||
stream.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
public static void WriteInt32(Stream stream, int value)
|
||||
{
|
||||
byte[] bytes = LittleEndianConverter.GetBytes(value);
|
||||
stream.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
public static void WriteUInt32(Stream stream, uint value)
|
||||
{
|
||||
byte[] bytes = LittleEndianConverter.GetBytes(value);
|
||||
stream.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue