public DOSHeader(StreamParser parser) { ushort magic = parser.ReadU16(); if (magic != 0x5a4d) throw new ParseFailedException("Invalid DOS header"); parser.Skip(58); PEHeaderOffset = parser.ReadU32(); }
public CLRMetaData(StreamParser parser, CLRAssembly assembly) { Assembly = assembly; long metaRootPosition = parser.Position; uint magic = parser.ReadU32(); if (magic != 0x424a5342) throw new ParseFailedException("Bad metadata magic"); MajorVersion = parser.ReadU16(); MinorVersion = parser.ReadU16(); parser.Skip(4); // Reserved uint versionLength = parser.ReadU32(); if (versionLength > 255) throw new ParseFailedException("Oversized section length"); uint paddedLength = versionLength + 3; paddedLength -= paddedLength % 4; Version = parser.ReadUTF8String((int)versionLength); parser.Skip(paddedLength - versionLength); Flags = parser.ReadU16(); ushort nStreams = parser.ReadU16(); StreamHeaders = new CLRStreamHeader[nStreams]; Dictionary<string, CLRStreamHeader> streamHeadersByName = new Dictionary<string, CLRStreamHeader>(); for (int i = 0; i < nStreams; i++) { CLRStreamHeader sh = new CLRStreamHeader(parser); if (streamHeadersByName.ContainsKey(sh.Name)) throw new ParseFailedException("Duplicate metadata stream"); streamHeadersByName[sh.Name] = sh; } // Strings US GUID Blob CLRMetaStreamBinaryData binData = new CLRMetaStreamBinaryData(parser, metaRootPosition, streamHeadersByName); // Parse metadata tables parser.Seek(streamHeadersByName["#~"].Offset + metaRootPosition); MetaDataTables = new CLRMetaDataTables(parser, this, binData); }
public CLRHeader(StreamParser parser) { parser.Skip(8); HeaderSize = parser.ReadU32(); if (HeaderSize != 0x48) throw new ParseFailedException("Invalid CLI header"); MajorRuntimeVersion = parser.ReadU16(); MinorRuntimeVersion = parser.ReadU16(); MetaData = new RvaAndSize(parser); Flags = parser.ReadU32(); EntryPointToken = parser.ReadU32(); Resources = new RvaAndSize(parser); StrongNameSignature = new RvaAndSize(parser); CodeManagerTable = new RvaAndSize(parser); VTableFixups = new RvaAndSize(parser); ExportAddressTableJumps = new RvaAndSize(parser); ManagedNativeHeader = new RvaAndSize(parser); if (EntryPointToken != 0) throw new NotImplementedException(); // Need to figure this out }
public CLRMetaDataTables(StreamParser parser, CLRMetaData metaData, CLRMetaStreamBinaryData binData) { MetaData = metaData; parser.Skip(4); // Reserved byte majorVersion = parser.ReadU8(); byte minorVersion = parser.ReadU8(); byte heapSizes = parser.ReadU8(); parser.Skip(1); // Reserved ulong validMask = parser.ReadU64(); ulong sortedMask = parser.ReadU64(); m_rowCounts = new uint[64]; for (int i = 0; i < 64; i++) { if ((validMask & ((ulong)1 << i)) != 0) m_rowCounts[i] = parser.ReadU32(); } StringOffsets32Bit = ((heapSizes & 1) != 0); GuidOffsets32Bit = ((heapSizes & 2) != 0); BlobOffsets32Bit = ((heapSizes & 4) != 0); if (majorVersion != 2 || minorVersion != 0) throw new ParseFailedException("Unknown metadata table version"); m_clrTables = new ICLRTable[64]; AddTable(0x00, new CLRTable<CLRModuleRow>()); AddTable(0x01, new CLRTable<CLRTypeRefRow>()); AddTable(0x02, new CLRTable<CLRTypeDefRow>()); AddTable(0x04, new CLRTable<CLRFieldRow>()); AddTable(0x06, new CLRTable<CLRMethodDefRow>()); AddTable(0x08, new CLRTable<CLRParamRow>()); AddTable(0x09, new CLRTable<CLRInterfaceImplRow>()); AddTable(0x0a, new CLRTable<CLRMemberRefRow>()); AddTable(0x0b, new CLRTable<CLRConstantRow>()); AddTable(0x0c, new CLRTable<CLRCustomAttributeRow>()); AddTable(0x0d, new CLRTable<CLRFieldMarshalRow>()); AddTable(0x0e, new CLRTable<CLRDeclSecurityRow>()); AddTable(0x0f, new CLRTable<CLRClassLayoutRow>()); AddTable(0x10, new CLRTable<CLRFieldLayoutRow>()); AddTable(0x11, new CLRTable<CLRStandAloneSigRow>()); AddTable(0x12, new CLRTable<CLREventMapRow>()); AddTable(0x14, new CLRTable<CLREventRow>()); AddTable(0x15, new CLRTable<CLRPropertyMapRow>()); AddTable(0x17, new CLRTable<CLRPropertyRow>()); AddTable(0x18, new CLRTable<CLRMethodSemanticsRow>()); AddTable(0x19, new CLRTable<CLRMethodImplRow>()); AddTable(0x1a, new CLRTable<CLRModuleRefRow>()); AddTable(0x1b, new CLRTable<CLRTypeSpecRow>()); AddTable(0x1c, new CLRTable<CLRImplMapRow>()); AddTable(0x1d, new CLRTable<CLRFieldRVARow>()); AddTable(0x20, new CLRTable<CLRAssemblyRow>()); AddTable(0x21, new CLRTable<CLRAssemblyProcessorRow>()); AddTable(0x22, new CLRTable<CLRAssemblyOSRow>()); AddTable(0x23, new CLRTable<CLRAssemblyRefRow>()); AddTable(0x24, new CLRTable<CLRAssemblyRefProcessorRow>()); AddTable(0x25, new CLRTable<CLRAssemblyRefOSRow>()); AddTable(0x26, new CLRTable<CLRFileRow>()); AddTable(0x27, new CLRTable<CLRExportedTypeRow>()); AddTable(0x28, new CLRTable<CLRManifestResourceRow>()); AddTable(0x29, new CLRTable<CLRNestedClassRow>()); AddTable(0x2a, new CLRTable<CLRGenericParamRow>()); AddTable(0x2c, new CLRTable<CLRGenericParamConstraintRow>()); AddTable(0x2b, new CLRTable<CLRMethodSpecRow>()); MetaDataParser = new CLRMetaDataParser(parser, binData, this, StringOffsets32Bit, GuidOffsets32Bit, BlobOffsets32Bit); for (int i = 0; i < 64; i++) { if ((validMask & (ulong)1 << i) != 0) { if (m_clrTables[i] == null) throw new ParseFailedException("Unknown table type"); m_clrTables[i].Parse(MetaDataParser); } } }