public void Load(Stream s, StringBuilder builder) { Offset = s.ReadUIntLE(); Size = s.ReadUIntLE(); Util.Assume(s.AbosultePosition() % 4 == 0, "Name field not alligned"); using (var subStream = new SubStream(s, s_maxNameLen, "Invalid stream header (name too long)")) { var c = (char) subStream.ReadByteOrThrow(); while (c != '\0') { builder.Append(c); c = (char)subStream.ReadByteOrThrow(); } var padding = (builder.Length + 1)%4; for (; padding > 0 && padding < 4 ; ++padding) { subStream.ReadByteOrThrow().AssumeEquals( (byte)0, "Expected a padding byte" ); } Name = builder.ToString(); builder.Remove(0, builder.Length); } }
internal void Load(Stream stream, long size) { stream.AssumeArgNotNull("stream"); size.AssumeArgGte(s_minSize, "size"); using(var subStream = new SubStream(stream, size, "Invalid meta-data root.")) { subStream.ReadUIntLE().AssumeEquals( 0x424A5342U, "Incorrect meta-data signature." ); MajorVersion = subStream.ReadUShortLE(); MinorVersion = subStream.ReadUShortLE(); Reserved = subStream.ReadUIntLE(); var versionLen = (int)( subStream.ReadUIntLE().AssumeLte( 256, "CLR Version string too long" )); Util.Assume( versionLen % 4 == 0, "Mis-algned version string length in CLR Header." ); Version = Encoding.UTF8.GetString( subStream.ReadBytes(versionLen) ).TrimEnd('\0'); Flags = subStream.ReadUShortLE(); var numberOfStreams = subStream.ReadUShortLE(); var streamHeaders = new StreamHeader[numberOfStreams]; var b = new StringBuilder(); for (var i = 0; i < numberOfStreams; ++i) { streamHeaders[i] = new StreamHeader(); streamHeaders[i].Load(subStream, b); } StreamHeaders = new ReadOnlyDictionary<string,StreamHeader>( streamHeaders.ToDictionary(h=>h.Name) ); } }