using System.IO; using System.Runtime.InteropServices; namespace Sandbox; public static partial class SandboxSystemExtensions { /// /// Read a null terminated string from the stream, at given offset. /// /// The stream to read from. /// Offset where to start reading, from the beginning of the stream. public static string ReadNullTerminatedString( this Stream stream, long offset ) { stream.Seek( offset, SeekOrigin.Begin ); int b; List bytes = new List(); while ( (b = stream.ReadByte()) != 0x00 ) { bytes.Add( (byte)b ); } return Encoding.UTF8.GetString( bytes.ToArray() ); } }