-
Notifications
You must be signed in to change notification settings - Fork 1
/
protectdbg.lua
41 lines (37 loc) · 1.04 KB
/
protectdbg.lua
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
38
39
40
41
local blocks = {}
function run_handler(state, pos)
-- loop through all of the symbols and mark blocks
-- of memory that are protected
local start = nil
blocks = {}
for i, v in ipairs(state:symbols()) do
if (v.data == "protection:start") then
start = v.address
elseif (v.data == "protection:end") then
table.insert(blocks, { start, v.address })
end
end
end
function write_handler(state, pos)
-- check to see if the position was protected
for i, v in ipairs(blocks) do
if (v[1] <= pos and v[2] > pos) then
print("protected memory was written to! automatically")
print("halting VM. the address that was written to is " .. pos);
state:_break()
return
end
end
end
function setup()
-- perform setup
add_hook("run", run_handler)
add_hook("write", write_handler)
end
MODULE = {
Type = "Debugger",
Name = "Memory Protection Module",
Version = "1.0",
SDescription = "Checks protected memory blocks at runtime",
URL = "http://dcputoolcha.in/docs/modules/list/protect.html"
};