QuestionHelpReadProcessMemory dont work?!

Posts 1–10 of 10 · Page 1 of 1
ReadProcessMemory dont work?!
Can anybody help me with this code on windows 7 x32

int main(){
BYTE Buffer[4] = {0x12,0x12};
HWND handle = FindWindow(0, "Diablo 2");
if (ReadProcessMemory(handle, (LPVOID)0x2352222, &Buffer, sizeof(Buffer), 0))
{
MessageBoxA(0, "Wrong", "Wrong", MB_ICONINFORMATION);
}else{
MessageBoxA(0, "Right", "Right", MB_ICONINFORMATION);
}
}

if i inject this code in Diablo 2 then i get every time this messege "MessageBoxA(0, "Wrong", "Wrong", MB_ICONINFORMATION);"
and if i put wrong BYTE buffer i get this messege too and if its right BYTE buffer i get this messege again?

whats wrong on this code
maybe can i fix it?!
Quote Originally Posted by Biesi View Post
Why do you use ReadProcessMemory if you inject it..?
ReadProcessMemory function (Windows)

btw you failed your if condition
because i rewrite like this adress with other byte and then will be check if that changed or not!
can you fixing this code or like other code write if you can?!
Code:
if (ReadProcessMemory(handle, (LPVOID)0x2352222, &Buffer, sizeof(Buffer), 0))
{
   MessageBoxA(0, "Right", "Right", MB_ICONINFORMATION);
} else {
   MessageBoxA(0, "Wrong", "Wrong", MB_ICONINFORMATION);
}
you have copy paste my code this code not worked , if i change or not, they show me every time only this messege box with "wrong"

but i needed that they show me if the byte changed then show "right" if by not changed then show me "wrong"!
@OP Well, since you have that covered in an IF/ELSE ...obviously that means "ReadProcessMemory" is returning false, indicating a failure.

edit: Your If statement is backwards --> It will say "Wrong" when the function has success, and vice-versa.
Biesi posted the correction.

HWND handle = FindWindow(0, "Diablo 2");
if (ReadProcessMemory(handle, (LPVOID)0x2352222, &Buffer, sizeof(Buffer), 0


handle should be returned from OpenProcess(), not FindWindow ?


 
OpenProcess

http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

Code:
HANDLE WINAPI OpenProcess(
  _In_  DWORD dwDesiredAccess,
  _In_  BOOL bInheritHandle,
  _In_  DWORD dwProcessId
);
@abuckau907
i have tryed with the openprocess but is didnt work!
maybe can you make a simple source code of readprocessmemory
You cannot read memory from a HWND (window handle). You need to convert this window handle into a process id using GetWindowThreadProcessId.

Code:
DWORD pId;
GetWindowThreadProcessId(handle, &pId);

// Open the process with read only access.
HANDLE hProcess = OpenProcess(PROCESS_VM_READ, FALSE, pId);
@abuckau907
thx, but i dont nedd anymore this i have already maked with other code!
Posts 1–10 of 10 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?