/// <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?)");
     }
 }
示例#2
0
        /// <summary>
        /// Save an assembly
        /// </summary>
        /// <param name="adef">Assembly definition</param>
        /// <param name="originalLocation">Original location</param>
        public static void SaveAssembly(AssemblyDefinition adef, string originalLocation)
        {
            if (adef != null)
            {
                using (var dialog = new SaveFileDialog())
                {
                    dialog.Filter = @"Assembly files (*.exe, *.dll)|*.exe;*.dll";
                    dialog.InitialDirectory = Path.GetDirectoryName(originalLocation);
                    dialog.FileName = Path.GetFileNameWithoutExtension(originalLocation) + ".Patched" + Path.GetExtension(originalLocation);
                    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;
 }