Writing a hex editor?

Discussion in 'Technical Discussion' started by Aerosol, Aug 9, 2012.

  1. Aerosol

    Aerosol

    FML and FU2 Moderator
    10,624
    85
    28
    Not where I want to be.
    Sonic (?): Coming summer of 2055...?
    What do I need to know to be able to load a file and manipulate it in hex using C++?
     
  2. EXOGGEDDEN

    EXOGGEDDEN

    orgasmic Member
    411
    0
    16
    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 =/
     
  3. TmEE

    TmEE

    Master of OPL3-SA2/3 Tech Member
    1,726
    0
    16
    Estonia, Rapla City
    T-04YBSC-A !
    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.
     
  4. Travelsonic

    Travelsonic

    Member
    816
    14
    18
    Wouldn't it be easier to load the file into an array, especially if it is a larger file?
     
  5. EXOGGEDDEN

    EXOGGEDDEN

    orgasmic Member
    411
    0
    16
    That's really what I meant, I just wasn't as explicit about it ;p
     
  6. Travelsonic

    Travelsonic

    Member
    816
    14
    18
    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]
     
  7. EXOGGEDDEN

    EXOGGEDDEN

    orgasmic Member
    411
    0
    16
    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.
     
  8. Travelsonic

    Travelsonic

    Member
    816
    14
    18
    I guess I'm just confused about doing the conversion.