tags:

views:

103

answers:

2

Let's assume I want to change something in the 000F5344 address of an executable. How do I do it?

+9  A: 

Four steps solution follows:

  1. Open the file with binary flag (use fopen).
  2. Move to the address (offset) (use fseek).
  3. Write your data (use fwrite).
  4. Close the file (use fclose).

Use google to get help on the four mentioned functions calls. Will also work in C.

Pablo Santa Cruz
Much appreciated.
Queops
Just for correctness, wouldn't that be fseek instead of ftell?
TheUndeadFish
@TheUndeadFish: yes.
mingos
@TheUndeadFish: yes! Thanks. Fixed that.
Pablo Santa Cruz
+9  A: 

@Pablo Santa Cruz provides an excellent way, but in C. If you prefer to go pure C++, here's how:

  1. Open file: fstream::open (remember to use the binary flag)
  2. Set the put pointer position: fstream::seekp
  3. Write data at the put pointer position: fstream::put
  4. Close file: fstream::close

This is by no means better than the C version though.

mingos
Also much appreciated.
Queops
Totally agree. Great answer!
Pablo Santa Cruz