private static StreamHeader[] ReadStreamHeaders(BinaryReader br, out string Version) { uint Signature = br.ReadUInt32(); if (Signature != 0x424A5342) { throw new BadImageFormatException("Invalid metadata signature"); } /*ushort MajorVersion =*/ br.ReadUInt16(); /*ushort MinorVersion =*/ br.ReadUInt16(); /*uint Reserved =*/ br.ReadUInt32(); uint Length = br.ReadUInt32(); byte[] buf = br.ReadBytes((int)Length); Version = Encoding.UTF8.GetString(buf).TrimEnd('\u0000'); /*ushort Flags =*/ br.ReadUInt16(); ushort Streams = br.ReadUInt16(); StreamHeader[] streamHeaders = new StreamHeader[Streams]; for (int i = 0; i < streamHeaders.Length; i++) { streamHeaders[i] = new StreamHeader(); streamHeaders[i].Read(br); } return(streamHeaders); }
private byte[] ReadHeap(Stream stream, StreamHeader sh) { byte[] buf = new byte[sh.Size]; stream.Seek(peFile.RvaToFileOffset(cliHeader.MetaData.VirtualAddress + sh.Offset), SeekOrigin.Begin); for (int pos = 0; pos < buf.Length;) { int read = stream.Read(buf, pos, buf.Length - pos); if (read == 0) { throw new BadImageFormatException(); } pos += read; } return(buf); }
private static StreamHeader[] ReadStreamHeaders(BinaryReader br, out string Version) { uint Signature = br.ReadUInt32(); if (Signature != 0x424A5342) { throw new BadImageFormatException("Invalid metadata signature"); } /*ushort MajorVersion =*/ br.ReadUInt16(); /*ushort MinorVersion =*/ br.ReadUInt16(); /*uint Reserved =*/ br.ReadUInt32(); uint Length = br.ReadUInt32(); byte[] buf = br.ReadBytes((int)Length); Version = Encoding.UTF8.GetString(buf).TrimEnd('\u0000'); /*ushort Flags =*/ br.ReadUInt16(); ushort Streams = br.ReadUInt16(); StreamHeader[] streamHeaders = new StreamHeader[Streams]; for (int i = 0; i < streamHeaders.Length; i++) { streamHeaders[i] = new StreamHeader(); streamHeaders[i].Read(br); } return streamHeaders; }
private byte[] ReadHeap(Stream stream, StreamHeader sh) { byte[] buf = new byte[sh.Size]; stream.Seek(peFile.RvaToFileOffset(cliHeader.MetaDataRVA + sh.Offset), SeekOrigin.Begin); for (int pos = 0; pos < buf.Length; ) { int read = stream.Read(buf, pos, buf.Length - pos); if (read == 0) { throw new BadImageFormatException(); } pos += read; } return buf; }