public void Read(BinaryReader reader, MDStream stream) { offs = reader.ReadUInt32 (); size = reader.ReadUInt32 (); StringBuilder name_builder = new StringBuilder (); while (true) { sbyte c = reader.ReadSByte(); if (c == 0) break; name_builder.Append ((char) c); } name = name_builder.ToString (); if (name.Length == 0) throw new BadImageException("Invalid stream name."); // Round up to dword boundary. long pos = reader.BaseStream.Position; if (stream != null) pos -= stream.Root.filePos; pos += 3; pos &= ~3; if (stream != null) pos += stream.Root.filePos; // Advance file pointer. reader.BaseStream.Position = pos; }
protected MDHeap(MDStream stream) { this.stream = stream; if (stream.RawData != null) { FromRawData(stream.RawData); } }
public void Write(BinaryWriter writer, MDStream stream) { writer.Write(offs); writer.Write(size); for (int i = 0; i < name.Length; i++) { writer.Write((sbyte)name[i]); } writer.Write((sbyte)'\0'); // Round up to dword boundary. long pos = writer.BaseStream.Position; if (stream != null) { pos -= stream.Root.filePos; } pos += 3; pos &= ~3; if (stream != null) { pos += stream.Root.filePos; } // Advance file pointer. writer.BaseStream.Position = pos; }
public MethodIL GetMethodBody(int num) { MethodIL il = null; if (img == null) { return(il); } MDStream tabs = Streams["#~"] as MDStream; TablesHeap tabsHeap = tabs.Heap as TablesHeap; if (tabsHeap.HasMethod) { MDTable methods = tabsHeap[TableId.Method]; if (methods == null) { return(il); } MethodRow row = methods[num] as MethodRow; if (row == null) { return(il); } BinaryReader reader = img.reader; reader.BaseStream.Position = img.RVAToVA(row.RVA); il = new MethodIL(); il.Read(reader); } return(il); }
/// <summary> /// Heap factory. /// </summary> /// <param name="stream">Base stream.</param> /// <returns></returns> public static MDHeap Create(MDStream stream) { MDHeap res = null; switch (stream.Name) { case "#~" : case "#-" : res = new TablesHeap(stream); break; case "#Strings" : res = new StringsHeap(stream); break; case "#GUID" : res = new GUIDHeap(stream); break; } return res; }
public void Write (BinaryWriter writer, MDStream stream) { writer.Write (offs); writer.Write (size); for (int i=0; i<name.Length; i++) writer.Write ((sbyte)name[i]); writer.Write ((sbyte) '\0'); // Round up to dword boundary. long pos = writer.BaseStream.Position; if (stream != null) pos -= stream.Root.filePos; pos += 3; pos &= ~3; if (stream != null) pos += stream.Root.filePos; // Advance file pointer. writer.BaseStream.Position = pos; }
public void Read(BinaryReader reader, MDStream stream) { offs = reader.ReadUInt32(); size = reader.ReadUInt32(); StringBuilder name_builder = new StringBuilder(); while (true) { sbyte c = reader.ReadSByte(); if (c == 0) { break; } name_builder.Append((char)c); } name = name_builder.ToString(); if (name.Length == 0) { throw new BadImageException("Invalid stream name."); } // Round up to dword boundary. long pos = reader.BaseStream.Position; if (stream != null) { pos -= stream.Root.filePos; } pos += 3; pos &= ~3; if (stream != null) { pos += stream.Root.filePos; } // Advance file pointer. reader.BaseStream.Position = pos; }
/// <summary> /// Heap factory. /// </summary> /// <param name="stream">Base stream.</param> /// <returns></returns> public static MDHeap Create(MDStream stream) { MDHeap res = null; switch (stream.Name) { case "#~": case "#-": res = new TablesHeap(stream); break; case "#Strings": res = new StringsHeap(stream); break; case "#GUID": res = new GUIDHeap(stream); break; } return(res); }
internal TablesHeap(MDStream stream) : base(stream) { }
internal StringsHeap(MDStream stream) : base(stream) { }
internal TablesHeapBase(MDStream stream) : base(stream) { }
internal GUIDHeap(MDStream stream) : base(stream) { }
unsafe public void Read(BinaryReader reader) { filePos = reader.BaseStream.Position; sig = reader.ReadUInt32(); if (sig != Sig) { throw new BadImageException("Invalid MetaData Signature."); } majVer = reader.ReadInt16(); minVer = reader.ReadInt16(); reserved = reader.ReadUInt32(); // Length of version string. len = reader.ReadInt32(); // Read version string. if (len != 0) { sbyte *pVer = stackalloc sbyte [len]; sbyte *p = pVer; long pos = reader.BaseStream.Position; int i; for (i = len; --i >= 0;) { sbyte c = reader.ReadSByte(); if (c == 0) { break; } *p++ = c; } verStr = PEUtils.GetString(pVer, 0, len - i - 1, Encoding.UTF8); // Round up to dword boundary, relative to header start. pos += len; pos -= filePos; pos += 3; pos &= ~3; pos += filePos; // Advance file pointer. reader.BaseStream.Position = pos; } else { VersionString = String.Empty; } flags = reader.ReadInt16(); nStreams = reader.ReadInt16(); streams = new Hashtable(nStreams); // load all streams into memory for (int i = nStreams; --i >= 0;) { MDStream s = new MDStream(this); s.Read(reader); // TODO: check for duplicated streams, // use Add instead of indexer. streams[s.Name] = s; } MDStream tabs = Streams["#~"] as MDStream; // Try uncompressed stream. if (tabs == null) { tabs = Streams["#-"] as MDStream; } if (tabs == null) { throw new BadMetaDataException("Missing #~ stream."); } TablesHeap tabsHeap = tabs.Heap as TablesHeap; // cache index sizes strIdx = tabsHeap.StringsIndexSize; guidIdx = tabsHeap.GUIDIndexSize; blobIdx = tabsHeap.BlobIndexSize; }
unsafe public void Read(BinaryReader reader) { filePos = reader.BaseStream.Position; sig = reader.ReadUInt32(); if (sig != Sig) { throw new BadImageException("Invalid MetaData Signature."); } majVer = reader.ReadInt16(); minVer = reader.ReadInt16(); reserved = reader.ReadUInt32(); // Length of version string. len = reader.ReadInt32(); // Read version string. if (len != 0) { sbyte* pVer = stackalloc sbyte [len]; sbyte* p = pVer; long pos = reader.BaseStream.Position; int i; for (i = len; --i >= 0;) { sbyte c = reader.ReadSByte(); if (c == 0) break; *p++ = c; } verStr = PEUtils.GetString (pVer, 0, len-i-1, Encoding.UTF8); // Round up to dword boundary, relative to header start. pos += len; pos -= filePos; pos += 3; pos &= ~3; pos += filePos; // Advance file pointer. reader.BaseStream.Position = pos; } else { VersionString = String.Empty; } flags = reader.ReadInt16(); nStreams = reader.ReadInt16(); streams = new Hashtable(nStreams); // load all streams into memory for (int i = nStreams; --i >=0;) { MDStream s = new MDStream(this); s.Read(reader); // TODO: check for duplicated streams, // use Add instead of indexer. streams[s.Name] = s; } MDStream tabs = Streams["#~"] as MDStream; // Try uncompressed stream. if (tabs == null) tabs = Streams["#-"] as MDStream; if (tabs == null) throw new BadMetaDataException("Missing #~ stream."); TablesHeap tabsHeap = tabs.Heap as TablesHeap; // cache index sizes strIdx = tabsHeap.StringsIndexSize; guidIdx = tabsHeap.GUIDIndexSize; blobIdx = tabsHeap.BlobIndexSize; }