Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to edit a binary file's hex value using C#

Tags:

c#

hex

binary

edit

So here's my issue. I have a binary file that I want to edit. I can use a hex editor to edit it of course, but I need to make a program to edit this particular file. Say that I know a certain hex I want to edit, I know it's address etc. Let's say that it's a 16-bit binary, and the address is 00000000, it's on row 04 and it has a value of 02. How could I create a program that would change the value of that hex, and only that hex with the click of a button?

I've found resources that talk about similar things, but I can't for the life of me find help with the exact issue.

Any help would be appreciated, and please, don't just tell me the answer if there is one but try and explain a bit.

like image 309
JC Leyba Avatar asked Jul 10 '10 03:07

JC Leyba


1 Answers

Well the first thing would probably be to understand the conversions. Hex to decimal probably isn't as important (unless of course you need to change the value from a decimal first, but that's a simple conversion formula), but hex to binary will be important seeing as each hex character (0-9,A-F) corresponds to a specific binary output.

After understanding that stuff, the next step is to figure out exactly what you are searching for, make the proper conversion, and replace that exact string. I would recommend (if the buffer wouldn't be too large) to take the entire hex dump and replace whatever you're searching for in there to avoid overwriting a duplicate binary sequence.

Hope that helps!

Regards,
Dennis M.

like image 174
RageD Avatar answered Oct 14 '22 15:10

RageD