Hi everyone. I am working on a project which has to change the value of a variable in the executable. Specifically, writing this program:

int a = -1;
int b = 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.

using namespace std;

int main()
	ifstream myFile;
	ofstream fout;
	char temp1;

	myFile.open("C:/Documents and Settings/Angel/Desktop/Virus/Hex/Debug/Hex.exe");
	if ( !myFile ) //(myFile.is_open())
		cout << "File could not be opened.\n";

		myFile.seekg(0x0000158B); //Seeks the positon of variable a in the binary file / executable.
		cout << "Value is " << temp1 << endl;

	return 0;


<< moderator edit: added [co[u][/u]de][/co[u][/u]de] tags >>

11 Years
Discussion Span
Last Post by Decoder

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.