예제 #1
0
        public CompactNetTextContents(WindowsAssembly assembly)
        {
            ImportBuffer = new ImportDirectoryBuffer(assembly);

            Segments.Add(ImportBuffer.AddressTables);
            Segments.Add(NetDirectory    = assembly.NetDirectory);
            Segments.Add(MethodBodyTable = new MethodBodyTableBuffer());

            if (assembly.NetDirectory.ResourcesManifest != null)
            {
                Segments.Add(assembly.NetDirectory.ResourcesManifest);
            }

            Segments.Add(FieldDataTable    = new SimpleFileSegmentBuilder());
            Segments.Add(MetadataDirectory = new MetadataDirectoryBuffer(assembly.NetDirectory.MetadataHeader));

            if (assembly.DebugDirectory != null)
            {
                Segments.Add(DebugDirectory = assembly.DebugDirectory);
                Segments.Add(assembly.DebugDirectory.Data);
            }

            if (NetDirectory.StrongNameData != null)
            {
                Segments.Add(NetDirectory.StrongNameData);
            }

            if (NetDirectory.VTablesDirectory != null)
            {
                VTableFixups = new VTableFixupsBuffer(NetDirectory.VTablesDirectory);
                Segments.Add(VTableFixups.Directory);
                Segments.Add(VTableFixups.EntriesTable);
            }

            _importDirectory.Segments.Add(ImportBuffer.ModuleImportTable);
            _importDirectory.Segments.Add(ImportBuffer.LookupTables);
            _importDirectory.Segments.Add(ImportBuffer.NameTable);
            Segments.Add(_importDirectory);

            Segments.Add(Bootstrapper = new BootstrapperSegment());

            foreach (var method in assembly.NetDirectory.MetadataHeader.GetStream <TableStream>()
                     .GetTable <MethodDefinitionTable>())
            {
                if (method.Column1 != null)
                {
                    MethodBodyTable.Segments.Add(method.Column1);
                }
            }
        }
예제 #2
0
        public CompactNetTextContents(WindowsAssembly assembly)
        {
            ImportBuffer = new ImportDirectoryBuffer(assembly);

            // IAT
            Segments.Add(ImportBuffer.AddressTables);

            // .NET Directory
            Segments.Add(NetDirectory = assembly.NetDirectory);

            // Method bodies.
            Segments.Add(MethodBodyTable = new MethodBodyTableBuffer());

            // Manifest resource data.
            if (assembly.NetDirectory.ResourcesManifest != null)
            {
                Segments.Add(assembly.NetDirectory.ResourcesManifest);
            }

            // Field data (FieldRVAs).
            Segments.Add(FieldDataTable = new SimpleFileSegmentBuilder());

            // Metadata directory header.
            Segments.Add(MetadataDirectory = new MetadataDirectoryBuffer(assembly.NetDirectory.MetadataHeader));

            // Debug directory.
            if (assembly.DebugDirectory != null)
            {
                Segments.Add(DebugDirectory = assembly.DebugDirectory);
                Segments.Add(assembly.DebugDirectory.Data);
            }

            // Strong name.
            if (NetDirectory.StrongNameData != null)
            {
                Segments.Add(NetDirectory.StrongNameData);
            }

            // VTables.
            if (NetDirectory.VTablesDirectory != null)
            {
                VTableFixups = new VTableFixupsBuffer(NetDirectory.VTablesDirectory);
                Segments.Add(VTableFixups.Directory);
                Segments.Add(VTableFixups.EntriesTable);
            }

            // Export directory.
            if (assembly.ExportDirectory != null)
            {
                Segments.Add(ExportDirectory = new ExportDirectoryBuffer(assembly.ExportDirectory, assembly));
            }

            // Remaining bits of the import tables.
            _importDirectory.Segments.Add(ImportBuffer.ModuleImportTable);
            _importDirectory.Segments.Add(ImportBuffer.LookupTables);
            _importDirectory.Segments.Add(ImportBuffer.NameTable);
            Segments.Add(_importDirectory);

            // Bootstrapper (Call to _CorExeMain / _CorDllMain).
            Segments.Add(Bootstrapper = new BootstrapperSegment());

            var tableStream = assembly.NetDirectory.MetadataHeader.GetStream <TableStream>();

            // Initialize field data segment.
            foreach (var fieldRva in tableStream.GetTable <FieldRvaTable>())
            {
                if (fieldRva.Column1 != null)
                {
                    FieldDataTable.Segments.Add(fieldRva.Column1);
                }
            }

            // Initialize method body table.
            foreach (var method in tableStream.GetTable <MethodDefinitionTable>())
            {
                if (method.Column1 != null)
                {
                    MethodBodyTable.Segments.Add(method.Column1);
                }
            }
        }