Lua ByteCode

I was reading up on LuaJIT when I stumbled upon a function I’ve never seen before, string.dump.

Apparently string.dump compiles a function ( the first argument ) and returns the Lua byte-code of that function ( the same thing happens when you run a file, it’s compiled into a function then called ).

I compiled LuaJIT then tested it on my desktop :

Then tested in Garry’s Mod :

Notice how the compiled code printed out into the console consists only of the two letters “LJ” and of course, it doesn’t work.

I tried compiling code through luajit.exe then running it in Garry’s Mod and that too, doesn’t work. Though that gives me “cannot load malformed byecode” errors instead.

I know that Garry has rejected requests to implement byte-code related features.
Can I get some clarification on whether or not this is him blocking the functionality himself or what?

I believe bytecode is disabled in GMod. I might be wrong.
About the console output, it doesn’t print anything else after a null byte ( 0x0 )

Afaik bytecode security is a really huge issue thus it’s disabled.

The weird thing is, I had a little look a while ago, and I couldn’t actually find any part that explicitly disabled it; at least in the loading/running code. Though I’m not the best at these things.

And another thing to note is that when you try running it, sometimes it errors with what oubliette posted, the “cannot load incompatible bytecode” error, but other times it will error with something about malformed bytecode, inconsistently. And if you try running the bytecode enough, it will crash for whatever reason.

Also, the output from Garry’s Mod’s string.dump is entirely valid too, it works when run using the vanilla luajit executable.

I requested bytecode support a while back on github but only for binary modules because of the security issues if it was usable in lua.

that sounds like a good solution, was it ever implemented?


As far as i know, loading of bytecode was disabled to prevent hacks. This is also exactly the reason Oubliette wants to use it.

Isn’t LuaJIT disabled atm?

By default yes, but you can enable it via lua

I can load bytecode fine, compiling my own luaL_loadbuffer and using it on the lua_State pointer that’s passed to the function seems to get around whatever Garry has done. The Lua you have isn’t compiled because you’re using the beta branch and it’s a pain to compile it each time I change the code.

I posted this because I hadn’t known there was ways to do this without binaries and I didn’t know if these methods were blocked by Garry, loading bytecode has very useful no-cheating related uses.

Allow bytecode serverside if a command line parameter is specified. Same shit with the FFI feature that LuaJIT has. I don’t see any reason why this can’t be implemented. Clients don’t really need bytecode anyways.

There aren’t any non-cheating uses for it though.
No-one would trust an addon that uses compiled lua, especially for servers as it could have backdoors etc and they can’t review the code And if it breaks in an update or they want to edit it, they can’t.

How would it not help you? Your AC ( and all the other AC’s based off your AC ) could have each HACBurst packet sent as compiled lua and you could have your scripts sent as compiled lua, you could also increase the amount of code in each HACBurst packet because of the smaller size.

Bytecode has the ability to send binary ( for example, functions ) other net. Cheaters aren’t the only people that want their scripts concealed.

Then it would all have to pass through RunString on the client, which the client could have messed with/overriden. Having all the code rely on one function is too risky.

Much better to spread it out over ~30 or so files and do over 100 checks to make sure it’s loaded as it should.

They would have had to load before you to detour that, the function they use to load before you is also used to run files, handle Player.SendLua, _G.RunString, _G.RunStringEx and lua_run_cl.

I know the function, i’ve used it myself for testing HAC. They could still override RunString after HAC has loaded as not all of it loads first, and it could be messed with from that point.

Also i couldn’t use HACBurst until they’ve spawned anyway so the main HAC parts would have to be as files.