Page 1 of 1

Disabling lua restrictions

Posted: Tue Nov 29, 2016 10:55 pm
by bigjust12345
I'm sure most of you have noticed that several standard lua functions have been disabled in factorio. This includes the entirety of io and os. (you may however not be aware the serpent library has been added). Based on what I’ve read in the forums it would appear this is done to ensure determinism, all clients had to be able to perform lock step simulation which can’t work if they each read different data from outside the game. I don’t know if this is still true with the client server model currently being used. These restrictions also exist for security reasons, to prevent arbitrary code from executing. This has made it impossible to make a personal single player mod I’m working on and I can imagine makes debugging harder. These restrictions however are quite simple to remove, factorio is built with debug info and the lua functions are removed in LuaHelper::initLuaState. You can disassemble the executable (using tools like IDA) find the instructions you need to edit (it’s just load lua state, call pushnil, load the name of the thing to disable, load the lua state and call setglobal), open the executable in a hex editor (like hxd) and replace the bytes of those instructions with 0x90 (this is an x86_64 instruction that does nothing). I unfortunately can’t simply post the values to replace as they are different for every version, between 32 and 64 bit, based on os and potentially between steam and non-steam.

Re: Disabling lua restrictions

Posted: Tue Nov 29, 2016 11:43 pm
by daniel34
For further reading on this topic I recommend RE Series Part 1: A wild LUA appears !
bigjust12345 wrote:Based on what I’ve read in the forums it would appear this is done to ensure determinism, all clients had to be able to perform lock step simulation which can’t work if they each read different data from outside the game. I don’t know if this is still true with the client server model currently being used.
It is still true for the multiplayer model used in 0.14/0.15.

Re: Disabling lua restrictions

Posted: Wed Nov 30, 2016 12:49 pm
by bigjust12345
Thanks for linking that, I do wish I had seen it before I had done all of the reverse engineering