/// <summary> /// Save an assembly in place /// </summary> /// <param name="adef">Assembly definition</param> /// <param name="assemblyLocation">Original location</param> public static void SaveAssemblyInPlace(AssemblyDefinition adef, string assemblyLocation) { if (adef != null) { string fileName = assemblyLocation; try { adef.Write(fileName, new WriterParameters()); if (!adef.Name.HasPublicKey) { // No StrongNameKey, we're done here. return; } else { // Show the user the StrongNameKey removal dialog using (var snform = new StrongNameForm()) { snform.AssemblyDefinition = adef; snform.DelaySignedFileName = fileName; snform.ShowDialog(); } } } catch (Exception ex) { MessageBox.Show(String.Format("Reflexil is unable to save this assembly: {0}", ex.Message)); throw; } } else { MessageBox.Show(@"Assembly definition is not loaded (not a CLI image?)"); } }
/// <summary> /// Save an assembly /// </summary> /// <param name="adef">Assembly definition</param> public static void SaveAssembly(AssemblyDefinition adef) { if (adef != null) { var location = adef.MainModule.Image.FileName; using (var dialog = new SaveFileDialog()) { dialog.Filter = @"Assembly files (*.exe, *.dll)|*.exe;*.dll"; dialog.InitialDirectory = Path.GetDirectoryName(location); dialog.FileName = Path.GetFileNameWithoutExtension(location) + ".Patched" + Path.GetExtension(location); if (dialog.ShowDialog() == DialogResult.OK) { try { adef.Write(dialog.FileName); if (!adef.Name.HasPublicKey) { return; } // Reload the assembly to have a proper Image.Filename var plugin = PluginFactory.GetInstance() as BasePlugin; if (plugin != null) { adef = plugin.LoadAssembly(dialog.FileName, false); } using (var snform = new StrongNameForm()) { snform.AssemblyDefinition = adef; snform.DelaySignedFileName = dialog.FileName; snform.ShowDialog(); } } catch (Exception ex) { MessageBox.Show(String.Format("Reflexil is unable to save this assembly: {0}", ex.Message)); } } } } else { MessageBox.Show(@"Assembly definition is not loaded (not a CLI image?)"); } }
/// <summary> /// Save an assembly /// </summary> /// <param name="adef">Assembly definition</param> /// <param name="originallocation">Original location</param> public static bool TrySaveAssembly(AssemblyDefinition adef, string originallocation) { if (adef != null) { using (var SaveFileDialog = new SaveFileDialog()) { SaveFileDialog.Filter = "Assembly files (*.exe, *.dll)|*.exe;*.dll"; SaveFileDialog.InitialDirectory = Path.GetDirectoryName(originallocation); SaveFileDialog.FileName = Path.GetFileNameWithoutExtension(originallocation) + ".Patched" + Path.GetExtension(originallocation); if (SaveFileDialog.ShowDialog() == DialogResult.OK) { try { adef.Write(SaveFileDialog.FileName); if (adef.Name.HasPublicKey) { using (StrongNameForm snform = new StrongNameForm()) { snform.AssemblyDefinition = adef; snform.DelaySignedFileName = SaveFileDialog.FileName; snform.ShowDialog(); } } return(true); } catch (Exception ex) { MessageBox.Show(String.Format("Reflexil is unable to save this assembly: {0}", ex.Message)); } } } } else { MessageBox.Show("Assembly definition is not loaded (not a CLI image?)"); } return(false); }