101Tomatoes
101Tomatoes

Reputation: 1

How to get memory address in lua?

Have checked the lua documentation and haven't found the function that ouput specific value from the memory address. Is there a function in lua that allows to output the memory address value?

Upvotes: 0

Views: 6302

Answers (3)

SkyyySi
SkyyySi

Reputation: 73

While this doesn't work with nil, boolean or number types, you can use string.format:

("%p"):format(my_object)

to get a string representation of the memory address of the object behind the variable my_object in vanilla Lua.

Upvotes: 2

Creator
Creator

Reputation: 161

Or if it is not a string you do

blabla = tostring(obj)

Upvotes: 1

Egor Skriptunoff
Egor Skriptunoff

Reputation: 23737

If you are working with LuaJIT, you can create this function yourself (works only on x86-32):

read_memory_dword = require"ffi".cast("__fastcall uint32_t (*)(uint32_t)",
                                      "\x8B\x01\xC3") -- mov EAX,[ECX] / ret
YourValue = read_memory_dword(YourAddress)

Upvotes: 0

Related Questions