mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-07-14 13:25:03 +02:00
SMB2TransformHeader: Added WriteAssociatedData and IsTransformHeader methods
This commit is contained in:
parent
95fa303bca
commit
34ca830f78
1 changed files with 29 additions and 8 deletions
|
@ -15,7 +15,10 @@ namespace SMBLibrary.SMB2
|
||||||
public class SMB2TransformHeader
|
public class SMB2TransformHeader
|
||||||
{
|
{
|
||||||
public const int Length = 52;
|
public const int Length = 52;
|
||||||
public const int SignatureOffset = 4;
|
public const int SignatureLength = 16;
|
||||||
|
public const int NonceLength = 16;
|
||||||
|
|
||||||
|
private const int NonceStartOffset = 20;
|
||||||
|
|
||||||
public static readonly byte[] ProtocolSignature = new byte[] { 0xFD, 0x53, 0x4D, 0x42 };
|
public static readonly byte[] ProtocolSignature = new byte[] { 0xFD, 0x53, 0x4D, 0x42 };
|
||||||
|
|
||||||
|
@ -35,8 +38,8 @@ namespace SMBLibrary.SMB2
|
||||||
public SMB2TransformHeader(byte[] buffer, int offset)
|
public SMB2TransformHeader(byte[] buffer, int offset)
|
||||||
{
|
{
|
||||||
ProtocolId = ByteReader.ReadBytes(buffer, offset + 0, 4);
|
ProtocolId = ByteReader.ReadBytes(buffer, offset + 0, 4);
|
||||||
Signature = ByteReader.ReadBytes(buffer, offset + 4, 16);
|
Signature = ByteReader.ReadBytes(buffer, offset + 4, SignatureLength);
|
||||||
Nonce = ByteReader.ReadBytes(buffer, offset + 20, 16);
|
Nonce = ByteReader.ReadBytes(buffer, offset + 20, NonceLength);
|
||||||
OriginalMessageSize = LittleEndianConverter.ToUInt32(buffer, offset + 36);
|
OriginalMessageSize = LittleEndianConverter.ToUInt32(buffer, offset + 36);
|
||||||
Reserved = LittleEndianConverter.ToUInt16(buffer, offset + 40);
|
Reserved = LittleEndianConverter.ToUInt16(buffer, offset + 40);
|
||||||
Flags = (SMB2TransformHeaderFlags)LittleEndianConverter.ToUInt16(buffer, offset + 42);
|
Flags = (SMB2TransformHeaderFlags)LittleEndianConverter.ToUInt16(buffer, offset + 42);
|
||||||
|
@ -47,11 +50,29 @@ namespace SMBLibrary.SMB2
|
||||||
{
|
{
|
||||||
ByteWriter.WriteBytes(buffer, offset + 0, ProtocolId);
|
ByteWriter.WriteBytes(buffer, offset + 0, ProtocolId);
|
||||||
ByteWriter.WriteBytes(buffer, offset + 4, Signature);
|
ByteWriter.WriteBytes(buffer, offset + 4, Signature);
|
||||||
ByteWriter.WriteBytes(buffer, offset + 20, Nonce);
|
WriteAssociatedData(buffer, offset + 20);
|
||||||
LittleEndianWriter.WriteUInt32(buffer, offset + 36, OriginalMessageSize);
|
}
|
||||||
LittleEndianWriter.WriteUInt16(buffer, offset + 40, Reserved);
|
|
||||||
LittleEndianWriter.WriteUInt16(buffer, offset + 42, (ushort)Flags);
|
private void WriteAssociatedData(byte[] buffer, int offset)
|
||||||
LittleEndianWriter.WriteUInt64(buffer, offset + 44, SessionId);
|
{
|
||||||
|
ByteWriter.WriteBytes(buffer, offset + 0, Nonce);
|
||||||
|
LittleEndianWriter.WriteUInt32(buffer, offset + 16, OriginalMessageSize);
|
||||||
|
LittleEndianWriter.WriteUInt16(buffer, offset + 20, Reserved);
|
||||||
|
LittleEndianWriter.WriteUInt16(buffer, offset + 22, (ushort)Flags);
|
||||||
|
LittleEndianWriter.WriteUInt64(buffer, offset + 24, SessionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] GetAssociatedData()
|
||||||
|
{
|
||||||
|
byte[] buffer = new byte[Length - NonceStartOffset];
|
||||||
|
WriteAssociatedData(buffer, 0);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsTransformHeader(byte[] buffer, int offset)
|
||||||
|
{
|
||||||
|
byte[] protocolId = ByteReader.ReadBytes(buffer, offset + 0, 4);
|
||||||
|
return ByteUtils.AreByteArraysEqual(ProtocolSignature, protocolId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue