Results 1 to 10 of 10
  1. #1
    BlueSkittles's Avatar
    Join Date
    Mar 2011
    Gender
    male
    Posts
    2
    Reputation
    10
    Thanks
    0
    My Mood
    Amused

    No access reading memory

    Every time I try to read process memory it tells me I don't have access. I tried using GetLastError and it kept returning error 998, which tells me I don't have access. Am I using VirtualProtect wrong or what? Can someone help me out? Thanks.

    Code:
    #include <iostream>
    #include <Windows.h>
    #include <TlHelp32.h>
    
    using namespace std;
    
    int main()
    {
    
    	HANDLE openprocess;
    	PROCESSENTRY32 pEntry;
    	MODULEENTRY32 mEntry;
    	
    	HANDLE processes  = CreateToolhelp32Snapshot(TH32CS_SNAPALL, NULL);
    
    	
    	Process32First(processes, &pEntry);
    
    	while(Process32Next(processes, &pEntry))
    	{
    		if(strcmp(pEntry.szExeFile, "test.exe")==0)
    		{
    			break;
    		}
    	}
    	
    	HANDLE process = CreateToolhelp32Snapshot(TH32CS_SNAPALL, pEntry.th32ProcessID);
    
    	Module32First(process, &mEntry);
    
    	int a = (int)mEntry.modBaseAddr;
    	int s = (int)mEntry.modBaseSize;
    	BYTE* b;
    	b = new BYTE[s];
    
    	cout<< mEntry.szModule << " " << hex << a << endl;
    
    	while(true)
    	{
    		bool a = Module32Next(process, &mEntry);
    		if(a == false)
    		{
    			break;
    		}
    		cout<< mEntry.szModule << " " << hex << (int)mEntry.modBaseAddr << endl;
    		
    	}
    	
    	
    	openprocess = OpenProcess(PROCESS_VM_READ|PROCESS_VM_OPERATION, 0, pEntry.th32ProcessID);
    
    	DWORD old = 0;
    	
    	VirtualProtectEx(openprocess,(LPVOID)a, s, PAGE_READWRITE, &old);
    	
    	
    	
    
    	if(!ReadProcessMemory(openprocess, (LPCVOID)a, &b, s, 0))
    	{
    		cout<< "fail";
    	}
    
    	cout<< b[0];
    	
    	cin.get();
    
    }

  2. #2
    [implicit]'s Avatar
    Join Date
    Oct 2012
    Gender
    male
    Posts
    16
    Reputation
    10
    Thanks
    1
    My Mood
    Cynical
    Try checking the VirtualProtectEx return. Also, you may need PAGE_EXECUTE_READWRITE depending on if you're reading bytes from the .code section, and the PROCESS_QUERY_INFORMATION flag in the handle.

  3. #3
    Fovea's Avatar
    Join Date
    Mar 2011
    Gender
    male
    Posts
    325
    Reputation
    101
    Thanks
    411
    My Mood
    Amused
    Your call to ReadProcessMemory is wrong (though it is probably not the problem). You supply the address of b as the buffer in which the data is to be written to instead of the allocated data (new BYTE[s]).

    Make sure your process has the right privileges in order to perform reads and page access protection changes.

  4. The Following User Says Thank You to Fovea For This Useful Post:

    BlueSkittles (11-18-2012)

  5. #4
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by Fovea View Post
    Your call to ReadProcessMemory is wrong (though it is probably not the problem). You supply the address of b as the buffer in which the data is to be written to instead of the allocated data (new BYTE[s]).

    Make sure your process has the right privileges in order to perform reads and page access protection changes.
    And perhaps the fact that he's calling OpenProcess with only OPERATION access? From MSDN, ReadProcessMemory requires a process handle that has PROCESS_VM_READ access attached to it.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  6. #5
    master131's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    Melbourne, Australia
    Posts
    8,858
    Reputation
    3438
    Thanks
    101,669
    My Mood
    Breezy
    Quote Originally Posted by Jason View Post


    And perhaps the fact that he's calling OpenProcess with only OPERATION access? From MSDN, ReadProcessMemory requires a process handle that has PROCESS_VM_READ access attached to it.
    Code:
    openprocess = OpenProcess(PROCESS_VM_READ|PROCESS_VM_OPERATION, 0, pEntry.th32ProcessID);
    Donate:
    BTC: 1GEny3y5tsYfw8E8A45upK6PKVAEcUDNv9


    Handy Tools/Hacks:
    Extreme Injector v3.7.3
    A powerful and advanced injector in a simple GUI.
    Can scramble DLLs on injection making them harder to detect and even make detected hacks work again!

    Minion Since: 13th January 2011
    Moderator Since: 6th May 2011
    Global Moderator Since: 29th April 2012
    Super User/Unknown Since: 23rd July 2013
    'Game Hacking' Team Since: 30th July 2013

    --My Art--
    [Roxas - Pixel Art, WIP]
    [Natsu - Drawn]
    [Natsu - Coloured]


    All drawings are coloured using Photoshop.

    --Gifts--
    [Kyle]

  7. #6
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by master131 View Post
    Code:
    openprocess = OpenProcess(PROCESS_VM_READ|PROCESS_VM_OPERATION, 0, pEntry.th32ProcessID);
    Fuck this hangover.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  8. #7
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    You're removing the execution rights from the entire module as well..
    Ah we-a blaze the fyah, make it bun dem!

  9. #8
    R3Dx666†'s Avatar
    Join Date
    Sep 2010
    Gender
    male
    Location
    Steam: MrTricklez
    Posts
    1,723
    Reputation
    141
    Thanks
    2,913
    My Mood
    Devilish
    Quote Originally Posted by BlueSkittles View Post
    Every time I try to read process memory it tells me I don't have access. I tried using GetLastError and it kept returning error 998, which tells me I don't have access. Am I using VirtualProtect wrong or what? Can someone help me out? Thanks.

    Code:
    #include <iostream>
    #include <Windows.h>
    #include <TlHelp32.h>
    
    using namespace std;
    
    int main()
    {
    
    	HANDLE openprocess;
    	PROCESSENTRY32 pEntry;
    	MODULEENTRY32 mEntry;
    	
    	HANDLE processes  = CreateToolhelp32Snapshot(TH32CS_SNAPALL, NULL);
    
    	
    	Process32First(processes, &pEntry);
    
    	while(Process32Next(processes, &pEntry))
    	{
    		if(strcmp(pEntry.szExeFile, "test.exe")==0)
    		{
    			break;
    		}
    	}
    	
    	HANDLE process = CreateToolhelp32Snapshot(TH32CS_SNAPALL, pEntry.th32ProcessID);
    
    	Module32First(process, &mEntry);
    
    	int a = (int)mEntry.modBaseAddr;
    	int s = (int)mEntry.modBaseSize;
    	BYTE* b;
    	b = new BYTE[s];
    
    	cout<< mEntry.szModule << " " << hex << a << endl;
    
    	while(true)
    	{
    		bool a = Module32Next(process, &mEntry);
    		if(a == false)
    		{
    			break;
    		}
    		cout<< mEntry.szModule << " " << hex << (int)mEntry.modBaseAddr << endl;
    		
    	}
    	
    	
    	openprocess = OpenProcess(PROCESS_VM_READ|PROCESS_VM_OPERATION, 0, pEntry.th32ProcessID);
    
    	DWORD old = 0;
    	
    	VirtualProtectEx(openprocess,(LPVOID)a, s, PAGE_READWRITE, &old);
    	
    	
    	
    
    	if(!ReadProcessMemory(openprocess, (LPCVOID)a, &b, s, 0))
    	{
    		cout<< "fail";
    	}
    
    	cout<< b[0];
    	
    	cin.get();
    
    }
    you do relise it will be detected? and what game is this for btw?

  10. #9
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    Quote Originally Posted by jameshk67 View Post
    you do relise it will be detected? and what game is this for btw?
    It doesnt matter, some people just want to learn first. Not everyone jumps into a dll hack and leech like a mad guy.
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  11. The Following User Says Thank You to 'Bruno For This Useful Post:

    Void (11-26-2012)

  12. #10
    WoLfulus's Avatar
    Join Date
    Aug 2011
    Gender
    male
    Posts
    1
    Reputation
    10
    Thanks
    0
    i know its old, but the problem is here:


    if(!ReadProcessMemory(openprocess, (LPCVOID)a, &b, s, 0))
    b is already a pointer, you're passing the pointer to the pointer, that will fail.


    if(!ReadProcessMemory(openprocess, (LPCVOID)a, b, s, 0))
    this should do the trick

Similar Threads

  1. [Help] Reading Memory Problem / If
    By intervention61 in forum C++/C Programming
    Replies: 3
    Last Post: 07-31-2011, 04:01 AM
  2. [VB.Net] Read Memory
    By jabbathehutt in forum Visual Basic Programming
    Replies: 10
    Last Post: 11-21-2010, 09:55 AM
  3. Dll's and accessing program memory
    By zeco in forum C++/C Programming
    Replies: 6
    Last Post: 08-31-2009, 08:59 AM
  4. [Request] Write/Read Memory Tutorial
    By Infection_X in forum Visual Basic Programming
    Replies: 1
    Last Post: 08-15-2008, 06:11 PM
  5. Ventrilo Read Memory
    By Imperceptus in forum General Game Hacking
    Replies: 0
    Last Post: 04-13-2008, 05:27 AM