Example #1
0
        static void ResetImage(ModuleDefinition mod)
        {
            Image ni = Image.CreateImage();

            ni.Accept(new CopyImageVisitor(mod.Image));
            mod.Image = ni;
        }
        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();
            }
        }
 /// <summary>
 /// Accepts a <see cref="IImageVisitor"/> to implement a double-dispatch pattern in order to
 /// apply pixel-specific operations on non-generic <see cref="Image"/> instances
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="visitor">The visitor.</param>
 public static void AcceptVisitor(this Image source, IImageVisitor visitor)
 => source.Accept(visitor);