From 50bd758876adb8a39c54f107af9a5bd2274a3638 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Tue, 19 Jun 2012 18:48:22 +0400 Subject: [PATCH] Replace dfhack.internal.getBase with getRebaseDelta. Also, when printing found offsets, subtract the delta. --- LUA_API.rst | 4 ++-- library/LuaApi.cpp | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/LUA_API.rst b/LUA_API.rst index 1723711d3..9515690eb 100644 --- a/LUA_API.rst +++ b/LUA_API.rst @@ -1172,9 +1172,9 @@ and are only documented here for completeness: Returns the pre-extracted vtable address ``name``, or *nil*. -* ``dfhack.internal.getBase()`` +* ``dfhack.internal.getRebaseDelta()`` - Returns the base address of the process. + Returns the ASLR rebase offset of the DF executable. * ``dfhack.internal.getMemRanges()`` diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index 631b3c499..3693070d0 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -1036,10 +1036,10 @@ static void *checkaddr(lua_State *L, int idx, bool allow_null = false) return rv; } -static uint32_t getBase() { return Core::getInstance().p->getBase(); } +static uint32_t getRebaseDelta() { return Core::getInstance().vinfo->getRebaseDelta(); } static const LuaWrapper::FunctionReg dfhack_internal_module[] = { - WRAP(getBase), + WRAP(getRebaseDelta), { NULL, NULL } }; @@ -1074,6 +1074,7 @@ static int internal_setAddress(lua_State *L) } // Print via printerr, so that it is definitely logged to stderr.log. + addr -= Core::getInstance().vinfo->getRebaseDelta(); std::string msg = stl_sprintf("", name.c_str(), addr); dfhack_printerr(L, msg);