Sonic and Sega Retro Message Board: Writing a hex editor? - Sonic and Sega Retro Message Board

Jump to content

Hey there, Guest!  (Log In · Register) Help
Page 1 of 1
    Locked
    Locked Forum

Writing a hex editor? What do I need to know?

#1 User is offline Aerosol 

Posted 08 August 2012 - 11:04 PM

  • FML and FU2
  • Posts: 7627
  • Joined: 27-April 08
  • Gender:Male
  • Location:Not where I want to be.
  • Project: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 User is offline EXOGGEDDEN 

Posted 09 August 2012 - 05:12 AM

  • orgasmic
  • Posts: 410
  • Joined: 24-July 03
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 User is offline TmEE 

Posted 09 August 2012 - 05:40 AM

  • Hot music ~~~~
  • Posts: 1716
  • Joined: 06-January 08
  • Gender:Male
  • Location:Estonia, Rapla City
  • Project:Big Neighbor Disturber, Laser Raster Scan Projector
  • Wiki edits:11
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 User is offline Travelsonic 

Posted 14 August 2012 - 10:16 AM

  • Posts: 661
  • Joined: 01-March 05

View PostEXOGGEDDEN, on 09 August 2012 - 05:12 AM, said:

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.)


Wouldn't it be easier to load the file into an array, especially if it is a larger file?
This post has been edited by Travelsonic: 14 August 2012 - 10:18 AM

#5 User is offline EXOGGEDDEN 

Posted 15 August 2012 - 07:52 AM

  • orgasmic
  • Posts: 410
  • Joined: 24-July 03

View PostTravelsonic, on 14 August 2012 - 10:16 AM, said:

View PostEXOGGEDDEN, on 09 August 2012 - 05:12 AM, said:

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.)


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

#6 User is offline Travelsonic 

Posted 15 August 2012 - 09:36 AM

  • Posts: 661
  • Joined: 01-March 05

View PostEXOGGEDDEN, on 15 August 2012 - 07:52 AM, said:

View PostTravelsonic, on 14 August 2012 - 10:16 AM, said:

View PostEXOGGEDDEN, on 09 August 2012 - 05:12 AM, said:

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.)


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]

#7 User is offline EXOGGEDDEN 

Posted 15 August 2012 - 10:09 AM

  • orgasmic
  • Posts: 410
  • Joined: 24-July 03

View PostTravelsonic, on 15 August 2012 - 09:36 AM, said:

View PostEXOGGEDDEN, on 15 August 2012 - 07:52 AM, said:

View PostTravelsonic, on 14 August 2012 - 10:16 AM, said:

View PostEXOGGEDDEN, on 09 August 2012 - 05:12 AM, said:

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.)


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.

#8 User is offline Travelsonic 

Posted 17 August 2012 - 10:50 AM

  • Posts: 661
  • Joined: 01-March 05

View PostEXOGGEDDEN, on 15 August 2012 - 10:09 AM, said:

View PostTravelsonic, on 15 August 2012 - 09:36 AM, said:

View PostEXOGGEDDEN, on 15 August 2012 - 07:52 AM, said:

View PostTravelsonic, on 14 August 2012 - 10:16 AM, said:

View PostEXOGGEDDEN, on 09 August 2012 - 05:12 AM, said:

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.)


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.

Page 1 of 1
    Locked
    Locked Forum

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users