diff --git a/WindowsFormsApp8/Form1.Designer.cs b/WindowsFormsApp8/Form1.Designer.cs index 9ad9fb1..d26d808 100644 --- a/WindowsFormsApp8/Form1.Designer.cs +++ b/WindowsFormsApp8/Form1.Designer.cs @@ -32,6 +32,7 @@ private void InitializeComponent() this.richTextBox1 = new System.Windows.Forms.RichTextBox(); this.richTextBox2 = new System.Windows.Forms.RichTextBox(); this.richTextBox3 = new System.Windows.Forms.RichTextBox(); + this.button2 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 @@ -68,11 +69,22 @@ private void InitializeComponent() this.richTextBox3.TabIndex = 5; this.richTextBox3.Text = "Filecontent"; // + // button2 + // + this.button2.Location = new System.Drawing.Point(109, 12); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(75, 28); + this.button2.TabIndex = 6; + this.button2.Text = "Save"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.button2); this.Controls.Add(this.richTextBox3); this.Controls.Add(this.richTextBox2); this.Controls.Add(this.richTextBox1); @@ -89,6 +101,7 @@ private void InitializeComponent() private System.Windows.Forms.RichTextBox richTextBox1; private System.Windows.Forms.RichTextBox richTextBox2; private System.Windows.Forms.RichTextBox richTextBox3; + private System.Windows.Forms.Button button2; } } diff --git a/WindowsFormsApp8/Form1.cs b/WindowsFormsApp8/Form1.cs index 4836271..c3bad47 100644 --- a/WindowsFormsApp8/Form1.cs +++ b/WindowsFormsApp8/Form1.cs @@ -28,7 +28,7 @@ private void button1_Click(object sender, EventArgs e) using (OpenFileDialog openFileDialog = new OpenFileDialog()) { - openFileDialog.InitialDirectory = "c:\\"; + openFileDialog.InitialDirectory = "C:\\Users\\Felix\\Downloads\\txtstuff"; openFileDialog.Filter = "XCP files (*.xcp)|*.xcp"; openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = true; @@ -123,11 +123,23 @@ void DecodeFile(byte[] fileContent) { } byte[] EncodeFile() { + byte checksum = 0; List xcpFile = new List(); //Add the Header (VCP.XDATA�5f4d4353) xcpFile.AddRange(new byte[] { 0x56, 0x43, 0x50, 0x2E, 0x58, 0x44, 0x41, 0x54, 0x41, 0x00, 0x35, 0x66, 0x34, 0x64, 0x34, 0x33, 0x35, 0x33 }); + + foreach (byte b in new byte[] { 0x56, 0x43, 0x50, 0x2E, 0x58, 0x44, 0x41, 0x54, 0x41, 0x00 }) { + checksum-=b; + } + checksum -= 0x5f; + checksum -= 0x4d; + checksum -= 0x43; + checksum -= 0x53; //Add the Folderlength + the Schwarzenegger - char[] Folderlength = (richTextBox2.Text.Length+1).ToString("X4").ToCharArray(); + char[] Folderlength = (richTextBox2.Text.Length+1).ToString("X2").ToCharArray(); + foreach (byte b in BitConverter.GetBytes(richTextBox2.Text.Length + 1)) { + checksum -= b; + } foreach (char c in Folderlength) { xcpFile.Add(Convert.ToByte(c)); } @@ -135,19 +147,26 @@ byte[] EncodeFile() { char[] Folder =richTextBox2.Text.ToCharArray(); foreach (char c in Folder) { xcpFile.Add(Convert.ToByte(c)); + checksum -= Convert.ToByte(c); } xcpFile.Add(0x00); - //Add the Folderlength + the Schwarzenegger - char[] Filenamelength = (richTextBox1.Text.Length + 1).ToString("X4").ToCharArray(); + + //Add the Filenamelength + the Schwarzenegger + char[] Filenamelength = (richTextBox1.Text.Length + 1).ToString("X2").ToCharArray(); foreach (char c in Filenamelength) { xcpFile.Add(Convert.ToByte(c)); } - //Add the Foldername and the 0x00 Terminator + foreach (byte b in BitConverter.GetBytes(richTextBox1.Text.Length + 1)) + { + checksum -= b; + } + //Add the Filename and the 0x00 Terminator char[] Filename = richTextBox1.Text.ToCharArray(); foreach (char c in Filename) { xcpFile.Add(Convert.ToByte(c)); + checksum -= Convert.ToByte(c); } xcpFile.Add(0x00); //add 8 Bytes of 00000031 (but the num is a String!) @@ -156,40 +175,41 @@ byte[] EncodeFile() { { xcpFile.Add(Convert.ToByte(c)); } + checksum -= 0x31; // add the foldername again, but it has to be 16 bytes and if smaller padded with 0xff - bool addedFolder = false; - for (int i = 0; i == 16; i++) + + for (int i = 0; i < 16; i++) { - if (addedFolder == false) + if (i >= Folder.Length) { - foreach (char c in Folder) - { - xcpFile.Add(Convert.ToByte(c)); - i++; - } - addedFolder = true; + xcpFile.Add(0xff); + checksum -= 0xff; } - xcpFile.Add(0xff); + else { + xcpFile.Add(Convert.ToByte(Folder[i])); + checksum -= Convert.ToByte(Folder[i]); + } + } - - bool addedFilename = false; - for (int i = 0; i == 16; i++) + //same for filename + for (int i = 0; i < 16; i++) { - if (addedFilename == false) + if (i >= Filename.Length) { - foreach (char c in Filename) - { - xcpFile.Add(Convert.ToByte(c)); - i++; - } - addedFilename = true; + xcpFile.Add(0xff); + checksum -= 0xff; + } + else { + xcpFile.Add(Convert.ToByte(Filename[i])); + checksum -= Convert.ToByte(Filename[i]); } - xcpFile.Add(0xff); + } + //nextup is the length of the Datablock, so i just make it now and check it like that List DataBlock = new List(); UInt32 length = (UInt32) richTextBox3.Text.Length + 3; - DataBlock.AddRange(BitConverter.GetBytes(length).Reverse()); + DataBlock.AddRange(BitConverter.GetBytes(length)); //9 Bytes of 0 DataBlock.AddRange(new Byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }); //now we have to add the actual text @@ -201,21 +221,30 @@ byte[] EncodeFile() { DataBlock.Add(0x00); DataBlock.Add(0xff); //and a padding that makes the length value from before a multiple of 4 - for (; 0 == DataBlock.Count%4;) { + for (; 0 != DataBlock.Count%4;) { DataBlock.Add(0x00); } //datablock done //now just add the length to the file UInt32 Length = (UInt32)DataBlock.Count; - xcpFile.AddRange(BitConverter.GetBytes(Length)); + foreach (byte b in BitConverter.GetBytes(Length)) { + checksum -= b; + } + xcpFile.AddRange(BitConverter.GetBytes(Length).Reverse()); //add the Vartype padded in 0xff List vartype = new List(); vartype.AddRange(new byte[] {(byte)'G',(byte)'U',(byte)'Q'}); - for (; vartype.Count == 13;) { + for (; vartype.Count < 13;) { vartype.Add(0xff); } + foreach (byte b in vartype) { + checksum -= b; + } xcpFile.AddRange(vartype); - char[] lenn = Length.ToString("x16").ToCharArray(); + char[] lenn = Length.ToString("x8").ToCharArray(); + foreach (byte b in BitConverter.GetBytes(Length)) { + checksum -= b; + } List len = new List(); foreach (char c in lenn) { @@ -225,38 +254,14 @@ byte[] EncodeFile() { xcpFile.AddRange(len); //add the DataBlock xcpFile.AddRange(DataBlock); - //calculate the checksum - int checksum = 0; - foreach (byte b in xcpFile) { + foreach (byte b in DataBlock) { checksum -= b; } - List HexAsciis = new List(); - UInt64 longnum = 0x5f4d4353; - byte[]longnumber = BitConverter.GetBytes(longnum); - foreach (byte b in longnumber) { - HexAsciis.Add(b); - } - //we need to add the Foldernamelength - foreach (char c in Folderlength) - { - HexAsciis.Add(Convert.ToByte(c)); - } - foreach (char c in Filenamelength) - { - HexAsciis.Add(Convert.ToByte(c)); - } - HexAsciis.AddRange(new byte[] { 30, 30, 30, 30, 30, 30, 33, 31 }); - HexAsciis.AddRange(len); - // now add every element of HexAsciis to the Checksum - foreach (byte b in HexAsciis) { - checksum += b; - } - foreach (byte b in HexAsciis) - { - checksum -= Int32.Parse(b.ToString()); + char[] chekksum = checksum.ToString("x2").ToCharArray(); + foreach (char c in chekksum) { + xcpFile.Add((byte)c); } - xcpFile.Add(BitConverter.GetBytes(checksum)[3]); return xcpFile.ToArray(); diff --git a/WindowsFormsApp8/bin/Debug/WindowsFormsApp8.exe b/WindowsFormsApp8/bin/Debug/WindowsFormsApp8.exe index ecd76ce..0185040 100644 Binary files a/WindowsFormsApp8/bin/Debug/WindowsFormsApp8.exe and b/WindowsFormsApp8/bin/Debug/WindowsFormsApp8.exe differ diff --git a/WindowsFormsApp8/bin/Debug/WindowsFormsApp8.pdb b/WindowsFormsApp8/bin/Debug/WindowsFormsApp8.pdb index e93edc9..18e627f 100644 Binary files a/WindowsFormsApp8/bin/Debug/WindowsFormsApp8.pdb and b/WindowsFormsApp8/bin/Debug/WindowsFormsApp8.pdb differ diff --git a/WindowsFormsApp8/bin/Debug/XCP-Viewer.exe b/WindowsFormsApp8/bin/Debug/XCP-Viewer.exe new file mode 100644 index 0000000..ecd76ce Binary files /dev/null and b/WindowsFormsApp8/bin/Debug/XCP-Viewer.exe differ diff --git a/WindowsFormsApp8/obj/Debug/DesignTimeResolveAssemblyReferences.cache b/WindowsFormsApp8/obj/Debug/DesignTimeResolveAssemblyReferences.cache index 5a7ad52..5b58f9b 100644 Binary files a/WindowsFormsApp8/obj/Debug/DesignTimeResolveAssemblyReferences.cache and b/WindowsFormsApp8/obj/Debug/DesignTimeResolveAssemblyReferences.cache differ