Can someone help me out writing hex string to file hex address from textbox?

This is my current code:

private void button1_Click(object sender, EventArgs e)
        BinaryWriter wr = new BinaryWriter(File.OpenWrite(listBox1.SelectedItem.ToString()));

        for (int i = 0x83C410; i <= 0x83C417; i++)



But it doesn't work after i click button nothing happens to file, even it doesn't show any error which is kinda strange.

Recommended Answers

All 4 Replies

C# isn't my language, but why are you trying to count from 8.635.408 to 8.635.415? Why not just count from 0 to 7...

Not sure how many bytes go into an integer in C#, or how you actually feed a hexadecimal value into it, but I'm gonna guess that you issue is related to that part of your program.

If you're actually trying to write to an offset address inside your file, I would think you had to use something like; or give the offset address as an argument to wr.write(offset, data);.
As I said in the beginning; C# is not my language, so the specific syntax is most probably not correct. But just counting from one integer to another is not enough to skip to that part of the file.

Another thing is that you're using a BinaryWriter, but you are trying to write a string to the file. This would probably cause some problems, as wr.Write most probably wants a byte array to properly handle the binary write.

So my conclusion is that you're missing some vital part(s) of your code.
1. You need to convert textBox1.Text to a byte array.
2. Then; to the specific part of the file. (Or read the whole file into a buffer, then edit the buffer, then write the buffer back to the file. But this would only be practical on small files though).
3. Write the byte array to the specified file.
4. Close the file.

But this is only based on my experience with other languages, C# might have some magic methods that I don't know about.

Hope I'm not overcomplicating things... again ;)

I managed to get writing working now having problem reading it always take me off first char that needs to be readed idk why :S

Please post some code?

Well if your code is anything like what is above, I am not sure why you are indexing. You simply are pulling the TextBox text everytime. So no matter how many times you loop through it will be the same thing.

As for yoru first character, post code please, would make this a lot easier

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.