diff --git a/PS5 NOR Modifier/Common/Helpers/Browser.cs b/PS5 NOR Modifier/Common/Helpers/Browser.cs new file mode 100644 index 0000000..072d3fd --- /dev/null +++ b/PS5 NOR Modifier/Common/Helpers/Browser.cs @@ -0,0 +1,40 @@ +using System.Diagnostics; +using System.Runtime.InteropServices; + +namespace PS5_NOR_Modifier.Common.Helpers +{ + public static class Browser + { + /// + /// Lauinches a URL in a new window using the default browser... + /// + /// The URL you want to launch + public static void OpenUrl(string url) + { + try + { + Process.Start(url); + } + catch + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + url = url.Replace("&", "^&"); + Process.Start(new ProcessStartInfo(url) { UseShellExecute = true }); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + Process.Start("xdg-open", url); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + Process.Start("open", url); + } + else + { + throw; + } + } + } + } +} diff --git a/PS5 NOR Modifier/Common/Helpers/XmlSerializationHelper.cs b/PS5 NOR Modifier/Common/Helpers/XmlSerializationHelper.cs new file mode 100644 index 0000000..ba24fc8 --- /dev/null +++ b/PS5 NOR Modifier/Common/Helpers/XmlSerializationHelper.cs @@ -0,0 +1,51 @@ +using System; +using System.Xml.Serialization; + +namespace PS5_NOR_Modifier.Common.Helpers +{ + public static class XmlSerializationHelper + { + public static T? DeserilazeXmlFromFile(string filePath) + { + T? result = default; + + if (string.IsNullOrEmpty(filePath)) + { + throw new ArgumentNullException("File path is empty"); + } + + if (!File.Exists(filePath)) + { + throw new FileNotFoundException("Local XML file '" + filePath + "' not found."); + } + + XmlSerializer serializer = new XmlSerializer(typeof(T)); + + using (StreamReader reader = new StreamReader(filePath)) + { + result = (T?)serializer.Deserialize(reader); + } + + return result; + } + + public static T? DeserilazeXmlFromString(string xmlData) + { + T? result = default; + + if (string.IsNullOrEmpty(xmlData)) + { + throw new ArgumentNullException("XML data to deserialize is empty"); + } + + XmlSerializer serializer = new XmlSerializer(typeof(T)); + + using (StringReader reader = new StringReader(xmlData)) + { + result = (T?)serializer.Deserialize(reader); + } + + return result; + } + } +} diff --git a/PS5 NOR Modifier/Events/StatusUpdateEventArgs.cs b/PS5 NOR Modifier/Events/StatusUpdateEventArgs.cs new file mode 100644 index 0000000..38e49c3 --- /dev/null +++ b/PS5 NOR Modifier/Events/StatusUpdateEventArgs.cs @@ -0,0 +1,20 @@ +using System; + + +namespace PS5_NOR_Modifier.UserControls.Events +{ + public class StatusUpdateEventArgs : EventArgs + { + private string _text; + + public string Text + { + get { return _text; } + } + + public StatusUpdateEventArgs(string newStatus) : base() + { + _text = newStatus; + } + } +} diff --git a/PS5 NOR Modifier/Form1.Designer.cs b/PS5 NOR Modifier/Form1.Designer.cs index 3889d30..45b07a5 100644 --- a/PS5 NOR Modifier/Form1.Designer.cs +++ b/PS5 NOR Modifier/Form1.Designer.cs @@ -1,6 +1,6 @@ namespace PS5_NOR_Modifier { - partial class Form1 + partial class fMainForm { /// /// Required designer variable. @@ -28,66 +28,21 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(fMainForm)); this.label1 = new System.Windows.Forms.Label(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.label2 = new System.Windows.Forms.Label(); this.pictureBox2 = new System.Windows.Forms.PictureBox(); this.label4 = new System.Windows.Forms.Label(); - this.label5 = new System.Windows.Forms.Label(); - this.fileLocationBox = new System.Windows.Forms.TextBox(); - this.browseFileButton = new System.Windows.Forms.Button(); - this.label6 = new System.Windows.Forms.Label(); - this.label7 = new System.Windows.Forms.Label(); - this.label9 = new System.Windows.Forms.Label(); - this.label10 = new System.Windows.Forms.Label(); - this.serialNumber = new System.Windows.Forms.Label(); - this.modelInfo = new System.Windows.Forms.Label(); - this.fileSizeInfo = new System.Windows.Forms.Label(); this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); - this.label8 = new System.Windows.Forms.Label(); - this.boardVariant = new System.Windows.Forms.Label(); - this.label11 = new System.Windows.Forms.Label(); - this.convertToDigitalEditionButton = new System.Windows.Forms.Button(); - this.boardVariantSelectionBox = new System.Windows.Forms.ComboBox(); - this.label12 = new System.Windows.Forms.Label(); - this.label13 = new System.Windows.Forms.Label(); - this.serialNumberTextbox = new System.Windows.Forms.TextBox(); - this.label14 = new System.Windows.Forms.Label(); - this.boardModelSelectionBox = new System.Windows.Forms.ComboBox(); this.label15 = new System.Windows.Forms.Label(); - this.label16 = new System.Windows.Forms.Label(); - this.macAddressInfo = new System.Windows.Forms.Label(); - this.LANMacAddressInfo = new System.Windows.Forms.Label(); - this.label18 = new System.Windows.Forms.Label(); - this.moboSerialInfo = new System.Windows.Forms.Label(); - this.label19 = new System.Windows.Forms.Label(); - this.label17 = new System.Windows.Forms.Label(); - this.wifiMacAddressTextbox = new System.Windows.Forms.TextBox(); - this.lanMacAddressTextbox = new System.Windows.Forms.TextBox(); - this.label20 = new System.Windows.Forms.Label(); this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabPage1 = new System.Windows.Forms.TabPage(); + this.ucNORModifier = new PS5_NOR_Modifier.UserControls.NorModifier.NorModifierUserControl(); this.tabPage2 = new System.Windows.Forms.TabPage(); - this.btnSendCommand = new System.Windows.Forms.Button(); - this.txtCustomCommand = new System.Windows.Forms.TextBox(); - this.label24 = new System.Windows.Forms.Label(); - this.chkUseOffline = new System.Windows.Forms.CheckBox(); - this.btnDownloadDatabase = new System.Windows.Forms.Button(); - this.btnRefreshPorts = new System.Windows.Forms.Button(); - this.button3 = new System.Windows.Forms.Button(); - this.txtUARTOutput = new System.Windows.Forms.TextBox(); - this.label22 = new System.Windows.Forms.Label(); - this.btnClearErrorCodes = new System.Windows.Forms.Button(); - this.label21 = new System.Windows.Forms.Label(); - this.button1 = new System.Windows.Forms.Button(); - this.comboComPorts = new System.Windows.Forms.ComboBox(); - this.btnDisconnectCom = new System.Windows.Forms.Button(); - this.btnConnectCom = new System.Windows.Forms.Button(); - this.label3 = new System.Windows.Forms.Label(); + this.ucUART = new PS5_NOR_Modifier.UserControls.UART.UartUserControl(); this.label23 = new System.Windows.Forms.Label(); - this.label25 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); this.statusStrip1.SuspendLayout(); @@ -99,21 +54,19 @@ private void InitializeComponent() // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(8, 84); - this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label1.Location = new System.Drawing.Point(18, 195); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(768, 45); + this.label1.Size = new System.Drawing.Size(1352, 90); this.label1.TabIndex = 0; this.label1.Text = resources.GetString("label1.Text"); - this.label1.Click += new System.EventHandler(this.label1_Click); // // pictureBox1 // this.pictureBox1.Image = global::PS5_NOR_Modifier.Properties.Resources.PS5_Nor_Logo; - this.pictureBox1.Location = new System.Drawing.Point(8, 7); - this.pictureBox1.Margin = new System.Windows.Forms.Padding(2); + this.pictureBox1.Location = new System.Drawing.Point(14, 14); + this.pictureBox1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.pictureBox1.Name = "pictureBox1"; - this.pictureBox1.Size = new System.Drawing.Size(117, 75); + this.pictureBox1.Size = new System.Drawing.Size(201, 150); this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pictureBox1.TabIndex = 1; this.pictureBox1.TabStop = false; @@ -122,20 +75,20 @@ private void InitializeComponent() // this.label2.AutoSize = true; this.label2.Font = new System.Drawing.Font("Segoe UI", 22F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); - this.label2.Location = new System.Drawing.Point(140, 7); - this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label2.Location = new System.Drawing.Point(240, 14); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(277, 41); + this.label2.Size = new System.Drawing.Size(476, 70); this.label2.TabIndex = 2; this.label2.Text = "PS5 NOR Modifier"; // // pictureBox2 // + this.pictureBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.pictureBox2.Image = global::PS5_NOR_Modifier.Properties.Resources.Paypal_128; - this.pictureBox2.Location = new System.Drawing.Point(8, 459); - this.pictureBox2.Margin = new System.Windows.Forms.Padding(2); + this.pictureBox2.Location = new System.Drawing.Point(24, 1276); + this.pictureBox2.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.pictureBox2.Name = "pictureBox2"; - this.pictureBox2.Size = new System.Drawing.Size(45, 38); + this.pictureBox2.Size = new System.Drawing.Size(77, 76); this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pictureBox2.TabIndex = 4; this.pictureBox2.TabStop = false; @@ -143,613 +96,120 @@ private void InitializeComponent() // // label4 // + this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(65, 459); - this.label4.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label4.Location = new System.Drawing.Point(121, 1276); this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(702, 30); + this.label4.Size = new System.Drawing.Size(1227, 60); this.label4.TabIndex = 5; this.label4.Text = resources.GetString("label4.Text"); this.label4.Click += new System.EventHandler(this.label4_Click); // - // label5 - // - this.label5.AutoSize = true; - this.label5.Location = new System.Drawing.Point(5, 3); - this.label5.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); - this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(102, 15); - this.label5.TabIndex = 6; - this.label5.Text = "Select NOR Dump"; - // - // fileLocationBox - // - this.fileLocationBox.Location = new System.Drawing.Point(5, 20); - this.fileLocationBox.Margin = new System.Windows.Forms.Padding(2); - this.fileLocationBox.Name = "fileLocationBox"; - this.fileLocationBox.Size = new System.Drawing.Size(717, 23); - this.fileLocationBox.TabIndex = 7; - // - // browseFileButton - // - this.browseFileButton.Location = new System.Drawing.Point(727, 19); - this.browseFileButton.Margin = new System.Windows.Forms.Padding(2); - this.browseFileButton.Name = "browseFileButton"; - this.browseFileButton.Size = new System.Drawing.Size(78, 20); - this.browseFileButton.TabIndex = 8; - this.browseFileButton.Text = "Browse"; - this.browseFileButton.UseVisualStyleBackColor = true; - this.browseFileButton.Click += new System.EventHandler(this.browseFileButton_Click); - // - // label6 - // - this.label6.AutoSize = true; - this.label6.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); - this.label6.Location = new System.Drawing.Point(5, 49); - this.label6.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); - this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(87, 15); - this.label6.TabIndex = 9; - this.label6.Text = "Dump Results:"; - // - // label7 - // - this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(5, 72); - this.label7.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); - this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(85, 15); - this.label7.TabIndex = 10; - this.label7.Text = "Serial Number:"; - // - // label9 - // - this.label9.AutoSize = true; - this.label9.Location = new System.Drawing.Point(5, 159); - this.label9.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); - this.label9.Name = "label9"; - this.label9.Size = new System.Drawing.Size(66, 15); - this.label9.TabIndex = 12; - this.label9.Text = "PS5 Model:"; - // - // label10 - // - this.label10.AutoSize = true; - this.label10.Location = new System.Drawing.Point(5, 189); - this.label10.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); - this.label10.Name = "label10"; - this.label10.Size = new System.Drawing.Size(51, 15); - this.label10.TabIndex = 13; - this.label10.Text = "File Size:"; - // - // serialNumber - // - this.serialNumber.AutoSize = true; - this.serialNumber.Location = new System.Drawing.Point(124, 72); - this.serialNumber.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); - this.serialNumber.Name = "serialNumber"; - this.serialNumber.Size = new System.Drawing.Size(16, 15); - this.serialNumber.TabIndex = 14; - this.serialNumber.Text = "..."; - // - // modelInfo - // - this.modelInfo.AutoSize = true; - this.modelInfo.Location = new System.Drawing.Point(124, 159); - this.modelInfo.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); - this.modelInfo.Name = "modelInfo"; - this.modelInfo.Size = new System.Drawing.Size(16, 15); - this.modelInfo.TabIndex = 16; - this.modelInfo.Text = "..."; - // - // fileSizeInfo - // - this.fileSizeInfo.AutoSize = true; - this.fileSizeInfo.Location = new System.Drawing.Point(124, 189); - this.fileSizeInfo.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); - this.fileSizeInfo.Name = "fileSizeInfo"; - this.fileSizeInfo.Size = new System.Drawing.Size(16, 15); - this.fileSizeInfo.TabIndex = 17; - this.fileSizeInfo.Text = "..."; - // // statusStrip1 // this.statusStrip1.ImageScalingSize = new System.Drawing.Size(24, 24); this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripStatusLabel1}); - this.statusStrip1.Location = new System.Drawing.Point(0, 535); + this.statusStrip1.Location = new System.Drawing.Point(0, 1433); this.statusStrip1.Name = "statusStrip1"; - this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 10, 0); - this.statusStrip1.Size = new System.Drawing.Size(847, 22); + this.statusStrip1.Padding = new System.Windows.Forms.Padding(2, 0, 17, 0); + this.statusStrip1.Size = new System.Drawing.Size(1933, 39); this.statusStrip1.TabIndex = 18; this.statusStrip1.Text = "statusStrip1"; // // toolStripStatusLabel1 // this.toolStripStatusLabel1.Name = "toolStripStatusLabel1"; - this.toolStripStatusLabel1.Size = new System.Drawing.Size(135, 17); + this.toolStripStatusLabel1.Size = new System.Drawing.Size(237, 30); this.toolStripStatusLabel1.Text = "Status: Waiting for input"; // - // label8 - // - this.label8.AutoSize = true; - this.label8.Location = new System.Drawing.Point(5, 130); - this.label8.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); - this.label8.Name = "label8"; - this.label8.Size = new System.Drawing.Size(80, 15); - this.label8.TabIndex = 20; - this.label8.Text = "Board Variant:"; - // - // boardVariant - // - this.boardVariant.AutoSize = true; - this.boardVariant.Location = new System.Drawing.Point(124, 130); - this.boardVariant.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); - this.boardVariant.Name = "boardVariant"; - this.boardVariant.Size = new System.Drawing.Size(16, 15); - this.boardVariant.TabIndex = 21; - this.boardVariant.Text = "..."; - // - // label11 - // - this.label11.AutoSize = true; - this.label11.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); - this.label11.Location = new System.Drawing.Point(393, 49); - this.label11.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); - this.label11.Name = "label11"; - this.label11.Size = new System.Drawing.Size(84, 15); - this.label11.TabIndex = 22; - this.label11.Text = "Modify Values"; - // - // convertToDigitalEditionButton - // - this.convertToDigitalEditionButton.Location = new System.Drawing.Point(655, 221); - this.convertToDigitalEditionButton.Margin = new System.Windows.Forms.Padding(2); - this.convertToDigitalEditionButton.Name = "convertToDigitalEditionButton"; - this.convertToDigitalEditionButton.Size = new System.Drawing.Size(150, 46); - this.convertToDigitalEditionButton.TabIndex = 23; - this.convertToDigitalEditionButton.Text = "Save New\r\nBIOS Information"; - this.convertToDigitalEditionButton.UseVisualStyleBackColor = true; - this.convertToDigitalEditionButton.Click += new System.EventHandler(this.convertToDigitalEditionButton_Click); - // - // boardVariantSelectionBox - // - this.boardVariantSelectionBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.boardVariantSelectionBox.FormattingEnabled = true; - this.boardVariantSelectionBox.Items.AddRange(new object[] { - "CFI-1000A", - "CFI-1000A01", - "CFI-1000B", - "CFI-1002A", - "CFI-1008A", - "CFI-1014A", - "CFI-1015A", - "CFI-1015B", - "CFI-1016A", - "CFI-1018A", - "CFI-1100A01", - "CFI-1102A", - "CFI-1108A", - "CFI-1109A", - "CFI-1114A", - "CFI-1115A", - "CFI-1116A", - "CFI-1118A", - "CFI-1208A", - "CFI-1215A", - "CFI-1216A", - "DFI-T1000AA", - "DFI-D1000AA"}); - this.boardVariantSelectionBox.Location = new System.Drawing.Point(507, 98); - this.boardVariantSelectionBox.Margin = new System.Windows.Forms.Padding(2); - this.boardVariantSelectionBox.Name = "boardVariantSelectionBox"; - this.boardVariantSelectionBox.Size = new System.Drawing.Size(298, 23); - this.boardVariantSelectionBox.TabIndex = 29; - // - // label12 - // - this.label12.AutoSize = true; - this.label12.Location = new System.Drawing.Point(393, 72); - this.label12.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); - this.label12.Name = "label12"; - this.label12.Size = new System.Drawing.Size(85, 15); - this.label12.TabIndex = 30; - this.label12.Text = "Serial Number:"; - // - // label13 - // - this.label13.AutoSize = true; - this.label13.Location = new System.Drawing.Point(393, 100); - this.label13.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); - this.label13.Name = "label13"; - this.label13.Size = new System.Drawing.Size(80, 15); - this.label13.TabIndex = 31; - this.label13.Text = "Board Variant:"; - // - // serialNumberTextbox - // - this.serialNumberTextbox.Location = new System.Drawing.Point(507, 70); - this.serialNumberTextbox.Margin = new System.Windows.Forms.Padding(2); - this.serialNumberTextbox.Name = "serialNumberTextbox"; - this.serialNumberTextbox.Size = new System.Drawing.Size(298, 23); - this.serialNumberTextbox.TabIndex = 32; - // - // label14 - // - this.label14.AutoSize = true; - this.label14.Location = new System.Drawing.Point(393, 129); - this.label14.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); - this.label14.Name = "label14"; - this.label14.Size = new System.Drawing.Size(66, 15); - this.label14.TabIndex = 33; - this.label14.Text = "PS5 Model:"; - // - // boardModelSelectionBox - // - this.boardModelSelectionBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.boardModelSelectionBox.FormattingEnabled = true; - this.boardModelSelectionBox.Items.AddRange(new object[] { - "Digital Edition", - "Disc Edition"}); - this.boardModelSelectionBox.Location = new System.Drawing.Point(507, 127); - this.boardModelSelectionBox.Margin = new System.Windows.Forms.Padding(2); - this.boardModelSelectionBox.Name = "boardModelSelectionBox"; - this.boardModelSelectionBox.Size = new System.Drawing.Size(298, 23); - this.boardModelSelectionBox.TabIndex = 34; - // // label15 // + this.label15.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.label15.AutoSize = true; this.label15.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); - this.label15.Location = new System.Drawing.Point(65, 495); - this.label15.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label15.Location = new System.Drawing.Point(111, 1348); this.label15.Name = "label15"; - this.label15.Size = new System.Drawing.Size(387, 21); + this.label15.Size = new System.Drawing.Size(666, 38); this.label15.TabIndex = 35; this.label15.Text = "This project is sponsored by www.consolefix.shop"; this.label15.Click += new System.EventHandler(this.label15_Click); // - // label16 - // - this.label16.AutoSize = true; - this.label16.Location = new System.Drawing.Point(5, 221); - this.label16.Name = "label16"; - this.label16.Size = new System.Drawing.Size(104, 15); - this.label16.TabIndex = 36; - this.label16.Text = "WiFi Mac Address:"; - // - // macAddressInfo - // - this.macAddressInfo.AutoSize = true; - this.macAddressInfo.Location = new System.Drawing.Point(124, 221); - this.macAddressInfo.Name = "macAddressInfo"; - this.macAddressInfo.Size = new System.Drawing.Size(16, 15); - this.macAddressInfo.TabIndex = 37; - this.macAddressInfo.Text = "..."; - // - // LANMacAddressInfo - // - this.LANMacAddressInfo.AutoSize = true; - this.LANMacAddressInfo.Location = new System.Drawing.Point(124, 252); - this.LANMacAddressInfo.Name = "LANMacAddressInfo"; - this.LANMacAddressInfo.Size = new System.Drawing.Size(16, 15); - this.LANMacAddressInfo.TabIndex = 39; - this.LANMacAddressInfo.Text = "..."; - // - // label18 - // - this.label18.AutoSize = true; - this.label18.Location = new System.Drawing.Point(5, 252); - this.label18.Name = "label18"; - this.label18.Size = new System.Drawing.Size(104, 15); - this.label18.TabIndex = 38; - this.label18.Text = "LAN Mac Address:"; - // - // moboSerialInfo - // - this.moboSerialInfo.AutoSize = true; - this.moboSerialInfo.Location = new System.Drawing.Point(124, 101); - this.moboSerialInfo.Name = "moboSerialInfo"; - this.moboSerialInfo.Size = new System.Drawing.Size(16, 15); - this.moboSerialInfo.TabIndex = 41; - this.moboSerialInfo.Text = "..."; - // - // label19 - // - this.label19.AutoSize = true; - this.label19.Location = new System.Drawing.Point(5, 101); - this.label19.Name = "label19"; - this.label19.Size = new System.Drawing.Size(111, 15); - this.label19.TabIndex = 40; - this.label19.Text = "Motherboard Serial:"; - // - // label17 - // - this.label17.AutoSize = true; - this.label17.Location = new System.Drawing.Point(393, 159); - this.label17.Name = "label17"; - this.label17.Size = new System.Drawing.Size(108, 15); - this.label17.TabIndex = 42; - this.label17.Text = "WiFi MAC Address:"; - // - // wifiMacAddressTextbox - // - this.wifiMacAddressTextbox.Enabled = false; - this.wifiMacAddressTextbox.Location = new System.Drawing.Point(507, 156); - this.wifiMacAddressTextbox.Name = "wifiMacAddressTextbox"; - this.wifiMacAddressTextbox.Size = new System.Drawing.Size(298, 23); - this.wifiMacAddressTextbox.TabIndex = 43; - // - // lanMacAddressTextbox - // - this.lanMacAddressTextbox.Enabled = false; - this.lanMacAddressTextbox.Location = new System.Drawing.Point(507, 185); - this.lanMacAddressTextbox.Name = "lanMacAddressTextbox"; - this.lanMacAddressTextbox.Size = new System.Drawing.Size(298, 23); - this.lanMacAddressTextbox.TabIndex = 44; - // - // label20 - // - this.label20.AutoSize = true; - this.label20.Location = new System.Drawing.Point(393, 188); - this.label20.Name = "label20"; - this.label20.Size = new System.Drawing.Size(104, 15); - this.label20.TabIndex = 45; - this.label20.Text = "LAN Mac Address:"; - // // tabControl1 // + this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.tabControl1.Controls.Add(this.tabPage1); this.tabControl1.Controls.Add(this.tabPage2); - this.tabControl1.Location = new System.Drawing.Point(12, 132); + this.tabControl1.Location = new System.Drawing.Point(21, 315); + this.tabControl1.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; - this.tabControl1.Size = new System.Drawing.Size(821, 311); + this.tabControl1.Size = new System.Drawing.Size(1888, 929); this.tabControl1.TabIndex = 46; // // tabPage1 // - this.tabPage1.Controls.Add(this.label5); - this.tabPage1.Controls.Add(this.label20); - this.tabPage1.Controls.Add(this.fileLocationBox); - this.tabPage1.Controls.Add(this.lanMacAddressTextbox); - this.tabPage1.Controls.Add(this.browseFileButton); - this.tabPage1.Controls.Add(this.wifiMacAddressTextbox); - this.tabPage1.Controls.Add(this.label6); - this.tabPage1.Controls.Add(this.label17); - this.tabPage1.Controls.Add(this.label7); - this.tabPage1.Controls.Add(this.moboSerialInfo); - this.tabPage1.Controls.Add(this.label9); - this.tabPage1.Controls.Add(this.label19); - this.tabPage1.Controls.Add(this.label10); - this.tabPage1.Controls.Add(this.LANMacAddressInfo); - this.tabPage1.Controls.Add(this.serialNumber); - this.tabPage1.Controls.Add(this.label18); - this.tabPage1.Controls.Add(this.modelInfo); - this.tabPage1.Controls.Add(this.macAddressInfo); - this.tabPage1.Controls.Add(this.fileSizeInfo); - this.tabPage1.Controls.Add(this.label16); - this.tabPage1.Controls.Add(this.label8); - this.tabPage1.Controls.Add(this.boardVariant); - this.tabPage1.Controls.Add(this.boardModelSelectionBox); - this.tabPage1.Controls.Add(this.label11); - this.tabPage1.Controls.Add(this.label14); - this.tabPage1.Controls.Add(this.convertToDigitalEditionButton); - this.tabPage1.Controls.Add(this.serialNumberTextbox); - this.tabPage1.Controls.Add(this.boardVariantSelectionBox); - this.tabPage1.Controls.Add(this.label13); - this.tabPage1.Controls.Add(this.label12); - this.tabPage1.Location = new System.Drawing.Point(4, 24); + this.tabPage1.Controls.Add(this.ucNORModifier); + this.tabPage1.Location = new System.Drawing.Point(4, 39); + this.tabPage1.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); this.tabPage1.Name = "tabPage1"; - this.tabPage1.Padding = new System.Windows.Forms.Padding(3); - this.tabPage1.Size = new System.Drawing.Size(813, 283); + this.tabPage1.Padding = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.tabPage1.Size = new System.Drawing.Size(1880, 886); this.tabPage1.TabIndex = 0; this.tabPage1.Text = "NOR Modifier"; this.tabPage1.UseVisualStyleBackColor = true; // + // ucNORModifier + // + this.ucNORModifier.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.ucNORModifier.Location = new System.Drawing.Point(3, 9); + this.ucNORModifier.Name = "ucNORModifier"; + this.ucNORModifier.Size = new System.Drawing.Size(1867, 868); + this.ucNORModifier.TabIndex = 0; + // // tabPage2 // - this.tabPage2.Controls.Add(this.label25); - this.tabPage2.Controls.Add(this.btnSendCommand); - this.tabPage2.Controls.Add(this.txtCustomCommand); - this.tabPage2.Controls.Add(this.label24); - this.tabPage2.Controls.Add(this.chkUseOffline); - this.tabPage2.Controls.Add(this.btnDownloadDatabase); - this.tabPage2.Controls.Add(this.btnRefreshPorts); - this.tabPage2.Controls.Add(this.button3); - this.tabPage2.Controls.Add(this.txtUARTOutput); - this.tabPage2.Controls.Add(this.label22); - this.tabPage2.Controls.Add(this.btnClearErrorCodes); - this.tabPage2.Controls.Add(this.label21); - this.tabPage2.Controls.Add(this.button1); - this.tabPage2.Controls.Add(this.comboComPorts); - this.tabPage2.Controls.Add(this.btnDisconnectCom); - this.tabPage2.Controls.Add(this.btnConnectCom); - this.tabPage2.Controls.Add(this.label3); - this.tabPage2.Location = new System.Drawing.Point(4, 24); + this.tabPage2.Controls.Add(this.ucUART); + this.tabPage2.Location = new System.Drawing.Point(4, 39); + this.tabPage2.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); this.tabPage2.Name = "tabPage2"; - this.tabPage2.Padding = new System.Windows.Forms.Padding(3); - this.tabPage2.Size = new System.Drawing.Size(813, 283); + this.tabPage2.Padding = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.tabPage2.Size = new System.Drawing.Size(1824, 816); this.tabPage2.TabIndex = 1; this.tabPage2.Text = "UART Communication"; this.tabPage2.UseVisualStyleBackColor = true; // - // btnSendCommand - // - this.btnSendCommand.Location = new System.Drawing.Point(732, 125); - this.btnSendCommand.Name = "btnSendCommand"; - this.btnSendCommand.Size = new System.Drawing.Size(75, 23); - this.btnSendCommand.TabIndex = 16; - this.btnSendCommand.Text = "Send"; - this.btnSendCommand.UseVisualStyleBackColor = true; - this.btnSendCommand.Click += new System.EventHandler(this.btnSendCommand_Click); - // - // txtCustomCommand - // - this.txtCustomCommand.Location = new System.Drawing.Point(610, 96); - this.txtCustomCommand.Name = "txtCustomCommand"; - this.txtCustomCommand.Size = new System.Drawing.Size(197, 23); - this.txtCustomCommand.TabIndex = 15; - this.txtCustomCommand.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtCustomCommand_KeyPress); - // - // label24 - // - this.label24.AutoSize = true; - this.label24.Location = new System.Drawing.Point(610, 78); - this.label24.Name = "label24"; - this.label24.Size = new System.Drawing.Size(186, 15); - this.label24.TabIndex = 14; - this.label24.Text = "Send custom command via UART:"; - // - // chkUseOffline - // - this.chkUseOffline.AutoSize = true; - this.chkUseOffline.Location = new System.Drawing.Point(472, 47); - this.chkUseOffline.Name = "chkUseOffline"; - this.chkUseOffline.Size = new System.Drawing.Size(132, 19); - this.chkUseOffline.TabIndex = 13; - this.chkUseOffline.Text = "Use offline database"; - this.chkUseOffline.UseVisualStyleBackColor = true; - // - // btnDownloadDatabase - // - this.btnDownloadDatabase.Location = new System.Drawing.Point(310, 44); - this.btnDownloadDatabase.Name = "btnDownloadDatabase"; - this.btnDownloadDatabase.Size = new System.Drawing.Size(156, 23); - this.btnDownloadDatabase.TabIndex = 12; - this.btnDownloadDatabase.Text = "Download Error Database"; - this.btnDownloadDatabase.UseVisualStyleBackColor = true; - this.btnDownloadDatabase.Click += new System.EventHandler(this.btnDownloadDatabase_Click); + // ucUART // - // btnRefreshPorts - // - this.btnRefreshPorts.Location = new System.Drawing.Point(515, 13); - this.btnRefreshPorts.Name = "btnRefreshPorts"; - this.btnRefreshPorts.Size = new System.Drawing.Size(89, 23); - this.btnRefreshPorts.TabIndex = 11; - this.btnRefreshPorts.Text = "Refresh Ports"; - this.btnRefreshPorts.UseVisualStyleBackColor = true; - this.btnRefreshPorts.Click += new System.EventHandler(this.btnRefreshPorts_Click); - // - // button3 - // - this.button3.Location = new System.Drawing.Point(448, 254); - this.button3.Name = "button3"; - this.button3.Size = new System.Drawing.Size(156, 23); - this.button3.TabIndex = 10; - this.button3.Text = "Clear Output Window"; - this.button3.UseVisualStyleBackColor = true; - this.button3.Click += new System.EventHandler(this.button3_Click); - // - // txtUARTOutput - // - this.txtUARTOutput.Location = new System.Drawing.Point(73, 78); - this.txtUARTOutput.Multiline = true; - this.txtUARTOutput.Name = "txtUARTOutput"; - this.txtUARTOutput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this.txtUARTOutput.Size = new System.Drawing.Size(531, 170); - this.txtUARTOutput.TabIndex = 9; - // - // label22 - // - this.label22.AutoSize = true; - this.label22.Location = new System.Drawing.Point(6, 78); - this.label22.Name = "label22"; - this.label22.Size = new System.Drawing.Size(48, 15); - this.label22.TabIndex = 8; - this.label22.Text = "Output:"; - // - // btnClearErrorCodes - // - this.btnClearErrorCodes.Location = new System.Drawing.Point(186, 44); - this.btnClearErrorCodes.Name = "btnClearErrorCodes"; - this.btnClearErrorCodes.Size = new System.Drawing.Size(118, 23); - this.btnClearErrorCodes.TabIndex = 7; - this.btnClearErrorCodes.Text = "Clear Error Codes"; - this.btnClearErrorCodes.UseVisualStyleBackColor = true; - this.btnClearErrorCodes.Click += new System.EventHandler(this.btnClearErrorCodes_Click); - // - // label21 - // - this.label21.AutoSize = true; - this.label21.Location = new System.Drawing.Point(6, 48); - this.label21.Name = "label21"; - this.label21.Size = new System.Drawing.Size(52, 15); - this.label21.TabIndex = 6; - this.label21.Text = "Options:"; - // - // button1 - // - this.button1.Location = new System.Drawing.Point(73, 44); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(107, 23); - this.button1.TabIndex = 5; - this.button1.Text = "Get Error Codes"; - this.button1.UseVisualStyleBackColor = true; - this.button1.Click += new System.EventHandler(this.button1_Click); - // - // comboComPorts - // - this.comboComPorts.FormattingEnabled = true; - this.comboComPorts.Location = new System.Drawing.Point(73, 13); - this.comboComPorts.Name = "comboComPorts"; - this.comboComPorts.Size = new System.Drawing.Size(274, 23); - this.comboComPorts.TabIndex = 4; - // - // btnDisconnectCom - // - this.btnDisconnectCom.Location = new System.Drawing.Point(434, 13); - this.btnDisconnectCom.Name = "btnDisconnectCom"; - this.btnDisconnectCom.Size = new System.Drawing.Size(75, 23); - this.btnDisconnectCom.TabIndex = 3; - this.btnDisconnectCom.Text = "Disconnect"; - this.btnDisconnectCom.UseVisualStyleBackColor = true; - this.btnDisconnectCom.Click += new System.EventHandler(this.btnDisconnectCom_Click); - // - // btnConnectCom - // - this.btnConnectCom.Location = new System.Drawing.Point(353, 12); - this.btnConnectCom.Name = "btnConnectCom"; - this.btnConnectCom.Size = new System.Drawing.Size(75, 23); - this.btnConnectCom.TabIndex = 2; - this.btnConnectCom.Text = "Connect"; - this.btnConnectCom.UseVisualStyleBackColor = true; - this.btnConnectCom.Click += new System.EventHandler(this.btnConnectCom_Click); - // - // label3 - // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(6, 16); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(61, 15); - this.label3.TabIndex = 0; - this.label3.Text = "Com Port:"; + this.ucUART.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.ucUART.Location = new System.Drawing.Point(0, 0); + this.ucUART.Name = "ucUART"; + this.ucUART.Size = new System.Drawing.Size(1816, 807); + this.ucUART.TabIndex = 0; // // label23 // this.label23.AutoSize = true; this.label23.Font = new System.Drawing.Font("Segoe UI Semibold", 9F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point); - this.label23.Location = new System.Drawing.Point(193, 48); + this.label23.Location = new System.Drawing.Point(331, 96); + this.label23.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.label23.Name = "label23"; - this.label23.Size = new System.Drawing.Size(215, 15); + this.label23.Size = new System.Drawing.Size(383, 30); this.label23.TabIndex = 47; this.label23.Text = "and UART stuff too... BwE can SUCK IT!"; // - // label25 - // - this.label25.AutoSize = true; - this.label25.Location = new System.Drawing.Point(610, 151); - this.label25.Name = "label25"; - this.label25.Size = new System.Drawing.Size(198, 105); - this.label25.TabIndex = 17; - this.label25.Text = resources.GetString("label25.Text"); - // - // Form1 + // fMainForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 30F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.White; - this.ClientSize = new System.Drawing.Size(847, 557); + this.ClientSize = new System.Drawing.Size(1933, 1472); this.Controls.Add(this.label23); this.Controls.Add(this.tabControl1); this.Controls.Add(this.label15); @@ -759,20 +219,18 @@ private void InitializeComponent() this.Controls.Add(this.label2); this.Controls.Add(this.pictureBox1); this.Controls.Add(this.label1); - this.Margin = new System.Windows.Forms.Padding(2); - this.Name = "Form1"; + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.MinimumSize = new System.Drawing.Size(1901, 1466); + this.Name = "fMainForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "PS5 NOR Modifier"; - this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); - this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit(); this.statusStrip1.ResumeLayout(false); this.statusStrip1.PerformLayout(); this.tabControl1.ResumeLayout(false); this.tabPage1.ResumeLayout(false); - this.tabPage1.PerformLayout(); this.tabPage2.ResumeLayout(false); - this.tabPage2.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -785,59 +243,14 @@ private void InitializeComponent() private Label label2; private PictureBox pictureBox2; private Label label4; - private Label label5; - private TextBox fileLocationBox; - private Button browseFileButton; - private Label label6; - private Label label7; - private Label label9; - private Label label10; - private Label serialNumber; - private Label modelInfo; - private Label fileSizeInfo; private StatusStrip statusStrip1; private ToolStripStatusLabel toolStripStatusLabel1; - private Label label8; - private Label boardVariant; - private Label label11; - private Button convertToDigitalEditionButton; - private ComboBox boardVariantSelectionBox; - private Label label12; - private Label label13; - private TextBox serialNumberTextbox; - private Label label14; - private ComboBox boardModelSelectionBox; private Label label15; - private Label label16; - private Label macAddressInfo; - private Label LANMacAddressInfo; - private Label label18; - private Label moboSerialInfo; - private Label label19; - private Label label17; - private TextBox wifiMacAddressTextbox; - private TextBox lanMacAddressTextbox; - private Label label20; private TabControl tabControl1; private TabPage tabPage1; private TabPage tabPage2; - private Button button3; - private TextBox txtUARTOutput; - private Label label22; - private Button btnClearErrorCodes; - private Label label21; - private Button button1; - private ComboBox comboComPorts; - private Button btnDisconnectCom; - private Button btnConnectCom; - private Label label3; - private Button btnRefreshPorts; private Label label23; - private Button btnDownloadDatabase; - private CheckBox chkUseOffline; - private Button btnSendCommand; - private TextBox txtCustomCommand; - private Label label24; - private Label label25; + private UserControls.UART.UartUserControl ucUART; + private UserControls.NorModifier.NorModifierUserControl ucNORModifier; } } \ No newline at end of file diff --git a/PS5 NOR Modifier/Form1.cs b/PS5 NOR Modifier/Form1.cs index 8f6dec8..0677f24 100644 --- a/PS5 NOR Modifier/Form1.cs +++ b/PS5 NOR Modifier/Form1.cs @@ -1,340 +1,36 @@ -using System.Diagnostics; -using System.Globalization; -using System.IO; -using System.Runtime.InteropServices; -using System.Text; -using System.Text.RegularExpressions; -using System.Windows.Forms; -using System.IO.Ports; -using System; -using System.Threading; -using System.Collections.Generic; -using static System.Windows.Forms.LinkLabel; -using static System.Windows.Forms.VisualStyles.VisualStyleElement; -using System.Net; -using System.Xml; -using System.Security.Policy; +using PS5_NOR_Modifier.Common.Helpers; +using PS5_NOR_Modifier.UserControls.Events; namespace PS5_NOR_Modifier { - public partial class Form1 : Form + public partial class fMainForm : Form { - - public Form1() + public fMainForm() { InitializeComponent(); - } - - static string CalculateChecksum(string str) - { - int sum = 0; - foreach (char c in str) - { - sum += (int)c; - } - return str + ":" + (sum & 0xFF).ToString("X2"); - } - - private void throwError(string errmsg) - { - MessageBox.Show(errmsg, "An Error Has Occurred", MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - - // We want this app to work offline, so let's declare where the local "offline" database will be stored - string localDatabaseFile = "errorDB.xml"; - - static SerialPort UARTSerial = new SerialPort(); - - /// - /// With thanks to @jjxtra on Github. The code has already been created and there's no need to reinvent the wheel is there? - /// - #region Hex Code - - private static IEnumerable PatternAt(byte[] source, byte[] pattern) - { - for (int i = 0; i < source.Length; i++) - { - if (source.Skip(i).Take(pattern.Length).SequenceEqual(pattern)) - { - yield return i; - } - } - } - - private static byte[] ConvertHexStringToByteArray(string hexString) - { - if (hexString.Length % 2 != 0) - { - throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "The binary key cannot have an odd number of digits: {0}", hexString)); - } - - byte[] data = new byte[hexString.Length / 2]; - for (int index = 0; index < data.Length; index++) - { - string byteValue = hexString.Substring(index * 2, 2); - data[index] = byte.Parse(byteValue, NumberStyles.HexNumber, CultureInfo.InvariantCulture); - } - - return data; - } - - #endregion - - private void Form1_Load(object sender, EventArgs e) - { - // Upon first launch, we need to get a list of COM ports available for UART - string[] ports = SerialPort.GetPortNames(); - comboComPorts.Items.Clear(); - comboComPorts.Items.AddRange(ports); - comboComPorts.SelectedIndex = 0; - btnConnectCom.Enabled = true; - btnDisconnectCom.Enabled = false; - } - - // Declare offsets to detect console version - long offsetOne = 0x1c7010; - long offsetTwo = 0x1c7030; - long WiFiMacOffset = 0x1C73C0; - string? WiFiMacValue = null; - long LANMacOffset = 0x1C4020; - string? LANMacValue = null; - string? offsetOneValue = null; - string? offsetTwoValue = null; - long serialOffset = 0x1c7210; - string? serialValue = null; - long variantOffset = 0x1c7226; - string? variantValue = null; - long moboSerialOffset = 0x1C7200; - string? moboSerialValue = null; - - private async Task DownloadDatabaseAsync() - { - // Define the URL - string url = "http://uartcodes.com/xml.php"; // Update with your URL - - // Define the file path to save the XML - - try - { - // Create a WebClient instance - using (HttpClient client = new()) - { - // Download the XML data from the URL - string xmlData = await client.GetStringAsync(url); - - // Create an XmlDocument instance and load the XML data - XmlDocument xmlDoc = new XmlDocument(); - xmlDoc.LoadXml(xmlData); - // Save the XML data to a file - xmlDoc.Save(localDatabaseFile); - - MessageBox.Show("The most recent offline database has been updated successfully.", "Offline Database Updated!", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } - catch (Exception ex) - { - Console.WriteLine("Error: " + ex.Message); - } + LoadNorModifierControl(); + LoadUARTControl(); } - /// - /// We need to be able to send the error code we received from the console and fetch an XML result back from the server - /// Once we have a result from the server, parse the XML data and output it in an easy to understand format for the user - /// - /// - /// - async Task ParseErrorsAsync(string ErrorCode) + private void LoadUARTControl() { - // If the user has opted to parse errors with an offline database, run the parse offline function - if (chkUseOffline.Checked == true) - { - return ParseErrorsOffline(ErrorCode); - } - else - { - // The user wants to use the online version. Proceed at will - - // Define the URL with the error code parameter - string url = "http://uartcodes.com/xml.php?errorCode=" + ErrorCode; - - string results = ""; - - try - { - string response = ""; - // Create a WebClient instance to send the request - using (HttpClient client = new()) - { - // Send the request and retrieve the response as a string - response = await client.GetStringAsync(url); - } - // Load the XML response into an XmlDocument - XmlDocument xmlDoc = new XmlDocument(); - xmlDoc.LoadXml(response); - - - // Get the root node - XmlNode? root = xmlDoc.DocumentElement; - if (root is null) { - throw new Exception("Error reading the file"); - } - - // Check if the root node is - if (root.Name == "errorCodes") - { - // Loop through each errorCode node - foreach (XmlNode errorCodeNode in root.ChildNodes) - { - // Check if the node is - if (errorCodeNode.Name == "errorCode") - { - // Get ErrorCode and Description - string errorCode = errorCodeNode.SelectSingleNode("ErrorCode")?.InnerText ?? ""; - string description = errorCodeNode.SelectSingleNode("Description")?.InnerText??""; - - // Output the results - results = "Error code: " - + errorCode - + Environment.NewLine - + "Description: " - + description; - } - } - } - else - { - results = "Error code: " - + ErrorCode - + Environment.NewLine - + "An error occurred while fetching a result for this error. Please try again!"; - } - } - catch (Exception ex) - { - results = "Error code: " - + ErrorCode - + Environment.NewLine - + ex.Message; - } - return results; - } + ucUART.statusUpdateEvent += ucUART_statusUpdateEvent; } - string ParseErrorsOffline(string errorCode) + private void LoadNorModifierControl() { - string results = ""; - - try - { - // Check if the XML file exists - if (File.Exists(localDatabaseFile)) - { - // Load the XML file - XmlDocument xmlDoc = new XmlDocument(); - xmlDoc.Load(localDatabaseFile); - - // Get the root node - XmlNode? root = xmlDoc.DocumentElement; - if (root is null) return results; - - // Check if the root node is - if (root.Name == "errorCodes") - { - // Loop through each errorCode node - foreach (XmlNode errorCodeNode in root.ChildNodes) - { - // Check if the node is - if (errorCodeNode.Name == "errorCode") - { - // Get ErrorCode and Description - string errorCodeValue = errorCodeNode.SelectSingleNode("ErrorCode")?.InnerText??""; - string description = errorCodeNode.SelectSingleNode("Description")?.InnerText??""; - - // Check if the current error code matches the requested error code - if (errorCodeValue == errorCode) - { - // Output the results - results = "Error code: " + errorCodeValue + Environment.NewLine + "Description: " + description; - break; // Exit the loop after finding the matching error code - } - } - } - } - else - { - results = "Error: Invalid XML database file. Please reconfigure the application, redownload the offline database, or uncheck the option to use the offline database."; - } - } - else - { - results = "Error: Local XML file not found."; - } - } - catch (Exception ex) - { - results = "Error: " + ex.Message; - } - - return results; + ucNORModifier.statusUpdateEvent += ucNORModifier_statusUpdateEvent; } - string HexStringToString(string hexString) + private void ucNORModifier_statusUpdateEvent(object? sender, StatusUpdateEventArgs e) { - if (hexString == null || (hexString.Length & 1) == 1) - { - throw new ArgumentException(); - } - var sb = new StringBuilder(); - for (var i = 0; i < hexString.Length; i += 2) - { - var hexChar = hexString.Substring(i, 2); - sb.Append((char)Convert.ToByte(hexChar, 16)); - } - return sb.ToString(); + toolStripStatusLabel1.Text = e.Text; } - /// - /// Lauinches a URL in a new window using the default browser... - /// - /// The URL you want to launch - private void OpenUrl(string url) + private void ucUART_statusUpdateEvent(object? sender, StatusUpdateEventArgs e) { - try - { - Process.Start(url); - } - catch - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - url = url.Replace("&", "^&"); - Process.Start(new ProcessStartInfo(url) { UseShellExecute = true }); - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - Process.Start("xdg-open", url); - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - { - Process.Start("open", url); - } - else - { - throw; - } - } - } - - private void ResetAppFields() - { - fileLocationBox.Text = ""; - serialNumber.Text = "..."; - boardVariant.Text = "..."; - modelInfo.Text = "..."; - fileSizeInfo.Text = "..."; - serialNumberTextbox.Text = ""; - toolStripStatusLabel1.Text = "Status: Waiting for input"; + toolStripStatusLabel1.Text = e.Text; } #region Donations @@ -346,814 +42,20 @@ private void ResetAppFields() /// private void label4_Click(object sender, EventArgs e) { - OpenUrl("https://www.streamelements.com/thecod3r/tip"); + Browser.OpenUrl("https://www.streamelements.com/thecod3r/tip"); } private void pictureBox2_Click(object sender, EventArgs e) { - OpenUrl("https://www.streamelements.com/thecod3r/tip"); + Browser.OpenUrl("https://www.streamelements.com/thecod3r/tip"); } #endregion - private void browseFileButton_Click(object sender, EventArgs e) - { - OpenFileDialog fileDialogBox = new OpenFileDialog(); - fileDialogBox.Title = "Open NOR BIN File"; - fileDialogBox.Filter = "PS5 BIN Files|*.bin"; - - if (fileDialogBox.ShowDialog() == DialogResult.OK) - { - if(fileDialogBox.CheckFileExists == false) - { - throwError("The file you selected could not be found. Please check the file exists and is a valid BIN file."); - } - else - { - if(!fileDialogBox.SafeFileName.EndsWith(".bin")) - { - throwError("The file you selected is not a valid. Please ensure the file you are choosing is a correct BIN file and try again."); - } - else - { - // Let's load simple information first, before loading BIN specific data - fileLocationBox.Text = ""; - // Get the path selected and print it into the path box - string selectedPath = fileDialogBox.FileName; - toolStripStatusLabel1.Text = "Status: Selected file " + selectedPath; - fileLocationBox.Text = selectedPath; - - // Get file length and show in bytes and MB - long length = new System.IO.FileInfo(selectedPath).Length; - fileSizeInfo.Text = length.ToString() + " bytes (" + length / 1024 / 1024 + "MB)"; - - #region Extract PS5 Version - - try - { - BinaryReader reader = new BinaryReader(new FileStream(fileDialogBox.FileName, FileMode.Open)); - //Set the position of the reader - reader.BaseStream.Position = offsetOne; - //Read the offset - offsetOneValue = BitConverter.ToString(reader.ReadBytes(12)).Replace("-", null); - reader.Close(); - } - catch - { - // Obviously this value is invalid, so null the value and move on - offsetOneValue = null; - } - - try - { - BinaryReader reader = new BinaryReader(new FileStream(fileDialogBox.FileName, FileMode.Open)); - //Set the position of the reader - reader.BaseStream.Position = offsetOne; - //Read the offset - offsetTwoValue = BitConverter.ToString(reader.ReadBytes(12)).Replace("-", null); - reader.Close(); - } - catch - { - // Obviously this value is invalid, so null the value and move on - offsetTwoValue = null; - } - - - if(offsetOneValue?.Contains("22020101")??false) - { - modelInfo.Text = "Disc Edition"; - } - else - { - if(offsetTwoValue?.Contains("22030101") ?? false) - { - modelInfo.Text = "Digital Edition"; - } - else - { - modelInfo.Text = "Unknown"; - } - } - - #endregion - - #region Extract Motherboard Serial Number - - try - { - BinaryReader reader = new BinaryReader(new FileStream(fileDialogBox.FileName, FileMode.Open)); - //Set the position of the reader - reader.BaseStream.Position = moboSerialOffset; - //Read the offset - moboSerialValue = BitConverter.ToString(reader.ReadBytes(16)).Replace("-", null); - reader.Close(); - } - catch - { - // Obviously this value is invalid, so null the value and move on - moboSerialValue = null; - } - - - - if(moboSerialValue != null) - { - moboSerialInfo.Text = HexStringToString(moboSerialValue); - } - else - { - moboSerialInfo.Text = "Unknown"; - } - - #endregion - - #region Extract Board Serial Number - - try - { - BinaryReader reader = new BinaryReader(new FileStream(fileDialogBox.FileName, FileMode.Open)); - //Set the position of the reader - reader.BaseStream.Position = serialOffset; - //Read the offset - serialValue = BitConverter.ToString(reader.ReadBytes(17)).Replace("-", null); - reader.Close(); - } - catch - { - // Obviously this value is invalid, so null the value and move on - serialValue = null; - } - - - - if (serialValue != null) - { - serialNumber.Text = HexStringToString(serialValue); - serialNumberTextbox.Text = HexStringToString(serialValue); - - } - else - { - serialNumber.Text = "Unknown"; - } - - #endregion - - #region Extract WiFi Mac Address - - try - { - BinaryReader reader = new BinaryReader(new FileStream(fileDialogBox.FileName, FileMode.Open)); - //Set the position of the reader - reader.BaseStream.Position = WiFiMacOffset; - //Read the offset - WiFiMacValue = BitConverter.ToString(reader.ReadBytes(6)); - reader.Close(); - } - catch - { - // Obviously this value is invalid, so null the value and move on - WiFiMacValue = null; - } - - if (WiFiMacValue != null) - { - macAddressInfo.Text = WiFiMacValue; - wifiMacAddressTextbox.Text = WiFiMacValue; - } - else - { - macAddressInfo.Text = "Unknown"; - wifiMacAddressTextbox.Text = ""; - } - - #endregion - - #region Extract LAN Mac Address - - try - { - BinaryReader reader = new BinaryReader(new FileStream(fileDialogBox.FileName, FileMode.Open)); - //Set the position of the reader - reader.BaseStream.Position = LANMacOffset; - //Read the offset - LANMacValue = BitConverter.ToString(reader.ReadBytes(6)); - reader.Close(); - } - catch - { - // Obviously this value is invalid, so null the value and move on - LANMacValue = null; - } - - if (LANMacValue != null) - { - LANMacAddressInfo.Text = LANMacValue; - lanMacAddressTextbox.Text = LANMacValue; - } - else - { - LANMacAddressInfo.Text = "Unknown"; - lanMacAddressTextbox.Text = ""; - } - - #endregion - - #region Extract Board Variant - - try - { - BinaryReader reader = new BinaryReader(new FileStream(fileDialogBox.FileName, FileMode.Open)); - //Set the position of the reader - reader.BaseStream.Position = variantOffset; - //Read the offset - variantValue = BitConverter.ToString(reader.ReadBytes(19)).Replace("-", null).Replace("FF", null); - reader.Close(); - } - catch - { - // Obviously this value is invalid, so null the value and move on - variantValue = null; - } - - - - if (variantValue != null) - { - boardVariant.Text = HexStringToString(variantValue); - } - else - { - boardVariant.Text = "Unknown"; - } - - boardVariant.Text += boardVariant.Text switch { - _ when boardVariant.Text.EndsWith("00A") || boardVariant.Text.EndsWith("00B") => " - Japan", - _ when boardVariant.Text.EndsWith("01A") || boardVariant.Text.EndsWith("01B") || - boardVariant.Text.EndsWith("15A") || boardVariant.Text.EndsWith("15B") => " - US, Canada, (North America)", - _ when boardVariant.Text.EndsWith("02A") || boardVariant.Text.EndsWith("02B") => " - Australia / New Zealand, (Oceania)", - _ when boardVariant.Text.EndsWith("03A") || boardVariant.Text.EndsWith("03B") => " - United Kingdom / Ireland", - _ when boardVariant.Text.EndsWith("04A") || boardVariant.Text.EndsWith("04B") => " - Europe / Middle East / Africa", - _ when boardVariant.Text.EndsWith("05A") || boardVariant.Text.EndsWith("05B") => " - South Korea", - _ when boardVariant.Text.EndsWith("06A") || boardVariant.Text.EndsWith("06B") => " - Southeast Asia / Hong Kong", - _ when boardVariant.Text.EndsWith("07A") || boardVariant.Text.EndsWith("07B") => " - Taiwan", - _ when boardVariant.Text.EndsWith("08A") || boardVariant.Text.EndsWith("08B") => " - Russia, Ukraine, India, Central Asia", - _ when boardVariant.Text.EndsWith("09A") || boardVariant.Text.EndsWith("09B") => " - Mainland China", - _ when boardVariant.Text.EndsWith("11A") || boardVariant.Text.EndsWith("11B") || - boardVariant.Text.EndsWith("14A") || boardVariant.Text.EndsWith("14B") - => " - Mexico, Central America, South America", - _ when boardVariant.Text.EndsWith("16A") || boardVariant.Text.EndsWith("16B") => " - Europe / Middle East / Africa", - _ when boardVariant.Text.EndsWith("18A") || boardVariant.Text.EndsWith("18B") => " - Singapore, Korea, Asia", - _=> " - Unknown Region" - }; - #endregion - } - } - } - } - - private void convertToDigitalEditionButton_Click(object sender, EventArgs e) - { - - string fileNameToLookFor = ""; - bool errorShownAlready = false; - - if (modelInfo.Text == "" || modelInfo.Text == "...") - { - // No valid BIN file seems to have been selected - throwError("Please select a valid BIOS file first..."); - errorShownAlready = true; - } - else - { - if(boardModelSelectionBox.Text == "") - { - throwError("Please select a valid board model before saving new BIOS information!"); - errorShownAlready = true; - } - else - { - if(boardVariantSelectionBox.Text == "") - { - throwError("Please select a valid board variant before saving new BIOS information!"); - errorShownAlready = true; - } - else - { - SaveFileDialog saveBox = new SaveFileDialog(); - saveBox.Title = "Save NOR BIN File"; - saveBox.Filter = "PS5 BIN Files|*.bin"; - - if (saveBox.ShowDialog() == DialogResult.OK) - { - // First create a copy of the old BIOS file - byte[] existingFile = File.ReadAllBytes(fileLocationBox.Text); - string newFile = saveBox.FileName; - - File.WriteAllBytes(newFile, existingFile); - - fileNameToLookFor = saveBox.FileName; - - #region Set the new model info - if (modelInfo.Text == "Disc Edition") - { - try - { - - if (boardModelSelectionBox.Text == "Digital Edition") - - { - - byte[] find = ConvertHexStringToByteArray(Regex.Replace("22020101", "0x|[ ,]", string.Empty).Normalize().Trim()); - byte[] replace = ConvertHexStringToByteArray(Regex.Replace("22030101", "0x|[ ,]", string.Empty).Normalize().Trim()); - if (find.Length != replace.Length) - { - throwError("The length of the old hex value does not match the length of the new hex value!"); - errorShownAlready = true; - } - byte[] bytes = File.ReadAllBytes(newFile); - foreach (int index in PatternAt(bytes, find)) - { - for (int i = index, replaceIndex = 0; i < bytes.Length && replaceIndex < replace.Length; i++, replaceIndex++) - { - bytes[i] = replace[replaceIndex]; - } - File.WriteAllBytes(newFile, bytes); - } - } - - } - catch - { - throwError("An error occurred while saving your BIOS file"); - errorShownAlready = true; - } - } - else - { - if(modelInfo.Text == "Digital Edition") - { - try - { - - if (boardModelSelectionBox.Text == "Disc Edition") - - { - - byte[] find = ConvertHexStringToByteArray(Regex.Replace("22030101", "0x|[ ,]", string.Empty).Normalize().Trim()); - byte[] replace = ConvertHexStringToByteArray(Regex.Replace("22020101", "0x|[ ,]", string.Empty).Normalize().Trim()); - if (find.Length != replace.Length) - { - throwError("The length of the old hex value does not match the length of the new hex value!"); - errorShownAlready = true; - } - byte[] bytes = File.ReadAllBytes(newFile); - foreach (int index in PatternAt(bytes, find)) - { - for (int i = index, replaceIndex = 0; i < bytes.Length && replaceIndex < replace.Length; i++, replaceIndex++) - { - bytes[i] = replace[replaceIndex]; - } - File.WriteAllBytes(newFile, bytes); - } - } - - } - catch - { - throwError("An error occurred while saving your BIOS file"); - errorShownAlready = true; - } - } - } - #endregion - - #region Set the new board variant - - try - { - byte[] oldVariant = Encoding.UTF8.GetBytes(boardVariant.Text); - string oldVariantHex = Convert.ToHexString(oldVariant); - - byte[] newVariantSelection = Encoding.UTF8.GetBytes(boardVariantSelectionBox.Text); - string newVariantHex = Convert.ToHexString(newVariantSelection); - - byte[] find = ConvertHexStringToByteArray(Regex.Replace(oldVariantHex, "0x|[ ,]", string.Empty).Normalize().Trim()); - byte[] replace = ConvertHexStringToByteArray(Regex.Replace(newVariantHex, "0x|[ ,]", string.Empty).Normalize().Trim()); - - byte[] bytes = File.ReadAllBytes(newFile); - foreach (int index in PatternAt(bytes, find)) - { - for (int i = index, replaceIndex = 0; i < bytes.Length && replaceIndex < replace.Length; i++, replaceIndex++) - { - bytes[i] = replace[replaceIndex]; - } - File.WriteAllBytes(newFile, bytes); - } - - } - catch(System.ArgumentException ex) - { - throwError(ex.Message.ToString()); - errorShownAlready = true; - } - - #endregion - - #region Change Serial Number - - try - { - - byte[] oldSerial = Encoding.UTF8.GetBytes(serialNumber.Text); - string oldSerialHex = Convert.ToHexString(oldSerial); - - byte[] newSerial = Encoding.UTF8.GetBytes(serialNumberTextbox.Text); - string newSerialHex = Convert.ToHexString(newSerial); - - byte[] find = ConvertHexStringToByteArray(Regex.Replace(oldSerialHex, "0x|[ ,]", string.Empty).Normalize().Trim()); - byte[] replace = ConvertHexStringToByteArray(Regex.Replace(newSerialHex, "0x|[ ,]", string.Empty).Normalize().Trim()); - - byte[] bytes = File.ReadAllBytes(newFile); - foreach (int index in PatternAt(bytes, find)) - { - for (int i = index, replaceIndex = 0; i < bytes.Length && replaceIndex < replace.Length; i++, replaceIndex++) - { - bytes[i] = replace[replaceIndex]; - } - File.WriteAllBytes(newFile, bytes); - } - - } - catch (System.ArgumentException ex) - { - throwError(ex.Message.ToString()); - errorShownAlready = true; - } - - #endregion - } - else - { - throwError("Save operation cancelled!"); - errorShownAlready = true; - } - } - } - } - - if(File.Exists(fileNameToLookFor) && errorShownAlready == false) - { - // Reset everything and show message - ResetAppFields(); - MessageBox.Show("A new BIOS file was successfully created. Please load the new BIOS file to verify the information you entered before installing onto your motherboard. Remember this software was created by TheCod3r with nothing but love. Why not show some love back by dropping me a small donation to say thanks ;).", "All done!", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - - } - private void label15_Click(object sender, EventArgs e) { - OpenUrl("https://www.consolefix.shop"); - } - - private void label1_Click(object sender, EventArgs e) - { - - } - - private void btnRefreshPorts_Click(object sender, EventArgs e) - { - // When the "refresh ports" button is pressed, we need to refresh the list of available COM ports for UART - string[] ports = SerialPort.GetPortNames(); - comboComPorts.Items.Clear(); - comboComPorts.Items.AddRange(ports); - comboComPorts.SelectedIndex = 0; - btnConnectCom.Enabled = true; - btnDisconnectCom.Enabled = false; - } - - private void btnConnectCom_Click(object sender, EventArgs e) - { - // Let's try and connect to the UART reader - btnConnectCom.Enabled = false; - - if (comboComPorts.Text != "") - { - - try - { - // Set port to selected port - UARTSerial.PortName = comboComPorts.Text; - // Set the BAUD rate to 115200 - UARTSerial.BaudRate = 115200; - // Enable RTS - UARTSerial.RtsEnable = true; - // Open the COM port - UARTSerial.Open(); - btnDisconnectCom.Enabled = true; - toolStripStatusLabel1.Text = "Connected to UART via COM port " + comboComPorts.Text + " at a BAUD rate of 115200."; - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "An error occurred...", MessageBoxButtons.OK, MessageBoxIcon.Error); - btnConnectCom.Enabled = true; - btnDisconnectCom.Enabled = false; - toolStripStatusLabel1.Text = "Could not connect to UART. Please try again!"; - } - - } - else - { - MessageBox.Show("Please select a COM port from the ports list to establish a connection.", "An error occurred...", MessageBoxButtons.OK, MessageBoxIcon.Error); - btnConnectCom.Enabled = true; - btnDisconnectCom.Enabled = false; - toolStripStatusLabel1.Text = "Could not connect to UART. Please try again!"; - } - } - - private void btnDisconnectCom_Click(object sender, EventArgs e) - { - // Let's close the COM port - try - { - if(UARTSerial.IsOpen == true) - { - UARTSerial.Close(); - btnConnectCom.Enabled = true; - btnDisconnectCom.Enabled = false; - toolStripStatusLabel1.Text = "Disconnected from UART..."; - } - } - catch(Exception ex) - { - MessageBox.Show(ex.Message, "An error occurred...", MessageBoxButtons.OK, MessageBoxIcon.Error); - toolStripStatusLabel1.Text = "An error occurred while disconnecting from UART. Please try again..."; - } - } - - /// - /// Read error codes from UART - /// - /// - /// - private async void button1_Click(object sender, EventArgs e) - { - // Let's read the error codes from UART - txtUARTOutput.Text = ""; - - if (UARTSerial.IsOpen == true) - { - try - { - - List UARTLines = new(); - - for (var i = 0; i <= 10; i++) - { - var command = $"errlog {i}"; - var checksum = CalculateChecksum(command); - UARTSerial.WriteLine(checksum); - do - { - var line = UARTSerial.ReadLine(); - if (!string.Equals($"{command}:{checksum:X2}", line, StringComparison.InvariantCultureIgnoreCase)) - { - UARTLines.Add(line); - } - } while (UARTSerial.BytesToRead != 0); - - foreach (var l in UARTLines) - { - var split = l.Split(' '); - if (!split.Any()) continue; - switch (split[0]) - { - case "NG": - break; - case "OK": - var errorCode = split[2]; - // Now that the error code has been isolated from the rest of the junk sent by the system - // let's check it against the database. The error server will need to return XML results - string errorResult = await ParseErrorsAsync(errorCode); - if (!txtUARTOutput.Text.Contains(errorResult)) - { - txtUARTOutput.AppendText(errorResult + Environment.NewLine); - } - break; - } - } - } - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "An error occurred...", MessageBoxButtons.OK, MessageBoxIcon.Error); - toolStripStatusLabel1.Text = "An error occurred while reading error codes from UART. Please try again..."; - } - } - else - { - MessageBox.Show("Please connect to UART before attempting to read the error codes.", "An error occurred...", MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - } - - // If the app is closed before UART is terminated, we need to at least try to close the COM port gracefully first - private void Form1_FormClosing(object sender, FormClosingEventArgs e) - { - if(UARTSerial.IsOpen == true) - { - try - { - UARTSerial.Close(); - } - catch(Exception ex) - { - MessageBox.Show(ex.Message, "An error occurred...", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - } - - /// - /// Clear the UART output window - /// - /// - /// - private void button3_Click(object sender, EventArgs e) - { - txtUARTOutput.Text = ""; - } - - /// - /// When the user clicks on the download error database button, show a confirmation first and then if they click yes, - /// continue to download the latest database from the update server - /// - /// - /// - private async void btnDownloadDatabase_Click(object sender, EventArgs e) - { - DialogResult result = MessageBox.Show("Downloading the error database will overwrite any existing offline database you currently have. Are you sure you would like to do this?", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); - - // Check if user wants to proceed - if (result == DialogResult.Yes) - { - // Call the function to download and save the XML data - await DownloadDatabaseAsync(); - } - else - { - // Do nothing. The user cancelled the request// The user cancelled - } - } - - /// - /// The user can clear the error codes from the console if required but let's make sure they actually want to do - /// that by showing a confirmation dialog first. If the click yes, send the UART command and wipe the codes from - /// the console. This action cannot be undone! - /// - /// - /// - private void btnClearErrorCodes_Click(object sender, EventArgs e) - { - DialogResult result = MessageBox.Show("This will clear error codes from the console by sending the \"errlog clear\" command. Are you sure you would like to proceed? This action cannot be undone!", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); - - if(result == DialogResult.Yes) - { - // Let's read the error codes from UART - txtUARTOutput.Text = ""; - - if (UARTSerial.IsOpen == true) - { - try - { - - List UARTLines = new(); - - var command = "errlog clear"; - var checksum = CalculateChecksum(command); - UARTSerial.WriteLine(checksum); - do - { - var line = UARTSerial.ReadLine(); - if (!string.Equals($"{command}:{checksum:X2}", line, StringComparison.InvariantCultureIgnoreCase)) - { - UARTLines.Add(line); - } - } while (UARTSerial.BytesToRead != 0); - - foreach (var l in UARTLines) - { - var split = l.Split(' '); - if (!split.Any()) continue; - switch (split[0]) - { - case "NG": - if (!txtUARTOutput.Text.Contains("FAIL")) - { - txtUARTOutput.AppendText("Response: FAIL" + Environment.NewLine + "Information: An error occurred while clearing the error logs from the system. Please try again..."); - } - break; - case "OK": - if (!txtUARTOutput.Text.Contains("SUCCESS")) - { - txtUARTOutput.AppendText("Response: SUCCESS" + Environment.NewLine + "Information: All error codes cleared successfully"); - } - break; - } - } - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "An error occurred...", MessageBoxButtons.OK, MessageBoxIcon.Error); - toolStripStatusLabel1.Text = "An error occurred while attempting to send a UART command. Please try again..."; - } - } - else - { - MessageBox.Show("Please connect to UART before attempting to send commands.", "An error occurred...", MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - } - else - { - // Do nothing. The user cancelled the request - } - } - - /// - /// Sometimes the user might want to send a custom command. Let them do that here! - /// - /// - /// - private void btnSendCommand_Click(object sender, EventArgs e) - { - if (txtCustomCommand.Text != "") - { - // Let's read the error codes from UART - txtUARTOutput.Text = ""; - - if (UARTSerial.IsOpen == true) - { - try - { - - List UARTLines = new(); - - var checksum = CalculateChecksum(txtCustomCommand.Text); - UARTSerial.WriteLine(checksum); - do - { - var line = UARTSerial.ReadLine(); - if (!string.Equals($"{txtCustomCommand.Text}:{checksum:X2}", line, StringComparison.InvariantCultureIgnoreCase)) - { - UARTLines.Add(line); - } - } while (UARTSerial.BytesToRead != 0); - - foreach (var l in UARTLines) - { - var split = l.Split(' '); - if (!split.Any()) continue; - switch (split[0]) - { - case "NG": - txtUARTOutput.Text = "ERROR: " + l; - break; - case "OK": - txtUARTOutput.Text = "SUCCESS: " + l; - break; - } - } - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "An error occurred...", MessageBoxButtons.OK, MessageBoxIcon.Error); - toolStripStatusLabel1.Text = "An error occurred while reading error codes from UART. Please try again..."; - } - } - else - { - MessageBox.Show("Please connect to UART before attempting to send commands.", "An error occurred...", MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - } - else - { - MessageBox.Show("Please enter a command to send via UART.", "An error occurred...", MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - } - - /// - /// If the user presses the enter key while using the custom command box, handle it by programmatically pressing the - /// send button. This is more of a convenience thing really! - /// - /// - /// - private void txtCustomCommand_KeyPress(object sender, KeyPressEventArgs e) - { - if(e.KeyChar == (char)Keys.Enter) - { - btnSendCommand.PerformClick(); - } + Browser.OpenUrl("https://www.consolefix.shop"); } } -} \ No newline at end of file +} diff --git a/PS5 NOR Modifier/Form1.resx b/PS5 NOR Modifier/Form1.resx index 0184f73..09bc460 100644 --- a/PS5 NOR Modifier/Form1.resx +++ b/PS5 NOR Modifier/Form1.resx @@ -69,13 +69,4 @@ coffee addiction! Click here to donate to me. Even a dollar helps :) Don't forge 17, 17 - - You can send custom commands -with UART using this feature. Note -that any command entered here -will return unparsed results. Please -also be sure to know what you are -doing as sending unsafe commands -can damage your device. - \ No newline at end of file diff --git a/PS5 NOR Modifier/PS5 NOR Modifier.csproj.user b/PS5 NOR Modifier/PS5 NOR Modifier.csproj.user index 834d222..71720a7 100644 --- a/PS5 NOR Modifier/PS5 NOR Modifier.csproj.user +++ b/PS5 NOR Modifier/PS5 NOR Modifier.csproj.user @@ -7,5 +7,11 @@ Form + + UserControl + + + UserControl + \ No newline at end of file diff --git a/PS5 NOR Modifier/Program.cs b/PS5 NOR Modifier/Program.cs index 62a6e6b..0caa59f 100644 --- a/PS5 NOR Modifier/Program.cs +++ b/PS5 NOR Modifier/Program.cs @@ -11,7 +11,7 @@ static void Main() // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(new fMainForm()); } } } \ No newline at end of file diff --git a/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.Designer.cs b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.Designer.cs new file mode 100644 index 0000000..6ea2d01 --- /dev/null +++ b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.Designer.cs @@ -0,0 +1,649 @@ +namespace PS5_NOR_Modifier.UserControls.NorModifier +{ + partial class NorModifierUserControl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label5 = new System.Windows.Forms.Label(); + this.label20 = new System.Windows.Forms.Label(); + this.fileLocationBox = new System.Windows.Forms.TextBox(); + this.lanMacAddressTextbox = new System.Windows.Forms.TextBox(); + this.browseFileButton = new System.Windows.Forms.Button(); + this.wifiMacAddressTextbox = new System.Windows.Forms.TextBox(); + this.label6 = new System.Windows.Forms.Label(); + this.label17 = new System.Windows.Forms.Label(); + this.label7 = new System.Windows.Forms.Label(); + this.moboSerialInfo = new System.Windows.Forms.Label(); + this.label9 = new System.Windows.Forms.Label(); + this.label19 = new System.Windows.Forms.Label(); + this.label10 = new System.Windows.Forms.Label(); + this.LANMacAddressInfo = new System.Windows.Forms.Label(); + this.serialNumber = new System.Windows.Forms.Label(); + this.label18 = new System.Windows.Forms.Label(); + this.modelInfo = new System.Windows.Forms.Label(); + this.macAddressInfo = new System.Windows.Forms.Label(); + this.fileSizeInfo = new System.Windows.Forms.Label(); + this.label16 = new System.Windows.Forms.Label(); + this.label8 = new System.Windows.Forms.Label(); + this.boardVariant = new System.Windows.Forms.Label(); + this.boardModelSelectionBox = new System.Windows.Forms.ComboBox(); + this.label11 = new System.Windows.Forms.Label(); + this.label14 = new System.Windows.Forms.Label(); + this.convertToDigitalEditionButton = new System.Windows.Forms.Button(); + this.serialNumberTextbox = new System.Windows.Forms.TextBox(); + this.boardVariantSelectionBox = new System.Windows.Forms.ComboBox(); + this.label13 = new System.Windows.Forms.Label(); + this.label12 = new System.Windows.Forms.Label(); + this.lblSkuValue = new System.Windows.Forms.Label(); + this.lblSkuText = new System.Windows.Forms.Label(); + this.lblFWVersionValue = new System.Windows.Forms.Label(); + this.lblFWVersionText = new System.Windows.Forms.Label(); + this.lblMD5Value = new System.Windows.Forms.Label(); + this.lblMD5Text = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(5, 8); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(182, 30); + this.label5.TabIndex = 46; + this.label5.Text = "Select NOR Dump"; + // + // label20 + // + this.label20.AutoSize = true; + this.label20.Location = new System.Drawing.Point(670, 378); + this.label20.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.label20.Name = "label20"; + this.label20.Size = new System.Drawing.Size(185, 30); + this.label20.TabIndex = 75; + this.label20.Text = "LAN Mac Address:"; + this.label20.Visible = false; + // + // fileLocationBox + // + this.fileLocationBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.fileLocationBox.Location = new System.Drawing.Point(5, 42); + this.fileLocationBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.fileLocationBox.Name = "fileLocationBox"; + this.fileLocationBox.Size = new System.Drawing.Size(1226, 35); + this.fileLocationBox.TabIndex = 47; + // + // lanMacAddressTextbox + // + this.lanMacAddressTextbox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.lanMacAddressTextbox.Enabled = false; + this.lanMacAddressTextbox.Location = new System.Drawing.Point(865, 372); + this.lanMacAddressTextbox.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.lanMacAddressTextbox.Name = "lanMacAddressTextbox"; + this.lanMacAddressTextbox.Size = new System.Drawing.Size(508, 35); + this.lanMacAddressTextbox.TabIndex = 74; + this.lanMacAddressTextbox.Visible = false; + // + // browseFileButton + // + this.browseFileButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.browseFileButton.Location = new System.Drawing.Point(1242, 40); + this.browseFileButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.browseFileButton.Name = "browseFileButton"; + this.browseFileButton.Size = new System.Drawing.Size(134, 40); + this.browseFileButton.TabIndex = 48; + this.browseFileButton.Text = "Browse"; + this.browseFileButton.UseVisualStyleBackColor = true; + this.browseFileButton.Click += new System.EventHandler(this.browseFileButton_Click); + // + // wifiMacAddressTextbox + // + this.wifiMacAddressTextbox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.wifiMacAddressTextbox.Enabled = false; + this.wifiMacAddressTextbox.Location = new System.Drawing.Point(865, 314); + this.wifiMacAddressTextbox.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.wifiMacAddressTextbox.Name = "wifiMacAddressTextbox"; + this.wifiMacAddressTextbox.Size = new System.Drawing.Size(508, 35); + this.wifiMacAddressTextbox.TabIndex = 73; + this.wifiMacAddressTextbox.Visible = false; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this.label6.Location = new System.Drawing.Point(5, 100); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(154, 30); + this.label6.TabIndex = 49; + this.label6.Text = "Dump Results:"; + // + // label17 + // + this.label17.AutoSize = true; + this.label17.Location = new System.Drawing.Point(670, 320); + this.label17.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.label17.Name = "label17"; + this.label17.Size = new System.Drawing.Size(190, 30); + this.label17.TabIndex = 72; + this.label17.Text = "WiFi MAC Address:"; + this.label17.Visible = false; + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(5, 146); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(150, 30); + this.label7.TabIndex = 50; + this.label7.Text = "Serial Number:"; + // + // moboSerialInfo + // + this.moboSerialInfo.AutoSize = true; + this.moboSerialInfo.Location = new System.Drawing.Point(209, 204); + this.moboSerialInfo.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.moboSerialInfo.Name = "moboSerialInfo"; + this.moboSerialInfo.Size = new System.Drawing.Size(28, 30); + this.moboSerialInfo.TabIndex = 71; + this.moboSerialInfo.Text = "..."; + // + // label9 + // + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(5, 320); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(117, 30); + this.label9.TabIndex = 51; + this.label9.Text = "PS5 Model:"; + // + // label19 + // + this.label19.AutoSize = true; + this.label19.Location = new System.Drawing.Point(5, 204); + this.label19.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.label19.Name = "label19"; + this.label19.Size = new System.Drawing.Size(196, 30); + this.label19.TabIndex = 70; + this.label19.Text = "Motherboard Serial:"; + // + // label10 + // + this.label10.AutoSize = true; + this.label10.Location = new System.Drawing.Point(5, 380); + this.label10.Name = "label10"; + this.label10.Size = new System.Drawing.Size(92, 30); + this.label10.TabIndex = 52; + this.label10.Text = "File Size:"; + // + // LANMacAddressInfo + // + this.LANMacAddressInfo.AutoSize = true; + this.LANMacAddressInfo.Location = new System.Drawing.Point(209, 506); + this.LANMacAddressInfo.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.LANMacAddressInfo.Name = "LANMacAddressInfo"; + this.LANMacAddressInfo.Size = new System.Drawing.Size(28, 30); + this.LANMacAddressInfo.TabIndex = 69; + this.LANMacAddressInfo.Text = "..."; + // + // serialNumber + // + this.serialNumber.AutoSize = true; + this.serialNumber.Location = new System.Drawing.Point(209, 146); + this.serialNumber.Name = "serialNumber"; + this.serialNumber.Size = new System.Drawing.Size(28, 30); + this.serialNumber.TabIndex = 53; + this.serialNumber.Text = "..."; + // + // label18 + // + this.label18.AutoSize = true; + this.label18.Location = new System.Drawing.Point(5, 506); + this.label18.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.label18.Name = "label18"; + this.label18.Size = new System.Drawing.Size(185, 30); + this.label18.TabIndex = 68; + this.label18.Text = "LAN Mac Address:"; + // + // modelInfo + // + this.modelInfo.AutoSize = true; + this.modelInfo.Location = new System.Drawing.Point(209, 320); + this.modelInfo.Name = "modelInfo"; + this.modelInfo.Size = new System.Drawing.Size(28, 30); + this.modelInfo.TabIndex = 54; + this.modelInfo.Text = "..."; + // + // macAddressInfo + // + this.macAddressInfo.AutoSize = true; + this.macAddressInfo.Location = new System.Drawing.Point(209, 444); + this.macAddressInfo.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.macAddressInfo.Name = "macAddressInfo"; + this.macAddressInfo.Size = new System.Drawing.Size(28, 30); + this.macAddressInfo.TabIndex = 67; + this.macAddressInfo.Text = "..."; + // + // fileSizeInfo + // + this.fileSizeInfo.AutoSize = true; + this.fileSizeInfo.Location = new System.Drawing.Point(209, 380); + this.fileSizeInfo.Name = "fileSizeInfo"; + this.fileSizeInfo.Size = new System.Drawing.Size(28, 30); + this.fileSizeInfo.TabIndex = 55; + this.fileSizeInfo.Text = "..."; + // + // label16 + // + this.label16.AutoSize = true; + this.label16.Location = new System.Drawing.Point(5, 444); + this.label16.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.label16.Name = "label16"; + this.label16.Size = new System.Drawing.Size(184, 30); + this.label16.TabIndex = 66; + this.label16.Text = "WiFi Mac Address:"; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(5, 262); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(142, 30); + this.label8.TabIndex = 56; + this.label8.Text = "Board Variant:"; + // + // boardVariant + // + this.boardVariant.AutoSize = true; + this.boardVariant.Location = new System.Drawing.Point(209, 262); + this.boardVariant.Name = "boardVariant"; + this.boardVariant.Size = new System.Drawing.Size(28, 30); + this.boardVariant.TabIndex = 57; + this.boardVariant.Text = "..."; + // + // boardModelSelectionBox + // + this.boardModelSelectionBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.boardModelSelectionBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.boardModelSelectionBox.FormattingEnabled = true; + this.boardModelSelectionBox.Items.AddRange(new object[] { + "Slim", + "Digital Edition", + "Disc Edition"}); + this.boardModelSelectionBox.Location = new System.Drawing.Point(865, 256); + this.boardModelSelectionBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.boardModelSelectionBox.Name = "boardModelSelectionBox"; + this.boardModelSelectionBox.Size = new System.Drawing.Size(508, 38); + this.boardModelSelectionBox.TabIndex = 65; + // + // label11 + // + this.label11.AutoSize = true; + this.label11.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this.label11.Location = new System.Drawing.Point(670, 100); + this.label11.Name = "label11"; + this.label11.Size = new System.Drawing.Size(164, 30); + this.label11.TabIndex = 58; + this.label11.Text = "Modify Values: "; + // + // label14 + // + this.label14.AutoSize = true; + this.label14.Location = new System.Drawing.Point(670, 260); + this.label14.Name = "label14"; + this.label14.Size = new System.Drawing.Size(117, 30); + this.label14.TabIndex = 64; + this.label14.Text = "PS5 Model:"; + // + // convertToDigitalEditionButton + // + this.convertToDigitalEditionButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.convertToDigitalEditionButton.Location = new System.Drawing.Point(1119, 743); + this.convertToDigitalEditionButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.convertToDigitalEditionButton.Name = "convertToDigitalEditionButton"; + this.convertToDigitalEditionButton.Size = new System.Drawing.Size(257, 92); + this.convertToDigitalEditionButton.TabIndex = 59; + this.convertToDigitalEditionButton.Text = "Save New\r\nBIOS Information"; + this.convertToDigitalEditionButton.UseVisualStyleBackColor = true; + this.convertToDigitalEditionButton.Click += new System.EventHandler(this.convertToDigitalEditionButton_Click); + // + // serialNumberTextbox + // + this.serialNumberTextbox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.serialNumberTextbox.Location = new System.Drawing.Point(865, 142); + this.serialNumberTextbox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.serialNumberTextbox.Name = "serialNumberTextbox"; + this.serialNumberTextbox.Size = new System.Drawing.Size(508, 35); + this.serialNumberTextbox.TabIndex = 63; + // + // boardVariantSelectionBox + // + this.boardVariantSelectionBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.boardVariantSelectionBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.boardVariantSelectionBox.FormattingEnabled = true; + this.boardVariantSelectionBox.Items.AddRange(new object[] { + "CFI-1000A", + "CFI-1000A01", + "CFI-1000B", + "CFI-1001A", + "CFI-1001B", + "CFI-1002A", + "CFI-1002B", + "CFI-1003A", + "CFI-1003B", + "CFI-1004A", + "CFI-1004B", + "CFI-1005A", + "CFI-1005B", + "CFI-1006A", + "CFI-1006B", + "CFI-1007A", + "CFI-1007B", + "CFI-1008A", + "CFI-1008B", + "CFI-1009A", + "CFI-1009B", + "CFI-1011A", + "CFI-1011B", + "CFI-1014A", + "CFI-1014B", + "CFI-1015A", + "CFI-1015B", + "CFI-1016A", + "CFI-1016B", + "CFI-1018A", + "CFI-1018B", + "CFI-1100A", + "CFI-1100A01", + "CFI-1100B", + "CFI-1101A", + "CFI-1101B", + "CFI-1102A", + "CFI-1102B", + "CFI-1103A", + "CFI-1103B", + "CFI-1104A", + "CFI-1104B", + "CFI-1105A", + "CFI-1105B", + "CFI-1106A", + "CFI-1106B", + "CFI-1107A", + "CFI-1107B", + "CFI-1108A", + "CFI-1108B", + "CFI-1109A", + "CFI-1109B", + "CFI-1111A", + "CFI-1111B", + "CFI-1114A", + "CFI-1114B", + "CFI-1115A", + "CFI-1115B", + "CFI-1116A", + "CFI-1116B", + "CFI-1118A", + "CFI-1118B", + "CFI-1200A", + "CFI-1200A01", + "CFI-1200B", + "CFI-1201A", + "CFI-1201B", + "CFI-1202A", + "CFI-1202B", + "CFI-1203A", + "CFI-1203B", + "CFI-1204A", + "CFI-1204B", + "CFI-1205A", + "CFI-1205B", + "CFI-1206A", + "CFI-1206B", + "CFI-1207A", + "CFI-1207B", + "CFI-1208A", + "CFI-1208B", + "CFI-1209A", + "CFI-1209B", + "CFI-1211A", + "CFI-1211B", + "CFI-1214A", + "CFI-1214B", + "CFI-1215A", + "CFI-1215B", + "CFI-1216A", + "CFI-1216B", + "CFI-1218A", + "CFI-1218B", + "CFI-2000A", + "CFI-2000A01", + "CFI-2000B", + "CFI-2001A", + "CFI-2001B", + "CFI-2002A", + "CFI-2002B", + "CFI-2003A", + "CFI-2003B", + "CFI-2004A", + "CFI-2004B", + "CFI-2005A", + "CFI-2005B", + "CFI-2006A", + "CFI-2006B", + "CFI-2007A", + "CFI-2007B", + "CFI-2008A", + "CFI-2008B", + "CFI-2009A", + "CFI-2009B", + "CFI-2011A", + "CFI-2011B", + "CFI-2014A", + "CFI-2014B", + "CFI-2015A", + "CFI-2015B", + "CFI-2016A", + "CFI-2016B", + "CFI-2018A", + "CFI-2018B", + "DFI-T1000AA", + "DFI-D1000AA"}); + this.boardVariantSelectionBox.Location = new System.Drawing.Point(865, 198); + this.boardVariantSelectionBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.boardVariantSelectionBox.Name = "boardVariantSelectionBox"; + this.boardVariantSelectionBox.Size = new System.Drawing.Size(508, 38); + this.boardVariantSelectionBox.TabIndex = 60; + // + // label13 + // + this.label13.AutoSize = true; + this.label13.Location = new System.Drawing.Point(670, 202); + this.label13.Name = "label13"; + this.label13.Size = new System.Drawing.Size(142, 30); + this.label13.TabIndex = 62; + this.label13.Text = "Board Variant:"; + // + // label12 + // + this.label12.AutoSize = true; + this.label12.Location = new System.Drawing.Point(670, 146); + this.label12.Name = "label12"; + this.label12.Size = new System.Drawing.Size(150, 30); + this.label12.TabIndex = 61; + this.label12.Text = "Serial Number:"; + // + // lblSkuValue + // + this.lblSkuValue.AutoSize = true; + this.lblSkuValue.Location = new System.Drawing.Point(209, 566); + this.lblSkuValue.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.lblSkuValue.Name = "lblSkuValue"; + this.lblSkuValue.Size = new System.Drawing.Size(28, 30); + this.lblSkuValue.TabIndex = 77; + this.lblSkuValue.Text = "..."; + // + // lblSkuText + // + this.lblSkuText.AutoSize = true; + this.lblSkuText.Location = new System.Drawing.Point(5, 566); + this.lblSkuText.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.lblSkuText.Name = "lblSkuText"; + this.lblSkuText.Size = new System.Drawing.Size(55, 30); + this.lblSkuText.TabIndex = 76; + this.lblSkuText.Text = "SKU:"; + // + // lblFWVersionValue + // + this.lblFWVersionValue.AutoSize = true; + this.lblFWVersionValue.Location = new System.Drawing.Point(209, 623); + this.lblFWVersionValue.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.lblFWVersionValue.Name = "lblFWVersionValue"; + this.lblFWVersionValue.Size = new System.Drawing.Size(28, 30); + this.lblFWVersionValue.TabIndex = 79; + this.lblFWVersionValue.Text = "..."; + // + // lblFWVersionText + // + this.lblFWVersionText.AutoSize = true; + this.lblFWVersionText.Location = new System.Drawing.Point(5, 623); + this.lblFWVersionText.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.lblFWVersionText.Name = "lblFWVersionText"; + this.lblFWVersionText.Size = new System.Drawing.Size(197, 30); + this.lblFWVersionText.TabIndex = 78; + this.lblFWVersionText.Text = "Current FW Version:"; + // + // lblMD5Value + // + this.lblMD5Value.AutoSize = true; + this.lblMD5Value.Location = new System.Drawing.Point(209, 685); + this.lblMD5Value.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.lblMD5Value.Name = "lblMD5Value"; + this.lblMD5Value.Size = new System.Drawing.Size(28, 30); + this.lblMD5Value.TabIndex = 81; + this.lblMD5Value.Text = "..."; + // + // lblMD5Text + // + this.lblMD5Text.AutoSize = true; + this.lblMD5Text.Location = new System.Drawing.Point(5, 685); + this.lblMD5Text.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.lblMD5Text.Name = "lblMD5Text"; + this.lblMD5Text.Size = new System.Drawing.Size(153, 30); + this.lblMD5Text.TabIndex = 80; + this.lblMD5Text.Text = "MD5 File Hash:"; + // + // NorModifierUserControl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 30F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.lblMD5Value); + this.Controls.Add(this.lblMD5Text); + this.Controls.Add(this.lblFWVersionValue); + this.Controls.Add(this.lblFWVersionText); + this.Controls.Add(this.lblSkuValue); + this.Controls.Add(this.lblSkuText); + this.Controls.Add(this.label5); + this.Controls.Add(this.label20); + this.Controls.Add(this.fileLocationBox); + this.Controls.Add(this.lanMacAddressTextbox); + this.Controls.Add(this.browseFileButton); + this.Controls.Add(this.wifiMacAddressTextbox); + this.Controls.Add(this.label6); + this.Controls.Add(this.label17); + this.Controls.Add(this.label7); + this.Controls.Add(this.moboSerialInfo); + this.Controls.Add(this.label9); + this.Controls.Add(this.label19); + this.Controls.Add(this.label10); + this.Controls.Add(this.LANMacAddressInfo); + this.Controls.Add(this.serialNumber); + this.Controls.Add(this.label18); + this.Controls.Add(this.modelInfo); + this.Controls.Add(this.macAddressInfo); + this.Controls.Add(this.fileSizeInfo); + this.Controls.Add(this.label16); + this.Controls.Add(this.label8); + this.Controls.Add(this.boardVariant); + this.Controls.Add(this.boardModelSelectionBox); + this.Controls.Add(this.label11); + this.Controls.Add(this.label14); + this.Controls.Add(this.convertToDigitalEditionButton); + this.Controls.Add(this.serialNumberTextbox); + this.Controls.Add(this.boardVariantSelectionBox); + this.Controls.Add(this.label13); + this.Controls.Add(this.label12); + this.Name = "NorModifierUserControl"; + this.Size = new System.Drawing.Size(1382, 842); + this.Load += new System.EventHandler(this.NorModifierUserControl_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label5; + private Label label20; + private TextBox fileLocationBox; + private TextBox lanMacAddressTextbox; + private Button browseFileButton; + private TextBox wifiMacAddressTextbox; + private Label label6; + private Label label17; + private Label label7; + private Label moboSerialInfo; + private Label label9; + private Label label19; + private Label label10; + private Label LANMacAddressInfo; + private Label serialNumber; + private Label label18; + private Label modelInfo; + private Label macAddressInfo; + private Label fileSizeInfo; + private Label label16; + private Label label8; + private Label boardVariant; + private ComboBox boardModelSelectionBox; + private Label label11; + private Label label14; + private Button convertToDigitalEditionButton; + private TextBox serialNumberTextbox; + private ComboBox boardVariantSelectionBox; + private Label label13; + private Label label12; + private Label lblSkuValue; + private Label lblSkuText; + private Label lblFWVersionValue; + private Label lblFWVersionText; + private Label lblMD5Value; + private Label lblMD5Text; + } +} diff --git a/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs new file mode 100644 index 0000000..976e64b --- /dev/null +++ b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs @@ -0,0 +1,528 @@ +using System; +using System.Linq; +using System.Globalization; +using System.Text; +using System.Text.RegularExpressions; +using PS5_NOR_Modifier.UserControls.Events; +using System.Security.Cryptography; + +namespace PS5_NOR_Modifier.UserControls.NorModifier +{ + public partial class NorModifierUserControl : UserControl + { + public event EventHandler? statusUpdateEvent; + + private const string NO_VALUE = "Unknown"; + + private const long WIFI_OFFSET = 0x1C73C0; + private const long SN_OFFSET = 0x1c7210; + private const long MB_SN_OFFSET = 0x1C7200; + private const long LAN_MAC_OFFSET = 0x1C4020; + private const long MODEL_OFFSET = 0x1C7011; + private const long REGION_OFFSET = 0x1C7236; + private const long SKU_OFFSET = 0x1C7230; + private const long CURRENT_FW_VERSION = 0x1C8C34; + + private readonly Dictionary _regions = new Dictionary() + { + { "00", "Japan" }, + { "01", "US, Canada, (North America)" }, + { "02", "Australia / New Zealand, (Oceania)" }, + { "03", "United Kingdom / Ireland" }, + { "04", "Europe / Middle East / Africa" }, + { "05", "South Korea" }, + { "06", "Southeast Asia / Hong Kong" }, + { "07", "Taiwan" }, + { "08", "Russia, Ukraine, India, Central Asia" }, + { "09", "Mainland China" }, + { "11", "Mexico, Central America, South America" }, + { "14", "Mexico, Central America, South America" }, + { "15", "US, Canada, (North America)" }, + { "16", "Europe / Middle East / Africa" }, + { "18", "Singapore, Korea, Asia" }, + }; + + public NorModifierUserControl() + { + InitializeComponent(); + } + + private void throwError(string errmsg) + { + MessageBox.Show(errmsg, "An Error Has Occurred", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + + private void UpdateStatus(string newStatus) + { + if (statusUpdateEvent != null) + { + statusUpdateEvent(this, new StatusUpdateEventArgs(newStatus)); + } + } + + string HexStringToString(string hexString) + { + if (hexString == null || (hexString.Length & 1) == 1) + { + throw new ArgumentException(); + } + var sb = new StringBuilder(); + for (var i = 0; i < hexString.Length; i += 2) + { + var hexChar = hexString.Substring(i, 2); + sb.Append((char)Convert.ToByte(hexChar, 16)); + } + return sb.ToString(); + } + + private void ResetAppFields() + { + fileLocationBox.Text = ""; + serialNumber.Text = "..."; + boardVariant.Text = "..."; + modelInfo.Text = "..."; + fileSizeInfo.Text = "..."; + serialNumberTextbox.Text = ""; + lblSkuValue.Text = "..."; + lblFWVersionValue.Text = "..."; + serialNumberTextbox.Enabled = false; + boardVariantSelectionBox.Enabled = false; + boardVariantSelectionBox.SelectedIndex = -1; + boardModelSelectionBox.Enabled = false; + boardModelSelectionBox.SelectedIndex = -1; + convertToDigitalEditionButton.Enabled = false; + UpdateStatus( "Status: Waiting for input"); + } + + /// + /// With thanks to @jjxtra on Github. The code has already been created and there's no need to reinvent the wheel is there? + /// + #region Hex Code + + private static IEnumerable PatternAt(byte[] source, byte[] pattern) + { + for (int i = 0; i < source.Length; i++) + { + if (source.Skip(i).Take(pattern.Length).SequenceEqual(pattern)) + { + yield return i; + } + } + } + + private static byte[] ConvertHexStringToByteArray(string hexString) + { + if (hexString.Length % 2 != 0) + { + throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "The binary key cannot have an odd number of digits: {0}", hexString)); + } + + byte[] data = new byte[hexString.Length / 2]; + for (int index = 0; index < data.Length; index++) + { + string byteValue = hexString.Substring(index * 2, 2); + data[index] = byte.Parse(byteValue, NumberStyles.HexNumber, CultureInfo.InvariantCulture); + } + + return data; + } + + #endregion + + private byte[]? ReadStreamBytes(BinaryReader reader, long offset, int length) + { + byte[]? result = null; + + try + { + reader.BaseStream.Position = offset; + result = reader.ReadBytes(length); + } + catch + { + //Hmm, something is wrong, but continue + } + + return result; + } + + private void browseFileButton_Click(object sender, EventArgs e) + { + OpenFileDialog fileDialogBox = new OpenFileDialog(); + fileDialogBox.Title = "Open NOR BIN File"; + fileDialogBox.Filter = "PS5 BIN Files|*.bin"; + + if (fileDialogBox.ShowDialog() == DialogResult.OK) + { + if (fileDialogBox.CheckFileExists == false) + { + throwError("The file you selected could not be found. Please check the file exists and is a valid BIN file."); + } + else + { + if (!fileDialogBox.SafeFileName.ToLower().EndsWith(".bin")) + { + throwError("The file you selected is not a valid. Please ensure the file you are choosing is a correct BIN file and try again."); + } + else + { + // Let's load simple information first, before loading BIN specific data + fileLocationBox.Text = ""; + // Get the path selected and print it into the path box + string selectedPath = fileDialogBox.FileName; + UpdateStatus("Status: Selected file " + selectedPath); + fileLocationBox.Text = selectedPath; + + // Get file length and show in bytes and MB + long length = new FileInfo(selectedPath).Length; + fileSizeInfo.Text = length.ToString() + " bytes (" + length / 1024 / 1024 + "MB)"; + + using (BinaryReader reader = new BinaryReader(new FileStream(fileDialogBox.FileName, FileMode.Open))) + { + //Reading Motherboard Serial + byte[]? rawBytes = ReadStreamBytes(reader, MB_SN_OFFSET, 16); + + moboSerialInfo.Text = NO_VALUE; + + if (rawBytes != null) + { + string mbSerialValue = BitConverter.ToString(rawBytes).Replace("-", null); + moboSerialInfo.Text = HexStringToString(mbSerialValue); + } + + //Reading serial number + rawBytes = ReadStreamBytes(reader, SN_OFFSET, 17); + + serialNumber.Text = NO_VALUE; + serialNumberTextbox.Text = NO_VALUE; + + if (rawBytes != null) + { + string sn = BitConverter.ToString(rawBytes).Replace("-", null); + string readableSn = HexStringToString(sn); + serialNumber.Text = readableSn; + serialNumberTextbox.Text = readableSn; + } + + //Reading SKU + rawBytes = ReadStreamBytes(reader, SKU_OFFSET, 13); + + boardModelSelectionBox.SelectedIndex = -1; + + if (rawBytes != null) + { + string skuBytes = BitConverter.ToString(rawBytes).Replace("-", null); + string skuFullText = HexStringToString(skuBytes); + lblSkuValue.Text = skuFullText; + string skuText = skuFullText.Split(' ')[0]; + boardVariantSelectionBox.SelectedIndex = boardVariantSelectionBox.FindStringExact(skuText); + } + + //Reading Current Firmware Version + rawBytes = ReadStreamBytes(reader, CURRENT_FW_VERSION, 4); + + if (rawBytes != null) + { + Array.Reverse(rawBytes); + string firmwareVersion = BitConverter.ToString(rawBytes).Replace("-", "."); + lblFWVersionValue.Text = firmwareVersion; + } + + //Reading WIFI + rawBytes = ReadStreamBytes(reader, WIFI_OFFSET, 6); + + macAddressInfo.Text = NO_VALUE; + wifiMacAddressTextbox.Text = NO_VALUE; + + if (rawBytes != null) + { + string wifi = BitConverter.ToString(rawBytes); + macAddressInfo.Text = wifi; + wifiMacAddressTextbox.Text = wifi; + } + + //Reading LAN + rawBytes = ReadStreamBytes(reader, LAN_MAC_OFFSET, 6); + + LANMacAddressInfo.Text = NO_VALUE; + lanMacAddressTextbox.Text = NO_VALUE; + + if (rawBytes != null) + { + string lan = BitConverter.ToString(rawBytes); + LANMacAddressInfo.Text = lan; + lanMacAddressTextbox.Text = lan; + } + + //Region + rawBytes = ReadStreamBytes(reader, REGION_OFFSET, 2); + + boardVariant.Text = NO_VALUE; + + if (rawBytes != null) + { + string regionHex = BitConverter.ToString(rawBytes).Replace("-", null); + string regionReadable = HexStringToString(regionHex); + + if (_regions.Keys.Contains(regionReadable)) + { + boardVariant.Text = String.Format("{0} - {1}", regionReadable, _regions[regionReadable]); + } + } + + //Reading Model + rawBytes = ReadStreamBytes(reader, MODEL_OFFSET, 1); + + if (rawBytes != null) + { + string model = BitConverter.ToString(rawBytes).Replace("-", null); + + string modelText = NO_VALUE; + + if (model == "01") + { + modelText = "Slim"; + } + else if (model == "02") + { + modelText = "Disc Edition"; + } + else if (model == "03") + { + modelText = "Digital Edition"; + } + + modelInfo.Text = modelText; + + boardModelSelectionBox.SelectedIndex = boardModelSelectionBox.FindStringExact(modelText); + } + + serialNumberTextbox.Enabled = true; + boardVariantSelectionBox.Enabled = true; + boardModelSelectionBox.Enabled = true; + convertToDigitalEditionButton.Enabled = true; + } + + //Calculate MD5 File hash + + string md5Hash = NO_VALUE; + + using (var md5 = MD5.Create()) + { + using (var stream = File.OpenRead(fileDialogBox.FileName)) + { + byte[] hash = md5.ComputeHash(stream); + + md5Hash = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); + } + } + + lblMD5Value.Text = md5Hash; + } + } + } + } + + private void convertToDigitalEditionButton_Click(object sender, EventArgs e) + { + string fileNameToLookFor = ""; + bool errorShownAlready = false; + + if (modelInfo.Text == "" || modelInfo.Text == "...") + { + // No valid BIN file seems to have been selected + throwError("Please select a valid BIOS file first..."); + errorShownAlready = true; + } + else + { + if (boardModelSelectionBox.Text == "") + { + throwError("Please select a valid board model before saving new BIOS information!"); + errorShownAlready = true; + } + else + { + if (boardVariantSelectionBox.Text == "") + { + throwError("Please select a valid board variant before saving new BIOS information!"); + errorShownAlready = true; + } + else + { + SaveFileDialog saveBox = new SaveFileDialog(); + saveBox.Title = "Save NOR BIN File"; + saveBox.Filter = "PS5 BIN Files|*.bin"; + + if (saveBox.ShowDialog() == DialogResult.OK) + { + // First create a copy of the old BIOS file + byte[] existingFile = File.ReadAllBytes(fileLocationBox.Text); + string newFile = saveBox.FileName; + + File.WriteAllBytes(newFile, existingFile); + + fileNameToLookFor = saveBox.FileName; + + #region Set the new model info + if (modelInfo.Text == "Disc Edition") + { + try + { + + if (boardModelSelectionBox.Text == "Digital Edition") + + { + + byte[] find = ConvertHexStringToByteArray(Regex.Replace("22020101", "0x|[ ,]", string.Empty).Normalize().Trim()); + byte[] replace = ConvertHexStringToByteArray(Regex.Replace("22030101", "0x|[ ,]", string.Empty).Normalize().Trim()); + if (find.Length != replace.Length) + { + throwError("The length of the old hex value does not match the length of the new hex value!"); + errorShownAlready = true; + } + byte[] bytes = File.ReadAllBytes(newFile); + foreach (int index in PatternAt(bytes, find)) + { + for (int i = index, replaceIndex = 0; i < bytes.Length && replaceIndex < replace.Length; i++, replaceIndex++) + { + bytes[i] = replace[replaceIndex]; + } + File.WriteAllBytes(newFile, bytes); + } + } + + } + catch + { + throwError("An error occurred while saving your BIOS file"); + errorShownAlready = true; + } + } + else + { + if (modelInfo.Text == "Digital Edition") + { + try + { + + if (boardModelSelectionBox.Text == "Disc Edition") + + { + + byte[] find = ConvertHexStringToByteArray(Regex.Replace("22030101", "0x|[ ,]", string.Empty).Normalize().Trim()); + byte[] replace = ConvertHexStringToByteArray(Regex.Replace("22020101", "0x|[ ,]", string.Empty).Normalize().Trim()); + if (find.Length != replace.Length) + { + throwError("The length of the old hex value does not match the length of the new hex value!"); + errorShownAlready = true; + } + byte[] bytes = File.ReadAllBytes(newFile); + foreach (int index in PatternAt(bytes, find)) + { + for (int i = index, replaceIndex = 0; i < bytes.Length && replaceIndex < replace.Length; i++, replaceIndex++) + { + bytes[i] = replace[replaceIndex]; + } + File.WriteAllBytes(newFile, bytes); + } + } + + } + catch + { + throwError("An error occurred while saving your BIOS file"); + errorShownAlready = true; + } + } + } + #endregion + + #region Set the new board variant + + try + { + byte[] oldVariant = Encoding.UTF8.GetBytes(boardVariant.Text); + string oldVariantHex = Convert.ToHexString(oldVariant); + + byte[] newVariantSelection = Encoding.UTF8.GetBytes(boardVariantSelectionBox.Text); + string newVariantHex = Convert.ToHexString(newVariantSelection); + + byte[] find = ConvertHexStringToByteArray(Regex.Replace(oldVariantHex, "0x|[ ,]", string.Empty).Normalize().Trim()); + byte[] replace = ConvertHexStringToByteArray(Regex.Replace(newVariantHex, "0x|[ ,]", string.Empty).Normalize().Trim()); + + byte[] bytes = File.ReadAllBytes(newFile); + foreach (int index in PatternAt(bytes, find)) + { + for (int i = index, replaceIndex = 0; i < bytes.Length && replaceIndex < replace.Length; i++, replaceIndex++) + { + bytes[i] = replace[replaceIndex]; + } + File.WriteAllBytes(newFile, bytes); + } + + } + catch (System.ArgumentException ex) + { + throwError(ex.Message.ToString()); + errorShownAlready = true; + } + + #endregion + + #region Change Serial Number + + try + { + + byte[] oldSerial = Encoding.UTF8.GetBytes(serialNumber.Text); + string oldSerialHex = Convert.ToHexString(oldSerial); + + byte[] newSerial = Encoding.UTF8.GetBytes(serialNumberTextbox.Text); + string newSerialHex = Convert.ToHexString(newSerial); + + byte[] find = ConvertHexStringToByteArray(Regex.Replace(oldSerialHex, "0x|[ ,]", string.Empty).Normalize().Trim()); + byte[] replace = ConvertHexStringToByteArray(Regex.Replace(newSerialHex, "0x|[ ,]", string.Empty).Normalize().Trim()); + + byte[] bytes = File.ReadAllBytes(newFile); + foreach (int index in PatternAt(bytes, find)) + { + for (int i = index, replaceIndex = 0; i < bytes.Length && replaceIndex < replace.Length; i++, replaceIndex++) + { + bytes[i] = replace[replaceIndex]; + } + File.WriteAllBytes(newFile, bytes); + } + + } + catch (System.ArgumentException ex) + { + throwError(ex.Message.ToString()); + errorShownAlready = true; + } + + #endregion + } + else + { + throwError("Save operation cancelled!"); + errorShownAlready = true; + } + } + } + } + + if (File.Exists(fileNameToLookFor) && errorShownAlready == false) + { + // Reset everything and show message + ResetAppFields(); + MessageBox.Show("A new BIOS file was successfully created. Please load the new BIOS file to verify the information you entered before installing onto your motherboard. Remember this software was created by TheCod3r with nothing but love. Why not show some love back by dropping me a small donation to say thanks ;).", "All done!", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + private void NorModifierUserControl_Load(object sender, EventArgs e) + { + ResetAppFields(); + } + } +} diff --git a/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.resx b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.resx new file mode 100644 index 0000000..6dae11d --- /dev/null +++ b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PS5 NOR Modifier/UserControls/UART/Data/ErrorCode.cs b/PS5 NOR Modifier/UserControls/UART/Data/ErrorCode.cs new file mode 100644 index 0000000..e9c1ebb --- /dev/null +++ b/PS5 NOR Modifier/UserControls/UART/Data/ErrorCode.cs @@ -0,0 +1,27 @@ +using System; +using System.Xml.Serialization; + +namespace PS5_NOR_Modifier.UserControls.UART.Data +{ + public class ErrorCode + { + public ErrorCode() + { + ErrorCodeNumber = String.Empty; + Description= String.Empty; + } + + [XmlElement(ElementName = "ErrorCode")] + public string ErrorCodeNumber + { + get; + set; + } + + public string Description + { + get; + set; + } + } +} diff --git a/PS5 NOR Modifier/UserControls/UART/Data/ErrorCodeInfo.cs b/PS5 NOR Modifier/UserControls/UART/Data/ErrorCodeInfo.cs new file mode 100644 index 0000000..3afc92a --- /dev/null +++ b/PS5 NOR Modifier/UserControls/UART/Data/ErrorCodeInfo.cs @@ -0,0 +1,29 @@ +using System; + +namespace PS5_NOR_Modifier.UserControls.UART.Data +{ + public class ErrorCodeInfo + { + public ErrorCodeInfo() + { + } + + public string ErrorCode + { + get; + set; + } + + public string Description + { + get; + set; + } + + public string DetailsLink + { + get; + set; + } + } +} diff --git a/PS5 NOR Modifier/UserControls/UART/Data/ErrorCodesList.cs b/PS5 NOR Modifier/UserControls/UART/Data/ErrorCodesList.cs new file mode 100644 index 0000000..44acf0b --- /dev/null +++ b/PS5 NOR Modifier/UserControls/UART/Data/ErrorCodesList.cs @@ -0,0 +1,17 @@ +using System; +using System.Xml.Serialization; + +namespace PS5_NOR_Modifier.UserControls.UART.Data +{ + [XmlRoot("errorCodes")] + public class ErrorCodesList + { + public ErrorCodesList() + { + Items = new List(); + } + + [XmlElement("errorCode")] + public List Items { get; set; } + } +} diff --git a/PS5 NOR Modifier/UserControls/UART/UartUserControl.Designer.cs b/PS5 NOR Modifier/UserControls/UART/UartUserControl.Designer.cs new file mode 100644 index 0000000..ee228cf --- /dev/null +++ b/PS5 NOR Modifier/UserControls/UART/UartUserControl.Designer.cs @@ -0,0 +1,387 @@ +namespace PS5_NOR_Modifier.UserControls.UART +{ + partial class UartUserControl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UartUserControl)); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); + this.label25 = new System.Windows.Forms.Label(); + this.btnSendCommand = new System.Windows.Forms.Button(); + this.txtCustomCommand = new System.Windows.Forms.TextBox(); + this.label24 = new System.Windows.Forms.Label(); + this.chkUseOffline = new System.Windows.Forms.CheckBox(); + this.btnDownloadDatabase = new System.Windows.Forms.Button(); + this.btnRefreshPorts = new System.Windows.Forms.Button(); + this.btnClearOutput = new System.Windows.Forms.Button(); + this.txtUARTOutput = new System.Windows.Forms.TextBox(); + this.label22 = new System.Windows.Forms.Label(); + this.btnClearErrorCodes = new System.Windows.Forms.Button(); + this.label21 = new System.Windows.Forms.Label(); + this.btnGet10LastErrors = new System.Windows.Forms.Button(); + this.comboComPorts = new System.Windows.Forms.ComboBox(); + this.btnDisconnectCom = new System.Windows.Forms.Button(); + this.btnConnectCom = new System.Windows.Forms.Button(); + this.label3 = new System.Windows.Forms.Label(); + this.gvErrorCodes = new System.Windows.Forms.DataGridView(); + this.cErrorCode = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.cDescription = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.cDetails = new System.Windows.Forms.DataGridViewLinkColumn(); + this.cCodeDetailsLink = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.lblLastErrorCodes = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.gvErrorCodes)).BeginInit(); + this.SuspendLayout(); + // + // label25 + // + this.label25.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.label25.AutoSize = true; + this.label25.Location = new System.Drawing.Point(1515, 285); + this.label25.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.label25.Name = "label25"; + this.label25.Size = new System.Drawing.Size(347, 210); + this.label25.TabIndex = 18; + this.label25.Text = resources.GetString("label25.Text"); + // + // btnSendCommand + // + this.btnSendCommand.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnSendCommand.Location = new System.Drawing.Point(1729, 233); + this.btnSendCommand.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.btnSendCommand.Name = "btnSendCommand"; + this.btnSendCommand.Size = new System.Drawing.Size(129, 46); + this.btnSendCommand.TabIndex = 17; + this.btnSendCommand.Text = "Send"; + this.btnSendCommand.UseVisualStyleBackColor = true; + this.btnSendCommand.Click += new System.EventHandler(this.btnSendCommand_Click); + // + // txtCustomCommand + // + this.txtCustomCommand.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.txtCustomCommand.Location = new System.Drawing.Point(1515, 175); + this.txtCustomCommand.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.txtCustomCommand.Name = "txtCustomCommand"; + this.txtCustomCommand.Size = new System.Drawing.Size(340, 35); + this.txtCustomCommand.TabIndex = 16; + this.txtCustomCommand.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtCustomCommand_KeyPress); + // + // label24 + // + this.label24.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.label24.AutoSize = true; + this.label24.Location = new System.Drawing.Point(1520, 139); + this.label24.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.label24.Name = "label24"; + this.label24.Size = new System.Drawing.Size(325, 30); + this.label24.TabIndex = 15; + this.label24.Text = "Send custom command via UART:"; + // + // chkUseOffline + // + this.chkUseOffline.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.chkUseOffline.AutoSize = true; + this.chkUseOffline.Location = new System.Drawing.Point(1629, 19); + this.chkUseOffline.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.chkUseOffline.Name = "chkUseOffline"; + this.chkUseOffline.Size = new System.Drawing.Size(228, 34); + this.chkUseOffline.TabIndex = 9; + this.chkUseOffline.Text = "Use offline database"; + this.chkUseOffline.UseVisualStyleBackColor = true; + // + // btnDownloadDatabase + // + this.btnDownloadDatabase.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnDownloadDatabase.Location = new System.Drawing.Point(1351, 15); + this.btnDownloadDatabase.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.btnDownloadDatabase.Name = "btnDownloadDatabase"; + this.btnDownloadDatabase.Size = new System.Drawing.Size(268, 46); + this.btnDownloadDatabase.TabIndex = 8; + this.btnDownloadDatabase.Text = "Download Error Database"; + this.btnDownloadDatabase.UseVisualStyleBackColor = true; + this.btnDownloadDatabase.Click += new System.EventHandler(this.btnDownloadDatabase_Click); + // + // btnRefreshPorts + // + this.btnRefreshPorts.Location = new System.Drawing.Point(879, 9); + this.btnRefreshPorts.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.btnRefreshPorts.Name = "btnRefreshPorts"; + this.btnRefreshPorts.Size = new System.Drawing.Size(153, 46); + this.btnRefreshPorts.TabIndex = 4; + this.btnRefreshPorts.Text = "Refresh Ports"; + this.btnRefreshPorts.UseVisualStyleBackColor = true; + this.btnRefreshPorts.Click += new System.EventHandler(this.btnRefreshPorts_Click); + // + // btnClearOutput + // + this.btnClearOutput.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnClearOutput.Location = new System.Drawing.Point(1238, 377); + this.btnClearOutput.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.btnClearOutput.Name = "btnClearOutput"; + this.btnClearOutput.Size = new System.Drawing.Size(267, 46); + this.btnClearOutput.TabIndex = 12; + this.btnClearOutput.Text = "Clear Output Window"; + this.btnClearOutput.UseVisualStyleBackColor = true; + this.btnClearOutput.Click += new System.EventHandler(this.button3_Click); + // + // txtUARTOutput + // + this.txtUARTOutput.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.txtUARTOutput.Location = new System.Drawing.Point(121, 139); + this.txtUARTOutput.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.txtUARTOutput.Multiline = true; + this.txtUARTOutput.Name = "txtUARTOutput"; + this.txtUARTOutput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + this.txtUARTOutput.Size = new System.Drawing.Size(1385, 226); + this.txtUARTOutput.TabIndex = 11; + // + // label22 + // + this.label22.AutoSize = true; + this.label22.Location = new System.Drawing.Point(6, 139); + this.label22.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.label22.Name = "label22"; + this.label22.Size = new System.Drawing.Size(84, 30); + this.label22.TabIndex = 10; + this.label22.Text = "Output:"; + // + // btnClearErrorCodes + // + this.btnClearErrorCodes.Location = new System.Drawing.Point(389, 71); + this.btnClearErrorCodes.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.btnClearErrorCodes.Name = "btnClearErrorCodes"; + this.btnClearErrorCodes.Size = new System.Drawing.Size(202, 46); + this.btnClearErrorCodes.TabIndex = 7; + this.btnClearErrorCodes.Text = "Clear Error Codes"; + this.btnClearErrorCodes.UseVisualStyleBackColor = true; + this.btnClearErrorCodes.Click += new System.EventHandler(this.btnClearErrorCodes_Click); + // + // label21 + // + this.label21.AutoSize = true; + this.label21.Location = new System.Drawing.Point(6, 79); + this.label21.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.label21.Name = "label21"; + this.label21.Size = new System.Drawing.Size(91, 30); + this.label21.TabIndex = 5; + this.label21.Text = "Options:"; + // + // btnGet10LastErrors + // + this.btnGet10LastErrors.Location = new System.Drawing.Point(121, 71); + this.btnGet10LastErrors.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.btnGet10LastErrors.Name = "btnGet10LastErrors"; + this.btnGet10LastErrors.Size = new System.Drawing.Size(258, 46); + this.btnGet10LastErrors.TabIndex = 6; + this.btnGet10LastErrors.Text = "Get 10 Last Error Codes"; + this.btnGet10LastErrors.UseVisualStyleBackColor = true; + this.btnGet10LastErrors.Click += new System.EventHandler(this.button1_Click); + // + // comboComPorts + // + this.comboComPorts.FormattingEnabled = true; + this.comboComPorts.Location = new System.Drawing.Point(121, 9); + this.comboComPorts.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.comboComPorts.Name = "comboComPorts"; + this.comboComPorts.Size = new System.Drawing.Size(467, 38); + this.comboComPorts.TabIndex = 1; + // + // btnDisconnectCom + // + this.btnDisconnectCom.Location = new System.Drawing.Point(740, 9); + this.btnDisconnectCom.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.btnDisconnectCom.Name = "btnDisconnectCom"; + this.btnDisconnectCom.Size = new System.Drawing.Size(129, 46); + this.btnDisconnectCom.TabIndex = 3; + this.btnDisconnectCom.Text = "Disconnect"; + this.btnDisconnectCom.UseVisualStyleBackColor = true; + this.btnDisconnectCom.Click += new System.EventHandler(this.btnDisconnectCom_Click); + // + // btnConnectCom + // + this.btnConnectCom.Location = new System.Drawing.Point(601, 7); + this.btnConnectCom.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.btnConnectCom.Name = "btnConnectCom"; + this.btnConnectCom.Size = new System.Drawing.Size(129, 46); + this.btnConnectCom.TabIndex = 2; + this.btnConnectCom.Text = "Connect"; + this.btnConnectCom.UseVisualStyleBackColor = true; + this.btnConnectCom.Click += new System.EventHandler(this.btnConnectCom_Click); + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(6, 15); + this.label3.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(104, 30); + this.label3.TabIndex = 0; + this.label3.Text = "Com Port:"; + // + // gvErrorCodes + // + this.gvErrorCodes.AllowUserToAddRows = false; + this.gvErrorCodes.AllowUserToDeleteRows = false; + this.gvErrorCodes.AllowUserToResizeRows = false; + dataGridViewCellStyle2.BackColor = System.Drawing.Color.AliceBlue; + this.gvErrorCodes.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle2; + this.gvErrorCodes.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.gvErrorCodes.ClipboardCopyMode = System.Windows.Forms.DataGridViewClipboardCopyMode.EnableWithoutHeaderText; + this.gvErrorCodes.ColumnHeadersHeight = 40; + this.gvErrorCodes.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing; + this.gvErrorCodes.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.cErrorCode, + this.cDescription, + this.cDetails, + this.cCodeDetailsLink}); + this.gvErrorCodes.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically; + this.gvErrorCodes.Location = new System.Drawing.Point(120, 432); + this.gvErrorCodes.MultiSelect = false; + this.gvErrorCodes.Name = "gvErrorCodes"; + this.gvErrorCodes.RowHeadersWidth = 72; + this.gvErrorCodes.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing; + this.gvErrorCodes.RowTemplate.Height = 37; + this.gvErrorCodes.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect; + this.gvErrorCodes.Size = new System.Drawing.Size(1385, 614); + this.gvErrorCodes.TabIndex = 14; + this.gvErrorCodes.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.gvErrorCodes_CellContentClick); + this.gvErrorCodes.RowPostPaint += new System.Windows.Forms.DataGridViewRowPostPaintEventHandler(this.gvErrorCodes_RowPostPaint); + // + // cErrorCode + // + this.cErrorCode.DataPropertyName = "ErrorCode"; + this.cErrorCode.HeaderText = "Error Code"; + this.cErrorCode.MinimumWidth = 9; + this.cErrorCode.Name = "cErrorCode"; + this.cErrorCode.ReadOnly = true; + this.cErrorCode.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; + this.cErrorCode.Width = 200; + // + // cDescription + // + this.cDescription.DataPropertyName = "Description"; + this.cDescription.HeaderText = "Error Code Description"; + this.cDescription.MinimumWidth = 9; + this.cDescription.Name = "cDescription"; + this.cDescription.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; + this.cDescription.Width = 930; + // + // cDetails + // + this.cDetails.DataPropertyName = "DetailsLink"; + this.cDetails.HeaderText = "Code Details"; + this.cDetails.MinimumWidth = 9; + this.cDetails.Name = "cDetails"; + this.cDetails.Resizable = System.Windows.Forms.DataGridViewTriState.False; + this.cDetails.Text = "Code Details"; + this.cDetails.TrackVisitedState = false; + this.cDetails.UseColumnTextForLinkValue = true; + this.cDetails.Width = 150; + // + // cCodeDetailsLink + // + this.cCodeDetailsLink.DataPropertyName = "DetailsLink"; + this.cCodeDetailsLink.HeaderText = "Link"; + this.cCodeDetailsLink.MinimumWidth = 9; + this.cCodeDetailsLink.Name = "cCodeDetailsLink"; + this.cCodeDetailsLink.ReadOnly = true; + this.cCodeDetailsLink.Resizable = System.Windows.Forms.DataGridViewTriState.False; + this.cCodeDetailsLink.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; + this.cCodeDetailsLink.Visible = false; + this.cCodeDetailsLink.Width = 175; + // + // lblLastErrorCodes + // + this.lblLastErrorCodes.AutoSize = true; + this.lblLastErrorCodes.Location = new System.Drawing.Point(6, 432); + this.lblLastErrorCodes.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.lblLastErrorCodes.Name = "lblLastErrorCodes"; + this.lblLastErrorCodes.Size = new System.Drawing.Size(75, 30); + this.lblLastErrorCodes.TabIndex = 13; + this.lblLastErrorCodes.Text = "Codes:"; + // + // UartUserControl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 30F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.lblLastErrorCodes); + this.Controls.Add(this.gvErrorCodes); + this.Controls.Add(this.label25); + this.Controls.Add(this.btnSendCommand); + this.Controls.Add(this.txtCustomCommand); + this.Controls.Add(this.label24); + this.Controls.Add(this.chkUseOffline); + this.Controls.Add(this.btnDownloadDatabase); + this.Controls.Add(this.btnRefreshPorts); + this.Controls.Add(this.btnClearOutput); + this.Controls.Add(this.txtUARTOutput); + this.Controls.Add(this.label22); + this.Controls.Add(this.btnClearErrorCodes); + this.Controls.Add(this.label21); + this.Controls.Add(this.btnGet10LastErrors); + this.Controls.Add(this.comboComPorts); + this.Controls.Add(this.btnDisconnectCom); + this.Controls.Add(this.btnConnectCom); + this.Controls.Add(this.label3); + this.Name = "UartUserControl"; + this.Size = new System.Drawing.Size(1865, 1049); + this.Load += new System.EventHandler(this.UartUserControl_Load); + ((System.ComponentModel.ISupportInitialize)(this.gvErrorCodes)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label25; + private Button btnSendCommand; + private TextBox txtCustomCommand; + private Label label24; + private CheckBox chkUseOffline; + private Button btnDownloadDatabase; + private Button btnRefreshPorts; + private Button btnClearOutput; + private TextBox txtUARTOutput; + private Label label22; + private Button btnClearErrorCodes; + private Label label21; + private Button btnGet10LastErrors; + private ComboBox comboComPorts; + private Button btnDisconnectCom; + private Button btnConnectCom; + private Label label3; + private DataGridView gvErrorCodes; + private Label lblLastErrorCodes; + private DataGridViewTextBoxColumn cErrorCode; + private DataGridViewTextBoxColumn cDescription; + private DataGridViewLinkColumn cDetails; + private DataGridViewTextBoxColumn cCodeDetailsLink; + } +} diff --git a/PS5 NOR Modifier/UserControls/UART/UartUserControl.cs b/PS5 NOR Modifier/UserControls/UART/UartUserControl.cs new file mode 100644 index 0000000..906965d --- /dev/null +++ b/PS5 NOR Modifier/UserControls/UART/UartUserControl.cs @@ -0,0 +1,595 @@ +using System; +using System.IO.Ports; +using System.Xml; +using PS5_NOR_Modifier.Common.Helpers; +using PS5_NOR_Modifier.UserControls.Events; +using PS5_NOR_Modifier.UserControls.UART.Data; + +namespace PS5_NOR_Modifier.UserControls.UART +{ + public partial class UartUserControl : UserControl + { + // We want this app to work offline, so let's declare where the local "offline" database will be stored + private const string LOCAL_DATABASE_FILE = "errorDB.xml"; + // Link to UART Codes knowledgebase + private const string WIKI_LINK = "https://uart.codes/"; + + public event EventHandler? statusUpdateEvent; + + private SerialPort _UARTSerial; + + public UartUserControl() + { + InitializeComponent(); + + _UARTSerial = new SerialPort(); + } + + protected override void OnCreateControl() + { + base.OnCreateControl(); + + if (this.ParentForm != null) + { + this.ParentForm.FormClosing += new FormClosingEventHandler(ParentForm_FormClosing); + } + } + + // If the app is closed before UART is terminated, we need to at least try to close the COM port gracefully first + void ParentForm_FormClosing(object sender, FormClosingEventArgs e) + { + if (_UARTSerial.IsOpen == true) + { + try + { + _UARTSerial.Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "An error occurred...", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private async Task DownloadDatabaseAsync() + { + // Define the URL + string url = "http://uartcodes.com/xml.php"; // Update with your URL + + // Define the file path to save the XML + + try + { + // Create a WebClient instance + using (HttpClient client = new()) + { + // Download the XML data from the URL + string xmlData = await client.GetStringAsync(url); + + // Create an XmlDocument instance and load the XML data + XmlDocument xmlDoc = new XmlDocument(); + xmlDoc.LoadXml(xmlData); + + // Save the XML data to a file + xmlDoc.Save(LOCAL_DATABASE_FILE); + + MessageBox.Show("The most recent offline database has been updated successfully.", "Offline Database Updated!", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + catch (Exception ex) + { + Console.WriteLine("Error: " + ex.Message); + } + } + + static string CalculateChecksum(string str) + { + int sum = 0; + foreach (char c in str) + { + sum += (int)c; + } + return str + ":" + (sum & 0xFF).ToString("X2"); + } + + string ParseErrorsOffline(string errorCode) + { + string result = String.Empty; + + try + { + ErrorCodesList errorCodes = XmlSerializationHelper.DeserilazeXmlFromFile(LOCAL_DATABASE_FILE); + + if (errorCode != null) + { + ErrorCode code = errorCodes.Items.Where(x => x.ErrorCodeNumber == errorCode).FirstOrDefault(); + + if (code != null) + { + result = code.Description; + } + } + } + catch (Exception ex) + { + result = "Error: " + ex.Message; + } + + return result; + } + + /// + /// We need to be able to send the error code we received from the console and fetch an XML result back from the server + /// Once we have a result from the server, parse the XML data and output it in an easy to understand format for the user + /// + /// + /// + private async Task ParseErrorsAsync(string errorCode) + { + string result = String.Empty; + + // If the user has opted to parse errors with an offline database, run the parse offline function + if (chkUseOffline.Checked == true) + { + result = ParseErrorsOffline(errorCode); + } + else + { + // The user wants to use the online version. Proceed at will + + // Define the URL with the error code parameter + string url = "http://uartcodes.com/xml.php?errorCode=" + errorCode; + + try + { + string response = ""; + + // Create a WebClient instance to send the request + using (HttpClient client = new()) + { + // Send the request and retrieve the response as a string + response = await client.GetStringAsync(url); + } + + ErrorCodesList errorCodes = XmlSerializationHelper.DeserilazeXmlFromString(response); + + if (errorCodes != null) + { + ErrorCode code = errorCodes.Items.Where(x => x.ErrorCodeNumber == errorCode).FirstOrDefault(); + + if (code != null) + { + result = code.Description; + } + } + } + catch (Exception ex) + { + result = "Error code: " + + errorCode + + Environment.NewLine + + ex.Message; + } + } + + return result; + } + + private void btnConnectCom_Click(object sender, EventArgs e) + { + // Let's try and connect to the UART reader + + if (comboComPorts.Text != String.Empty) + { + try + { + // Set port to selected port + _UARTSerial.PortName = comboComPorts.Text; + // Set the BAUD rate to 115200 + _UARTSerial.BaudRate = 115200; + // Enable RTS + _UARTSerial.RtsEnable = true; + // Open the COM port + _UARTSerial.Open(); + + SetConnectedUIState(true); + + UpdateStatus("Connected to UART via COM port " + comboComPorts.Text + " at a BAUD rate of 115200."); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "An error occurred...", MessageBoxButtons.OK, MessageBoxIcon.Error); + + SetConnectedUIState(false); + + UpdateStatus("Could not connect to UART. Please try again!"); + } + } + else + { + MessageBox.Show("Please select a COM port from the ports list to establish a connection.", "An error occurred...", MessageBoxButtons.OK, MessageBoxIcon.Error); + + SetConnectedUIState(false); + + UpdateStatus("Could not connect to UART. Please try again!"); + } + } + + private void UpdateStatus(string newStatus) + { + if (statusUpdateEvent != null) + { + statusUpdateEvent(this, new StatusUpdateEventArgs(newStatus)); + } + } + + private void btnDisconnectCom_Click(object sender, EventArgs e) + { + SetConnectedUIState(false); + + // Let's close the COM port + try + { + if (_UARTSerial.IsOpen == true) + { + _UARTSerial.Close(); + + UpdateStatus("Disconnected from UART..."); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "An error occurred...", MessageBoxButtons.OK, MessageBoxIcon.Error); + + UpdateStatus("An error occurred while disconnecting from UART. Please try again..."); + } + } + + private void btnRefreshPorts_Click(object sender, EventArgs e) + { + // When the "refresh ports" button is pressed, we need to refresh the list of available COM ports for UART + string[] ports = SerialPort.GetPortNames(); + + if (ports.Length > 0) + { + comboComPorts.Items.Clear(); + comboComPorts.Items.AddRange(ports); + comboComPorts.SelectedIndex = 0; + } + } + + /// + /// Read error codes from UART + /// + private async void button1_Click(object sender, EventArgs e) + { + List errorCodes = new List(); + BindingSource bsErrorCodes = new BindingSource(); + bsErrorCodes.DataSource = errorCodes; + gvErrorCodes.DataSource = bsErrorCodes; + + // Let's read the error codes from UART + txtUARTOutput.Text = ""; + + if (_UARTSerial.IsOpen == true) + { + try + { + for (var i = 0; i < 10; i++) + { + var command = $"errlog {i}"; + + string checksum = CalculateChecksum(command); + + _UARTSerial.WriteLine(checksum); + + string uartCodeDetails = String.Empty; + + do + { + string uartResponse = _UARTSerial.ReadLine(); + + if (String.Compare(uartResponse, checksum, true) != 0) + { + uartCodeDetails = uartResponse; + } + } while (_UARTSerial.BytesToRead != 0); + + if (!String.IsNullOrEmpty(uartCodeDetails)) + { + string[] split = uartCodeDetails.Split(' '); + + if (split.Length > 2) + { + switch (split[0]) + { + case "NG": + break; + case "OK": + var errorCode = split[2]; + // Now that the error code has been isolated from the rest of the junk sent by the system + // let's check it against the database. The error server will need to return XML result + string errorCodeDescription = await ParseErrorsAsync(errorCode); + + ErrorCodeInfo codeInfo = new ErrorCodeInfo(); + codeInfo.ErrorCode = errorCode; + codeInfo.Description = errorCodeDescription; + codeInfo.DetailsLink = WIKI_LINK + "errorDetails.php?errorCode=" + errorCode; + errorCodes.Add(codeInfo); + + bsErrorCodes.ResetBindings(false); + + if (!txtUARTOutput.Text.Contains(errorCodeDescription)) + { + string fullErrorMessage = "Error code: " + + errorCode + + Environment.NewLine + + "Description: " + + errorCodeDescription; + + txtUARTOutput.AppendText(fullErrorMessage + Environment.NewLine); + } + + break; + } + } + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "An error occurred...", MessageBoxButtons.OK, MessageBoxIcon.Error); + + UpdateStatus("An error occurred while reading error codes from UART. Please try again..."); + } + } + else + { + MessageBox.Show("Please connect to UART before attempting to read the error codes.", "An error occurred...", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + } + + /// + /// The user can clear the error codes from the console if required but let's make sure they actually want to do + /// that by showing a confirmation dialog first. If the click yes, send the UART command and wipe the codes from + /// the console. This action cannot be undone! + /// + private void btnClearErrorCodes_Click(object sender, EventArgs e) + { + DialogResult result = MessageBox.Show("This will clear error codes from the console by sending the \"errlog clear\" command. Are you sure you would like to proceed? This action cannot be undone!", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); + + if (result == DialogResult.Yes) + { + // Let's read the error codes from UART + txtUARTOutput.Text = ""; + + if (_UARTSerial.IsOpen == true) + { + try + { + List UARTLines = new(); + + var command = "errlog clear"; + var checksum = CalculateChecksum(command); + _UARTSerial.WriteLine(checksum); + do + { + var line = _UARTSerial.ReadLine(); + if (!string.Equals($"{command}:{checksum:X2}", line, StringComparison.InvariantCultureIgnoreCase)) + { + UARTLines.Add(line); + } + } while (_UARTSerial.BytesToRead != 0); + + foreach (var l in UARTLines) + { + var split = l.Split(' '); + if (!split.Any()) continue; + switch (split[0]) + { + case "NG": + if (!txtUARTOutput.Text.Contains("FAIL")) + { + txtUARTOutput.AppendText("Response: FAIL" + Environment.NewLine + "Information: An error occurred while clearing the error logs from the system. Please try again..."); + } + break; + case "OK": + if (!txtUARTOutput.Text.Contains("SUCCESS")) + { + txtUARTOutput.AppendText("Response: SUCCESS" + Environment.NewLine + "Information: All error codes cleared successfully"); + + BindingSource bsErrorCodes = new BindingSource(); + bsErrorCodes.DataSource = new List(); + gvErrorCodes.DataSource = bsErrorCodes; + } + break; + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "An error occurred...", MessageBoxButtons.OK, MessageBoxIcon.Error); + + UpdateStatus("An error occurred while attempting to send a UART command. Please try again..."); + } + } + else + { + MessageBox.Show("Please connect to UART before attempting to send commands.", "An error occurred...", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + } + else + { + // Do nothing. The user cancelled the request + } + } + + /// + /// When the user clicks on the download error database button, show a confirmation first and then if they click yes, + /// continue to download the latest database from the update server + /// + private async void btnDownloadDatabase_Click(object sender, EventArgs e) + { + DialogResult result = MessageBox.Show("Downloading the error database will overwrite any existing offline database you currently have. Are you sure you would like to do this?", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); + + // Check if user wants to proceed + if (result == DialogResult.Yes) + { + // Call the function to download and save the XML data + await DownloadDatabaseAsync(); + } + else + { + // Do nothing. The user cancelled the request// The user cancelled + } + } + + /// + /// Sometimes the user might want to send a custom command. Let them do that here! + /// + private void btnSendCommand_Click(object sender, EventArgs e) + { + if (txtCustomCommand.Text != "") + { + // Let's read the error codes from UART + txtUARTOutput.Text = ""; + + if (_UARTSerial.IsOpen == true) + { + try + { + + List UARTLines = new(); + + var checksum = CalculateChecksum(txtCustomCommand.Text); + _UARTSerial.WriteLine(checksum); + do + { + var line = _UARTSerial.ReadLine(); + if (!string.Equals($"{txtCustomCommand.Text}:{checksum:X2}", line, StringComparison.InvariantCultureIgnoreCase)) + { + UARTLines.Add(line); + } + } while (_UARTSerial.BytesToRead != 0); + + foreach (var l in UARTLines) + { + var split = l.Split(' '); + if (!split.Any()) continue; + switch (split[0]) + { + case "NG": + txtUARTOutput.Text = "ERROR: " + l; + break; + case "OK": + txtUARTOutput.Text = "SUCCESS: " + l; + break; + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "An error occurred...", MessageBoxButtons.OK, MessageBoxIcon.Error); + + UpdateStatus("An error occurred while reading error codes from UART. Please try again..."); + } + } + else + { + MessageBox.Show("Please connect to UART before attempting to send commands.", "An error occurred...", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + } + else + { + MessageBox.Show("Please enter a command to send via UART.", "An error occurred...", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + } + + /// + /// Clear the UART output window + /// + private void button3_Click(object sender, EventArgs e) + { + txtUARTOutput.Text = String.Empty; + } + + /// + /// If the user presses the enter key while using the custom command box, handle it by programmatically pressing the + /// send button. This is more of a convenience thing really! + /// + private void txtCustomCommand_KeyPress(object sender, KeyPressEventArgs e) + { + if (e.KeyChar == (char)Keys.Enter) + { + btnSendCommand.PerformClick(); + } + } + + private void UartUserControl_Load(object sender, EventArgs e) + { + SetConnectedUIState(false); + + // Upon first launch, we need to get a list of COM ports available for UART + comboComPorts.Items.Clear(); + + string[] ports = SerialPort.GetPortNames(); + + if (ports.Length > 0) + { + comboComPorts.Items.AddRange(ports); + comboComPorts.SelectedIndex = 0; + } + } + + //Add row numbers + private void gvErrorCodes_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) + { + var grid = sender as DataGridView; + var rowIdx = (e.RowIndex + 1).ToString(); + + var centerFormat = new StringFormat() + { + Alignment = StringAlignment.Center, + LineAlignment = StringAlignment.Center + }; + + var headerBounds = new Rectangle(e.RowBounds.Left, e.RowBounds.Top, grid.RowHeadersWidth, e.RowBounds.Height); + + e.Graphics.DrawString(rowIdx, this.Font, SystemBrushes.ControlText, headerBounds, centerFormat); + } + + //Make the Details link be browsable + private void gvErrorCodes_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + if (e.ColumnIndex == 2 && e.RowIndex >= 0) // Hyperlink column + { + string url = gvErrorCodes.Rows[e.RowIndex].Cells[3].Value.ToString(); + + if (!String.IsNullOrEmpty(url)) + { + Browser.OpenUrl(url); + } + } + } + + private void SetConnectedUIState(bool connected) + { + comboComPorts.Enabled = !connected; + btnConnectCom.Enabled = !connected; + btnDisconnectCom.Enabled = connected; + btnRefreshPorts.Enabled = !connected; + btnGet10LastErrors.Enabled = connected; + btnClearErrorCodes.Enabled = connected; + txtUARTOutput.Enabled = connected; + btnClearOutput.Enabled = connected; + txtCustomCommand.Enabled = connected; + btnSendCommand.Enabled = connected; + + txtUARTOutput.Text = String.Empty; + + BindingSource bsErrorCodes = new BindingSource(); + bsErrorCodes.DataSource = new List(); + gvErrorCodes.DataSource = bsErrorCodes; + } + } +} diff --git a/PS5 NOR Modifier/UserControls/UART/UartUserControl.resx b/PS5 NOR Modifier/UserControls/UART/UartUserControl.resx new file mode 100644 index 0000000..9f1be7e --- /dev/null +++ b/PS5 NOR Modifier/UserControls/UART/UartUserControl.resx @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + You can send custom commands +with UART using this feature. Note +that any command entered here +will return unparsed results. Please +also be sure to know what you are +doing as sending unsafe commands +can damage your device. + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/README.md b/README.md index 6781d07..0550812 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,11 @@ The PS5 NOR Modifier is a Windows GUI based application making it easier for peo Download compiled versions under the releases section -![PS5 NOR Modifier](https://raw.githubusercontent.com/thecod3ryoutube/PS5NorModifier/main/Screenshot1.png) +![image](https://github.com/user-attachments/assets/e9879421-39f0-43f8-a8c9-9c5f40bec558) -![PS5 NOR Modifier](https://raw.githubusercontent.com/thecod3ryoutube/PS5NorModifier/main/Screenshot2.png) +![image](https://github.com/user-attachments/assets/6873dc58-9557-4be1-851b-e5a3cb620884) -![PS5 NOR Modifier](https://raw.githubusercontent.com/thecod3ryoutube/PS5NorModifier/main/Screenshot3.png) +![image](https://github.com/user-attachments/assets/133842f8-50aa-45a4-b8fa-08dfbdcdd0fe) If you just want to use the software, download the standalone ZIP