943,965 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2900
  • C++ RSS
Nov 7th, 2005
0

Reading/Writing to Executable

Expand Post »
Hi everyone. I am working on a project which has to change the value of a variable in the executable. Specifically, writing this program:
C++ Syntax (Toggle Plain Text)
  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.

C++ Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Decoder is offline Offline
4 posts
since Sep 2005
Nov 7th, 2005
0

Re: Reading/Writing to Executable

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Decoder is offline Offline
4 posts
since Sep 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: segmentation fault... boooo!!!!
Next Thread in C++ Forum Timeline: Default values for STL container function arguments?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC