Not sure. (Pointers) Memory acess.

This is a discussion on Not sure. (Pointers) Memory acess. within the C++ Programming forums, part of the General Programming Boards category; Hello, im trying to acess the memory adress of my program using another program. How would that be possible? I ...

  1. #1
    deletedforumuser
    Guest

    Not sure. (Pointers) Memory acess.

    Hello, im trying to acess the memory adress of my program using another program. How would that be possible?

    I tryed this:

    This is the program that contains the variable for the memory to be acessed:

    Code:
    #include <iostream>
    #include <windows.h>
    
    
    using namespace std;
    
    
    int main()
    {
    
    	int* p_watk = new int(10);
    
    
    	while(1)
    	{
    		cout <<*p_watk<<endl;
    		cout <<&p_watk<<endl;
    		Sleep(2000);
    	}
    
    
            delete p_watk;
    	return 0;
    
    }


    This is the program to acess the memory:

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
    
    	int* p = (int*)0x016FC50;
    
    
    	cout <<*p;
    
    }
    Actually, All you got to do is open the first program. Then check the adress, and change 0x016FC50 to the adress you want to acess.

    I tryed it, doesn't really work. Maybe the way im doing it is wrong.

    This will help me to:

    Save the memory adress into a file.
    The "Server localhost" program will read the file, get the adress.
    It will then be able to modify the value.

    Thank you. If you are able to help me with that, it'll be great.

  2. #2
    deletedforumuser
    Guest
    Hmm, nevermind, i just heard about ReadProcessMemory.

    I will go learn it, if i still have problems, i'll tell you guys.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,554
    > Hello, im trying to acess the memory adress of my program using another program. How would that be possible?
    Given most operating systems today, very difficult.

    Each process runs in a virtual address space. So address 0x016FC50 in one program is completely meaningless in another program (or even another instance of the same program).

    Each OS (usually) has an API to do this, but you almost certainly have to run as root/admin to do it. Plus if you're doing anything more complicated than reading in one and writing in another to a single memory location, then you're going to need locks to prevent concurrent access.

    Perhaps you should explain what this "server" is trying to do.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    deletedforumuser
    Guest
    Code:
    #include <iostream>
    #include <windows.h>
    
    using namespace std;
    
    int main()
    {
    
    	HWND hwnd;
    
    	DWORD id;
    
    	hwnd = FindWindow(NULL,"Hey");
    
    	GetWindowThreadProcessId(hwnd, &id);
    
    	HANDLE client = OpenProcess(PROCESS_ALL_ACCESS, false, id);
    
    	int theadress = 0x0020F770;
    
    	DWORD bytesread = 5;
    	int buffer = 4;
    
    	ReadProcessMemory(client,(int*)theadress, &buffer, sizeof(int), &bytesread);
    
    	cout<<buffer;
    
    }
    I tryed this, i have set my console title to Hey. It actually found the process id.

    Trying to read from it...Not sure how to print the value of the adress.

  5. #5
    deletedforumuser
    Guest
    Got it right this time.

    Code:
    #include <iostream>
    #include <windows.h>
    
    using namespace std;
    
    int main()
    {
    
    	HANDLE client = OpenProcess(PROCESS_ALL_ACCESS, false, 26420);
    
    	int theadress = 0x012FC08;
    
    	DWORD bytesread = 0;
    	int buffer = -1;
    
    	ReadProcessMemory(client,(LPVOID)theadress, &buffer, sizeof(int), 0);
    
    	cout <<buffer;
    
    }
    It can acess the memory adress...But how do i print the value?

  6. #6
    deletedforumuser
    Guest
    Got it finally, i can now read the value .

    Great!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers and dynamic memory
    By tkansara in forum C Programming
    Replies: 1
    Last Post: 06-16-2009, 09:22 AM
  2. Memory usage and memory leaks
    By vsanandan in forum C Programming
    Replies: 1
    Last Post: 05-03-2008, 05:45 AM
  3. Replies: 2
    Last Post: 11-28-2003, 10:50 AM
  4. Pointer's
    By xlordt in forum C Programming
    Replies: 13
    Last Post: 10-14-2003, 02:15 PM
  5. pointers and memory
    By itld in forum C++ Programming
    Replies: 4
    Last Post: 02-06-2002, 10:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21