Discussion in 'Technical Discussion' started by Aerosol, Aug 9, 2012.
What do I need to know to be able to load a file and manipulate it in hex using C++?
Although I've never written a hex editor before, I would guess that at a very basic level you should just load the file into memory in binary format, then use itoa() or something to convert the bytes to text that you can display (then edit and convert back to bytes and overwrite the file.) Though on the interface, you're on your own ;p I would suggest you use java or C# or something though, as windows programming in C++ can be a bitch sometimes =/
you make a byte buffer, you load a file as binary into it, and then you show chunks of that buffer as hexadecimal values. when saving you just write that buffer as binary into the file again.
Wouldn't it be easier to load the file into an array, especially if it is a larger file?
That's really what I meant, I just wasn't as explicit about it ;p
Considering that in using ifstream to load a file in binary mode you can work with individual bytes in the form of integers or characters, is conversion using itoa really necessary if you're working with a file that has ASCII text? ASCII would still be read/displayed properly[ASCII being a byte per character]
I wouldn't say that conversion using itoa is absolutely necessary, since it all depends on what you're going to be using. The reason why I mentioned itoa is because I figured that since the bytes will ultimately be displayed on a hex editor, I would assume that the hex editor will be a GUI-based program. To my experience, usually if you want to display numerical data in those you'd have to convert the data to a string or something first, though I would guess this also depends on the API you're going to be using (I just haven't come across one yet that just allowed me to directly display numerical data without having to convert it first.) As for the ASCII text, I'm not really sure what you're trying to say. If I understand you correctly, all hex editors I've seen usually show the bytes' values and then their ASCII representations on the right (which is quite simple to figure out how to do.) The bytes' values are not the same thing as what ASCII character they represent.
I guess I'm just confused about doing the conversion.
Separate names with a comma.