diff --git a/MEInject/MEInject/MainForm.Designer.cs b/MEInject/MEInject/MainForm.Designer.cs index 46c10de..7222db3 100644 --- a/MEInject/MEInject/MainForm.Designer.cs +++ b/MEInject/MEInject/MainForm.Designer.cs @@ -43,6 +43,7 @@ private void InitializeComponent() this.MinorVer_checkBox = new System.Windows.Forms.CheckBox(); this.label1 = new System.Windows.Forms.Label(); this.WinKeyTextBox = new System.Windows.Forms.TextBox(); + this.ExtractButton = new System.Windows.Forms.Button(); this.SuspendLayout(); // // OpenBIOSButton @@ -134,10 +135,18 @@ private void InitializeComponent() resources.ApplyResources(this.WinKeyTextBox, "WinKeyTextBox"); this.WinKeyTextBox.Name = "WinKeyTextBox"; // + // ExtractButton + // + resources.ApplyResources(this.ExtractButton, "ExtractButton"); + this.ExtractButton.Name = "ExtractButton"; + this.ExtractButton.UseVisualStyleBackColor = true; + this.ExtractButton.Click += new System.EventHandler(this.ExtractButton_Click); + // // MainForm // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.ExtractButton); this.Controls.Add(this.WinKeyTextBox); this.Controls.Add(this.label1); this.Controls.Add(this.MinorVer_checkBox); @@ -176,6 +185,7 @@ private void InitializeComponent() private System.Windows.Forms.CheckBox MinorVer_checkBox; private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox WinKeyTextBox; + private System.Windows.Forms.Button ExtractButton; } } diff --git a/MEInject/MEInject/MainForm.cs b/MEInject/MEInject/MainForm.cs index 7fa0a37..cc62933 100644 --- a/MEInject/MEInject/MainForm.cs +++ b/MEInject/MEInject/MainForm.cs @@ -5,6 +5,7 @@ using System.IO; using System.Linq; using System.Runtime.InteropServices; +using System.Text.RegularExpressions; using System.Threading; using System.Windows.Forms; // ReSharper disable InconsistentNaming @@ -301,7 +302,40 @@ private void LoadBIOS(string path) BIOSfile = null; throw new Exception("Invalid input file " + path.SafeFileName()); } + private void ExtractButton_Click(object sender, EventArgs e) + { + if (BIOSfile == null) + { + Log("Nothing to save :(", LogLevel.Warning); + return; + } + var sfd = new SaveFileDialog + { + AddExtension = true, + DefaultExt = "bin", + FileName = _mode + " from bios " + BIOSfilename + }; + if (sfd.ShowDialog() != DialogResult.OK) return; + + try + { + var me = new byte[BIOS_ME_end_offset - BIOS_ME_start_offset]; + Array.Copy(BIOSfile, BIOS_ME_start_offset, me, 0, BIOS_ME_end_offset - BIOS_ME_start_offset); + var _me = new List(me); + for (int i = _me.Count - 1; i >= 0; i--) + { + if (_me[i] == 0xFF) _me.RemoveAt(i); + else break; + } + File.WriteAllBytes(sfd.FileName, _me.ToArray()); + Log("Saved to " + sfd.FileName, LogLevel.Info); + } + catch (Exception exception) + { + Log(exception.Message, LogLevel.Error); + } + } void UpdateComboBox() { MEsComboBox.Items.Clear(); @@ -341,15 +375,21 @@ private void SaveButton_Click(object sender, EventArgs e) return; } MEfile = File.ReadAllBytes(_validMEfiles[MEsComboBox.SelectedIndex]); - - - for (var i = 0; i < MEfile.Length; i++) BIOSfile[i + BIOS_ME_start_offset] = MEfile[i]; - + + for (var i = 0; i < BIOS_ME_end_offset - BIOS_ME_start_offset; i++) + { + if (i < MEfile.Length) + { + BIOSfile[i + BIOS_ME_start_offset] = MEfile[i]; + continue; + } + BIOSfile[i + BIOS_ME_start_offset] = (byte)0xFF; + } var sfd = new SaveFileDialog { AddExtension = true, DefaultExt = "bin", - FileName = $@"{BIOSfilename.Replace(".bin", string.Empty)} + {_mode} {MEsComboBox.Text}" + FileName = $@"{Regex.Replace(BIOSfilename, ".bin", string.Empty, RegexOptions.IgnoreCase)} + {_mode} {MEsComboBox.Text}" // $@"{BIOSfilename.Replace(".bin", string.Empty)} + {_mode} {MEsComboBox.Text}" }; if (sfd.ShowDialog() != DialogResult.OK) return; @@ -430,7 +470,6 @@ private void Log(string message, LogLevel level) color = Color.Green; break; case LogLevel.Warning: - return; color = Color.DarkOrange; break; case LogLevel.Error: @@ -474,5 +513,7 @@ private void MinorVer_checkBox_CheckedChanged(object sender, EventArgs e) { UpdateComboBox(); } + + } } diff --git a/MEInject/MEInject/MainForm.resx b/MEInject/MEInject/MainForm.resx index 0473f7d..26a0e55 100644 --- a/MEInject/MEInject/MainForm.resx +++ b/MEInject/MEInject/MainForm.resx @@ -141,7 +141,7 @@ $this - 13 + 14 932, 28 @@ -165,7 +165,7 @@ $this - 12 + 13 Courier New, 9.75pt, style=Bold @@ -192,7 +192,7 @@ $this - 11 + 12 268, 12 @@ -216,7 +216,7 @@ $this - 10 + 11 True @@ -246,7 +246,7 @@ $this - 9 + 10 524, 12 @@ -270,7 +270,7 @@ $this - 8 + 9 True @@ -300,7 +300,7 @@ $this - 7 + 8 True @@ -330,7 +330,7 @@ $this - 6 + 7 True @@ -364,7 +364,7 @@ $this - 5 + 6 Courier New, 9.75pt, style=Bold @@ -388,16 +388,16 @@ $this - 4 + 5 NoControl - 268, 45 + 398, 45 - 250, 27 + 120, 27 15 @@ -415,7 +415,7 @@ $this - 3 + 4 True @@ -445,7 +445,7 @@ $this - 2 + 3 True @@ -478,7 +478,7 @@ $this - 1 + 2 Courier New, 9.75pt, style=Bold @@ -505,6 +505,33 @@ $this + 1 + + + NoControl + + + 268, 45 + + + 120, 27 + + + 19 + + + Extract region + + + ExtractButton + + + System.Windows.Forms.Button, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + 0