From 7c7875212889d149b958e074ad237be79fe5b813 Mon Sep 17 00:00:00 2001 From: alcexhim Date: Mon, 11 May 2015 19:52:47 -0400 Subject: [PATCH] Improved Executable editor allowing ExecutableSection saving and loading --- .../Executable/ExecutableEditor.Designer.cs | 142 ++++++++++++++++-- .../Editors/Executable/ExecutableEditor.cs | 80 ++++++++++ .../Editors/Executable/ExecutableEditor.resx | 3 + ...ecutable.UserInterface.WindowsForms.csproj | 6 + 4 files changed, 222 insertions(+), 9 deletions(-) diff --git a/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/Editors/Executable/ExecutableEditor.Designer.cs b/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/Editors/Executable/ExecutableEditor.Designer.cs index 5a0eedda..16e67062 100644 --- a/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/Editors/Executable/ExecutableEditor.Designer.cs +++ b/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/Editors/Executable/ExecutableEditor.Designer.cs @@ -28,18 +28,142 @@ /// 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; } } diff --git a/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/Editors/Executable/ExecutableEditor.cs b/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/Editors/Executable/ExecutableEditor.cs index 83375eb5..11df709a 100644 --- a/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/Editors/Executable/ExecutableEditor.cs +++ b/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/Editors/Executable/ExecutableEditor.cs @@ -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); + } } } } diff --git a/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/Editors/Executable/ExecutableEditor.resx b/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/Editors/Executable/ExecutableEditor.resx index 7080a7d1..6435bc7f 100644 --- a/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/Editors/Executable/ExecutableEditor.resx +++ b/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/Editors/Executable/ExecutableEditor.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms.csproj b/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms.csproj index aa9f2c2e..5700eead 100644 --- a/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms.csproj +++ b/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms.csproj @@ -30,10 +30,16 @@ 4 + + False + ..\..\..\..\..\..\AwesomeControls\bin\Debug\AwesomeControls.dll + + +