public static ImageWriter CreateWriter(Metadata_ReaderWriter.MetadataReader mr, Stream stream) { var writer = new ImageWriter(mr, stream); writer.BuildSections(); return(writer); }
ImageWriter(Metadata_ReaderWriter.MetadataReader mr, Stream stream) : base(stream) { this.mr = mr; this.methodcode = new DataBuffer(); this.methodcode.WriteBytes(mr.methodcode.ToArray()); this.resources = mr.resources; this.Data = new DataBuffer(); this.Data.WriteBytes(mr.FieldsInitialData.ToArray()); this.Tables = new DataBuffer(); this.Tables.WriteBytes(mr.TablesBytes); this.Strings = new DataBuffer(); this.Strings.WriteBytes(mr.Strings); this.Blob = new DataBuffer(); this.Blob.WriteBytes(mr.Blob); this.US = new DataBuffer(); if (mr.US != null) { this.US.WriteBytes(mr.US); } this.StrongName = new DataBuffer(); if (mr.StrongName != null) { this.StrongName.WriteBytes(mr.StrongName); } //this.pe64 = module.Architecture != TargetArchitecture.I386; this.pe64 = mr.inh.ifh.Machine != 0x14C; //this.GetDebugHeader (); removed this.GetWin32Resources(); this.text_map = BuildTextMap(); this.sections = (ushort)(pe64 ? 1 : 2); // text + reloc this.time_stamp = (uint)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; }
void Button2Click(object sender, EventArgs e) { label2.ForeColor = Color.Blue; string path = textBox1.Text; if (path != "" && File.Exists(path)) { FileStream input = new FileStream(path, FileMode.Open, System.IO.FileAccess.Read, FileShare.ReadWrite); BinaryReader reader = new BinaryReader(input); Metadata_ReaderWriter.MetadataReader mr = new Metadata_ReaderWriter.MetadataReader(); bool isok = mr.Intialize(reader); if (isok) { mr.InitPEWriter(reader); } reader.Close(); input.Close(); if (isok) { string newfilename = Path.GetDirectoryName(path); if (!newfilename.EndsWith("\\")) { newfilename = newfilename + "\\"; } newfilename = newfilename + Path.GetFileNameWithoutExtension(path) + "_recon" + Path.GetExtension(path); mr.WriteToFile(newfilename, mr); label2.ForeColor = Color.Blue; label2.Text = "File saved on " + newfilename; } else { label2.ForeColor = Color.Red; label2.Text = "Not a valid assembly!"; } } }