v1.0.6 - Credits, RWD-2-BIN checksums

This commit is contained in:
Bouletmarc 2022-04-24 05:49:42 -04:00 committed by GitHub
parent 372257a5ae
commit 183e90b5d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 306 additions and 26 deletions

View File

@ -55,7 +55,14 @@ static class Class_RWD
return k1;
}
public static UInt16 checksum_by_sum(byte[] fw, uint start, uint end)
public static UInt32 ToUInt32BE(byte[] FourBytes)
{
int k0 = BitConverter.ToInt32(FourBytes, 0);
int k1 = BitConverter.ToInt32(BitConverter.GetBytes(k0).Reverse().ToArray(), 0);
return (UInt32) k1;
}
/*public static UInt16 checksum_by_sum(byte[] fw, uint start, uint end)
{
int s = 0;
uint valuescount = (end - start) / 2;
@ -81,6 +88,21 @@ static class Class_RWD
if (s < 0) s += 0xFFFF;
}
return (UInt16) s;
}*/
private static UInt32 Get_rwd_checksum(byte[] data, uint start, uint end)
{
uint s = 0;
uint valuescount = (end - start);
for (int i = 0; i < valuescount; i++)
{
byte ThisValuee = data[start + i];
s += ThisValuee;
if (s > 0xFFFFFFFF) s -= 0xFFFFFFFF;
}
s = ToUInt32BE(BitConverter.GetBytes(s));
return (UInt32)s;
}
//######################################################################################################
@ -93,8 +115,8 @@ static class Class_RWD
//Load .rwd file for obtaining 'encryption' method and then encrypt the .bin using the same method.
LoadRWD(f_nameFW, true, false);
//Copy Start file bytes from the selected rwd file
byte[] dataEncrypted = new byte[RWD_encrypted_StartFile.Length + data.Length];
//Copy Start file bytes from the selected rwd file, then add the dat aand checksum bytes
byte[] dataEncrypted = new byte[RWD_encrypted_StartFile.Length + data.Length + 4];
for (int i = 0; i < RWD_encrypted_StartFile.Length; i++) dataEncrypted[i] = RWD_encrypted_StartFile[i];
//Encrypt .bin data bytes to .rwd format
@ -105,9 +127,21 @@ static class Class_RWD
}
//Fix Checksums
//TODO HERE #######################################
//UInt16 thisnn = Class_RWD.checksum_by_sum(dataEncrypted, (uint)RWD_encrypted_StartFile.Length, (uint)dataEncrypted.Length);
//Console.WriteLine(thisnn.ToString("X4"));
UInt32 ChecksumValue = Get_rwd_checksum(dataEncrypted, 0, (uint)dataEncrypted.Length);
byte[] ChecksumBytes = BitConverter.GetBytes(ChecksumValue);
if (ChecksumBytes.Length == 4)
{
for (int i = 0; i < ChecksumBytes.Length; i++)
{
dataEncrypted[((dataEncrypted.Length - 1) - 4) + i] = ChecksumBytes[i];
}
GForm_Main_0.method_1("Checksum bytes fixed!");
}
else
{
GForm_Main_0.method_1("Checksum is not 4bytes long!");
}
//Console.WriteLine(Get_rwd_checksum(dataEncrypted, 0, (uint)dataEncrypted.Length).ToString("X8"));
//Save Encrypted rwd firmware
string ThisPath = Path.GetDirectoryName(f_name) + @"\" + Path.GetFileNameWithoutExtension(f_name) + ".rwd";

View File

@ -76,6 +76,9 @@
<Compile Include="GClass4.cs" />
<Compile Include="GEnum0.cs" />
<Compile Include="GEnum1.cs" />
<Compile Include="GForm_Credits.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="GForm_FWChkSum.cs">
<SubType>Form</SubType>
</Compile>
@ -100,6 +103,9 @@
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="frmOBD2Scan.resx" />
<EmbeddedResource Include="GForm_Credits.resx">
<DependentUpon>GForm_Credits.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="GForm_FWChkSum.resx">
<DependentUpon>GForm_FWChkSum.cs</DependentUpon>
</EmbeddedResource>

115
GForm_Credits.cs Normal file
View File

@ -0,0 +1,115 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
using DarkUI.Controls;
using DarkUI.Forms;
public class GForm_Credits : DarkForm
{
public GForm_Credits()
{
this.InitializeComponent();
}
private void method_0(object sender, EventArgs e)
{
base.Close();
}
private void method_1(object sender, EventArgs e)
{
}
private void method_2(object sender, EventArgs e)
{
base.DialogResult = DialogResult.Abort;
base.Close();
}
protected virtual void Dispose(bool disposing)
{
if (disposing && this.icontainer_0 != null)
{
this.icontainer_0.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.darkButton_0 = new DarkUI.Controls.DarkButton();
this.label1 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.SuspendLayout();
//
// darkButton_0
//
this.darkButton_0.Checked = false;
this.darkButton_0.DialogResult = System.Windows.Forms.DialogResult.OK;
this.darkButton_0.Location = new System.Drawing.Point(86, 139);
this.darkButton_0.Name = "darkButton_0";
this.darkButton_0.Size = new System.Drawing.Size(75, 23);
this.darkButton_0.TabIndex = 4;
this.darkButton_0.Text = "Accept";
this.darkButton_0.Click += new System.EventHandler(this.method_0);
//
// label1
//
this.label1.AutoSize = true;
this.label1.ForeColor = System.Drawing.SystemColors.ControlLight;
this.label1.Location = new System.Drawing.Point(59, 41);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(110, 65);
this.label1.TabIndex = 6;
this.label1.Text = "BMDevs (Bouletmarc)\r\nNii-Saan (Romraider)\r\nGreg Hogan\r\nKalisto2002\r\nDmitry";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label3.ForeColor = System.Drawing.SystemColors.ControlLight;
this.label3.Location = new System.Drawing.Point(6, 10);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(231, 20);
this.label3.TabIndex = 10;
this.label3.Text = "Credits from Honda community:";
this.label3.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// openFileDialog1
//
this.openFileDialog1.Title = "Select File";
//
// GForm_Credits
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(244, 172);
this.ControlBox = false;
this.Controls.Add(this.label3);
this.Controls.Add(this.label1);
this.Controls.Add(this.darkButton_0);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "GForm_Credits";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Credits";
this.Load += new System.EventHandler(this.method_1);
this.ResumeLayout(false);
this.PerformLayout();
}
[CompilerGenerated]
private IContainer icontainer_0;
private DarkButton darkButton_0;
private Label label1;
private Label label3;
private OpenFileDialog openFileDialog1;
}

123
GForm_Credits.resx Normal file
View File

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -1304,7 +1304,6 @@ public class GForm_Main : DarkForm
0x00 //0x00 -> Set later
};
arraySend1[2] = (byte) ((Addrr << 4) | Addrr);
//if (memory_address >= Math.Pow(2 ^ Addrr * 8)) throw new Exception(string.Format("invalid memory_address: 0x{0}", memory_address.ToString("X4")));
if (memory_address >= Math.Pow(2, Addrr * 8)) throw new Exception(string.Format("invalid memory_address: 0x{0}", memory_address.ToString("X4")));
for (int i = 0; i < Addrr; i++)
{
@ -1332,10 +1331,6 @@ public class GForm_Main : DarkForm
{
cnt += 1;
byte[] chunk = Class_RWD.Slice(Class_RWD._firmware_encrypted, i, i + chunk_size);
//console.log(`${ cnt}: 0x${ i.toString(16)} -0x${ (i + chunk_size).toString(16)}`);
//await this.client.transfer_data(cnt & 0xFF, chunk);
// bitwise | converts float to int
//postMessage({ command: 'flash-progress', result: (i / this.rwd.firmware.data.byteLength * 100) | 0 })
byte bsct = (byte) (cnt & 0xFF);
arraySend1 = new byte[]
@ -1561,6 +1556,7 @@ public class GForm_Main : DarkForm
this.darkButton_DownloadROM = new DarkUI.Controls.DarkButton();
this.darkButton_0 = new DarkUI.Controls.DarkButton();
this.darkGroupBox_0 = new DarkUI.Controls.DarkGroupBox();
this.darkButton5 = new DarkUI.Controls.DarkButton();
this.darkButton_FlashFW = new DarkUI.Controls.DarkButton();
this.darkButton_Unlock01 = new DarkUI.Controls.DarkButton();
this.darkButton_Unlock41 = new DarkUI.Controls.DarkButton();
@ -1586,7 +1582,6 @@ public class GForm_Main : DarkForm
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.DarkgroupBox1 = new DarkUI.Controls.DarkGroupBox();
this.darkButton4 = new DarkUI.Controls.DarkButton();
this.darkButton5 = new DarkUI.Controls.DarkButton();
this.darkGroupBox_0.SuspendLayout();
this.DarkgroupBox1.SuspendLayout();
this.SuspendLayout();
@ -1664,6 +1659,16 @@ public class GForm_Main : DarkForm
this.darkGroupBox_0.TabStop = false;
this.darkGroupBox_0.Text = "J2534 Controls";
//
// darkButton5
//
this.darkButton5.Checked = false;
this.darkButton5.Location = new System.Drawing.Point(6, 280);
this.darkButton5.Name = "darkButton5";
this.darkButton5.Size = new System.Drawing.Size(192, 23);
this.darkButton5.TabIndex = 69;
this.darkButton5.Text = "Open OBD2 Scan Tools";
this.darkButton5.Click += new System.EventHandler(this.darkButton5_Click);
//
// darkButton_FlashFW
//
this.darkButton_FlashFW.Checked = false;
@ -1822,13 +1827,14 @@ public class GForm_Main : DarkForm
// darkLabel_4
//
this.darkLabel_4.AutoSize = true;
this.darkLabel_4.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F);
this.darkLabel_4.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.darkLabel_4.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(220)))), ((int)(((byte)(220)))));
this.darkLabel_4.Location = new System.Drawing.Point(404, 509);
this.darkLabel_4.Location = new System.Drawing.Point(596, 509);
this.darkLabel_4.Name = "darkLabel_4";
this.darkLabel_4.Size = new System.Drawing.Size(272, 25);
this.darkLabel_4.Size = new System.Drawing.Size(80, 25);
this.darkLabel_4.TabIndex = 61;
this.darkLabel_4.Text = "Copyright 2022 @ BMDevs";
this.darkLabel_4.Text = "Credits";
this.darkLabel_4.Click += new System.EventHandler(this.darkLabel_4_Click);
//
// darkLabel_5
//
@ -1911,16 +1917,6 @@ public class GForm_Main : DarkForm
this.darkButton4.Text = "Fix Checksums";
this.darkButton4.Click += new System.EventHandler(this.darkButton4_Click);
//
// darkButton5
//
this.darkButton5.Checked = false;
this.darkButton5.Location = new System.Drawing.Point(6, 280);
this.darkButton5.Name = "darkButton5";
this.darkButton5.Size = new System.Drawing.Size(192, 23);
this.darkButton5.TabIndex = 69;
this.darkButton5.Text = "Open OBD2 Scan Tools";
this.darkButton5.Click += new System.EventHandler(this.darkButton5_Click);
//
// GForm_Main
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -2355,4 +2351,10 @@ public class GForm_Main : DarkForm
frmOBD2Scan frmOBD2Scan_0 = new frmOBD2Scan();
frmOBD2Scan_0.Show();
}
private void darkLabel_4_Click(object sender, EventArgs e)
{
GForm_Credits GForm_Credits_0 = new GForm_Credits();
GForm_Credits_0.ShowDialog();
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.