Reputation: 96
I have a Lua runtime environment exposed through an API to a larger C system. There are multiple entry points into the Lua program that are event driven by the C system. There are also callbacks that I can make into the C system from inside Lua. I have root access to the system running Lua but don't have the C source code.
I've discovered the list of valid callbacks I can make to the C function from inside Lua as this is exposed internally - Lua has to know that these are valid functions.
Is there any way of discovering the Lua functions that the C system will call? The API I'm using is not thoroughly documented and I'd like to know the list of Lua functions I can write that will be called by the C system.
Upvotes: 1
Views: 1502
Reputation: 96
In this particular instance, I was able to find the compiled file that contained the C code that called the Lua sandbox. I ran this through strings to get the list of strings hardcoded into the file, which led me to the API functions that were sent and received by the API into and out of my Lua sandbox.
I now have the list of all functions that can be called by the API in my Lua sandbox.
Upvotes: 1
Reputation: 59319
Lua has pretty thorough sandboxing abilities. If the API designer don't want you know something you wont.
To complicate it more Lua's API is very free form. There are 101 different ways an application designer could decide to expose an API to Lua. Of which not one is more standard than another. However Lua also has some very nice reflection and meta programming exposed in the language. If the designer didn't go out of their way to stop you, you may still be in luck.
If the C API accepts a table of methods (AKA a class) often you can override the __index
and __newindex
metamethods. When the C API tries to call a method on the table the __index
is called with the method name it is trying to execute. You can then print out a message or write a log containing the callback name. I would suggest then calling the base class function so that the application keeps running (and calling callbacks).
Upvotes: 2