public MetadataTableWriter (MetadataWriter mrv, MemoryBinaryWriter writer) { m_root = mrv.GetMetadataRoot (); m_heap = m_root.Streams.TablesHeap; m_binaryWriter = writer; m_mrrw = new MetadataRowWriter (this); }
public StructureReader(ImageReader ir) { m_ir = ir; m_img = ir.Image; m_streams = m_img.MetadataRoot.Streams; m_tHeap = m_streams.TablesHeap; m_tableReader = ir.MetadataReader.TableReader; }
public MetadataTableReader(MetadataReader mrv) { m_metadataRoot = mrv.GetMetadataRoot (); m_heap = m_metadataRoot.Streams.TablesHeap; m_binaryReader = new BinaryReader (new MemoryStream (m_heap.Data)); m_binaryReader.BaseStream.Position = 24; m_mrrv = new MetadataRowReader (this); }
public override void VisitTablesHeap(TablesHeap th) { th.Reserved = 0; th.MajorVersion = 1; th.MinorVersion = 0; th.Reserved2 = 1; th.Sorted = 0x2003301fa00; }
public StructureReader (ImageReader ir) { if (ir.Image.CLIHeader == null) throw new ImageFormatException ("The image is not a managed assembly"); m_ir = ir; m_img = ir.Image; m_streams = m_img.MetadataRoot.Streams; m_tHeap = m_streams.TablesHeap; m_tableReader = ir.MetadataReader.TableReader; }
public ReflectionReader(ModuleDefinition module) { m_module = module; m_reader = m_module.ImageReader; m_root = m_module.Image.MetadataRoot; m_tHeap = m_root.Streams.TablesHeap; m_checkDeleted = (m_tHeap.HeapSizes & 0x80) != 0; if (m_reader != null) m_tableReader = m_reader.MetadataReader.TableReader; m_codeReader = new CodeReader (this); m_sigReader = new SignatureReader (m_root, this); m_isCorlib = module.Assembly.Name.Name == Constants.Corlib; }
public override void VisitTablesHeap(TablesHeap heap) { this.VisitHeap (heap); heap.Tables = new TableCollection (heap); BinaryReader br = new BinaryReader ( new MemoryStream (heap.Data)); try { heap.Reserved = br.ReadUInt32 (); heap.MajorVersion = br.ReadByte (); heap.MinorVersion = br.ReadByte (); heap.HeapSizes = br.ReadByte (); heap.Reserved2 = br.ReadByte (); heap.Valid = br.ReadInt64 (); heap.Sorted = br.ReadInt64 (); } finally { // COMPACT FRAMEWORK NOTE: BinaryReader is not IDisposable br.Close(); } }
public override void VisitTablesHeap(TablesHeap heap) { PatchStreamHeaderOffset (heap); m_binaryWriter.Write (heap.Reserved); switch (m_runtime) { case TargetRuntime.NET_1_0 : case TargetRuntime.NET_1_1 : heap.MajorVersion = 1; heap.MinorVersion = 0; break; case TargetRuntime.NET_2_0 : heap.MajorVersion = 2; heap.MinorVersion = 0; break; } m_binaryWriter.Write (heap.MajorVersion); m_binaryWriter.Write (heap.MinorVersion); m_binaryWriter.Write (heap.HeapSizes); m_binaryWriter.Write (heap.Reserved2); m_binaryWriter.Write (heap.Valid); m_binaryWriter.Write (heap.Sorted); WriteMemStream (m_tWriter); }
internal TableCollection(TablesHeap heap) { m_heap = heap; }
void CopyOriginalImage () { original = assembly.MainModule.Image; stripped = Image.CreateImage(); stripped.Accept (new CopyImageVisitor (original)); assembly.MainModule.Image = stripped; original_tables = original.MetadataRoot.Streams.TablesHeap; stripped_tables = stripped.MetadataRoot.Streams.TablesHeap; TableCollection tables = original_tables.Tables; foreach (IMetadataTable table in tables) stripped_tables.Tables.Add(table); stripped_tables.Valid = original_tables.Valid; stripped_tables.Sorted = original_tables.Sorted; reflection_writer = new ReflectionWriter (assembly.MainModule); reflection_writer.StructureWriter = new StructureWriter (assembly, writer); reflection_writer.CodeWriter.Stripped = true; metadata_writer = reflection_writer.MetadataWriter; PatchHeap (metadata_writer.StringWriter, original.MetadataRoot.Streams.StringsHeap); PatchHeap (metadata_writer.GuidWriter, original.MetadataRoot.Streams.GuidHeap); PatchHeap (metadata_writer.UserStringWriter, original.MetadataRoot.Streams.UserStringsHeap); PatchHeap (metadata_writer.BlobWriter, original.MetadataRoot.Streams.BlobHeap); if (assembly.EntryPoint != null) metadata_writer.EntryPointToken = assembly.EntryPoint.MetadataToken.ToUInt (); }
public override void VisitTablesHeap (TablesHeap heap) { List <IMetadataTable> encodedTables = new List <IMetadataTable> (); foreach (IMetadataTable table in heap.Tables) { //this.asm.ALIGN (Assembly.OBJECT_ALIGNMENT); //this.asm.LABEL (moduleName + " " + table.GetType().Name); encodedTables.Add (table); if (table is AssemblyRefTable) EncodeAssemblyRefTable (table as AssemblyRefTable); if (table is AssemblyTable) EncodeAssemblyTable (table as AssemblyTable); if (table is ClassLayoutTable) EncodeClassLayoutTable (table as ClassLayoutTable); if (table is ConstantTable) EncodeConstantTable (table as ConstantTable); if (table is CustomAttributeTable) EncodeCustomAttributeTable (table as CustomAttributeTable); if (table is DeclSecurityTable) EncodeDeclSecurityTable (table as DeclSecurityTable); if (table is EventMapTable) EncodeEventMapTable (table as EventMapTable); if (table is EventPtrTable) EncodeEventPtrTable (table as EventPtrTable); if (table is EventTable) EncodeEventTable (table as EventTable); if (table is ExportedTypeTable) EncodeExportedTypeTable (table as ExportedTypeTable); if (table is FieldLayoutTable) EncodeFieldLayoutTable (table as FieldLayoutTable); if (table is FieldMarshalTable) EncodeFieldMarshalTable (table as FieldMarshalTable); if (table is FieldPtrTable) EncodeFieldPtrTable (table as FieldPtrTable); if (table is FieldRVATable) EncodeFieldRVATable (table as FieldRVATable); if (table is FieldTable) EncodeFieldTable (table as FieldTable); if (table is FileTable) EncodeFileTable (table as FileTable); if (table is GenericParamConstraintTable) EncodeGenericParamConstraintTable (table as GenericParamConstraintTable); if (table is GenericParamTable) EncodeGenericParamTable (table as GenericParamTable); if (table is ImplMapTable) EncodeImplMapTable (table as ImplMapTable); if (table is InterfaceImplTable) EncodeInterfaceImplTable (table as InterfaceImplTable); if (table is ManifestResourceTable) EncodeManifestResourceTable (table as ManifestResourceTable); if (table is MemberRefTable) EncodeMemberRefTable (table as MemberRefTable); if (table is MethodImplTable) EncodeMethodImplTable (table as MethodImplTable); if (table is MethodPtrTable) EncodeMethodPtrTable (table as MethodPtrTable); if (table is MethodSemanticsTable) EncodeMethodSemanticsTable (table as MethodSemanticsTable); if (table is MethodSpecTable) EncodeMethodSpecTable (table as MethodSpecTable); if (table is MethodTable) EncodeMethodTable (table as MethodTable); if (table is ModuleRefTable) EncodeModuleRefTable (table as ModuleRefTable); if (table is ModuleTable) EncodeModuleTable (table as ModuleTable); if (table is NestedClassTable) EncodeNestedClassTable (table as NestedClassTable); if (table is ParamPtrTable) EncodeParamPtrTable (table as ParamPtrTable); if (table is ParamTable) EncodeParamTable (table as ParamTable); if (table is PropertyMapTable) EncodePropertyMapTable (table as PropertyMapTable); if (table is PropertyPtrTable) EncodePropertyPtrTable (table as PropertyPtrTable); if (table is PropertyTable) EncodePropertyTable (table as PropertyTable); if (table is StandAloneSigTable) EncodeStandAloneSigTable (table as StandAloneSigTable); if (table is TypeDefTable) EncodeTypeDefTable (table as TypeDefTable); if (table is TypeRefTable) EncodeTypeRefTable (table as TypeRefTable); if (table is TypeSpecTable) EncodeTypeSpecTable (table as TypeSpecTable); } // Handle tables which were missing... foreach (string missing in potentiallyMissing) { bool found = false; foreach (IMetadataTable table in encodedTables) { if (table.GetType ().Name == missing + "Table") { found = true; break; } } if (found) continue; //Console.WriteLine ("Stubbing missing metadata table `{0} {1}Table'", moduleName, missing); this.asm.ALIGN (Assembly.OBJECT_ALIGNMENT); this.asm.LABEL (moduleName + " " + missing + "Array"); this.asm.AddArrayFields (0); } }