Improved Executable editor allowing ExecutableSection saving and loading

This commit is contained in:
Michael Becker 2015-05-11 19:52:47 -04:00
parent 41a30c67ba
commit 7c78752128
4 changed files with 222 additions and 9 deletions

View File

@ -28,18 +28,142 @@
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// ExecutableEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Name = "ExecutableEditor";
this.Size = new System.Drawing.Size(502, 247);
this.ResumeLayout(false);
this.components = new System.ComponentModel.Container();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.pnlSections = new System.Windows.Forms.Panel();
this.tv = new System.Windows.Forms.TreeView();
this.lvSections = new System.Windows.Forms.ListView();
this.chSectionName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chSectionOffset = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chSectionLength = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.mnuContextListViewSections = new AwesomeControls.CommandBars.CBContextMenu(this.components);
this.mnuContextListViewSectionsExport = new System.Windows.Forms.ToolStripMenuItem();
this.mnuContextListViewSectionsImport = new System.Windows.Forms.ToolStripMenuItem();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
this.pnlSections.SuspendLayout();
this.mnuContextListViewSections.SuspendLayout();
this.SuspendLayout();
//
// splitContainer1
//
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
this.splitContainer1.Location = new System.Drawing.Point(0, 0);
this.splitContainer1.Name = "splitContainer1";
//
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.Controls.Add(this.tv);
//
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.Controls.Add(this.pnlSections);
this.splitContainer1.Size = new System.Drawing.Size(502, 247);
this.splitContainer1.SplitterDistance = 167;
this.splitContainer1.TabIndex = 0;
//
// pnlSections
//
this.pnlSections.Controls.Add(this.lvSections);
this.pnlSections.Dock = System.Windows.Forms.DockStyle.Fill;
this.pnlSections.Location = new System.Drawing.Point(0, 0);
this.pnlSections.Name = "pnlSections";
this.pnlSections.Size = new System.Drawing.Size(331, 247);
this.pnlSections.TabIndex = 0;
//
// tv
//
this.tv.Dock = System.Windows.Forms.DockStyle.Fill;
this.tv.HideSelection = false;
this.tv.Location = new System.Drawing.Point(0, 0);
this.tv.Name = "tv";
this.tv.Size = new System.Drawing.Size(167, 247);
this.tv.TabIndex = 0;
//
// lvSections
//
this.lvSections.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.chSectionName,
this.chSectionOffset,
this.chSectionLength});
this.lvSections.ContextMenuStrip = this.mnuContextListViewSections;
this.lvSections.Dock = System.Windows.Forms.DockStyle.Fill;
this.lvSections.FullRowSelect = true;
this.lvSections.GridLines = true;
this.lvSections.HideSelection = false;
this.lvSections.Location = new System.Drawing.Point(0, 0);
this.lvSections.Name = "lvSections";
this.lvSections.Size = new System.Drawing.Size(331, 247);
this.lvSections.TabIndex = 0;
this.lvSections.UseCompatibleStateImageBehavior = false;
this.lvSections.View = System.Windows.Forms.View.Details;
//
// chSectionName
//
this.chSectionName.Text = "Name";
this.chSectionName.Width = 191;
//
// chSectionOffset
//
this.chSectionOffset.Text = "Offset";
//
// chSectionLength
//
this.chSectionLength.Text = "Length";
//
// mnuContextListViewSections
//
this.mnuContextListViewSections.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuContextListViewSectionsImport,
this.mnuContextListViewSectionsExport});
this.mnuContextListViewSections.Name = "mnuContextListViewSections";
this.mnuContextListViewSections.Size = new System.Drawing.Size(153, 70);
this.mnuContextListViewSections.Opening += new System.ComponentModel.CancelEventHandler(this.mnuContextListViewSections_Opening);
//
// mnuContextListViewSectionsExport
//
this.mnuContextListViewSectionsExport.Enabled = false;
this.mnuContextListViewSectionsExport.Name = "mnuContextListViewSectionsExport";
this.mnuContextListViewSectionsExport.Size = new System.Drawing.Size(152, 22);
this.mnuContextListViewSectionsExport.Text = "&Export...";
this.mnuContextListViewSectionsExport.Click += new System.EventHandler(this.mnuContextListViewSectionsExport_Click);
//
// mnuContextListViewSectionsImport
//
this.mnuContextListViewSectionsImport.Name = "mnuContextListViewSectionsImport";
this.mnuContextListViewSectionsImport.Size = new System.Drawing.Size(152, 22);
this.mnuContextListViewSectionsImport.Text = "&Import...";
this.mnuContextListViewSectionsImport.Click += new System.EventHandler(this.mnuContextListViewSectionsImport_Click);
//
// ExecutableEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.splitContainer1);
this.Name = "ExecutableEditor";
this.Size = new System.Drawing.Size(502, 247);
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel2.ResumeLayout(false);
this.splitContainer1.ResumeLayout(false);
this.pnlSections.ResumeLayout(false);
this.mnuContextListViewSections.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.TreeView tv;
private System.Windows.Forms.Panel pnlSections;
private System.Windows.Forms.ListView lvSections;
private System.Windows.Forms.ColumnHeader chSectionName;
private System.Windows.Forms.ColumnHeader chSectionOffset;
private System.Windows.Forms.ColumnHeader chSectionLength;
private AwesomeControls.CommandBars.CBContextMenu mnuContextListViewSections;
private System.Windows.Forms.ToolStripMenuItem mnuContextListViewSectionsExport;
private System.Windows.Forms.ToolStripMenuItem mnuContextListViewSectionsImport;
}
}

View File

@ -28,6 +28,86 @@ namespace UniversalEditor.Editors.Executable
public ExecutableEditor()
{
InitializeComponent();
tv.PopulateSystemIcons();
}
protected override void OnObjectModelChanged(EventArgs e)
{
base.OnObjectModelChanged(e);
tv.Nodes.Clear();
lvSections.Items.Clear();
ExecutableObjectModel executable = (ObjectModel as ExecutableObjectModel);
if (executable == null) return;
TreeNode nodeSections = new TreeNode();
nodeSections.Name = "nodeSections";
nodeSections.Text = "Sections";
nodeSections.ImageKey = "generic-folder-closed";
nodeSections.SelectedImageKey = "generic-folder-closed";
foreach (ExecutableSection section in executable.Sections)
{
TreeNode nodeSection = new TreeNode(section.Name);
nodeSection.Name = "nodeSection" + executable.Sections.IndexOf(section).ToString();
nodeSection.Tag = section;
nodeSections.Nodes.Add(nodeSection);
ListViewItem lvi = new ListViewItem();
lvi.Tag = section;
lvi.Text = section.Name;
lvi.SubItems.Add(section.PhysicalAddress.ToString());
lvi.SubItems.Add(section.VirtualSize.ToString());
lvSections.Items.Add(lvi);
}
tv.Nodes.Add(nodeSections);
}
private void mnuContextListViewSections_Opening(object sender, CancelEventArgs e)
{
mnuContextListViewSectionsExport.Enabled = (lvSections.SelectedItems.Count > 0);
}
private void mnuContextListViewSectionsExport_Click(object sender, EventArgs e)
{
foreach (ListViewItem lvi in lvSections.SelectedItems)
{
ExecutableSection section = (lvi.Tag as ExecutableSection);
SaveFileDialog sfd = new SaveFileDialog();
sfd.FileName = section.Name;
if (sfd.ShowDialog() == DialogResult.OK)
{
section.Save(sfd.FileName);
}
}
}
private void mnuContextListViewSectionsImport_Click(object sender, EventArgs e)
{
ExecutableObjectModel executable = (ObjectModel as ExecutableObjectModel);
if (executable == null) return;
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
ExecutableSection section = new ExecutableSection();
section.Name = ofd.FileName;
section.Load(ofd.FileName);
BeginEdit();
executable.Sections.Add(section);
EndEdit();
ListViewItem lvi = new ListViewItem();
lvi.Tag = section;
lvi.Text = section.Name;
lvi.SubItems.Add((0).ToString());
lvi.SubItems.Add((0).ToString());
lvSections.Items.Add(lvi);
}
}
}
}

View File

@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="mnuContextListViewSections.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -30,10 +30,16 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="AwesomeControls, Version=1.0.5609.33224, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\AwesomeControls\bin\Debug\AwesomeControls.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Design" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="UniversalEditor.Plugins.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</ItemGroup>
<ItemGroup>
<Compile Include="Editors\Executable\ExecutableEditor.cs">