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 returns blank on Windows 8

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
voidaccess
How do I cheat?
Reputation: 0

Joined: 01 Nov 2013
Posts: 9

PostPosted: Sun Nov 24, 2013 5:54 pm    Post subject: ReadProcessMemory returns blank on Windows 8 Reply with quote

I have this program that works in windows 7 perfectly the way I want it, but when I use it on windows 8 , readprocessmemory stores nothing in buffer. For the readprocessmemory I am using someone elses code since it was working. C++. GetLastError returns 299


Code:
int FindPointerAddr(HANDLE pHandle,int baseaddr, DWORD offsets[])
{
   int Address = baseaddr;
   int offset = 0;
   int offsetCount = 5;
   for (int i = 0; i < offsetCount; i++)
   {
      ReadProcessMemory(pHandle, (LPCVOID)Address, &Address , 4, NULL);
      Address+=offsets[i];
   }
   return Address;
}


void WriteToMemory()
{   
   //HANDLE hProcHandle;
   stats.clear();
   
   temp = "";
   
   //while(temp.size() < 150 ){
      //do{
            //hGameWindow = FindWindow( NULL, LGameWindow);
            hGameWindow = FindWindow(L"WFElementClient Window",NULL);
            if(hGameWindow){
                  GetWindowThreadProcessId( hGameWindow, &dwProcId );       
                     if( dwProcId != 0 ) { 
                         hProcHandle = OpenProcess( PROCESS_ALL_ACCESS, FALSE, dwProcId );
                         if( hProcHandle == INVALID_HANDLE_VALUE || hProcHandle == NULL ) {
                           GameStatus = "Failed to open process for valid handle";
                             }else{
                            GameStatus = "Game Found";
                            myaddr = FindPointerAddr(hProcHandle, ariaBase, aOffset);
                           // IsGameAvail = true;
                         }
                     }
                     else GameStatus = "Failed to obtain process id";
            }
            else GameStatus = "game handle not found";
      
         ReadProcessMemory(hProcHandle, (LPCVOID)myaddr, &buffer, sizeof(buffer), NULL);
//   memset(&buffer[0], 0, sizeof(buffer));
         ////std::cout << std::hex << GetLastError() << std::endl;
         temp = std::string((char*)buffer);
         std::cout << GameStatus << std::endl;
   //   }
      //while(temp == previous);      
   //}
   //temp = "Identified Attribute: " + GameStatus + "\r";
   previous = temp;
   std::replace( temp.begin(), temp.end(),(char)'\\', '*');
   stats.push_back(temp);
      
}

[/code]
Back to top
View user's profile Send private message
DELETED_USER
Newbie cheater
Reputation: 1

Joined: 02 Oct 2013
Posts: 24
Location: Venezuela

PostPosted: Mon Nov 25, 2013 12:28 am    Post subject: Reply with quote

I'm wondering if you have tried to debug the code?

Take a look at debugger, it may show where's the problem.
Back to top
View user's profile Send private message Send e-mail
justa_dude
Grandmaster Cheater
Reputation: 23

Joined: 29 Jun 2010
Posts: 891

PostPosted: Mon Nov 25, 2013 4:21 am    Post subject: Reply with quote

At a glance, it looks like there was once proper error handling and you stripped it all out. How do you know that the issue is with ReadProcessMemory and not one of the function calls prior?
Back to top
View user's profile Send private message
voidaccess
How do I cheat?
Reputation: 0

Joined: 01 Nov 2013
Posts: 9

PostPosted: Mon Nov 25, 2013 11:06 am    Post subject: Reply with quote

justa_dude wrote:
At a glance, it looks like there was once proper error handling and you stripped it all out. How do you know that the issue is with ReadProcessMemory and not one of the function calls prior?


Yes I added the error catching parts for window 7, however because readprocessmemory returns error 299, it returns blank string and sits in the while loop forever causing program to sit in frozen state in loop. Reason why I know its with readprocessmoemory is because this is only function not returning correctly while everything else is working and I know it works because I use it on windows 7 all time. Only other thing I can think of is processID is wrong, I double checked class name for window and it returns with valid window name.

GetLastError returns 0 for
Code:
hProcHandle = OpenProcess( PROCESS_ALL_ACCESS, FALSE, dwProcId );
Back to top
View user's profile Send private message
justa_dude
Grandmaster Cheater
Reputation: 23

Joined: 29 Jun 2010
Posts: 891

PostPosted: Mon Nov 25, 2013 4:05 pm    Post subject: Reply with quote

voidaccess wrote:
justa_dude wrote:
At a glance, it looks like there was once proper error handling and you stripped it all out. How do you know that the issue is with ReadProcessMemory and not one of the function calls prior?


Yes I added the error catching parts for window 7, however because readprocessmemory returns error 299, it returns blank string and sits in the while loop forever causing program to sit in frozen state in loop. Reason why I know its with readprocessmoemory is because this is only function not returning correctly while everything else is working and I know it works because I use it on windows 7 all time. Only other thing I can think of is processID is wrong, I double checked class name for window and it returns with valid window name.

GetLastError returns 0 for
Code:
hProcHandle = OpenProcess( PROCESS_ALL_ACCESS, FALSE, dwProcId );


If it's indeed stuck in the loop inside the FindPointerAddr function (passing the same variable for the in and out paramaters is really bad practice, btw), then you can never see the "game status" print and therefore don't know the status of the OpenProcess call... The other poster was right to suggest running a debugger (CE would work fine). Even if you were checking your return values properly, you could still be reading garbage from one of the pointers - I think the error code you mentioned translates to "I didn't read four bytes", but I don't know off-hand what happens if you try to read from address 0 or from a bad handle.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8585
Location: 127.0.0.1

PostPosted: Tue Nov 26, 2013 12:52 pm    Post subject: Reply with quote

You mentioned your read returns 299 though, which is 'ERROR_PARTIAL_COPY'. What is 'buffer' defined as? The size you are trying to read may be too much.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
SteveAndrew
Master Cheater
Reputation: 30

Joined: 02 Sep 2012
Posts: 323

PostPosted: Tue Nov 26, 2013 2:35 pm    Post subject: Reply with quote

Well I think I spotted the problem!

If my memory serves me correct, even if you do not care about how many bytes were read, you still must give it a pointer to a 32-bit memory location where it can write the 'BytesRead' variable to. (Actually it may be another API I'm thinking of... well it's worth a shot! lol)

Code:

DWORD BytesRead;
ReadProcessMemory(hProcHandle, (LPCVOID)myaddr, &buffer, sizeof(buffer), &BytesRead);


And yes I agree with Wiccaan, what is your buffer defined as? Also depending on how you defined 'buffer' sizeof(buffer) could return not what you'd expect. Though since you used '&buffer' it seems it isn't dynamically allocated, is that the case?

For example if you dynamically allocated 'buffer' sizeof(buffer) would return '4' if coding for 32-bit, (the size of the pointer, not your allocated data)

Code:

BYTE *buffer = new BYTE[100];
DWORD BytesRead;
ReadProcessMemory(hProcHandle, (LPCVOID)myaddr, buffer, 100,  &BytesRead);


Also you should clarify your code a bit, all the commented out stuff makes it confusing how your actually trying to run it! You say it gets stuck in the while loop, but it's commented out and there's more than 1. Also I'm not sure if its messing you up or not, but a Do While loop is just that, not the other way around. You don't go While () do {}, you go do { } while () [not sure if you have that backwards or not]

Maybe try this and see what gets printed out... You know it is a basic form of debugging without actually 'debugging' ? Just print out certain things at certain points in your program, if you don't see any output from your program how can you even see where the problem lies? You're just guessing if you don't output anything!

This is what I mean:

Code:

int FindPointerAddr(HANDLE pHandle, int baseaddr, DWORD offsets[])
{
   int Address = baseaddr;
   int offset = 0;
   int offsetCount = 5;
   for (int i = 0; i < offsetCount; i++)
   {
      ReadProcessMemory(pHandle, (LPCVOID)Address, &Address, 4, NULL);
      Address += offsets[i];
   }
   return Address;
}

void WriteToMemory()
{
   HANDLE hProcHandle;
   stats.clear();

   hGameWindow = FindWindow(L"WFElementClient Window", NULL);
   if (hGameWindow)
   {
      GetWindowThreadProcessId(hGameWindow, &dwProcId);
      if (dwProcId != 0)
      {
         hProcHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcId);
         if (hProcHandle == INVALID_HANDLE_VALUE || hProcHandle == NULL)
         {
            GameStatus = "Failed to open process for valid handle";
         }
         else
         {
            GameStatus = "Game Found!";
            myaddr = FindPointerAddr(hProcHandle, ariaBase, aOffset);
         }
      }
      else GameStatus = "\"Process ID\" Not Found!";
   }
   else GameStatus = "\"Game Window\" not found!";

   std::count << "Valid Pointer?: " << myaddr << "Valid Handle?: " << hProcHandle << "Status: " << GameStatus << "\n";

   BYTE *buffer = new BYTE[100];
   DWORD BytesRead;

   ReadProcessMemory(hProcHandle, (void*)myaddr, buffer, 100, &BytesRead);

   std::cout << "Your String Hopefully: " << buffer << "Bytes Read: " << BytesRead << "\n";

   delete[] buffer;
}


Anyways I find it very hard to read code where the {urly brackets are like how you've had them. I always drop it down to the next line and have them line up so you can easily tell where one begins and one ends.

Why is it the common coding style to do it like that? ex. (but see even when I do it like this I still somewhat line up the end brackets, most people don't though!
Code:

if(blah){
    if(blah2){
        bunched_up_nesting_is_lame = true;
        }
    }


instead of:
Code:

if(blah)
{
   if(blah2)
   {
      this_is_much_easier_to_read = !false;
   }
}

_________________
Back to top
View user's profile Send private message
DELETED_USER
Newbie cheater
Reputation: 1

Joined: 02 Oct 2013
Posts: 24
Location: Venezuela

PostPosted: Tue Nov 26, 2013 4:57 pm    Post subject: Reply with quote

Indent Style.
Back to top
View user's profile Send private message Send e-mail
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8585
Location: 127.0.0.1

PostPosted: Tue Nov 26, 2013 5:20 pm    Post subject: Reply with quote

SteveAndrew wrote:
Why is it the common coding style to do it like that? ex. (but see even when I do it like this I still somewhat line up the end brackets, most people don't though!
Code:

if(blah){
    if(blah2){
        bunched_up_nesting_is_lame = true;
        }
    }


instead of:
Code:

if(blah)
{
   if(blah2)
   {
      this_is_much_easier_to_read = !false;
   }
}


There is no standard to follow with code formatting for C/C++, there are various different styles that people use, as zShacktar linked to.

It's a "to-each-their-own" type thing, everyone likes something different.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
zirak
Expert Cheater
Reputation: 1

Joined: 15 Jun 2006
Posts: 121
Location: In the sewers

PostPosted: Wed Dec 04, 2013 10:10 pm    Post subject: Reply with quote

Make sure your app compiles to 32 bit and not Any CPU.

This happened to me and wouldn't read memory on Windows 8 for some reason and worked on 7, but doing that fixed it.

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 programming 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