Home > database >  Binary file's hex value won't change using C#
Binary file's hex value won't change using C#

Time:09-25

I have an issue where my C# code wasn't able to change a hex value in the 13th position. See the screenshot from HxD Hex editor for further detail

This is C# my code:

private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string fileName = openFileDialog.FileName;
                textBox1.Text = fileName;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string fileName = textBox1.Text;
            using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite))
            {
                stream.Position = 13;
                stream.WriteByte(0x00);
            }
        }

CodePudding user response:

you have stream.Position = 13; (13 is in decimal) Your picture is pointing to 13 hex (19 in decimal) so you'll need stream.Position = 0x13

  • Related