/// <summary> /// Reads a zero-terminated ASCII string from the stream. /// </summary> /// <param name="reader">The reader to use for reading the data.</param> /// <returns>The string that was read from the stream.</returns> public static string ReadAsciiString(this IBinaryStreamReader reader) { var data = reader.ReadBytesUntil(0); int length = data.Length; // Exclude trailing 0 byte. if (data[data.Length - 1] == 0) { length--; } return(Encoding.ASCII.GetString(data, 0, length)); }
/// <summary> /// Initializes a new instance of <see cref="RsdsDataSegment"/> /// </summary> /// <param name="context">Context for the reader</param> /// <param name="reader">The input stream to read from.</param> /// <returns></returns> public new static RsdsDataSegment FromReader(PEReaderContext context, IBinaryStreamReader reader) { if (reader.Length < RsdsExpectedDataSize) { context.BadImage("RSDS Data was shorter than the minimal expected length"); return(null); } var result = new RsdsDataSegment(); byte[] buffer = new byte[16]; reader.ReadBytes(buffer, 0, 16); result.Guid = new Guid(buffer); result.Age = reader.ReadUInt32(); result.Path = Encoding.UTF8.GetString(reader.ReadBytesUntil(0x00)); return(result); }
protected string ReadString(IBinaryStreamReader reader) { var offset = (uint)(reader.Position - reader.StartPosition); string value; if (_cachedStrings.TryGetValue(offset, out value)) { reader.Position += Encoding.UTF8.GetByteCount(value) + 1; } else { value = Encoding.UTF8.GetString(reader.ReadBytesUntil(0)); reader.Position++; _cachedStrings.Add(offset, value); } return(value); }
/// <summary> /// Reads a zero-terminated ASCII string from the stream. /// </summary> /// <param name="reader">The reader to use for reading the data.</param> /// <returns>The string that was read from the stream.</returns> public static string ReadAsciiString(this IBinaryStreamReader reader) { return(Encoding.ASCII.GetString(reader.ReadBytesUntil(0))); }