From 897b98ef30b2885554ab38b8ab4964e173d3195b Mon Sep 17 00:00:00 2001 From: Vitali Balyshau Date: Fri, 16 May 2025 16:44:24 +0200 Subject: [PATCH 01/13] Refactoring: Extracted 'UART Communication' tab into a separate user control to improve code readability and loose coupling between independent software components --- PS5 NOR Modifier/Form1.Designer.cs | 448 ++++---------- PS5 NOR Modifier/Form1.cs | 552 +---------------- PS5 NOR Modifier/Form1.resx | 9 - PS5 NOR Modifier/PS5 NOR Modifier.csproj.user | 3 + .../UART/Events/StatusUpdateEventArgs.cs | 20 + .../UART/UartUserControl.Designer.cs | 277 +++++++++ .../UserControls/UART/UartUserControl.cs | 567 ++++++++++++++++++ .../UserControls/UART/UartUserControl.resx | 69 +++ 8 files changed, 1066 insertions(+), 879 deletions(-) create mode 100644 PS5 NOR Modifier/UserControls/UART/Events/StatusUpdateEventArgs.cs create mode 100644 PS5 NOR Modifier/UserControls/UART/UartUserControl.Designer.cs create mode 100644 PS5 NOR Modifier/UserControls/UART/UartUserControl.cs create mode 100644 PS5 NOR Modifier/UserControls/UART/UartUserControl.resx diff --git a/PS5 NOR Modifier/Form1.Designer.cs b/PS5 NOR Modifier/Form1.Designer.cs index 3889d30..90f931a 100644 --- a/PS5 NOR Modifier/Form1.Designer.cs +++ b/PS5 NOR Modifier/Form1.Designer.cs @@ -70,24 +70,8 @@ private void InitializeComponent() this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabPage1 = new System.Windows.Forms.TabPage(); 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 +83,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(14, 168); 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 +104,19 @@ 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.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(14, 918); + 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; @@ -144,10 +125,9 @@ private void InitializeComponent() // label4 // 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(111, 918); 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); @@ -155,27 +135,26 @@ private void InitializeComponent() // 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.Location = new System.Drawing.Point(9, 6); this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(102, 15); + this.label5.Size = new System.Drawing.Size(182, 30); 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.Location = new System.Drawing.Point(9, 40); + this.fileLocationBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.fileLocationBox.Name = "fileLocationBox"; - this.fileLocationBox.Size = new System.Drawing.Size(717, 23); + this.fileLocationBox.Size = new System.Drawing.Size(1226, 35); 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.Location = new System.Drawing.Point(1246, 38); + this.browseFileButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.browseFileButton.Name = "browseFileButton"; - this.browseFileButton.Size = new System.Drawing.Size(78, 20); + this.browseFileButton.Size = new System.Drawing.Size(134, 40); this.browseFileButton.TabIndex = 8; this.browseFileButton.Text = "Browse"; this.browseFileButton.UseVisualStyleBackColor = true; @@ -185,70 +164,63 @@ private void InitializeComponent() // 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.Location = new System.Drawing.Point(9, 98); this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(87, 15); + this.label6.Size = new System.Drawing.Size(154, 30); 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.Location = new System.Drawing.Point(9, 144); this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(85, 15); + this.label7.Size = new System.Drawing.Size(150, 30); 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.Location = new System.Drawing.Point(9, 318); this.label9.Name = "label9"; - this.label9.Size = new System.Drawing.Size(66, 15); + this.label9.Size = new System.Drawing.Size(117, 30); 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.Location = new System.Drawing.Point(9, 378); this.label10.Name = "label10"; - this.label10.Size = new System.Drawing.Size(51, 15); + this.label10.Size = new System.Drawing.Size(92, 30); 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.Location = new System.Drawing.Point(213, 144); this.serialNumber.Name = "serialNumber"; - this.serialNumber.Size = new System.Drawing.Size(16, 15); + this.serialNumber.Size = new System.Drawing.Size(28, 30); 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.Location = new System.Drawing.Point(213, 318); this.modelInfo.Name = "modelInfo"; - this.modelInfo.Size = new System.Drawing.Size(16, 15); + this.modelInfo.Size = new System.Drawing.Size(28, 30); 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.Location = new System.Drawing.Point(213, 378); this.fileSizeInfo.Name = "fileSizeInfo"; - this.fileSizeInfo.Size = new System.Drawing.Size(16, 15); + this.fileSizeInfo.Size = new System.Drawing.Size(28, 30); this.fileSizeInfo.TabIndex = 17; this.fileSizeInfo.Text = "..."; // @@ -257,36 +229,34 @@ private void InitializeComponent() 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, 1075); 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(1452, 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.Location = new System.Drawing.Point(9, 260); this.label8.Name = "label8"; - this.label8.Size = new System.Drawing.Size(80, 15); + this.label8.Size = new System.Drawing.Size(142, 30); 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.Location = new System.Drawing.Point(213, 260); this.boardVariant.Name = "boardVariant"; - this.boardVariant.Size = new System.Drawing.Size(16, 15); + this.boardVariant.Size = new System.Drawing.Size(28, 30); this.boardVariant.TabIndex = 21; this.boardVariant.Text = "..."; // @@ -294,19 +264,18 @@ private void InitializeComponent() // 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.Location = new System.Drawing.Point(674, 98); this.label11.Name = "label11"; - this.label11.Size = new System.Drawing.Size(84, 15); + this.label11.Size = new System.Drawing.Size(152, 30); 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.Location = new System.Drawing.Point(1123, 442); + this.convertToDigitalEditionButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.convertToDigitalEditionButton.Name = "convertToDigitalEditionButton"; - this.convertToDigitalEditionButton.Size = new System.Drawing.Size(150, 46); + this.convertToDigitalEditionButton.Size = new System.Drawing.Size(257, 92); this.convertToDigitalEditionButton.TabIndex = 23; this.convertToDigitalEditionButton.Text = "Save New\r\nBIOS Information"; this.convertToDigitalEditionButton.UseVisualStyleBackColor = true; @@ -340,47 +309,44 @@ private void InitializeComponent() "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.Location = new System.Drawing.Point(869, 196); + this.boardVariantSelectionBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.boardVariantSelectionBox.Name = "boardVariantSelectionBox"; - this.boardVariantSelectionBox.Size = new System.Drawing.Size(298, 23); + this.boardVariantSelectionBox.Size = new System.Drawing.Size(508, 38); 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.Location = new System.Drawing.Point(674, 144); this.label12.Name = "label12"; - this.label12.Size = new System.Drawing.Size(85, 15); + this.label12.Size = new System.Drawing.Size(150, 30); 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.Location = new System.Drawing.Point(674, 200); this.label13.Name = "label13"; - this.label13.Size = new System.Drawing.Size(80, 15); + this.label13.Size = new System.Drawing.Size(142, 30); 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.Location = new System.Drawing.Point(869, 140); + this.serialNumberTextbox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.serialNumberTextbox.Name = "serialNumberTextbox"; - this.serialNumberTextbox.Size = new System.Drawing.Size(298, 23); + this.serialNumberTextbox.Size = new System.Drawing.Size(508, 35); 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.Location = new System.Drawing.Point(674, 258); this.label14.Name = "label14"; - this.label14.Size = new System.Drawing.Size(66, 15); + this.label14.Size = new System.Drawing.Size(117, 30); this.label14.TabIndex = 33; this.label14.Text = "PS5 Model:"; // @@ -391,20 +357,19 @@ private void InitializeComponent() 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.Location = new System.Drawing.Point(869, 254); + this.boardModelSelectionBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.boardModelSelectionBox.Name = "boardModelSelectionBox"; - this.boardModelSelectionBox.Size = new System.Drawing.Size(298, 23); + this.boardModelSelectionBox.Size = new System.Drawing.Size(508, 38); this.boardModelSelectionBox.TabIndex = 34; // // label15 // 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, 990); 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); @@ -412,88 +377,98 @@ private void InitializeComponent() // label16 // this.label16.AutoSize = true; - this.label16.Location = new System.Drawing.Point(5, 221); + this.label16.Location = new System.Drawing.Point(9, 442); + this.label16.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.label16.Name = "label16"; - this.label16.Size = new System.Drawing.Size(104, 15); + this.label16.Size = new System.Drawing.Size(184, 30); 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.Location = new System.Drawing.Point(213, 442); + this.macAddressInfo.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.macAddressInfo.Name = "macAddressInfo"; - this.macAddressInfo.Size = new System.Drawing.Size(16, 15); + this.macAddressInfo.Size = new System.Drawing.Size(28, 30); this.macAddressInfo.TabIndex = 37; this.macAddressInfo.Text = "..."; // // LANMacAddressInfo // this.LANMacAddressInfo.AutoSize = true; - this.LANMacAddressInfo.Location = new System.Drawing.Point(124, 252); + this.LANMacAddressInfo.Location = new System.Drawing.Point(213, 504); + this.LANMacAddressInfo.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.LANMacAddressInfo.Name = "LANMacAddressInfo"; - this.LANMacAddressInfo.Size = new System.Drawing.Size(16, 15); + this.LANMacAddressInfo.Size = new System.Drawing.Size(28, 30); this.LANMacAddressInfo.TabIndex = 39; this.LANMacAddressInfo.Text = "..."; // // label18 // this.label18.AutoSize = true; - this.label18.Location = new System.Drawing.Point(5, 252); + this.label18.Location = new System.Drawing.Point(9, 504); + this.label18.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.label18.Name = "label18"; - this.label18.Size = new System.Drawing.Size(104, 15); + this.label18.Size = new System.Drawing.Size(185, 30); 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.Location = new System.Drawing.Point(213, 202); + this.moboSerialInfo.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.moboSerialInfo.Name = "moboSerialInfo"; - this.moboSerialInfo.Size = new System.Drawing.Size(16, 15); + this.moboSerialInfo.Size = new System.Drawing.Size(28, 30); this.moboSerialInfo.TabIndex = 41; this.moboSerialInfo.Text = "..."; // // label19 // this.label19.AutoSize = true; - this.label19.Location = new System.Drawing.Point(5, 101); + this.label19.Location = new System.Drawing.Point(9, 202); + this.label19.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.label19.Name = "label19"; - this.label19.Size = new System.Drawing.Size(111, 15); + this.label19.Size = new System.Drawing.Size(196, 30); 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.Location = new System.Drawing.Point(674, 318); + this.label17.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.label17.Name = "label17"; - this.label17.Size = new System.Drawing.Size(108, 15); + this.label17.Size = new System.Drawing.Size(190, 30); 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.Location = new System.Drawing.Point(869, 312); + this.wifiMacAddressTextbox.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); this.wifiMacAddressTextbox.Name = "wifiMacAddressTextbox"; - this.wifiMacAddressTextbox.Size = new System.Drawing.Size(298, 23); + this.wifiMacAddressTextbox.Size = new System.Drawing.Size(508, 35); this.wifiMacAddressTextbox.TabIndex = 43; // // lanMacAddressTextbox // this.lanMacAddressTextbox.Enabled = false; - this.lanMacAddressTextbox.Location = new System.Drawing.Point(507, 185); + this.lanMacAddressTextbox.Location = new System.Drawing.Point(869, 370); + this.lanMacAddressTextbox.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); this.lanMacAddressTextbox.Name = "lanMacAddressTextbox"; - this.lanMacAddressTextbox.Size = new System.Drawing.Size(298, 23); + this.lanMacAddressTextbox.Size = new System.Drawing.Size(508, 35); this.lanMacAddressTextbox.TabIndex = 44; // // label20 // this.label20.AutoSize = true; - this.label20.Location = new System.Drawing.Point(393, 188); + this.label20.Location = new System.Drawing.Point(674, 376); + this.label20.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.label20.Name = "label20"; - this.label20.Size = new System.Drawing.Size(104, 15); + this.label20.Size = new System.Drawing.Size(185, 30); this.label20.TabIndex = 45; this.label20.Text = "LAN Mac Address:"; // @@ -501,10 +476,11 @@ private void InitializeComponent() // 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, 264); + 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(1407, 622); this.tabControl1.TabIndex = 46; // // tabPage1 @@ -539,217 +515,51 @@ private void InitializeComponent() 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.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(1399, 579); this.tabPage1.TabIndex = 0; this.tabPage1.Text = "NOR Modifier"; this.tabPage1.UseVisualStyleBackColor = true; // // 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(1399, 579); 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); - // - // 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:"; + // ucUART + // + this.ucUART.Location = new System.Drawing.Point(0, 0); + this.ucUART.Name = "ucUART"; + this.ucUART.Size = new System.Drawing.Size(1391, 549); + 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 // - 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(1452, 1114); this.Controls.Add(this.label23); this.Controls.Add(this.tabControl1); this.Controls.Add(this.label15); @@ -759,10 +569,9 @@ 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.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.Name = "Form1"; 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(); @@ -772,7 +581,6 @@ private void InitializeComponent() this.tabPage1.ResumeLayout(false); this.tabPage1.PerformLayout(); this.tabPage2.ResumeLayout(false); - this.tabPage2.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -821,23 +629,7 @@ private void InitializeComponent() 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; } } \ No newline at end of file diff --git a/PS5 NOR Modifier/Form1.cs b/PS5 NOR Modifier/Form1.cs index 8f6dec8..0a2cc5f 100644 --- a/PS5 NOR Modifier/Form1.cs +++ b/PS5 NOR Modifier/Form1.cs @@ -1,38 +1,28 @@ 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; namespace PS5_NOR_Modifier { public partial class Form1 : Form { - public Form1() { InitializeComponent(); + + LoadUARTControl(); } - static string CalculateChecksum(string str) + private void LoadUARTControl() { - int sum = 0; - foreach (char c in str) - { - sum += (int)c; - } - return str + ":" + (sum & 0xFF).ToString("X2"); + ucUART.statusUpdateEvent += ucUART_statusUpdateEvent; + } + + private void ucUART_statusUpdateEvent(object? sender, UserControls.UART.Events.StatusUpdateEventArgs e) + { + toolStripStatusLabel1.Text = e.Text; } private void throwError(string errmsg) @@ -40,11 +30,6 @@ 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? /// @@ -82,13 +67,6 @@ private static byte[] ConvertHexStringToByteArray(string hexString) 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 @@ -107,178 +85,6 @@ private void Form1_Load(object sender, EventArgs e) 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); - } - } - - /// - /// 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) - { - // 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; - } - } - - string ParseErrorsOffline(string errorCode) - { - 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; - } - string HexStringToString(string hexString) { if (hexString == null || (hexString.Length & 1) == 1) @@ -817,343 +623,5 @@ 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(); - } - } } -} \ 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..9c27a76 100644 --- a/PS5 NOR Modifier/PS5 NOR Modifier.csproj.user +++ b/PS5 NOR Modifier/PS5 NOR Modifier.csproj.user @@ -7,5 +7,8 @@ Form + + UserControl + \ No newline at end of file diff --git a/PS5 NOR Modifier/UserControls/UART/Events/StatusUpdateEventArgs.cs b/PS5 NOR Modifier/UserControls/UART/Events/StatusUpdateEventArgs.cs new file mode 100644 index 0000000..2ca1c61 --- /dev/null +++ b/PS5 NOR Modifier/UserControls/UART/Events/StatusUpdateEventArgs.cs @@ -0,0 +1,20 @@ +using System; + + +namespace PS5_NOR_Modifier.UserControls.UART.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/UserControls/UART/UartUserControl.Designer.cs b/PS5 NOR Modifier/UserControls/UART/UartUserControl.Designer.cs new file mode 100644 index 0000000..fd0b947 --- /dev/null +++ b/PS5 NOR Modifier/UserControls/UART/UartUserControl.Designer.cs @@ -0,0 +1,277 @@ +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)); + 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.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.SuspendLayout(); + // + // label25 + // + this.label25.AutoSize = true; + this.label25.Location = new System.Drawing.Point(1042, 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 = 34; + this.label25.Text = resources.GetString("label25.Text"); + // + // btnSendCommand + // + this.btnSendCommand.Location = new System.Drawing.Point(1251, 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 = 33; + 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(1042, 175); + this.txtCustomCommand.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.txtCustomCommand.Name = "txtCustomCommand"; + this.txtCustomCommand.Size = new System.Drawing.Size(335, 35); + this.txtCustomCommand.TabIndex = 32; + this.txtCustomCommand.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtCustomCommand_KeyPress); + // + // label24 + // + this.label24.AutoSize = true; + this.label24.Location = new System.Drawing.Point(1042, 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 = 31; + this.label24.Text = "Send custom command via UART:"; + // + // chkUseOffline + // + this.chkUseOffline.AutoSize = true; + this.chkUseOffline.Location = new System.Drawing.Point(805, 77); + 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 = 30; + this.chkUseOffline.Text = "Use offline database"; + this.chkUseOffline.UseVisualStyleBackColor = true; + // + // btnDownloadDatabase + // + this.btnDownloadDatabase.Location = new System.Drawing.Point(527, 71); + this.btnDownloadDatabase.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.btnDownloadDatabase.Name = "btnDownloadDatabase"; + this.btnDownloadDatabase.Size = new System.Drawing.Size(267, 46); + this.btnDownloadDatabase.TabIndex = 29; + 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 = 28; + 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(764, 491); + this.button3.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(267, 46); + this.button3.TabIndex = 27; + 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(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(907, 336); + this.txtUARTOutput.TabIndex = 26; + // + // 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 = 25; + this.label22.Text = "Output:"; + // + // btnClearErrorCodes + // + this.btnClearErrorCodes.Location = new System.Drawing.Point(315, 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 = 24; + 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 = 23; + this.label21.Text = "Options:"; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(121, 71); + this.button1.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(183, 46); + this.button1.TabIndex = 22; + 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(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 = 21; + // + // 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 = 20; + 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 = 19; + 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 = 18; + this.label3.Text = "Com Port:"; + // + // UartUserControl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 30F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + 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.button3); + this.Controls.Add(this.txtUARTOutput); + this.Controls.Add(this.label22); + this.Controls.Add(this.btnClearErrorCodes); + this.Controls.Add(this.label21); + this.Controls.Add(this.button1); + 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(1387, 547); + this.Load += new System.EventHandler(this.UartUserControl_Load); + 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 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; + } +} diff --git a/PS5 NOR Modifier/UserControls/UART/UartUserControl.cs b/PS5 NOR Modifier/UserControls/UART/UartUserControl.cs new file mode 100644 index 0000000..6dfab4d --- /dev/null +++ b/PS5 NOR Modifier/UserControls/UART/UartUserControl.cs @@ -0,0 +1,567 @@ +using System; +using System.IO.Ports; +using System.Xml; +using PS5_NOR_Modifier.UserControls.UART.Events; + +namespace PS5_NOR_Modifier.UserControls.UART +{ + public partial class UartUserControl : UserControl + { + public event EventHandler? statusUpdateEvent; + + private SerialPort _UARTSerial; + + // 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"; + + 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 results = ""; + + try + { + // Check if the XML file exists + if (File.Exists(LOCAL_DATABASE_FILE)) + { + // Load the XML file + XmlDocument xmlDoc = new XmlDocument(); + xmlDoc.Load(LOCAL_DATABASE_FILE); + + // 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; + } + + /// + /// 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) + { + // 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; + } + } + + private void btnConnectCom_Click(object sender, EventArgs e) + { + // Let's try and connect to the UART reader + btnConnectCom.Enabled = false; + + 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(); + btnDisconnectCom.Enabled = 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); + btnConnectCom.Enabled = true; + btnDisconnectCom.Enabled = 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); + btnConnectCom.Enabled = true; + btnDisconnectCom.Enabled = 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) + { + // Let's close the COM port + try + { + if (_UARTSerial.IsOpen == true) + { + _UARTSerial.Close(); + btnConnectCom.Enabled = true; + btnDisconnectCom.Enabled = false; + + 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(); + comboComPorts.Items.Clear(); + comboComPorts.Items.AddRange(ports); + comboComPorts.SelectedIndex = 0; + btnConnectCom.Enabled = true; + btnDisconnectCom.Enabled = false; + } + + /// + /// 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); + + 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"); + } + 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) + { + // 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; + btnConnectCom.Enabled = true; + btnDisconnectCom.Enabled = false; + } + } + } +} diff --git a/PS5 NOR Modifier/UserControls/UART/UartUserControl.resx b/PS5 NOR Modifier/UserControls/UART/UartUserControl.resx new file mode 100644 index 0000000..f9d8cbb --- /dev/null +++ b/PS5 NOR Modifier/UserControls/UART/UartUserControl.resx @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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. + + \ No newline at end of file From 6a22cc135d5b20653a4426d7350d7fa478f9b80b Mon Sep 17 00:00:00 2001 From: Vitali Balyshau Date: Fri, 16 May 2025 16:52:23 +0200 Subject: [PATCH 02/13] Refactoring: Extracted 'NOR Modifier' tab into independent user control to improve code readability and loose coupling between components --- .../Events/StatusUpdateEventArgs.cs | 20 + PS5 NOR Modifier/Form1.Designer.cs | 413 +------------ PS5 NOR Modifier/Form1.cs | 550 +---------------- PS5 NOR Modifier/PS5 NOR Modifier.csproj.user | 3 + .../NorModifierUserControl.Designer.cs | 448 ++++++++++++++ .../NorModifier/NorModifierUserControl.cs | 562 ++++++++++++++++++ .../NorModifier/NorModifierUserControl.resx | 60 ++ .../UART/Events/StatusUpdateEventArgs.cs | 20 - .../UserControls/UART/UartUserControl.cs | 2 +- 9 files changed, 1113 insertions(+), 965 deletions(-) create mode 100644 PS5 NOR Modifier/Events/StatusUpdateEventArgs.cs create mode 100644 PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.Designer.cs create mode 100644 PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs create mode 100644 PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.resx delete mode 100644 PS5 NOR Modifier/UserControls/UART/Events/StatusUpdateEventArgs.cs 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 90f931a..e658337 100644 --- a/PS5 NOR Modifier/Form1.Designer.cs +++ b/PS5 NOR Modifier/Form1.Designer.cs @@ -34,41 +34,12 @@ private void InitializeComponent() 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.ucUART = new PS5_NOR_Modifier.UserControls.UART.UartUserControl(); this.label23 = new System.Windows.Forms.Label(); @@ -132,98 +103,6 @@ private void InitializeComponent() 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(9, 6); - this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(182, 30); - this.label5.TabIndex = 6; - this.label5.Text = "Select NOR Dump"; - // - // fileLocationBox - // - this.fileLocationBox.Location = new System.Drawing.Point(9, 40); - 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 = 7; - // - // browseFileButton - // - this.browseFileButton.Location = new System.Drawing.Point(1246, 38); - 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 = 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(9, 98); - this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(154, 30); - this.label6.TabIndex = 9; - this.label6.Text = "Dump Results:"; - // - // label7 - // - this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(9, 144); - this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(150, 30); - this.label7.TabIndex = 10; - this.label7.Text = "Serial Number:"; - // - // label9 - // - this.label9.AutoSize = true; - this.label9.Location = new System.Drawing.Point(9, 318); - this.label9.Name = "label9"; - this.label9.Size = new System.Drawing.Size(117, 30); - this.label9.TabIndex = 12; - this.label9.Text = "PS5 Model:"; - // - // label10 - // - this.label10.AutoSize = true; - this.label10.Location = new System.Drawing.Point(9, 378); - this.label10.Name = "label10"; - this.label10.Size = new System.Drawing.Size(92, 30); - this.label10.TabIndex = 13; - this.label10.Text = "File Size:"; - // - // serialNumber - // - this.serialNumber.AutoSize = true; - this.serialNumber.Location = new System.Drawing.Point(213, 144); - this.serialNumber.Name = "serialNumber"; - this.serialNumber.Size = new System.Drawing.Size(28, 30); - this.serialNumber.TabIndex = 14; - this.serialNumber.Text = "..."; - // - // modelInfo - // - this.modelInfo.AutoSize = true; - this.modelInfo.Location = new System.Drawing.Point(213, 318); - this.modelInfo.Name = "modelInfo"; - this.modelInfo.Size = new System.Drawing.Size(28, 30); - this.modelInfo.TabIndex = 16; - this.modelInfo.Text = "..."; - // - // fileSizeInfo - // - this.fileSizeInfo.AutoSize = true; - this.fileSizeInfo.Location = new System.Drawing.Point(213, 378); - this.fileSizeInfo.Name = "fileSizeInfo"; - this.fileSizeInfo.Size = new System.Drawing.Size(28, 30); - this.fileSizeInfo.TabIndex = 17; - this.fileSizeInfo.Text = "..."; - // // statusStrip1 // this.statusStrip1.ImageScalingSize = new System.Drawing.Size(24, 24); @@ -242,127 +121,6 @@ private void InitializeComponent() 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(9, 260); - this.label8.Name = "label8"; - this.label8.Size = new System.Drawing.Size(142, 30); - this.label8.TabIndex = 20; - this.label8.Text = "Board Variant:"; - // - // boardVariant - // - this.boardVariant.AutoSize = true; - this.boardVariant.Location = new System.Drawing.Point(213, 260); - this.boardVariant.Name = "boardVariant"; - this.boardVariant.Size = new System.Drawing.Size(28, 30); - 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(674, 98); - this.label11.Name = "label11"; - this.label11.Size = new System.Drawing.Size(152, 30); - this.label11.TabIndex = 22; - this.label11.Text = "Modify Values"; - // - // convertToDigitalEditionButton - // - this.convertToDigitalEditionButton.Location = new System.Drawing.Point(1123, 442); - 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 = 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(869, 196); - 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 = 29; - // - // label12 - // - this.label12.AutoSize = true; - this.label12.Location = new System.Drawing.Point(674, 144); - this.label12.Name = "label12"; - this.label12.Size = new System.Drawing.Size(150, 30); - this.label12.TabIndex = 30; - this.label12.Text = "Serial Number:"; - // - // label13 - // - this.label13.AutoSize = true; - this.label13.Location = new System.Drawing.Point(674, 200); - this.label13.Name = "label13"; - this.label13.Size = new System.Drawing.Size(142, 30); - this.label13.TabIndex = 31; - this.label13.Text = "Board Variant:"; - // - // serialNumberTextbox - // - this.serialNumberTextbox.Location = new System.Drawing.Point(869, 140); - 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 = 32; - // - // label14 - // - this.label14.AutoSize = true; - this.label14.Location = new System.Drawing.Point(674, 258); - this.label14.Name = "label14"; - this.label14.Size = new System.Drawing.Size(117, 30); - 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(869, 254); - 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 = 34; - // // label15 // this.label15.AutoSize = true; @@ -374,104 +132,6 @@ private void InitializeComponent() 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(9, 442); - 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 = 36; - this.label16.Text = "WiFi Mac Address:"; - // - // macAddressInfo - // - this.macAddressInfo.AutoSize = true; - this.macAddressInfo.Location = new System.Drawing.Point(213, 442); - 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 = 37; - this.macAddressInfo.Text = "..."; - // - // LANMacAddressInfo - // - this.LANMacAddressInfo.AutoSize = true; - this.LANMacAddressInfo.Location = new System.Drawing.Point(213, 504); - 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 = 39; - this.LANMacAddressInfo.Text = "..."; - // - // label18 - // - this.label18.AutoSize = true; - this.label18.Location = new System.Drawing.Point(9, 504); - 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 = 38; - this.label18.Text = "LAN Mac Address:"; - // - // moboSerialInfo - // - this.moboSerialInfo.AutoSize = true; - this.moboSerialInfo.Location = new System.Drawing.Point(213, 202); - 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 = 41; - this.moboSerialInfo.Text = "..."; - // - // label19 - // - this.label19.AutoSize = true; - this.label19.Location = new System.Drawing.Point(9, 202); - 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 = 40; - this.label19.Text = "Motherboard Serial:"; - // - // label17 - // - this.label17.AutoSize = true; - this.label17.Location = new System.Drawing.Point(674, 318); - 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 = 42; - this.label17.Text = "WiFi MAC Address:"; - // - // wifiMacAddressTextbox - // - this.wifiMacAddressTextbox.Enabled = false; - this.wifiMacAddressTextbox.Location = new System.Drawing.Point(869, 312); - 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 = 43; - // - // lanMacAddressTextbox - // - this.lanMacAddressTextbox.Enabled = false; - this.lanMacAddressTextbox.Location = new System.Drawing.Point(869, 370); - 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 = 44; - // - // label20 - // - this.label20.AutoSize = true; - this.label20.Location = new System.Drawing.Point(674, 376); - 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 = 45; - this.label20.Text = "LAN Mac Address:"; - // // tabControl1 // this.tabControl1.Controls.Add(this.tabPage1); @@ -485,36 +145,7 @@ private void InitializeComponent() // // 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.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"; @@ -524,6 +155,13 @@ private void InitializeComponent() this.tabPage1.Text = "NOR Modifier"; this.tabPage1.UseVisualStyleBackColor = true; // + // ucNORModifier + // + this.ucNORModifier.Location = new System.Drawing.Point(3, 9); + this.ucNORModifier.Name = "ucNORModifier"; + this.ucNORModifier.Size = new System.Drawing.Size(1388, 561); + this.ucNORModifier.TabIndex = 0; + // // tabPage2 // this.tabPage2.Controls.Add(this.ucUART); @@ -572,14 +210,12 @@ private void InitializeComponent() this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.Name = "Form1"; this.Text = "PS5 NOR Modifier"; - 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.ResumeLayout(false); this.PerformLayout(); @@ -593,43 +229,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 Label label23; 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 0a2cc5f..41d078d 100644 --- a/PS5 NOR Modifier/Form1.cs +++ b/PS5 NOR Modifier/Form1.cs @@ -1,8 +1,7 @@ using System.Diagnostics; -using System.Globalization; using System.Runtime.InteropServices; -using System.Text; -using System.Text.RegularExpressions; + +using PS5_NOR_Modifier.UserControls.Events; namespace PS5_NOR_Modifier { @@ -12,6 +11,7 @@ public Form1() { InitializeComponent(); + LoadNorModifierControl(); LoadUARTControl(); } @@ -20,84 +20,19 @@ private void LoadUARTControl() ucUART.statusUpdateEvent += ucUART_statusUpdateEvent; } - private void ucUART_statusUpdateEvent(object? sender, UserControls.UART.Events.StatusUpdateEventArgs e) - { - toolStripStatusLabel1.Text = e.Text; - } - - private void throwError(string errmsg) - { - MessageBox.Show(errmsg, "An Error Has Occurred", MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - - /// - /// 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) + private void LoadNorModifierControl() { - 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; + ucNORModifier.statusUpdateEvent += ucNORModifier_statusUpdateEvent; } - #endregion - - private void Form1_Load(object sender, EventArgs e) + private void ucNORModifier_statusUpdateEvent(object? sender, StatusUpdateEventArgs e) { + toolStripStatusLabel1.Text = e.Text; } - // 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; - - string HexStringToString(string hexString) + private void ucUART_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; } /// @@ -132,17 +67,6 @@ private void OpenUrl(string url) } } - private void ResetAppFields() - { - fileLocationBox.Text = ""; - serialNumber.Text = "..."; - boardVariant.Text = "..."; - modelInfo.Text = "..."; - fileSizeInfo.Text = "..."; - serialNumberTextbox.Text = ""; - toolStripStatusLabel1.Text = "Status: Waiting for input"; - } - #region Donations /// @@ -163,462 +87,6 @@ private void pictureBox2_Click(object sender, EventArgs e) #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"); diff --git a/PS5 NOR Modifier/PS5 NOR Modifier.csproj.user b/PS5 NOR Modifier/PS5 NOR Modifier.csproj.user index 9c27a76..71720a7 100644 --- a/PS5 NOR Modifier/PS5 NOR Modifier.csproj.user +++ b/PS5 NOR Modifier/PS5 NOR Modifier.csproj.user @@ -7,6 +7,9 @@ Form + + UserControl + UserControl 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..21b30d7 --- /dev/null +++ b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.Designer.cs @@ -0,0 +1,448 @@ +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.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:"; + // + // fileLocationBox + // + 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.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; + // + // browseFileButton + // + 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.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; + // + // 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:"; + // + // 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.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(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(152, 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.Location = new System.Drawing.Point(1119, 444); + 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.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.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(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:"; + // + // NorModifierUserControl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 30F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + 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, 543); + 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; + } +} diff --git a/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs new file mode 100644 index 0000000..cfd6cde --- /dev/null +++ b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs @@ -0,0 +1,562 @@ +using System.Globalization; +using System.Text; +using System.Text.RegularExpressions; +using PS5_NOR_Modifier.UserControls.Events; + +namespace PS5_NOR_Modifier.UserControls.NorModifier +{ + public partial class NorModifierUserControl : UserControl + { + public event EventHandler? statusUpdateEvent; + + // 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; + + 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 = ""; + 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 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; + UpdateStatus("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); + } + } + } +} 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/Events/StatusUpdateEventArgs.cs b/PS5 NOR Modifier/UserControls/UART/Events/StatusUpdateEventArgs.cs deleted file mode 100644 index 2ca1c61..0000000 --- a/PS5 NOR Modifier/UserControls/UART/Events/StatusUpdateEventArgs.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; - - -namespace PS5_NOR_Modifier.UserControls.UART.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/UserControls/UART/UartUserControl.cs b/PS5 NOR Modifier/UserControls/UART/UartUserControl.cs index 6dfab4d..28e3022 100644 --- a/PS5 NOR Modifier/UserControls/UART/UartUserControl.cs +++ b/PS5 NOR Modifier/UserControls/UART/UartUserControl.cs @@ -1,7 +1,7 @@ using System; using System.IO.Ports; using System.Xml; -using PS5_NOR_Modifier.UserControls.UART.Events; +using PS5_NOR_Modifier.UserControls.Events; namespace PS5_NOR_Modifier.UserControls.UART { From b5e67de05da4967bb812b80cecb9e93039478360 Mon Sep 17 00:00:00 2001 From: Vitali Balyshau Date: Fri, 16 May 2025 17:14:26 +0200 Subject: [PATCH 03/13] Improvement: Made main window and internal UI components expandable, to improve user experience --- PS5 NOR Modifier/Form1.Designer.cs | 40 +++++++++++++------ PS5 NOR Modifier/Form1.cs | 4 +- PS5 NOR Modifier/Program.cs | 2 +- .../NorModifierUserControl.Designer.cs | 14 +++++++ .../UART/UartUserControl.Designer.cs | 10 ++++- 5 files changed, 53 insertions(+), 17 deletions(-) diff --git a/PS5 NOR Modifier/Form1.Designer.cs b/PS5 NOR Modifier/Form1.Designer.cs index e658337..14b472f 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,7 +28,7 @@ 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(); @@ -54,7 +54,7 @@ private void InitializeComponent() // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(14, 168); + this.label1.Location = new System.Drawing.Point(18, 195); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(1352, 90); this.label1.TabIndex = 0; @@ -83,8 +83,9 @@ private void InitializeComponent() // // 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(14, 918); + this.pictureBox2.Location = new System.Drawing.Point(24, 969); this.pictureBox2.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.pictureBox2.Name = "pictureBox2"; this.pictureBox2.Size = new System.Drawing.Size(77, 76); @@ -95,8 +96,9 @@ 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(111, 918); + this.label4.Location = new System.Drawing.Point(121, 969); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(1227, 60); this.label4.TabIndex = 5; @@ -108,7 +110,7 @@ private void InitializeComponent() 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, 1075); + this.statusStrip1.Location = new System.Drawing.Point(0, 1126); this.statusStrip1.Name = "statusStrip1"; this.statusStrip1.Padding = new System.Windows.Forms.Padding(2, 0, 17, 0); this.statusStrip1.Size = new System.Drawing.Size(1452, 39); @@ -123,9 +125,10 @@ private void InitializeComponent() // // 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(111, 990); + this.label15.Location = new System.Drawing.Point(111, 1041); this.label15.Name = "label15"; this.label15.Size = new System.Drawing.Size(666, 38); this.label15.TabIndex = 35; @@ -134,9 +137,12 @@ private void InitializeComponent() // // 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(21, 264); + 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; @@ -157,9 +163,12 @@ private void InitializeComponent() // // 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(1388, 561); + this.ucNORModifier.Size = new System.Drawing.Size(1386, 561); this.ucNORModifier.TabIndex = 0; // // tabPage2 @@ -176,9 +185,12 @@ private void InitializeComponent() // // ucUART // + 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(1391, 549); + this.ucUART.Size = new System.Drawing.Size(1391, 570); this.ucUART.TabIndex = 0; // // label23 @@ -192,12 +204,12 @@ private void InitializeComponent() this.label23.TabIndex = 47; this.label23.Text = "and UART stuff too... BwE can SUCK IT!"; // - // Form1 + // fMainForm // 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(1452, 1114); + this.ClientSize = new System.Drawing.Size(1452, 1165); this.Controls.Add(this.label23); this.Controls.Add(this.tabControl1); this.Controls.Add(this.label15); @@ -208,7 +220,9 @@ private void InitializeComponent() this.Controls.Add(this.pictureBox1); this.Controls.Add(this.label1); this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.Name = "Form1"; + this.MinimumSize = new System.Drawing.Size(1476, 1229); + this.Name = "fMainForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "PS5 NOR Modifier"; ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit(); diff --git a/PS5 NOR Modifier/Form1.cs b/PS5 NOR Modifier/Form1.cs index 41d078d..6a74aae 100644 --- a/PS5 NOR Modifier/Form1.cs +++ b/PS5 NOR Modifier/Form1.cs @@ -5,9 +5,9 @@ namespace PS5_NOR_Modifier { - public partial class Form1 : Form + public partial class fMainForm : Form { - public Form1() + public fMainForm() { InitializeComponent(); 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 index 21b30d7..ce5f747 100644 --- a/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.Designer.cs +++ b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.Designer.cs @@ -81,6 +81,8 @@ private void InitializeComponent() // // 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"; @@ -89,6 +91,8 @@ private void InitializeComponent() // // 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); @@ -98,6 +102,7 @@ private void InitializeComponent() // // 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"; @@ -109,6 +114,8 @@ private void InitializeComponent() // // 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); @@ -270,6 +277,8 @@ private void InitializeComponent() // // 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[] { @@ -302,6 +311,7 @@ private void InitializeComponent() // // 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, 444); this.convertToDigitalEditionButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.convertToDigitalEditionButton.Name = "convertToDigitalEditionButton"; @@ -313,6 +323,8 @@ private void InitializeComponent() // // 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"; @@ -321,6 +333,8 @@ private void InitializeComponent() // // 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[] { diff --git a/PS5 NOR Modifier/UserControls/UART/UartUserControl.Designer.cs b/PS5 NOR Modifier/UserControls/UART/UartUserControl.Designer.cs index fd0b947..79da535 100644 --- a/PS5 NOR Modifier/UserControls/UART/UartUserControl.Designer.cs +++ b/PS5 NOR Modifier/UserControls/UART/UartUserControl.Designer.cs @@ -50,8 +50,9 @@ private void InitializeComponent() // // 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(1042, 285); + this.label25.Location = new System.Drawing.Point(1037, 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); @@ -60,6 +61,7 @@ private void InitializeComponent() // // 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(1251, 233); this.btnSendCommand.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); this.btnSendCommand.Name = "btnSendCommand"; @@ -71,6 +73,7 @@ private void InitializeComponent() // // 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(1042, 175); this.txtCustomCommand.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); this.txtCustomCommand.Name = "txtCustomCommand"; @@ -80,6 +83,7 @@ private void InitializeComponent() // // 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(1042, 139); this.label24.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); @@ -123,6 +127,7 @@ private void InitializeComponent() // // button3 // + this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.button3.Location = new System.Drawing.Point(764, 491); this.button3.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); this.button3.Name = "button3"; @@ -134,6 +139,9 @@ private void InitializeComponent() // // txtUARTOutput // + this.txtUARTOutput.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.txtUARTOutput.Location = new System.Drawing.Point(121, 139); this.txtUARTOutput.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); this.txtUARTOutput.Multiline = true; From c3471095cfeea8b5d81f16aa811d377e204e008e Mon Sep 17 00:00:00 2001 From: Vitali Balyshau Date: Fri, 16 May 2025 17:16:04 +0200 Subject: [PATCH 04/13] Bugfix: NOR file name should be case insensitive --- .../UserControls/NorModifier/NorModifierUserControl.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs index cfd6cde..5813755 100644 --- a/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs +++ b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs @@ -66,7 +66,7 @@ private void ResetAppFields() modelInfo.Text = "..."; fileSizeInfo.Text = "..."; serialNumberTextbox.Text = ""; - UpdateStatus( "Status: Waiting for input"); + UpdateStatus("Status: Waiting for input"); } /// @@ -118,7 +118,7 @@ private void browseFileButton_Click(object sender, EventArgs e) } else { - if (!fileDialogBox.SafeFileName.EndsWith(".bin")) + 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."); } From 9f59183c43be4c1b78b70748a49cd1616513fbc2 Mon Sep 17 00:00:00 2001 From: Vitali Balyshau Date: Fri, 16 May 2025 17:18:10 +0200 Subject: [PATCH 05/13] Refactoring: improved NOR data collection. --- PS5 NOR Modifier/Form1.Designer.cs | 22 +- .../NorModifierUserControl.Designer.cs | 1 + .../NorModifier/NorModifierUserControl.cs | 338 +++++++----------- 3 files changed, 135 insertions(+), 226 deletions(-) diff --git a/PS5 NOR Modifier/Form1.Designer.cs b/PS5 NOR Modifier/Form1.Designer.cs index 14b472f..e3d0d70 100644 --- a/PS5 NOR Modifier/Form1.Designer.cs +++ b/PS5 NOR Modifier/Form1.Designer.cs @@ -85,7 +85,7 @@ private void InitializeComponent() // 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(24, 969); + this.pictureBox2.Location = new System.Drawing.Point(24, 1206); this.pictureBox2.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.pictureBox2.Name = "pictureBox2"; this.pictureBox2.Size = new System.Drawing.Size(77, 76); @@ -98,7 +98,7 @@ private void InitializeComponent() // 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(121, 969); + this.label4.Location = new System.Drawing.Point(121, 1206); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(1227, 60); this.label4.TabIndex = 5; @@ -110,10 +110,10 @@ private void InitializeComponent() 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, 1126); + this.statusStrip1.Location = new System.Drawing.Point(0, 1363); this.statusStrip1.Name = "statusStrip1"; this.statusStrip1.Padding = new System.Windows.Forms.Padding(2, 0, 17, 0); - this.statusStrip1.Size = new System.Drawing.Size(1452, 39); + this.statusStrip1.Size = new System.Drawing.Size(1877, 39); this.statusStrip1.TabIndex = 18; this.statusStrip1.Text = "statusStrip1"; // @@ -128,7 +128,7 @@ private void InitializeComponent() 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(111, 1041); + this.label15.Location = new System.Drawing.Point(111, 1278); this.label15.Name = "label15"; this.label15.Size = new System.Drawing.Size(666, 38); this.label15.TabIndex = 35; @@ -146,7 +146,7 @@ private void InitializeComponent() 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(1407, 622); + this.tabControl1.Size = new System.Drawing.Size(1832, 859); this.tabControl1.TabIndex = 46; // // tabPage1 @@ -156,7 +156,7 @@ private void InitializeComponent() this.tabPage1.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); this.tabPage1.Name = "tabPage1"; this.tabPage1.Padding = new System.Windows.Forms.Padding(5, 6, 5, 6); - this.tabPage1.Size = new System.Drawing.Size(1399, 579); + this.tabPage1.Size = new System.Drawing.Size(1824, 816); this.tabPage1.TabIndex = 0; this.tabPage1.Text = "NOR Modifier"; this.tabPage1.UseVisualStyleBackColor = true; @@ -168,7 +168,7 @@ private void InitializeComponent() | 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(1386, 561); + this.ucNORModifier.Size = new System.Drawing.Size(1811, 798); this.ucNORModifier.TabIndex = 0; // // tabPage2 @@ -178,7 +178,7 @@ private void InitializeComponent() this.tabPage2.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); this.tabPage2.Name = "tabPage2"; this.tabPage2.Padding = new System.Windows.Forms.Padding(5, 6, 5, 6); - this.tabPage2.Size = new System.Drawing.Size(1399, 579); + this.tabPage2.Size = new System.Drawing.Size(1824, 816); this.tabPage2.TabIndex = 1; this.tabPage2.Text = "UART Communication"; this.tabPage2.UseVisualStyleBackColor = true; @@ -190,7 +190,7 @@ private void InitializeComponent() | 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(1391, 570); + this.ucUART.Size = new System.Drawing.Size(1816, 807); this.ucUART.TabIndex = 0; // // label23 @@ -209,7 +209,7 @@ private void InitializeComponent() 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(1452, 1165); + this.ClientSize = new System.Drawing.Size(1877, 1402); this.Controls.Add(this.label23); this.Controls.Add(this.tabControl1); this.Controls.Add(this.label15); diff --git a/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.Designer.cs b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.Designer.cs index ce5f747..85a5f64 100644 --- a/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.Designer.cs +++ b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.Designer.cs @@ -421,6 +421,7 @@ private void InitializeComponent() this.Controls.Add(this.label12); this.Name = "NorModifierUserControl"; this.Size = new System.Drawing.Size(1382, 543); + this.Load += new System.EventHandler(this.NorModifierUserControl_Load); this.ResumeLayout(false); this.PerformLayout(); diff --git a/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs index 5813755..6f8c126 100644 --- a/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs +++ b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs @@ -1,3 +1,5 @@ +using System; +using System.Linq; using System.Globalization; using System.Text; using System.Text.RegularExpressions; @@ -9,21 +11,33 @@ public partial class NorModifierUserControl : UserControl { public event EventHandler? statusUpdateEvent; - // 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 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 readonly Dictionary _regions = new Dictionary() + { + { "00", "Japan" }, + { "01", "US, Canada, (North America)" }, + { "15", "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" }, + { "16", "Europe / Middle East / Africa" }, + { "18", "Singapore, Korea, Asia" }, + }; public NorModifierUserControl() { @@ -66,7 +80,7 @@ private void ResetAppFields() modelInfo.Text = "..."; fileSizeInfo.Text = "..."; serialNumberTextbox.Text = ""; - UpdateStatus("Status: Waiting for input"); + UpdateStatus( "Status: Waiting for input"); } /// @@ -104,6 +118,23 @@ private static byte[] ConvertHexStringToByteArray(string hexString) #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(); @@ -132,231 +163,103 @@ private void browseFileButton_Click(object sender, EventArgs e) fileLocationBox.Text = selectedPath; // Get file length and show in bytes and MB - long length = new System.IO.FileInfo(selectedPath).Length; + long length = new FileInfo(selectedPath).Length; fileSizeInfo.Text = length.ToString() + " bytes (" + length / 1024 / 1024 + "MB)"; - #region Extract PS5 Version - - try + using (BinaryReader reader = new BinaryReader(new FileStream(fileDialogBox.FileName, FileMode.Open))) { - 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; - } + //Reading Motherboard Serial + byte[]? rawBytes = ReadStreamBytes(reader, MB_SN_OFFSET, 16); + moboSerialInfo.Text = NO_VALUE; - if (offsetOneValue?.Contains("22020101") ?? false) - { - modelInfo.Text = "Disc Edition"; - } - else - { - if (offsetTwoValue?.Contains("22030101") ?? false) + if (rawBytes != null) { - modelInfo.Text = "Digital Edition"; + string mbSerialValue = BitConverter.ToString(rawBytes).Replace("-", null); + moboSerialInfo.Text = HexStringToString(mbSerialValue); } - 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 + //Reading serial number + rawBytes = ReadStreamBytes(reader, SN_OFFSET, 17); - #region Extract Board Serial Number + serialNumber.Text = NO_VALUE; + serialNumberTextbox.Text = NO_VALUE; - 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); + if (rawBytes != null) + { + string sn = BitConverter.ToString(rawBytes).Replace("-", null); + string readableSn = HexStringToString(sn); + serialNumber.Text = readableSn; + serialNumberTextbox.Text = readableSn; + } - } - else - { - serialNumber.Text = "Unknown"; - } + //Reading WIFI + rawBytes = ReadStreamBytes(reader, WIFI_OFFSET, 6); - #endregion + macAddressInfo.Text = NO_VALUE; + wifiMacAddressTextbox.Text = NO_VALUE; - #region Extract WiFi Mac Address + if (rawBytes != null) + { + string wifi = BitConverter.ToString(rawBytes); + macAddressInfo.Text = wifi; + wifiMacAddressTextbox.Text = wifi; + } - 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; - } + //Reading LAN + rawBytes = ReadStreamBytes(reader, LAN_MAC_OFFSET, 6); - if (WiFiMacValue != null) - { - macAddressInfo.Text = WiFiMacValue; - wifiMacAddressTextbox.Text = WiFiMacValue; - } - else - { - macAddressInfo.Text = "Unknown"; - wifiMacAddressTextbox.Text = ""; - } + LANMacAddressInfo.Text = NO_VALUE; + lanMacAddressTextbox.Text = NO_VALUE; - #endregion + if (rawBytes != null) + { + string lan = BitConverter.ToString(rawBytes); + LANMacAddressInfo.Text = lan; + lanMacAddressTextbox.Text = lan; + } - #region Extract LAN Mac Address + //Region + rawBytes = ReadStreamBytes(reader, REGION_OFFSET, 2); - 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; - } + boardVariant.Text = NO_VALUE; - if (LANMacValue != null) - { - LANMacAddressInfo.Text = LANMacValue; - lanMacAddressTextbox.Text = LANMacValue; - } - else - { - LANMacAddressInfo.Text = "Unknown"; - lanMacAddressTextbox.Text = ""; - } + if (rawBytes != null) + { + string regionHex = BitConverter.ToString(rawBytes).Replace("-", null); + string regionReadable = HexStringToString(regionHex); - #endregion + if (_regions.Keys.Contains(regionReadable)) + { + boardVariant.Text = String.Format("{0} - {1}", regionReadable, _regions[regionReadable]); + } + } - #region Extract Board Variant + //Reading Model + rawBytes = ReadStreamBytes(reader, MODEL_OFFSET, 1); - 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 (rawBytes != null) + { + string model = BitConverter.ToString(rawBytes).Replace("-", null); + string modelText = "Unknown"; + if (model == "01") + { + modelText = "Slim"; + } + else if (model == "02") + { + modelText = "Disk Edition"; + } + else if (model == "03") + { + modelText = "Digital Edition"; + } - if (variantValue != null) - { - boardVariant.Text = HexStringToString(variantValue); - } - else - { - boardVariant.Text = "Unknown"; + modelInfo.Text = modelText; + } } - - 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 } } } @@ -558,5 +461,10 @@ private void convertToDigitalEditionButton_Click(object sender, EventArgs e) 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(); + } } } From ffac97b0b09074cdfda3184f19bb588c948c9c5c Mon Sep 17 00:00:00 2001 From: Vitali Balyshau Date: Fri, 16 May 2025 17:20:08 +0200 Subject: [PATCH 06/13] Improvement: 'Boadrd Variant' and 'PS5 Model' automatically selected when NOR data is loaded --- .../NorModifierUserControl.Designer.cs | 104 ++++++++++++++++++ .../NorModifier/NorModifierUserControl.cs | 30 ++++- 2 files changed, 131 insertions(+), 3 deletions(-) diff --git a/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.Designer.cs b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.Designer.cs index 85a5f64..303a7a5 100644 --- a/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.Designer.cs +++ b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.Designer.cs @@ -282,6 +282,7 @@ private void InitializeComponent() 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); @@ -341,24 +342,127 @@ private void InitializeComponent() "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); diff --git a/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs index 6f8c126..a929897 100644 --- a/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs +++ b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs @@ -19,12 +19,12 @@ public partial class NorModifierUserControl : UserControl 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 readonly Dictionary _regions = new Dictionary() { { "00", "Japan" }, { "01", "US, Canada, (North America)" }, - { "15", "US, Canada, (North America)" }, { "02", "Australia / New Zealand, (Oceania)" }, { "03", "United Kingdom / Ireland" }, { "04", "Europe / Middle East / Africa" }, @@ -35,6 +35,7 @@ public partial class NorModifierUserControl : UserControl { "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" }, }; @@ -80,6 +81,11 @@ private void ResetAppFields() modelInfo.Text = "..."; fileSizeInfo.Text = "..."; serialNumberTextbox.Text = ""; + serialNumberTextbox.Enabled = false; + boardVariantSelectionBox.Enabled = false; + boardVariantSelectionBox.SelectedIndex = -1; + boardModelSelectionBox.Enabled = false; + boardModelSelectionBox.SelectedIndex = -1; UpdateStatus( "Status: Waiting for input"); } @@ -193,6 +199,18 @@ private void browseFileButton_Click(object sender, EventArgs e) 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 skuText = HexStringToString(skuBytes).Split(' ')[0]; + boardVariantSelectionBox.SelectedIndex = boardVariantSelectionBox.FindStringExact(skuText); + } + //Reading WIFI rawBytes = ReadStreamBytes(reader, WIFI_OFFSET, 6); @@ -242,7 +260,7 @@ private void browseFileButton_Click(object sender, EventArgs e) { string model = BitConverter.ToString(rawBytes).Replace("-", null); - string modelText = "Unknown"; + string modelText = NO_VALUE; if (model == "01") { @@ -250,7 +268,7 @@ private void browseFileButton_Click(object sender, EventArgs e) } else if (model == "02") { - modelText = "Disk Edition"; + modelText = "Disc Edition"; } else if (model == "03") { @@ -258,7 +276,13 @@ private void browseFileButton_Click(object sender, EventArgs e) } modelInfo.Text = modelText; + + boardModelSelectionBox.SelectedIndex = boardModelSelectionBox.FindStringExact(modelText); } + + serialNumberTextbox.Enabled = true; + boardVariantSelectionBox.Enabled = true; + boardModelSelectionBox.Enabled = true; } } } From 517ec7b5af3c43aef9229a2c5cc2061f66f1b9ed Mon Sep 17 00:00:00 2001 From: Vitali Balyshau Date: Fri, 16 May 2025 17:21:27 +0200 Subject: [PATCH 07/13] Feature: Extended NOR file info with Current Firmware Version, SKU Data and MD5 file hash --- PS5 NOR Modifier/Form1.Designer.cs | 2 +- .../NorModifierUserControl.Designer.cs | 90 ++++++++++++++++++- .../NorModifier/NorModifierUserControl.cs | 34 ++++++- 3 files changed, 120 insertions(+), 6 deletions(-) diff --git a/PS5 NOR Modifier/Form1.Designer.cs b/PS5 NOR Modifier/Form1.Designer.cs index e3d0d70..c5e2c4b 100644 --- a/PS5 NOR Modifier/Form1.Designer.cs +++ b/PS5 NOR Modifier/Form1.Designer.cs @@ -220,7 +220,7 @@ private void InitializeComponent() this.Controls.Add(this.pictureBox1); this.Controls.Add(this.label1); this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.MinimumSize = new System.Drawing.Size(1476, 1229); + this.MinimumSize = new System.Drawing.Size(1901, 1466); this.Name = "fMainForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "PS5 NOR Modifier"; diff --git a/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.Designer.cs b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.Designer.cs index 303a7a5..6ea2d01 100644 --- a/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.Designer.cs +++ b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.Designer.cs @@ -58,6 +58,12 @@ private void InitializeComponent() 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 @@ -78,6 +84,7 @@ private void InitializeComponent() this.label20.Size = new System.Drawing.Size(185, 30); this.label20.TabIndex = 75; this.label20.Text = "LAN Mac Address:"; + this.label20.Visible = false; // // fileLocationBox // @@ -99,6 +106,7 @@ private void InitializeComponent() this.lanMacAddressTextbox.Name = "lanMacAddressTextbox"; this.lanMacAddressTextbox.Size = new System.Drawing.Size(508, 35); this.lanMacAddressTextbox.TabIndex = 74; + this.lanMacAddressTextbox.Visible = false; // // browseFileButton // @@ -122,6 +130,7 @@ private void InitializeComponent() this.wifiMacAddressTextbox.Name = "wifiMacAddressTextbox"; this.wifiMacAddressTextbox.Size = new System.Drawing.Size(508, 35); this.wifiMacAddressTextbox.TabIndex = 73; + this.wifiMacAddressTextbox.Visible = false; // // label6 // @@ -142,6 +151,7 @@ private void InitializeComponent() this.label17.Size = new System.Drawing.Size(190, 30); this.label17.TabIndex = 72; this.label17.Text = "WiFi MAC Address:"; + this.label17.Visible = false; // // label7 // @@ -297,9 +307,9 @@ private void InitializeComponent() 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(152, 30); + this.label11.Size = new System.Drawing.Size(164, 30); this.label11.TabIndex = 58; - this.label11.Text = "Modify Values"; + this.label11.Text = "Modify Values: "; // // label14 // @@ -313,7 +323,7 @@ private void InitializeComponent() // 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, 444); + 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); @@ -489,10 +499,76 @@ private void InitializeComponent() 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); @@ -524,7 +600,7 @@ private void InitializeComponent() this.Controls.Add(this.label13); this.Controls.Add(this.label12); this.Name = "NorModifierUserControl"; - this.Size = new System.Drawing.Size(1382, 543); + this.Size = new System.Drawing.Size(1382, 842); this.Load += new System.EventHandler(this.NorModifierUserControl_Load); this.ResumeLayout(false); this.PerformLayout(); @@ -563,5 +639,11 @@ private void InitializeComponent() 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 index a929897..5843abc 100644 --- a/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs +++ b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs @@ -4,6 +4,7 @@ using System.Text; using System.Text.RegularExpressions; using PS5_NOR_Modifier.UserControls.Events; +using System.Security.Cryptography; namespace PS5_NOR_Modifier.UserControls.NorModifier { @@ -20,6 +21,7 @@ public partial class NorModifierUserControl : UserControl 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() { @@ -81,6 +83,8 @@ private void ResetAppFields() modelInfo.Text = "..."; fileSizeInfo.Text = "..."; serialNumberTextbox.Text = ""; + lblSkuValue.Text = "..."; + lblFWVersionValue.Text = "..."; serialNumberTextbox.Enabled = false; boardVariantSelectionBox.Enabled = false; boardVariantSelectionBox.SelectedIndex = -1; @@ -207,10 +211,22 @@ private void browseFileButton_Click(object sender, EventArgs e) if (rawBytes != null) { string skuBytes = BitConverter.ToString(rawBytes).Replace("-", null); - string skuText = HexStringToString(skuBytes).Split(' ')[0]; + 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); @@ -284,6 +300,22 @@ private void browseFileButton_Click(object sender, EventArgs e) boardVariantSelectionBox.Enabled = true; boardModelSelectionBox.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; } } } From c628a32a9dd88d2f8a5633c5b270652872a7b5c7 Mon Sep 17 00:00:00 2001 From: Vitali Balyshau Date: Fri, 16 May 2025 17:24:48 +0200 Subject: [PATCH 08/13] Feature: Added GridView for 10 latest errors to improve user experience and make a connection with https://uart.codes/ --- PS5 NOR Modifier/Common/Helpers/Browser.cs | 40 +++++ PS5 NOR Modifier/Form1.Designer.cs | 18 +- PS5 NOR Modifier/Form1.cs | 42 +---- .../UserControls/UART/Data/ErrorCodeInfo.cs | 29 +++ .../UART/UartUserControl.Designer.cs | 168 ++++++++++++++---- .../UserControls/UART/UartUserControl.cs | 126 +++++++++---- .../UserControls/UART/UartUserControl.resx | 12 ++ 7 files changed, 320 insertions(+), 115 deletions(-) create mode 100644 PS5 NOR Modifier/Common/Helpers/Browser.cs create mode 100644 PS5 NOR Modifier/UserControls/UART/Data/ErrorCodeInfo.cs 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/Form1.Designer.cs b/PS5 NOR Modifier/Form1.Designer.cs index c5e2c4b..45b07a5 100644 --- a/PS5 NOR Modifier/Form1.Designer.cs +++ b/PS5 NOR Modifier/Form1.Designer.cs @@ -85,7 +85,7 @@ private void InitializeComponent() // 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(24, 1206); + 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(77, 76); @@ -98,7 +98,7 @@ private void InitializeComponent() // 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(121, 1206); + this.label4.Location = new System.Drawing.Point(121, 1276); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(1227, 60); this.label4.TabIndex = 5; @@ -110,10 +110,10 @@ private void InitializeComponent() 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, 1363); + this.statusStrip1.Location = new System.Drawing.Point(0, 1433); this.statusStrip1.Name = "statusStrip1"; this.statusStrip1.Padding = new System.Windows.Forms.Padding(2, 0, 17, 0); - this.statusStrip1.Size = new System.Drawing.Size(1877, 39); + this.statusStrip1.Size = new System.Drawing.Size(1933, 39); this.statusStrip1.TabIndex = 18; this.statusStrip1.Text = "statusStrip1"; // @@ -128,7 +128,7 @@ private void InitializeComponent() 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(111, 1278); + this.label15.Location = new System.Drawing.Point(111, 1348); this.label15.Name = "label15"; this.label15.Size = new System.Drawing.Size(666, 38); this.label15.TabIndex = 35; @@ -146,7 +146,7 @@ private void InitializeComponent() 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(1832, 859); + this.tabControl1.Size = new System.Drawing.Size(1888, 929); this.tabControl1.TabIndex = 46; // // tabPage1 @@ -156,7 +156,7 @@ private void InitializeComponent() this.tabPage1.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); this.tabPage1.Name = "tabPage1"; this.tabPage1.Padding = new System.Windows.Forms.Padding(5, 6, 5, 6); - this.tabPage1.Size = new System.Drawing.Size(1824, 816); + this.tabPage1.Size = new System.Drawing.Size(1880, 886); this.tabPage1.TabIndex = 0; this.tabPage1.Text = "NOR Modifier"; this.tabPage1.UseVisualStyleBackColor = true; @@ -168,7 +168,7 @@ private void InitializeComponent() | 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(1811, 798); + this.ucNORModifier.Size = new System.Drawing.Size(1867, 868); this.ucNORModifier.TabIndex = 0; // // tabPage2 @@ -209,7 +209,7 @@ private void InitializeComponent() 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(1877, 1402); + this.ClientSize = new System.Drawing.Size(1933, 1472); this.Controls.Add(this.label23); this.Controls.Add(this.tabControl1); this.Controls.Add(this.label15); diff --git a/PS5 NOR Modifier/Form1.cs b/PS5 NOR Modifier/Form1.cs index 6a74aae..0677f24 100644 --- a/PS5 NOR Modifier/Form1.cs +++ b/PS5 NOR Modifier/Form1.cs @@ -1,6 +1,4 @@ -using System.Diagnostics; -using System.Runtime.InteropServices; - +using PS5_NOR_Modifier.Common.Helpers; using PS5_NOR_Modifier.UserControls.Events; namespace PS5_NOR_Modifier @@ -35,38 +33,6 @@ private void ucUART_statusUpdateEvent(object? sender, StatusUpdateEventArgs e) 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) - { - 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; - } - } - } - #region Donations /// @@ -76,12 +42,12 @@ private void OpenUrl(string url) /// 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"); } @@ -89,7 +55,7 @@ private void pictureBox2_Click(object sender, EventArgs e) private void label15_Click(object sender, EventArgs e) { - OpenUrl("https://www.consolefix.shop"); + Browser.OpenUrl("https://www.consolefix.shop"); } } } 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/UartUserControl.Designer.cs b/PS5 NOR Modifier/UserControls/UART/UartUserControl.Designer.cs index 79da535..cf0b224 100644 --- a/PS5 NOR Modifier/UserControls/UART/UartUserControl.Designer.cs +++ b/PS5 NOR Modifier/UserControls/UART/UartUserControl.Designer.cs @@ -29,6 +29,7 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UartUserControl)); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = 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(); @@ -46,27 +47,34 @@ private void InitializeComponent() 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.lblLastErrorCodes = new System.Windows.Forms.Label(); + 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(); + ((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(1037, 285); + 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 = 34; + 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(1251, 233); + 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 = 33; + this.btnSendCommand.TabIndex = 17; this.btnSendCommand.Text = "Send"; this.btnSendCommand.UseVisualStyleBackColor = true; this.btnSendCommand.Click += new System.EventHandler(this.btnSendCommand_Click); @@ -74,42 +82,42 @@ private void InitializeComponent() // 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(1042, 175); + 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(335, 35); - this.txtCustomCommand.TabIndex = 32; + 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(1042, 139); + 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 = 31; + this.label24.TabIndex = 15; this.label24.Text = "Send custom command via UART:"; // // chkUseOffline // this.chkUseOffline.AutoSize = true; - this.chkUseOffline.Location = new System.Drawing.Point(805, 77); + this.chkUseOffline.Location = new System.Drawing.Point(879, 75); 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 = 30; + this.chkUseOffline.TabIndex = 9; this.chkUseOffline.Text = "Use offline database"; this.chkUseOffline.UseVisualStyleBackColor = true; // // btnDownloadDatabase // - this.btnDownloadDatabase.Location = new System.Drawing.Point(527, 71); + this.btnDownloadDatabase.Location = new System.Drawing.Point(601, 71); this.btnDownloadDatabase.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); this.btnDownloadDatabase.Name = "btnDownloadDatabase"; - this.btnDownloadDatabase.Size = new System.Drawing.Size(267, 46); - this.btnDownloadDatabase.TabIndex = 29; + 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); @@ -120,35 +128,34 @@ private void InitializeComponent() 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 = 28; + this.btnRefreshPorts.TabIndex = 4; this.btnRefreshPorts.Text = "Refresh Ports"; this.btnRefreshPorts.UseVisualStyleBackColor = true; this.btnRefreshPorts.Click += new System.EventHandler(this.btnRefreshPorts_Click); // // button3 // - this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.button3.Location = new System.Drawing.Point(764, 491); + this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button3.Location = new System.Drawing.Point(1238, 377); this.button3.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(267, 46); - this.button3.TabIndex = 27; + this.button3.TabIndex = 12; this.button3.Text = "Clear Output Window"; this.button3.UseVisualStyleBackColor = true; this.button3.Click += new System.EventHandler(this.button3_Click); // // txtUARTOutput // - this.txtUARTOutput.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) + 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(907, 336); - this.txtUARTOutput.TabIndex = 26; + this.txtUARTOutput.Size = new System.Drawing.Size(1385, 226); + this.txtUARTOutput.TabIndex = 11; // // label22 // @@ -157,16 +164,16 @@ private void InitializeComponent() 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 = 25; + this.label22.TabIndex = 10; this.label22.Text = "Output:"; // // btnClearErrorCodes // - this.btnClearErrorCodes.Location = new System.Drawing.Point(315, 71); + 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 = 24; + this.btnClearErrorCodes.TabIndex = 7; this.btnClearErrorCodes.Text = "Clear Error Codes"; this.btnClearErrorCodes.UseVisualStyleBackColor = true; this.btnClearErrorCodes.Click += new System.EventHandler(this.btnClearErrorCodes_Click); @@ -178,7 +185,7 @@ private void InitializeComponent() 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 = 23; + this.label21.TabIndex = 5; this.label21.Text = "Options:"; // // button1 @@ -186,9 +193,9 @@ private void InitializeComponent() this.button1.Location = new System.Drawing.Point(121, 71); this.button1.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(183, 46); - this.button1.TabIndex = 22; - this.button1.Text = "Get Error Codes"; + this.button1.Size = new System.Drawing.Size(258, 46); + this.button1.TabIndex = 6; + this.button1.Text = "Get 10 Last Error Codes"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // @@ -199,7 +206,7 @@ private void InitializeComponent() 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 = 21; + this.comboComPorts.TabIndex = 1; // // btnDisconnectCom // @@ -207,7 +214,7 @@ private void InitializeComponent() 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 = 20; + this.btnDisconnectCom.TabIndex = 3; this.btnDisconnectCom.Text = "Disconnect"; this.btnDisconnectCom.UseVisualStyleBackColor = true; this.btnDisconnectCom.Click += new System.EventHandler(this.btnDisconnectCom_Click); @@ -218,7 +225,7 @@ private void InitializeComponent() 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 = 19; + this.btnConnectCom.TabIndex = 2; this.btnConnectCom.Text = "Connect"; this.btnConnectCom.UseVisualStyleBackColor = true; this.btnConnectCom.Click += new System.EventHandler(this.btnConnectCom_Click); @@ -230,13 +237,99 @@ private void InitializeComponent() 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 = 18; + this.label3.TabIndex = 0; this.label3.Text = "Com Port:"; // + // gvErrorCodes + // + this.gvErrorCodes.AllowUserToAddRows = false; + this.gvErrorCodes.AllowUserToDeleteRows = false; + this.gvErrorCodes.AllowUserToResizeRows = false; + dataGridViewCellStyle1.BackColor = System.Drawing.Color.AliceBlue; + this.gvErrorCodes.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1; + 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); + // + // 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:"; + // + // 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; + // // 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); @@ -255,8 +348,9 @@ private void InitializeComponent() this.Controls.Add(this.btnConnectCom); this.Controls.Add(this.label3); this.Name = "UartUserControl"; - this.Size = new System.Drawing.Size(1387, 547); + 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(); @@ -281,5 +375,11 @@ private void InitializeComponent() 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 index 28e3022..32f3515 100644 --- a/PS5 NOR Modifier/UserControls/UART/UartUserControl.cs +++ b/PS5 NOR Modifier/UserControls/UART/UartUserControl.cs @@ -1,12 +1,16 @@ 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 { + private const string WIKI_LINK = "https://uart.codes/"; + public event EventHandler? statusUpdateEvent; private SerialPort _UARTSerial; @@ -203,20 +207,13 @@ async Task ParseErrorsAsync(string ErrorCode) string description = errorCodeNode.SelectSingleNode("Description")?.InnerText ?? ""; // Output the results - results = "Error code: " - + errorCode - + Environment.NewLine - + "Description: " - + description; + results = description; } } } else { - results = "Error code: " - + ErrorCode - + Environment.NewLine - + "An error occurred while fetching a result for this error. Please try again!"; + results = "An error occurred while fetching a result for this error. Please try again!"; } } catch (Exception ex) @@ -316,6 +313,11 @@ private void btnRefreshPorts_Click(object sender, EventArgs e) /// 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 = ""; @@ -323,41 +325,63 @@ private async void button1_Click(object sender, EventArgs e) { try { - - List UARTLines = new(); - - for (var i = 0; i <= 10; i++) + for (var i = 0; i < 10; i++) { var command = $"errlog {i}"; - var checksum = CalculateChecksum(command); + + string checksum = CalculateChecksum(command); + _UARTSerial.WriteLine(checksum); + + string uartCodeDetails = String.Empty; + do { - var line = _UARTSerial.ReadLine(); - if (!string.Equals($"{command}:{checksum:X2}", line, StringComparison.InvariantCultureIgnoreCase)) + string uartResponse = _UARTSerial.ReadLine(); + + if (String.Compare(uartResponse, checksum, true) != 0) { - UARTLines.Add(line); + uartCodeDetails = uartResponse; } } while (_UARTSerial.BytesToRead != 0); - foreach (var l in UARTLines) + if (!String.IsNullOrEmpty(uartCodeDetails)) { - var split = l.Split(' '); - if (!split.Any()) continue; - switch (split[0]) + string[] split = uartCodeDetails.Split(' '); + + if (split.Length > 2) { - 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; + 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 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; + } } } } @@ -393,7 +417,6 @@ private void btnClearErrorCodes_Click(object sender, EventArgs e) { try { - List UARTLines = new(); var command = "errlog clear"; @@ -424,6 +447,10 @@ private void btnClearErrorCodes_Click(object sender, EventArgs e) 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; } @@ -563,5 +590,36 @@ private void UartUserControl_Load(object sender, EventArgs e) btnDisconnectCom.Enabled = false; } } + + //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); + } + } + } } } diff --git a/PS5 NOR Modifier/UserControls/UART/UartUserControl.resx b/PS5 NOR Modifier/UserControls/UART/UartUserControl.resx index f9d8cbb..9f1be7e 100644 --- a/PS5 NOR Modifier/UserControls/UART/UartUserControl.resx +++ b/PS5 NOR Modifier/UserControls/UART/UartUserControl.resx @@ -66,4 +66,16 @@ 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 From c0cadeee515776cc31e69e634d28ea43fa85adf6 Mon Sep 17 00:00:00 2001 From: Vitali Balyshau Date: Fri, 16 May 2025 17:25:41 +0200 Subject: [PATCH 09/13] Improvement: Impelemnted transition between connected and disconnected UART state with reflection on UI --- .../UART/UartUserControl.Designer.cs | 84 ++++++++++--------- .../UserControls/UART/UartUserControl.cs | 42 +++++++--- 2 files changed, 73 insertions(+), 53 deletions(-) diff --git a/PS5 NOR Modifier/UserControls/UART/UartUserControl.Designer.cs b/PS5 NOR Modifier/UserControls/UART/UartUserControl.Designer.cs index cf0b224..ee228cf 100644 --- a/PS5 NOR Modifier/UserControls/UART/UartUserControl.Designer.cs +++ b/PS5 NOR Modifier/UserControls/UART/UartUserControl.Designer.cs @@ -29,7 +29,7 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UartUserControl)); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); + 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(); @@ -37,22 +37,22 @@ private void InitializeComponent() 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.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.button1 = new System.Windows.Forms.Button(); + 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.lblLastErrorCodes = new System.Windows.Forms.Label(); 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(); // @@ -102,8 +102,9 @@ private void InitializeComponent() // // 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(879, 75); + 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); @@ -113,7 +114,8 @@ private void InitializeComponent() // // btnDownloadDatabase // - this.btnDownloadDatabase.Location = new System.Drawing.Point(601, 71); + 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); @@ -133,17 +135,17 @@ private void InitializeComponent() this.btnRefreshPorts.UseVisualStyleBackColor = true; this.btnRefreshPorts.Click += new System.EventHandler(this.btnRefreshPorts_Click); // - // button3 + // btnClearOutput // - this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.button3.Location = new System.Drawing.Point(1238, 377); - this.button3.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); - this.button3.Name = "button3"; - this.button3.Size = new System.Drawing.Size(267, 46); - this.button3.TabIndex = 12; - this.button3.Text = "Clear Output Window"; - this.button3.UseVisualStyleBackColor = true; - this.button3.Click += new System.EventHandler(this.button3_Click); + 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 // @@ -188,16 +190,16 @@ private void InitializeComponent() this.label21.TabIndex = 5; this.label21.Text = "Options:"; // - // button1 + // btnGet10LastErrors // - this.button1.Location = new System.Drawing.Point(121, 71); - this.button1.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(258, 46); - this.button1.TabIndex = 6; - this.button1.Text = "Get 10 Last Error Codes"; - this.button1.UseVisualStyleBackColor = true; - this.button1.Click += new System.EventHandler(this.button1_Click); + 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 // @@ -245,8 +247,8 @@ private void InitializeComponent() this.gvErrorCodes.AllowUserToAddRows = false; this.gvErrorCodes.AllowUserToDeleteRows = false; this.gvErrorCodes.AllowUserToResizeRows = false; - dataGridViewCellStyle1.BackColor = System.Drawing.Color.AliceBlue; - this.gvErrorCodes.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1; + 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))); @@ -271,16 +273,6 @@ private void InitializeComponent() this.gvErrorCodes.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.gvErrorCodes_CellContentClick); this.gvErrorCodes.RowPostPaint += new System.Windows.Forms.DataGridViewRowPostPaintEventHandler(this.gvErrorCodes_RowPostPaint); // - // 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:"; - // // cErrorCode // this.cErrorCode.DataPropertyName = "ErrorCode"; @@ -324,6 +316,16 @@ private void InitializeComponent() 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); @@ -337,12 +339,12 @@ private void InitializeComponent() this.Controls.Add(this.chkUseOffline); this.Controls.Add(this.btnDownloadDatabase); this.Controls.Add(this.btnRefreshPorts); - this.Controls.Add(this.button3); + 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.button1); + this.Controls.Add(this.btnGet10LastErrors); this.Controls.Add(this.comboComPorts); this.Controls.Add(this.btnDisconnectCom); this.Controls.Add(this.btnConnectCom); @@ -365,12 +367,12 @@ private void InitializeComponent() private CheckBox chkUseOffline; private Button btnDownloadDatabase; private Button btnRefreshPorts; - private Button button3; + private Button btnClearOutput; private TextBox txtUARTOutput; private Label label22; private Button btnClearErrorCodes; private Label label21; - private Button button1; + private Button btnGet10LastErrors; private ComboBox comboComPorts; private Button btnDisconnectCom; private Button btnConnectCom; diff --git a/PS5 NOR Modifier/UserControls/UART/UartUserControl.cs b/PS5 NOR Modifier/UserControls/UART/UartUserControl.cs index 32f3515..c883481 100644 --- a/PS5 NOR Modifier/UserControls/UART/UartUserControl.cs +++ b/PS5 NOR Modifier/UserControls/UART/UartUserControl.cs @@ -230,7 +230,6 @@ async Task ParseErrorsAsync(string ErrorCode) private void btnConnectCom_Click(object sender, EventArgs e) { // Let's try and connect to the UART reader - btnConnectCom.Enabled = false; if (comboComPorts.Text != String.Empty) { @@ -244,15 +243,16 @@ private void btnConnectCom_Click(object sender, EventArgs e) _UARTSerial.RtsEnable = true; // Open the COM port _UARTSerial.Open(); - btnDisconnectCom.Enabled = true; + + 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); - btnConnectCom.Enabled = true; - btnDisconnectCom.Enabled = false; + + SetConnectedUIState(false); UpdateStatus("Could not connect to UART. Please try again!"); } @@ -260,8 +260,8 @@ private void btnConnectCom_Click(object sender, EventArgs e) 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; + + SetConnectedUIState(false); UpdateStatus("Could not connect to UART. Please try again!"); } @@ -283,8 +283,8 @@ private void btnDisconnectCom_Click(object sender, EventArgs e) if (_UARTSerial.IsOpen == true) { _UARTSerial.Close(); - btnConnectCom.Enabled = true; - btnDisconnectCom.Enabled = false; + + SetConnectedUIState(false); UpdateStatus("Disconnected from UART..."); } @@ -304,8 +304,6 @@ private void btnRefreshPorts_Click(object sender, EventArgs e) comboComPorts.Items.Clear(); comboComPorts.Items.AddRange(ports); comboComPorts.SelectedIndex = 0; - btnConnectCom.Enabled = true; - btnDisconnectCom.Enabled = false; } /// @@ -577,6 +575,8 @@ private void txtCustomCommand_KeyPress(object sender, KeyPressEventArgs e) 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(); @@ -586,8 +586,6 @@ private void UartUserControl_Load(object sender, EventArgs e) { comboComPorts.Items.AddRange(ports); comboComPorts.SelectedIndex = 0; - btnConnectCom.Enabled = true; - btnDisconnectCom.Enabled = false; } } @@ -621,5 +619,25 @@ private void gvErrorCodes_CellContentClick(object sender, DataGridViewCellEventA } } } + + 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; + } } } From d7e9865097f5a7a24ffd8e34ca5c0b602f612ea7 Mon Sep 17 00:00:00 2001 From: Vitali Balyshau Date: Fri, 16 May 2025 17:26:57 +0200 Subject: [PATCH 10/13] Bugfix: Button 'Save New BIOS Information' should be available only when NOR file data is loaded --- .../UserControls/NorModifier/NorModifierUserControl.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs index 5843abc..976e64b 100644 --- a/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs +++ b/PS5 NOR Modifier/UserControls/NorModifier/NorModifierUserControl.cs @@ -90,6 +90,7 @@ private void ResetAppFields() boardVariantSelectionBox.SelectedIndex = -1; boardModelSelectionBox.Enabled = false; boardModelSelectionBox.SelectedIndex = -1; + convertToDigitalEditionButton.Enabled = false; UpdateStatus( "Status: Waiting for input"); } @@ -299,6 +300,7 @@ private void browseFileButton_Click(object sender, EventArgs e) serialNumberTextbox.Enabled = true; boardVariantSelectionBox.Enabled = true; boardModelSelectionBox.Enabled = true; + convertToDigitalEditionButton.Enabled = true; } //Calculate MD5 File hash From d0a43ff50a32ea082a4b0519db092ef18da751e5 Mon Sep 17 00:00:00 2001 From: Vitali Balyshau Date: Fri, 16 May 2025 17:28:21 +0200 Subject: [PATCH 11/13] Bugfix: Fixed unhandled exception when pressing 'Refresh' button and there are no available COM ports --- .../UserControls/UART/UartUserControl.cs | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/PS5 NOR Modifier/UserControls/UART/UartUserControl.cs b/PS5 NOR Modifier/UserControls/UART/UartUserControl.cs index c883481..e9f6353 100644 --- a/PS5 NOR Modifier/UserControls/UART/UartUserControl.cs +++ b/PS5 NOR Modifier/UserControls/UART/UartUserControl.cs @@ -277,6 +277,8 @@ private void UpdateStatus(string newStatus) private void btnDisconnectCom_Click(object sender, EventArgs e) { + SetConnectedUIState(false); + // Let's close the COM port try { @@ -284,8 +286,6 @@ private void btnDisconnectCom_Click(object sender, EventArgs e) { _UARTSerial.Close(); - SetConnectedUIState(false); - UpdateStatus("Disconnected from UART..."); } } @@ -301,9 +301,13 @@ 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; + + if (ports.Length > 0) + { + comboComPorts.Items.Clear(); + comboComPorts.Items.AddRange(ports); + comboComPorts.SelectedIndex = 0; + } } /// @@ -339,7 +343,7 @@ private async void button1_Click(object sender, EventArgs e) if (String.Compare(uartResponse, checksum, true) != 0) { - uartCodeDetails = uartResponse; + uartCodeDetails = uartResponse; } } while (_UARTSerial.BytesToRead != 0); @@ -579,9 +583,9 @@ private void UartUserControl_Load(object sender, EventArgs e) // 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); @@ -626,7 +630,7 @@ private void SetConnectedUIState(bool connected) btnConnectCom.Enabled = !connected; btnDisconnectCom.Enabled = connected; btnRefreshPorts.Enabled = !connected; - btnGet10LastErrors.Enabled= connected; + btnGet10LastErrors.Enabled = connected; btnClearErrorCodes.Enabled = connected; txtUARTOutput.Enabled = connected; btnClearOutput.Enabled = connected; From 07dd650820f0e8b88894d42b7a7468cb29406527 Mon Sep 17 00:00:00 2001 From: Vitali-Balyshau <97793862+Vitali-Balyshau@users.noreply.github.com> Date: Fri, 16 May 2025 17:32:49 +0200 Subject: [PATCH 12/13] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 From b3dd9ea2e19d67a04a127b2234d279667fc3cd86 Mon Sep 17 00:00:00 2001 From: Vitali Balyshau Date: Fri, 16 May 2025 19:49:15 +0200 Subject: [PATCH 13/13] Refactoring: Replaces manual XML parsing with inbuild .NET XML data serialization/deserialization mechanism --- .../Common/Helpers/XmlSerializationHelper.cs | 51 ++++++++ .../UserControls/UART/Data/ErrorCode.cs | 27 +++++ .../UserControls/UART/Data/ErrorCodesList.cs | 17 +++ .../UserControls/UART/UartUserControl.cs | 110 +++++------------- 4 files changed, 124 insertions(+), 81 deletions(-) create mode 100644 PS5 NOR Modifier/Common/Helpers/XmlSerializationHelper.cs create mode 100644 PS5 NOR Modifier/UserControls/UART/Data/ErrorCode.cs create mode 100644 PS5 NOR Modifier/UserControls/UART/Data/ErrorCodesList.cs 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/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/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.cs b/PS5 NOR Modifier/UserControls/UART/UartUserControl.cs index e9f6353..906965d 100644 --- a/PS5 NOR Modifier/UserControls/UART/UartUserControl.cs +++ b/PS5 NOR Modifier/UserControls/UART/UartUserControl.cs @@ -9,15 +9,15 @@ 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; - // 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"; - public UartUserControl() { InitializeComponent(); @@ -94,137 +94,85 @@ static string CalculateChecksum(string str) string ParseErrorsOffline(string errorCode) { - string results = ""; + string result = String.Empty; try { - // Check if the XML file exists - if (File.Exists(LOCAL_DATABASE_FILE)) - { - // Load the XML file - XmlDocument xmlDoc = new XmlDocument(); - xmlDoc.Load(LOCAL_DATABASE_FILE); - - // Get the root node - XmlNode? root = xmlDoc.DocumentElement; - if (root is null) return results; + ErrorCodesList errorCodes = XmlSerializationHelper.DeserilazeXmlFromFile(LOCAL_DATABASE_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 errorCodeValue = errorCodeNode.SelectSingleNode("ErrorCode")?.InnerText ?? ""; - string description = errorCodeNode.SelectSingleNode("Description")?.InnerText ?? ""; + if (errorCode != null) + { + ErrorCode code = errorCodes.Items.Where(x => x.ErrorCodeNumber == errorCode).FirstOrDefault(); - // 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 + if (code != null) { - results = "Error: Invalid XML database file. Please reconfigure the application, redownload the offline database, or uncheck the option to use the offline database."; + result = code.Description; } } - else - { - results = "Error: Local XML file not found."; - } } catch (Exception ex) { - results = "Error: " + ex.Message; + result = "Error: " + ex.Message; } - return results; + 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 /// - /// + /// /// - async Task ParseErrorsAsync(string ErrorCode) + 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) { - return ParseErrorsOffline(ErrorCode); + 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; - - string results = ""; + 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); } - // Load the XML response into an XmlDocument - XmlDocument xmlDoc = new XmlDocument(); - xmlDoc.LoadXml(response); + ErrorCodesList errorCodes = XmlSerializationHelper.DeserilazeXmlFromString(response); - // Get the root node - XmlNode? root = xmlDoc.DocumentElement; - if (root is null) + if (errorCodes != null) { - throw new Exception("Error reading the file"); - } + ErrorCode code = errorCodes.Items.Where(x => x.ErrorCodeNumber == errorCode).FirstOrDefault(); - // Check if the root node is - if (root.Name == "errorCodes") - { - // Loop through each errorCode node - foreach (XmlNode errorCodeNode in root.ChildNodes) + if (code != null) { - // 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 = description; - } + result = code.Description; } } - else - { - results = "An error occurred while fetching a result for this error. Please try again!"; - } } catch (Exception ex) { - results = "Error code: " - + ErrorCode + result = "Error code: " + + errorCode + Environment.NewLine + ex.Message; } - return results; } + + return result; } private void btnConnectCom_Click(object sender, EventArgs e) @@ -360,7 +308,7 @@ private async void button1_Click(object sender, EventArgs e) 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 + // 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();