xgladius / luauDec

Decompiler for luau (https://luau-lang.org/)
58 stars 12 forks source link
decompiler luau roblox

luauDec

luauDec logo

Decompiler for Luau (https://luau-lang.org/) written by xgladius

luauDec is a decompiler for the Luau language created by Roblox, leveraging built-in Luau tooling to generate AST, and then transpile that AST into readable code.

Introduction

The decompiler was designed to have a few things in mind,

No dependencies - Other than the Luau language, luauDec has 0 dependencies other than the C++ STL.

Easy to understand and use - The code is written in a way that anyone can understand it, given they understand C++ of course.

Speed - The decompiler does not invoke the Luau VM, (like some other decompilers), allowing for it to be incredibly fast.

Multi-platform - Works on all platforms.

Building

  1. git clone --recursive https://github.com/xgladius/luauDec.git
  2. cd luauDec
  3. cmake . && make

How it works

  1. Luau bytecode is fed into the decompiler
    • The decompiler calls luau_load to produce an LClosure with a Proto member
  2. The decompiler iterates over each child Proto (Proto->p) which are passed to the decompiler's BlockGen class (BlockGen meaning non-main Proto)
    • The BlockGen class creates a AstExprFunction for each child Proto, which is added to a vector
      • Proto->code is iterated here to create Ast expressions of the relevant code
  3. The decompiler passes the main Proto, along with the vector of child Proto AstExprFunction to the decompilers BlockGen class (BlockGen meaning main Proto)
    • The BlockGen class creates a AstStatBlock containing all uses of code in Proto->code and child Protos
  4. The AstStatBlock is passed to Luau's built-in transpiler, which is turned into valid Luau code

Feature list