From 0ac7d23bcf69346374d9ff25470a1bb6866ae5da Mon Sep 17 00:00:00 2001 From: lethosor Date: Thu, 10 Aug 2023 15:06:24 -0400 Subject: [PATCH] Add memscan.read_global_table() and memscan.read_c_string() --- library/lua/memscan.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/library/lua/memscan.lua b/library/lua/memscan.lua index 4a9824010..a8c265adb 100644 --- a/library/lua/memscan.lua +++ b/library/lua/memscan.lua @@ -533,4 +533,32 @@ function get_screen_size() return w,h end +-- Global table + +function read_c_string(char_ptr) + local s = '' + local i = 0 + while char_ptr[i] ~= 0 do + s = s .. string.char(char_ptr[i]) + i = i + 1 + end + return s +end + +function read_global_table(global_table) + global_table = global_table or df.global.global_table + local out = {} + local i = 0 + while true do + -- use _displace() so we can read past the bounds of the array set in structures, if necessary + local entry = global_table[0]:_displace(i) + if not entry.name or not entry.address then + break + end + out[read_c_string(entry.name)] = entry + i = i + 1 + end + return out +end + return _ENV