From 3247f0365e6f74e142851dc8f3138ab807167e8f Mon Sep 17 00:00:00 2001 From: Tal Aloni Date: Sat, 6 Jul 2024 17:25:45 +0300 Subject: [PATCH] SMB2: CreateContext: Bugfix: Read and Write name as ANSI instead of UTF16 --- SMBLibrary/SMB2/Structures/CreateContext.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/SMBLibrary/SMB2/Structures/CreateContext.cs b/SMBLibrary/SMB2/Structures/CreateContext.cs index b537a42..f0037c1 100644 --- a/SMBLibrary/SMB2/Structures/CreateContext.cs +++ b/SMBLibrary/SMB2/Structures/CreateContext.cs @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Tal Aloni . All rights reserved. +/* Copyright (C) 2017-2024 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, @@ -44,7 +44,7 @@ namespace SMBLibrary.SMB2 DataLength = LittleEndianConverter.ToUInt32(buffer, offset + 12); if (NameLength > 0) { - Name = ByteReader.ReadUTF16String(buffer, offset + NameOffset, NameLength / 2); + Name = ByteReader.ReadAnsiString(buffer, offset + NameOffset, NameLength); } if (DataLength > 0) { @@ -56,7 +56,7 @@ namespace SMBLibrary.SMB2 { LittleEndianWriter.WriteUInt32(buffer, offset + 0, Next); NameOffset = 0; - NameLength = (ushort)(Name.Length * 2); + NameLength = (ushort)Name.Length; if (Name.Length > 0) { NameOffset = (ushort)FixedLength; @@ -68,11 +68,11 @@ namespace SMBLibrary.SMB2 DataLength = (uint)Data.Length; if (Data.Length > 0) { - int paddedNameLength = (int)Math.Ceiling((double)(Name.Length * 2) / 8) * 8; + int paddedNameLength = (int)Math.Ceiling((double)Name.Length / 8) * 8; DataOffset = (ushort)(FixedLength + paddedNameLength); } LittleEndianWriter.WriteUInt16(buffer, offset + 10, DataOffset); - ByteWriter.WriteUTF16String(buffer, NameOffset, Name); + ByteWriter.WriteAnsiString(buffer, NameOffset, Name); ByteWriter.WriteBytes(buffer, DataOffset, Data); }