Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


ReadProcessMemory always returns error

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
Michaelc
Cheater
Reputation: 0

Joined: 15 May 2016
Posts: 47

PostPosted: Thu May 10, 2018 1:35 am    Post subject: ReadProcessMemory always returns error Reply with quote

Hi all:

I am trying to create a memory scanner, but my readprocessmemory()
line always returns error!

The problem appears to originate from incorrect values/variables bed to the
function.



This is my code:


Code:
#include <windows.h>
#include <stdio.h>

int main()
{
    // I manually enter pid at this time for this experimental code.
   int pid = 5428;

   HANDLE process_handle = OpenProcess(
       PROCESS_ALL_ACCESS,
        FALSE,
        pid);


    // the values whose address are to be found by this code.
    int Val = 12345;

    char* p = NULL;
    int* q;
    int v;

    DWORD dwStart = 0, i;
    SIZE_T lpRead;
    SYSTEM_INFO si;
    MEMORY_BASIC_INFORMATION mbi;
    DWORD MinAddr, MaxAddr;
    DWORD lpBase;
    DWORD Size = sizeof(int);

    // Get Application Min And Max Value
    GetSystemInfo(&si);
    MinAddr = (DWORD)si.lpMinimumApplicationAddress;
    MaxAddr = (DWORD)si.lpMaximumApplicationAddress;
// printf("MinAddr : %p\n", MinAddr);
// printf("MaxAddr : %p\n", MaxAddr);
    dwStart = MinAddr;

    puts("Begin");

    while(1){
        if (VirtualQueryEx( process_handle,(void *)dwStart,&mbi,sizeof(MEMORY_BASIC_INFORMATION) == 0))
        {
            printf("VirtualQueryEx failed.");
        }
       


        if(dwStart + mbi.RegionSize < dwStart)
        {
            //printf("Break. \n");
            break;

        }
       
        //printf("This region has the size of: %p  \n", (int)mbi.RegionSize);

        if(mbi.State != MEM_COMMIT) {
            dwStart+=mbi.RegionSize;
            //printf("Continue. \n");
            continue;

        }
       
       

        for(i=dwStart; i<dwStart+mbi.RegionSize; i+= Size)  // i+= Size
        {
            //printf("It got to readprocess memory. \n");
           
            if(ReadProcessMemory(process_handle, (LPVOID)i, &v, Size, NULL) != 0) // &lpRead
            {
                printf("Val = %d \n", Val);
                if (v==Val)
                {
                    //Address[AddCnt++] = i;
                    //printf("Found one: %p\n",i);
                    printf("Found one.");
                }
            }
            else
            {
                printf("ReadProcessMemory has an error. \n");
            }
        }

        dwStart+=mbi.RegionSize;
    }

    puts("End");

    system("pause");
   return 0;
}
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8517
Location: 127.0.0.1

PostPosted: Thu May 10, 2018 1:45 am    Post subject: Reply with quote

You're probably failing to even open the process. Add error handling and check the returns of the functions to see where it's failing.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Michaelc
Cheater
Reputation: 0

Joined: 15 May 2016
Posts: 47

PostPosted: Thu May 10, 2018 1:50 am    Post subject: Reply with quote

Ok, I 'll start with openprocess!



I used this:

Code:
    if(process_handle != NULL)
    {
        printf("The process_handle returned is not NULL.");
    }



So I am now sure it's not openprocess... try virtualQueryEx now.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites