public void OnWriterEvent(ModuleWriterBase writer, ModuleWriterEvent evt) { if (otherListener != null) { otherListener.OnWriterEvent(writer, evt); } if (evt == ModuleWriterEvent.End) { PrintTokens(writer); } }
public void Save(string newFilename, MetadataFlags mdFlags, IModuleWriterListener writerListener) { if (module.IsILOnly) { var writerOptions = new ModuleWriterOptions(module); writerOptions.WriterEvent += (s, e) => writerListener?.OnWriterEvent(e.Writer, e.Event); writerOptions.MetadataOptions.Flags |= mdFlags; writerOptions.Logger = Logger.Instance; module.Write(newFilename, writerOptions); } else { var writerOptions = new NativeModuleWriterOptions(module, optimizeImageSize: true); writerOptions.WriterEvent += (s, e) => writerListener?.OnWriterEvent(e.Writer, e.Event); writerOptions.MetadataOptions.Flags |= mdFlags; writerOptions.Logger = Logger.Instance; writerOptions.KeepExtraPEData = true; writerOptions.KeepWin32Resources = true; module.NativeWrite(newFilename, writerOptions); } }
public void OnWriterEvent(object sender, ModuleWriterListenerEventArgs e) { var writer = (ModuleWriter)sender; if (commitListener != null) { commitListener.OnWriterEvent(writer, e.WriterEvent); } if (e.WriterEvent == ModuleWriterEvent.MDBeginWriteMethodBodies && methods.ContainsKey(writer.Module)) { vr.ProcessMethods(writer.Module); foreach (var repl in refRepl) { vr.Runtime.Descriptor.Data.ReplaceReference(repl.Key, repl.Value); } commitListener = vr.CommitModule((ModuleDefMD)module); } }
public void OnWriterEvent(object sender, ModuleWriterListenerEventArgs e) { var writer = (ModuleWriter)sender; if (commitListener != null) { commitListener.OnWriterEvent(writer, e.WriterEvent); } if (e.WriterEvent == ModuleWriterEvent.MDBeginWriteMethodBodies && methods.ContainsKey(writer.Module)) { ctx.Logger.Debug("Virtualizing methods..."); vr.ProcessMethods(writer.Module, (num, total) => { ctx.Logger.Progress(num, total); ctx.CheckCancellation(); }); ctx.Logger.EndProgress(); foreach (var repl in refRepl) { vr.Runtime.Descriptor.Data.ReplaceReference(repl.Key, repl.Value); } commitListener = vr.CommitModule(ctx.CurrentModule, (num, total) => { ctx.Logger.Progress(num, total); ctx.CheckCancellation(); }); } else if (commitListener != null && e.WriterEvent == ModuleWriterEvent.End && vr.ExportDbgInfo) { var mapName = Path.ChangeExtension(writer.Module.Name, "map"); var mapPath = Path.GetFullPath(Path.Combine(ctx.OutputDirectory, mapName)); Directory.CreateDirectory(ctx.OutputDirectory); File.WriteAllBytes(mapPath, vr.Runtime.DebugInfo); } }
/// <summary> /// Writes the module to a <see cref="Stream"/> /// </summary> /// <param name="dest">Destination stream</param> public void Write(Stream dest) { if (TheOptions.StrongNameKey != null || TheOptions.StrongNamePublicKey != null) TheOptions.Cor20HeaderOptions.Flags |= ComImageFlags.StrongNameSigned; Listener = TheOptions.Listener ?? DummyModuleWriterListener.Instance; destStream = dest; destStreamBaseOffset = destStream.Position; Listener.OnWriterEvent(this, ModuleWriterEvent.Begin); var imageLength = WriteImpl(); destStream.Position = destStreamBaseOffset + imageLength; Listener.OnWriterEvent(this, ModuleWriterEvent.End); }