Trying to right to memory with an old tutorial.
I've been reading around at some c++ tutorials on memory reading and writing and i've been trying to put it to the test.
This is from a tutorial I was reading but it will not write to the memory.
I get one warning when running this..I'm using dev c++, on windows vista 64bit.
This is the output....Well, i can't get it to copy.
It get down to this fine..
"I have persmissions to open the process!"
but never write the memory.
This is from a tutorial I was reading but it will not write to the memory.
I get one warning when running this..I'm using dev c++, on windows vista 64bit.
Code:
35:45 C:\Users\Woog\Documents\testmemory.cpp invalid suffix "O" on integer constant
Code:
#include <windows.h>
#include <tlhelp32.h>
#include <iostream>
using namespace std;
// Define them so we can use them in the rest of the program
#define mouseX 0x0685D8BO
#define mouseY 0x0685D8B4
void GetProcId(char* ProcName);
DWORD ProcId = 0; // THIS IS OUR GLOBAL VARIABLE FOR THE PROC ID;
int main()
{
char* ProcName="Random.exe";
SetConsoleTitle("Hope this is going to work......."); // Set your consoles title
int ValueOne=150, ValueTwo=250;
int i = 1;
do {
GetProcId(ProcName); // get the proc id from the processes name
cout << "The Process ID of " << ProcName << " is " << ProcId <<endl; // display it to the user
/*----Create a handle----*/
HANDLE phandle = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, 0, ProcId); //Get the needed permissions and open the process for access
if(phandle==INVALID_HANDLE_VALUE) //then
std::cout << "I don't have permissions to open the process!\n";
else
std::cout << "I have persmissions to open the process!\n";
/*----Write to the addresses----*/
WriteProcessMemory(phandle, (LPVOID)mouseX, &ValueOne, sizeof(ValueOne), 0); // Set the value of the first address
WriteProcessMemory(phandle, (LPVOID)mouseY, &ValueTwo, sizeof(ValueTwo), 0); // Set the value of the second address
Sleep(500); // We wouldn't want to lag now do we ;)
system("cls");
}while(i=1);
cin.get(); // to keep console open till we press a key
return 0;
}
void GetProcId(char* ProcName)
{
PROCESSENTRY32 pe32;
HANDLE hSnapshot = NULL;
pe32.dwSize = sizeof( PROCESSENTRY32 );
hSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
if( Process32First( hSnapshot, &pe32 ) )
{
do{
if( strcmp( pe32.szExeFile, ProcName ) == 0 )
break;
}while( Process32Next( hSnapshot, &pe32 ) );
}
if( hSnapshot != INVALID_HANDLE_VALUE )
CloseHandle( hSnapshot );
ProcId = pe32.th32ProcessID;
}
It get down to this fine..
"I have persmissions to open the process!"
but never write the memory.