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.

#include<iostream.h>
#include<fstream>
#include<stdio.h>
#include<string>
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.close();
	}

	else
	{
		myFile.seekg(0x0000158B); //Seeks the positon of variable a in the binary file / executable.
		myFile.read(temp1,1);
		cout << "Value is " << temp1 << endl;
		myFile.close();
	}

	return 0;

}

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.