Giter Site home page Giter Site logo

luaudec's Introduction

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

  • StatBlock AST generation
  • Basic arithmetic AST generation (+, -, *, /, %, etc)
  • Reading and writing from constants table AST generation (Proto->k[idx] to AST)
  • Call AST generation (print())
    • Arguments (print(1,2,3,4,5,6)
    • Vararg argument (print(...))
  • Function AST generation (Proto->p nested subprotos) (function x() print'a' end x())
    • Newclosure AST generation
  • Return AST generation
    • Normal returns (return 1)
    • Vararg return (return 1,2,3,4)
  • Table AST generation
    • Setlist support (x = {1, 2, 3, 4})
    • Newtable support (x = {})
    • Settable support (x[1] = 1)
  • Local variable AST generation
    • "Smart" local variable names
  • Numeric for loops (for i=1, 10 do end)
    • Nested numeric for loops (for i=1, 10 do for x=1, 100 do end end)
  • Range based for loops (for i,v in pairs() do end)
    • Nested range based for loops
  • if statements
    • if then (if true then end)
    • Nested if statements
    • else
    • elseif
  • while statements
    • Nested while statements

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.