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

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

Joined: 31 Oct 2007
Posts: 340
Location: Siberia

PostPosted: Wed Jan 27, 2010 11:31 am    Post subject: ReadProcessMemory Reply with quote

Just looking into this , probably missing something but ill ask anyway .

ok im trying to read the value of the address 0x80d0358 , but every time i run it outputs 0. ive done error checking to see if the window is found or if ReadProccessMemory failed , but they dont.

so what did i do wrong??

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

using namespace std;


   int ReadMyAddress()
   {
      int MyBuffer = 0;
      unsigned long Address = 0x80d0358;
      HANDLE hProc = FindWindow(NULL, "snes9x v1.52 for windows");
      VirtualProtectEx(hProc, (LPVOID)Address, 256, PAGE_EXECUTE_READWRITE, NULL);

      ReadProcessMemory(hProc, ULongToPtr(Address), &MyBuffer, sizeof(MyBuffer), NULL);

      return MyBuffer;

   }

   int main(int argc, char * argv[])
   {
      int buffer = ReadMyAddress();

      cout << buffer;
      system ("pause");
      return 0;

   }
Back to top
View user's profile Send private message
Haxory'
Grandmaster Cheater Supreme
Reputation: 92

Joined: 30 Jul 2007
Posts: 1900

PostPosted: Wed Jan 27, 2010 12:28 pm    Post subject: Reply with quote

Code:

HANDLE hProc = FindWindow(NULL, "snes9x v1.52 for windows");


Add an 'L' before the text.
Code:

HANDLE hProc = FindWindow(NULL, L"snes9x v1.52 for windows");


I did the same stuff today XD started a lil C++ yesterday Smile

_________________
you and me baby ain't nothing but mammals so lets do it like they do on the discovery channel
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed Jan 27, 2010 1:58 pm    Post subject: Reply with quote

window handle is not the same as a process handle
Back to top
View user's profile Send private message
Haxory'
Grandmaster Cheater Supreme
Reputation: 92

Joined: 30 Jul 2007
Posts: 1900

PostPosted: Wed Jan 27, 2010 2:36 pm    Post subject: Reply with quote

This works.

Code:
#include "stdafx.h"
#include <iostream>
#include <windows.h>

using namespace std;


   int ReadMyAddress()
   {
      int MyBuffer = 0;
      unsigned long Address = 0xDEADBEEF;
     
  HANDLE hProcess = 0;

  HWND hWindow;
  DWORD pid = 0;

  hWindow = FindWindow(NULL, L"InjecTOR v.1.1");
  if (hWindow){
     GetWindowThreadProcessId(hWindow, &pid);
  }
  hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
  ReadProcessMemory(hProcess, ULongToPtr(Address), &MyBuffer, sizeof(MyBuffer), NULL);

      return MyBuffer;

   }

   int main(int argc, char * argv[])
   {
      int buffer = ReadMyAddress();

      cout << buffer;
     cout << "\n";
      system ("pause");
      return 0;

   }

_________________
you and me baby ain't nothing but mammals so lets do it like they do on the discovery channel
Back to top
View user's profile Send private message
rooski
Master Cheater
Reputation: 0

Joined: 31 Oct 2007
Posts: 340
Location: Siberia

PostPosted: Wed Jan 27, 2010 2:49 pm    Post subject: Reply with quote

i was missing this whole bit

Code:
if (hWindow){
     GetWindowThreadProcessId(hWindow, &pid);
  }
  hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);


got it working now , thanks for the help

Wink



EDIT_____________________________________
quick question , how do i convert a 4 byte value to byte?
(google turned up absolutely nothing)
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 474

Joined: 09 May 2003
Posts: 25952
Location: The netherlands

PostPosted: Wed Jan 27, 2010 3:41 pm    Post subject: Reply with quote

you could also use "unsigned char mybuffer;"
that way "ReadProcessMemory(hProcess, ULongToPtr(Address), &MyBuffer, sizeof(MyBuffer), NULL); " will only read the 1 byte at the specified address

as for converting a 4 byte to a byte:
Code:

BYTE mybyte;
DWORD my4bytevalue;

my4bytevalue=112;
mybyte=my4bytevalue;



now if my4bytevalue is bigger than 255 then the higher bits will be lost

_________________
Tools give you results. Knowledge gives you control.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
rooski
Master Cheater
Reputation: 0

Joined: 31 Oct 2007
Posts: 340
Location: Siberia

PostPosted: Wed Jan 27, 2010 4:13 pm    Post subject: Reply with quote

your way worked

thanks again for all the help , really nice to know i can get quick help from somewhere Very Happy.


Last edited by rooski on Wed Jan 27, 2010 11:11 pm; edited 1 time in total
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed Jan 27, 2010 5:37 pm    Post subject: Reply with quote

remember to close the process handle you obtained
Back to top
View user's profile Send private message
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Wed Jan 27, 2010 8:30 pm    Post subject: Reply with quote

@Slugsnack To elaborate, after you read from the process close the handle to prevent memory leaks.
Back to top
View user's profile Send private message MSN Messenger
rooski
Master Cheater
Reputation: 0

Joined: 31 Oct 2007
Posts: 340
Location: Siberia

PostPosted: Wed Jan 27, 2010 10:49 pm    Post subject: Reply with quote

I have another question , using the pointer scanner i get

Code:
[[snes9x.exe+0031BF38]+e8]


how do i express this in c++ so i can get its value Question

as i understand it snes9x.exe is the EP and then i just go from there , so how do i find a process's EP?
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Thu Jan 28, 2010 2:16 am    Post subject: Reply with quote

snes9x is not the EP, it is the base of that module. you can get the address with GetModuleHandle(). add 0x0031BF38 to the returned address. dereference that new address, ie. get the 4 bytes there. treat that 4 bytes as a new pointer which you add 0xe8 to.
Back to top
View user's profile Send private message
AtheistCrusader
Grandmaster Cheater
Reputation: 6

Joined: 23 Sep 2006
Posts: 681

PostPosted: Thu Jan 28, 2010 3:55 am    Post subject: Reply with quote

rooski wrote:
I have another question , using the pointer scanner i get

Code:
[[snes9x.exe+0031BF38]+e8]


how do i express this in c++ so i can get its value Question

as i understand it snes9x.exe is the EP and then i just go from there , so how do i find a process's EP?


[TheValueOf(snes9x.exe+0031BF38)]+e8 = the address you need
Back to top
View user's profile Send private message
rooski
Master Cheater
Reputation: 0

Joined: 31 Oct 2007
Posts: 340
Location: Siberia

PostPosted: Thu Jan 28, 2010 12:45 pm    Post subject: Reply with quote

@vision , yes i understand that i just didnt know how to get the base address(snes9x.exe) , but like Slugsnack said , just use GetModuleHandle().

thanks again for the quick reply .
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