Reading/Writing to Executable

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2005
Posts: 4
Reputation: Decoder is an unknown quantity at this point 
Solved Threads: 0
Decoder Decoder is offline Offline
Newbie Poster

Reading/Writing to Executable

 
0
  #1
Nov 7th, 2005
Hi everyone. I am working on a project which has to change the value of a variable in the executable. Specifically, writing this program:
  1. int a = -1;
  2. int b = 3;
  3. int c = a + b;

I have to go into the executable and change the value of "a" into the executable. Let me not extend this too much, and show you what i have done. At this moment I do not know why this is not working. I am trying to make sure that I am looking at the right place before I try to change the value. Thanks for any help you can give me.

  1. #include<iostream.h>
  2. #include<fstream>
  3. #include<stdio.h>
  4. #include<string>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. ifstream myFile;
  10. ofstream fout;
  11. char temp1;
  12.  
  13. myFile.open("C:/Documents and Settings/Angel/Desktop/Virus/Hex/Debug/Hex.exe");
  14.  
  15. if ( !myFile ) //(myFile.is_open())
  16. {
  17. cout << "File could not be opened.\n";
  18. myFile.close();
  19. }
  20.  
  21. else
  22. {
  23. myFile.seekg(0x0000158B); //Seeks the positon of variable a in the binary file / executable.
  24. myFile.read(temp1,1);
  25. cout << "Value is " << temp1 << endl;
  26. myFile.close();
  27. }
  28.  
  29. return 0;
  30.  
  31. }
<< moderator edit: added [code][/code] tags >>
Last edited by Dave Sinkula; Nov 7th, 2005 at 6:00 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 4
Reputation: Decoder is an unknown quantity at this point 
Solved Threads: 0
Decoder Decoder is offline Offline
Newbie Poster

Re: Reading/Writing to Executable

 
0
  #2
Nov 7th, 2005
I forgot to say that i used a Hex editor to find the adress of the variable "a" in the executabe file. An "estimated" adress can also be seen on the debug/ dissasembly window. And this was written in Visual Studio 6. Thanks again.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC