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 


C++ ReadProcessMemory (Memory Access Violation)

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

Joined: 19 Jan 2018
Posts: 8

PostPosted: Mon Feb 19, 2018 5:58 am    Post subject: C++ ReadProcessMemory (Memory Access Violation) Reply with quote

Code:

DWORD read;
MEMORY_BASIC_INFORMATION mbi;

char* chunk = 0;


if (!VirtualQueryEx(readhandle, chunk, &mbi, sizeof(mbi))) {
            return GetLastError();
}

char buffer[mbi.RegionSize];

ReadProcessMemory(readhandle, mbi.BaseAddress, &buffer, mbi.RegionSize, &read);


I have a problem, because the Memory Region (Size:7864320) I want to read is actually resulting in a memory access violation, since the array is too big. Is there a way to avoid that?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Mon Feb 19, 2018 6:37 am    Post subject: Reply with quote

instead of &buffer give buffer, else you're giving the address of the buffer pointer in the stack

(Also, instead of allocating buffer in the stack, you may wish to allocate it separately. The stack might be big enough)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Tobilo
How do I cheat?
Reputation: 0

Joined: 19 Jan 2018
Posts: 8

PostPosted: Mon Feb 19, 2018 9:32 am    Post subject: Reply with quote

Dark Byte wrote:
instead of &buffer give buffer, else you're giving the address of the buffer pointer in the stack

(Also, instead of allocating buffer in the stack, you may wish to allocate it separately. The stack might be big enough)


Thank you, I am relatively new to c++, by allocating the buffer separately and by giving the buffer directly it worked. But the main problem was that I did not wrote
Code:
 char *buffer = new char[mbi.RegionSize];
since this statement was in a loop...
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