<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.cheatengine.org/index.php?action=history&amp;feed=atom&amp;title=Lua%3AmapMemory</id>
	<title>Lua:mapMemory - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.cheatengine.org/index.php?action=history&amp;feed=atom&amp;title=Lua%3AmapMemory"/>
	<link rel="alternate" type="text/html" href="https://wiki.cheatengine.org/index.php?title=Lua:mapMemory&amp;action=history"/>
	<updated>2026-06-27T03:55:26Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.32.0</generator>
	<entry>
		<id>https://wiki.cheatengine.org/index.php?title=Lua:mapMemory&amp;diff=8442&amp;oldid=prev</id>
		<title>Leunsel: Added related function template.</title>
		<link rel="alternate" type="text/html" href="https://wiki.cheatengine.org/index.php?title=Lua:mapMemory&amp;diff=8442&amp;oldid=prev"/>
		<updated>2026-06-26T23:39:29Z</updated>

		<summary type="html">&lt;p&gt;Added related function template.&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 23:39, 26 June 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l165&quot; &gt;Line 165:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 165:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{LuaSeeAlso}}&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{LuaSeeAlso}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;{{Memory}}&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Leunsel</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.cheatengine.org/index.php?title=Lua:mapMemory&amp;diff=8376&amp;oldid=prev</id>
		<title>Leunsel: Initial page creation.</title>
		<link rel="alternate" type="text/html" href="https://wiki.cheatengine.org/index.php?title=Lua:mapMemory&amp;diff=8376&amp;oldid=prev"/>
		<updated>2026-06-26T20:26:31Z</updated>

		<summary type="html">&lt;p&gt;Initial page creation.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:Lua]]&lt;br /&gt;
{{CodeBox|'''function''' mapMemory(''address'', ''size'', ''frompid'' OPTIONAL, ''topid'' OPTIONAL) ''':''' integer, integer}}&lt;br /&gt;
&lt;br /&gt;
Maps a specific address range into the usermode context of another process.&lt;br /&gt;
&lt;br /&gt;
The memory is mapped from the given source process ID to the given target process ID. If a process ID is 0 or not specified, the Cheat Engine process is used.&lt;br /&gt;
&lt;br /&gt;
This function returns two values: the mapped address and an MDL handle. The MDL value is required when calling [[Lua:unmapMemory|unmapMemory]].&lt;br /&gt;
&lt;br /&gt;
===Function Parameters===&lt;br /&gt;
{|width=&amp;quot;85%&amp;quot; cellpadding=&amp;quot;10%&amp;quot; cellspacing=&amp;quot;0&amp;quot; border=&amp;quot;0&amp;quot;&lt;br /&gt;
!align=&amp;quot;left&amp;quot;|Parameter&lt;br /&gt;
!align=&amp;quot;left&amp;quot;|Type&lt;br /&gt;
!style=&amp;quot;width: 80%;background-color:white;&amp;quot; align=&amp;quot;left&amp;quot;|Description&lt;br /&gt;
|-&lt;br /&gt;
|address&lt;br /&gt;
|Integer&lt;br /&gt;
|The address to map.&lt;br /&gt;
|-&lt;br /&gt;
|size&lt;br /&gt;
|Integer&lt;br /&gt;
|The number of bytes to map.&lt;br /&gt;
|-&lt;br /&gt;
|frompid&lt;br /&gt;
|Integer OPTIONAL&lt;br /&gt;
|The source process ID. If 0 or omitted, the Cheat Engine process is used.&lt;br /&gt;
|-&lt;br /&gt;
|topid&lt;br /&gt;
|Integer OPTIONAL&lt;br /&gt;
|The target process ID. If 0 or omitted, the Cheat Engine process is used.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
{|width=&amp;quot;85%&amp;quot; cellpadding=&amp;quot;10%&amp;quot; cellspacing=&amp;quot;0&amp;quot; border=&amp;quot;0&amp;quot;&lt;br /&gt;
!align=&amp;quot;left&amp;quot;|Return Value&lt;br /&gt;
!align=&amp;quot;left&amp;quot;|Type&lt;br /&gt;
!style=&amp;quot;width: 80%;background-color:white;&amp;quot; align=&amp;quot;left&amp;quot;|Description&lt;br /&gt;
|-&lt;br /&gt;
|mappedAddress&lt;br /&gt;
|Integer&lt;br /&gt;
|The mapped address in the target usermode context.&lt;br /&gt;
|-&lt;br /&gt;
|mdl&lt;br /&gt;
|Integer&lt;br /&gt;
|The MDL handle required to unmap the mapped memory with unmapMemory.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Examples===&lt;br /&gt;
&lt;br /&gt;
====Map memory from the opened process to Cheat Engine====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
local address = getAddress(&amp;quot;game.exe+1234&amp;quot;)&lt;br /&gt;
local size = 4096&lt;br /&gt;
local frompid = getOpenedProcessID()&lt;br /&gt;
&lt;br /&gt;
local mappedAddress, mdl = mapMemory(address, size, frompid, 0)&lt;br /&gt;
&lt;br /&gt;
print(string.format(&amp;quot;Mapped address: %X&amp;quot;, mappedAddress))&lt;br /&gt;
print(string.format(&amp;quot;MDL: %X&amp;quot;, mdl))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Map memory and unmap it later====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
local address = getAddress(&amp;quot;game.exe+1234&amp;quot;)&lt;br /&gt;
local size = 4096&lt;br /&gt;
local frompid = getOpenedProcessID()&lt;br /&gt;
&lt;br /&gt;
local mappedAddress, mdl = mapMemory(address, size, frompid, 0)&lt;br /&gt;
&lt;br /&gt;
if mappedAddress ~= nil and mappedAddress ~= 0 then&lt;br /&gt;
  print(string.format(&amp;quot;Mapped address: %X&amp;quot;, mappedAddress))&lt;br /&gt;
&lt;br /&gt;
  -- Access mapped memory here&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
if mdl ~= nil and mdl ~= 0 then&lt;br /&gt;
  unmapMemory(mappedAddress, mdl)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Map memory using the default process IDs====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;3&amp;quot;&amp;gt;&lt;br /&gt;
local address = allocateMemory(4096)&lt;br /&gt;
local size = 4096&lt;br /&gt;
local mappedAddress, mdl = mapMemory(address, size)&lt;br /&gt;
&lt;br /&gt;
print(string.format(&amp;quot;Mapped address: %X&amp;quot;, mappedAddress))&lt;br /&gt;
&lt;br /&gt;
unmapMemory(mappedAddress, mdl)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Map memory from Cheat Engine to the opened process====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;6&amp;quot;&amp;gt;&lt;br /&gt;
local address = allocateMemory(4096)&lt;br /&gt;
local size = 4096&lt;br /&gt;
local frompid = 0&lt;br /&gt;
local topid = getOpenedProcessID()&lt;br /&gt;
&lt;br /&gt;
local mappedAddress, mdl = mapMemory(address, size, frompid, topid)&lt;br /&gt;
&lt;br /&gt;
print(string.format(&amp;quot;Mapped address in target: %X&amp;quot;, mappedAddress))&lt;br /&gt;
&lt;br /&gt;
unmapMemory(mappedAddress, mdl)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Validate the returned values====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
local address = getAddress(&amp;quot;game.exe+1234&amp;quot;)&lt;br /&gt;
local size = 4096&lt;br /&gt;
local frompid = getOpenedProcessID()&lt;br /&gt;
&lt;br /&gt;
local mappedAddress, mdl = mapMemory(address, size, frompid, 0)&lt;br /&gt;
&lt;br /&gt;
if mappedAddress == nil or mappedAddress == 0 or mdl == nil or mdl == 0 then&lt;br /&gt;
  print(&amp;quot;mapMemory failed&amp;quot;)&lt;br /&gt;
  return&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
print(&amp;quot;Memory mapped successfully&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
unmapMemory(mappedAddress, mdl)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Read from mapped memory====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;5&amp;gt;&lt;br /&gt;
local address = getAddress(&amp;quot;game.exe+1234&amp;quot;)&lt;br /&gt;
local size = 4096&lt;br /&gt;
local frompid = getOpenedProcessID()&lt;br /&gt;
&lt;br /&gt;
local mappedAddress, mdl = mapMemory(address, size, frompid, 0)&lt;br /&gt;
&lt;br /&gt;
if mappedAddress ~= nil and mappedAddress ~= 0 then&lt;br /&gt;
  local value = readInteger(mappedAddress)&lt;br /&gt;
&lt;br /&gt;
  print(&amp;quot;Value: &amp;quot; .. tostring(value))&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
if mdl ~= nil and mdl ~= 0 then&lt;br /&gt;
  unmapMemory(mappedAddress, mdl)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use pcall to ensure cleanup====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
local address = getAddress(&amp;quot;game.exe+1234&amp;quot;)&lt;br /&gt;
local size = 4096&lt;br /&gt;
local frompid = getOpenedProcessID()&lt;br /&gt;
&lt;br /&gt;
local mappedAddress, mdl = mapMemory(address, size, frompid, 0)&lt;br /&gt;
&lt;br /&gt;
local ok, err = pcall(function()&lt;br /&gt;
  if mappedAddress ~= nil and mappedAddress ~= 0 then&lt;br /&gt;
    print(readInteger(mappedAddress))&lt;br /&gt;
  end&lt;br /&gt;
end)&lt;br /&gt;
&lt;br /&gt;
if mdl ~= nil and mdl ~= 0 then&lt;br /&gt;
  unmapMemory(mappedAddress, mdl)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
if not ok then&lt;br /&gt;
  print(err)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{LuaSeeAlso}}&lt;/div&gt;</summary>
		<author><name>Leunsel</name></author>
		
	</entry>
</feed>