-
Notifications
You must be signed in to change notification settings - Fork 240
Expand file tree
/
Copy pathChapter5_VerifyMap.lua
More file actions
37 lines (30 loc) · 1.05 KB
/
Chapter5_VerifyMap.lua
File metadata and controls
37 lines (30 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function _verifyMap(address)
local parentItem = readInteger(address + 4) or 0
local parentLeftItem = readInteger(parentItem + 0) or 0
local parentRightItem = readInteger(parentItem + 8) or 0
local validParent =
parentLeftItem == address
or parentRightItem == address
if (not validParent) then return false end
local tries = 0
local lastChecked = parentItem
local parentsParent = readInteger(parentItem + 4) or 0
while (readInteger(parentsParent + 4) ~= lastChecked and tries < 200) do
tries = tries + 1
lastChecked = parentsParent
parentsParent = readInteger(parentsParent + 4) or 0
end
return readInteger(parentsParent + 4) == lastChecked
end
function isValueInMap(valueAddress)
for address = valueAddress - 12, valueAddress - 52, -4 do
if (_verifyMap(address)) then
return address
end
end
return 0
end
local node = isValueInMap(addressOfSomeValue)
if (node > 0) then
print(string.format("Value in map, top of node at 0x0%x", node))
end