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 

how use allocateSharedMemory?

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

Joined: 16 Jan 2016
Posts: 9

PostPosted: Tue Jan 19, 2016 6:50 pm    Post subject: how use allocateSharedMemory? Reply with quote

how use allocateSharedMemory?
Back to top
View user's profile Send private message
Grandmaster Cheater
Reputation: 34

Joined: 01 Oct 2008
Posts: 799

PostPosted: Wed Jan 20, 2016 2:25 pm    Post subject: Reply with quote

The lua function return the address of a Memory View Accessor (MV) of a Memory Mapped File (MF) address on target process.

Each execute of the function return a NEW MV with the same MF of the same name.
Modification of one MV with reflect on all other MV of the same MF.

For example, attaching CE to a target, run :

local function hex(n)return string.format("%X",n) end
local m1 = allocateSharedMemory("TESTMF",4096)
local m2 = allocateSharedMemory("TESTMF",4096)
print("Memory View 1 :"..hex(m1))
print("Memory View 2 :"..hex(m2))

It should show 2 hex address, like 3070000 and 30b0000.
Go to m1 address in memory viewer, make some modification, then go to m2 will see the same change.

Now if another CE attaching another process run the allocateSharedMemory with same parameter (name,size) as previous. Then it will be seen that modifying the returned memory address content will also reflect the same change on previous CE's target process memory.

That's how shared memory work.

Now one problem left. Each call of allocateSharedMemory will make a new Memory Viewer which is a waste of memory, and each returned numerical address is different. May be this helper function :
function getMMFAddress(name,size)
  local mv = readQword(name)
  if getOpenedProcessID()>0 and (mv==nil or mv~=readQword(mv)) then
    mv = allocateSharedMemory(name,size)
    if mv~=nil and mv>0 then
  return readQword(name)

This will define a symbol as the name for use, and prevent extra memory allocation (EDITED: this is not right, it should be a mapping that consume no extra physical memory). Note that allocateSharedMemory always create at least 4096 bytes, so if want to communicate between processes with multiple variable, it is better reuse same shared memory, differential the variables by offset to the shared address, eg.
str -> xxx+10
agl -> xxx+20
stm -> xxx+30

The address "xxx" (xxx+0) is already used to identify itself, it should not be use.

Back to example by Dark Byte in your previous post.

The example use a ce feature to automatic update a memory value from another address.

Say if want to automatic update value at DSC (desalinate address) from SRC (source address), do this (it is repeated of Dark Byte's step with more confusing word Wink
1. Name the memory record description with address = SRC as, say, "Source" (no quote);
2. Freeze the memory record with address = DSC;
3. Edit the value of DSC's MR;
4. Enter the DSC value as "(Source)" (no quote, exact description at 1 with enclosing bracket)
Now change on value of SRC will automatic reflect into DSC.

Now to complete the original example, this need to make:


in Process1, Source:                  in Process2, desalinate:
[SRC]   -- auto-copy --> MMF[xxx]   -- auto-copy -->  [DSC]

Try make a *.ct file with these 5 entry:
1. script type memory record:
function getMMFAddress(name,size)
  return readQword(name)
getMMFAddress("xxx") -- use default size 4096

2. source mr in process1, name it, say SRC, address/value setting depend on actual usage
3. target mr in process1, should be a shared memory slot, say address = "xxx"+10, of same type (string, byte etc) as 1, enter value = (SRC) while freezing ;

4. the source mr in process2, should be the same address as 3 "xxx"+10 (numerically different, but the same symbol), name its Description, say XXX

5 the target mr in process2, enter value as (XXX) while freezing.

saved this *.ct.
Then open this *.ct and attaching process1, activate 1 then 3 (make auto-ciopy step) ;
open the ct and attching process2, activate 1 then 5 (make auto-ciopy step).

It should be transfer value at Memory record #2 in process1 into #5 in another process2 now.

This is a poor expansion of DB's example, hopefully not confusing you more~


- Retarded.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting 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