This repository demonstrates how to use the WriteProcessMemory function in a Windows environment to overwrite memory in a target process. It includes two programs:
- Dummy Program: A simple console application that runs in a loop and prints out memory addresses and values of variables.
- WriteProcessMemory Program: A console application that allows you to write new values to the memory of the Dummy Program.
- Build and run the
DummyProgram.cppfile.- This program prints out the memory addresses and values of variables such as
varInt,varString, andarrChar. - The program also prints the process ID (PID), which will be used in the
WriteProcessMemoryprogram. - The program will loop indefinitely, allowing you to keep it running while you execute the
WriteProcessMemoryprogram.
- This program prints out the memory addresses and values of variables such as
- Build and run the
WriteProcessMemory.cppfile. - Enter the PID of the Dummy Program that is printed in its output.
- Select the type of variable to overwrite. In this demo, you can overwrite the
varIntinteger variable. - Enter the memory address of the variable (
varInt) from the Dummy Program. - The program will use the
WriteProcessMemoryfunction to overwrite the integer with a new value (intToWrite = 312532). - If the operation is successful, the console will display a success message. Otherwise, it will show an error message with the error code.
- Run the Dummy Program and note the output:
Process ID: 12345
varInt(0x7ff64812f8ac) = 123456
varString(0x7ff64812f8c0) = DefaultString
arrChar128 = Long char array right here ->- Run the WriteProcessMemory Program:
PID: 12345
Select the type of variable to read:
1.integer
Memory address of the integer to read (in hexadecimal): 0x7ff64812f8ac
Overwritten successfully- After the write operation, the
DummyProgramwill display the updatedvarIntvalue:
varInt(0x7ff64812f8ac) = 312532DummyProgram.cpp: Source code for the Dummy Program.WriteProcessMemory.cpp: Source code for the WriteProcessMemory Program.
This project is for educational purposes only. Modifying the memory of other processes can be illegal or harmful if used improperly. Always ensure that you have the right to modify the memory of the target process, and do not use this code for malicious purposes.