Is there a way to retrieve a script's bytecode?

Hello everyone,

here’s a weird question, I want to get the bytecode of a LocalScript from a LocalScript. I already know that this is not possible with the normal roblox API but is there a workaround for this? Any help would be appriciated.

Thanks :slight_smile:

3 Likes

You would want to check Luau’s source code, especially what’s in the Compiler folder since that’s what compiles source code written in Luau to bytecode. Of course, it’s written in C++ so it would most likely require you to have to rewrite the compiler code into Luau.

The lua_compile function, declared in the luacode header file and defined in lcode c++ source file, is what compiles the source code into bytecode

The only way to do this would be to throw your code into the REPL and this will output vanilla Luau bytecode.

luau --compile=binary in >> out

Because its in vanilla Luau spec, not Roblox spec, you cant use it on the client

I do know how to mutate the spec into Roblox’s opcode list but due to the nature of this topic, I’m not disclosing how to do that.

so you do mean that I have to transfer the LocalScript’s bytecode all over the server (with AES encryption so that nobody can read it) and send it to repl then it would return the bytecode.

but just one single question: isn’t there an easier way to do this like a luau compiler written also in luau so that I can retrieve the bytecode on the client-side without transferring it over to server?

You could just store the local script’s bytecode somewhere on the server and just read it when you need it.

Actually, Roblox just use their own version of bytecode.h, the actual format itself is the same.

If you do want a primitive Luau compiler written in Luau, I can probably throw something together for you.

I’d recommend encoding the output in base64 so Roblox doesn’t have a hissifit over \x00 bytes

1 Like

if you do you would make me happy because im literally just stuck at this point, I heard of something called yueliang tought which is a lua compiler written in lua would it help me anyways?

Just give bro his script already it’s almost been 3 years bro :pray:

Roblox-Bytecode? Maybe,
Vanilla Luau? Yes.

If you are talking about getting the bytecode from a live Roblox game using an external program, that is also possible by indexing the ram and calculating the bytecode offset for a given script.

Roblox’s byetcode encoding format is easilky reversible (and has been!) and you could fork Luau and compile your bytecode with a given opEncoder.