954,480 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Reading/Writing to Executable

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 [code][/code] tags >>

Decoder
Newbie Poster
4 posts since Sep 2005
Reputation Points: 10
Solved Threads: 0
 

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.

Decoder
Newbie Poster
4 posts since Sep 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You