Trying to right to memory with an old tutorial.

Posts 112 of 12 · Page 1 of 1
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.

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;
}
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.
[php]
#define mouseX 0x0685D8BO
[/php]

Hexadecimal goes from 0 to F. Replace the O with a 0 and see how it goes, post results.
Aha, you have a good eye. Let me check that out, brb.

EDIT: Perfect tyvm Void.
All I did was look at the error/warning.
I just completely mis-read the warning. I haven't tried to program in c++ in a long while. Thanks a bunch for your help though...and expect to see more of me.
Do you know which lib i should be looking at for keyboard/mouse hooking? I'm going to google this but maybe you know something better?
Erm, though have no authority here, no double posting.

Use SetWindowsHookEx() and create a low level keyboard hook, not sure what you would do for mouse.
Sorry, maybe i should just make a new topic next go around. Hm, I'll need the mouse hook for sure. I'm working on a simple bot atm for a small game just for practice.
Void ftw .
I was just reading that and I'm not quite sure how to work that code in.
My example:

[php]
#include <windows.h>
#include <iostream>

using namespace std;

HHOOK hHook;

LRESULT CALLBACK KeyboardProcedure(int Code,WPARAM wParam,LPARAM lParam)
{
if(wParam == WM_KEYDOWN)
{
PKBDLLHOOKSTRUCT LowLevelHookStructure = (PKBDLLHOOKSTRUCT)lParam;
if(LowLevelHookStructure->vkCode == VkKeyScan('a'))
cout << "A has been pressed" << endl;

if(LowLevelHookStructure->vkCode == VK_ESCAPE)
PostQuitMessage(0);
}
CallNextHookEx(hHook,Code,wParam,lParam);
}

int main()
{
MSG msg;
HMODULE hMod = GetModuleHandle(NULL);
hHook = SetWindowsHookEx(WH_KEYBOARD_LL,KeyboardProcedure, hMod,0);
GetMessage(&msg,0,0,0);
return 0;
}
[/php]

As you can see, if A is pressed it will output a certain message, if ESC is pressed the callback will stop accepting messages and the window will continue execution from the main function and close.

Someone correct me if I'm wrong here.
Posts 112 of 12 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?