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 


Memory Management Functions.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Renkokuken
GO Moderator
Reputation: 4

Joined: 22 Oct 2006
Posts: 3249

PostPosted: Fri Oct 12, 2007 2:48 pm    Post subject: Memory Management Functions. Reply with quote

I'll make some clear examples of using most memory management functions.

We'll go over :

VirtualProtect
VirtualAlloc
VirtualFree
VirtualQuery

In the following languages :

Delphi
(C++ Tomorrow)
__________________________________________________________

Delphi Users : I'll go over these functions with you first!

VirtualAlloc :

Code:
VAR nAddress : Pointer;    //Declare the variables, nAddress will be the pointer to the new allocated page.
       Size : Cardinal; //Size, in bytes, of the allocated page.
begin
 Size := 4096; //4096 is a decent size for a new page.
 nAddress := VirtualAlloc(NIL, // The first parameter is NIL, since we don't require the memory at a set address.
                          Size,  //Size of the allocated page.
                          MEM_COMMIT, //Allocates physical storage in memory on disk for the specified reserved memory pages.
                          PAGE_READWRITE); //Give the page read and write access to the committed region of pages.
// If all went well, nAddress should point to the newly allocated memory.
end;


VirtualQuery :

Code:
var MBI : MEMORY_BASIC_INFORMATION; //Contains information about a range of pages in the virtual address space of a process.
begin
VirtualQuery(nAddress, //We'll use the pointer from the VirtualAlloc above.
                   MBI, //Pointer to the MEMORY_BASIC_INFORMATION structure.
                   sizeof(MBI)); //Sizeof() retrieves the general size of the variable, in this case MBI.
//If no errors occured, the MBI structure should hold information on the page allocated by VirtualAlloc.
end;


VirtualProtect :

Code:
VAR OldRights : DWORD; //Declare this, we'll need it later for VirtualProtect.
begin
VirtualProtect(MBI.BaseAddress, //Since VQ filled MBI's structure, MBI.BaseAddress is a pointer to the allocated page.
                    Size, //We'll need the size of the memory to change protections, so we'll use the variable from before.
                    PAGE_EXECUTE_READWRITE, //Give execute/read/write access to the committed region of pages.
                    @OldRights); //Pointer to a DWORD that will hold the old protection for replacing it later.
//If it all went well, VirtualProtect should have changed the protections in the page.
end;


VirtualFree :

Code:
begin
VirtualFree(MBI.BaseAddress, //Starting address for the page to be deallocated.
             0, //"0" will deallocate the entire page, if the starting address is inbetween 2 pages, both will be deallocated.
             MEM_RELEASE); //Release the memory in the specified page, afterwards, the page is in a free-state.
//If all went well, the page allocated by VirtualAlloc should be released.
end;


That's all for now, I'll add more later today or tomorrow, I'm sick currently.
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Fri Oct 12, 2007 5:12 pm    Post subject: Reply with quote

what about delete? lol
Back to top
View user's profile Send private message MSN Messenger
Renkokuken
GO Moderator
Reputation: 4

Joined: 22 Oct 2006
Posts: 3249

PostPosted: Fri Oct 12, 2007 6:53 pm    Post subject: Reply with quote

noz3001 wrote:
what about delete? lol
Due time.

Also, C is funner than expected, and syntax isn't as hard to switch to as expected.
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