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

luaudec's People

Contributors

xgladius avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

luaudec's Issues

(Arch Linux) Error when building. (ast.h???)

When I attempt to build the program, it throws an error, here is my whole command history.

[naymmm@DESKTOP-OB1AJL ~]$ git clone --recursive https://github.com/xgladius/luauDec.git
Cloning into 'luauDec'...
remote: Enumerating objects: 814, done.
remote: Counting objects: 100% (552/552), done.
remote: Compressing objects: 100% (226/226), done.
remote: Total 814 (delta 147), reused 520 (delta 127), pack-reused 262
Receiving objects: 100% (814/814), 279.45 KiB | 3.17 MiB/s, done.
Resolving deltas: 100% (310/310), done.
Submodule 'luau' (https://www.github.com/roblox/luau) registered for path 'luau'
Cloning into '/home/naymmm/luauDec/luau'...
warning: redirecting to https://github.com/roblox/luau.git/
remote: Enumerating objects: 8837, done.
remote: Counting objects: 100% (8837/8837), done.
remote: Compressing objects: 100% (2319/2319), done.
remote: Total 8837 (delta 6787), reused 8122 (delta 6228), pack-reused 0
Receiving objects: 100% (8837/8837), 9.92 MiB | 4.39 MiB/s, done.
Resolving deltas: 100% (6787/6787), done.
Submodule path 'luau': checked out 'b066e4c8f8851d9727d079935cfa2e0f9b108531'
[naymmm@DESKTOP-OB1AJL ~]$ cd luaudec
-bash: cd: luaudec: No such file or directory
[naymmm@DESKTOP-OB1AJL ~]$ ls
esmBot  libvips  luauDec  yay
[naymmm@DESKTOP-OB1AJL ~]$ cd luauDec
[naymmm@DESKTOP-OB1AJL luauDec]$ ls
CMakeLists.txt  Decompiler  README.md  luau  luauDec.png  main.cpp
[naymmm@DESKTOP-OB1AJL luauDec]$ cmake . && make
-- The C compiler identification is GNU 13.2.1
-- The CXX compiler identification is GNU 13.2.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/sbin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/sbin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Deprecation Warning at luau/CMakeLists.txt:7 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- Configuring done (10.5s)
-- Generating done (0.1s)
-- Build files have been written to: /home/naymmm/luauDec
[  0%] Built target Luau.Common
[  1%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/lapi.cpp.o
[  2%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/laux.cpp.o
[  3%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/lbaselib.cpp.o
[  4%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/lbitlib.cpp.o
[  5%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/lbuiltins.cpp.o
[  6%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/lcorolib.cpp.o
[  7%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/ldblib.cpp.o
[  8%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/ldebug.cpp.o
[  9%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/ldo.cpp.o
[ 10%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/lfunc.cpp.o
[ 11%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/lgc.cpp.o
[ 12%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/lgcdebug.cpp.o
[ 13%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/linit.cpp.o
[ 14%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/lmathlib.cpp.o
[ 15%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/lmem.cpp.o
[ 16%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/lnumprint.cpp.o
[ 17%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/lobject.cpp.o
[ 18%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/loslib.cpp.o
[ 19%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/lperf.cpp.o
[ 20%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/lstate.cpp.o
[ 21%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/lstring.cpp.o
[ 22%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/lstrlib.cpp.o
[ 23%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/ltable.cpp.o
[ 24%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/ltablib.cpp.o
[ 25%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/ltm.cpp.o
[ 26%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/ludata.cpp.o
[ 27%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/lutf8lib.cpp.o
[ 28%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/lvmexecute.cpp.o
[ 29%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/lvmload.cpp.o
[ 30%] Building CXX object luau/CMakeFiles/Luau.VM.dir/VM/src/lvmutils.cpp.o
[ 31%] Linking CXX static library libLuau.VM.a
[ 31%] Built target Luau.VM
[ 32%] Building CXX object luau/CMakeFiles/Luau.Ast.dir/Ast/src/Ast.cpp.o
In file included from /home/naymmm/luauDec/luau/Ast/src/Ast.cpp:2:
/home/naymmm/luauDec/luau/Ast/include/Luau/Ast.h: In member function 'std::size_t std::hash<Luau::AstName>::operator()(const Luau::AstName&) const':
/home/naymmm/luauDec/luau/Ast/include/Luau/Ast.h:1264:17: error: 'uintptr_t' was not declared in this scope
 1264 |         return (uintptr_t(value.value) >> 4) ^ (uintptr_t(value.value) >> 9);
      |                 ^~~~~~~~~
/home/naymmm/luauDec/luau/Ast/include/Luau/Ast.h:10:1: note: 'uintptr_t' is defined in header '<cstdint>'; did you forget to '#include <cstdint>'?
    9 | #include <string.h>
  +++ |+#include <cstdint>
   10 |
make[2]: *** [luau/CMakeFiles/Luau.Ast.dir/build.make:76: luau/CMakeFiles/Luau.Ast.dir/Ast/src/Ast.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:924: luau/CMakeFiles/Luau.Ast.dir/all] Error 2
make: *** [Makefile:121: all] Error 2
[naymmm@DESKTOP-OB1AJL luauDec]$```

error when building on windows under cygwin

[ 86%] Building CXX object CMakeFiles/luauDec.dir/main.cpp.o
In file included from /home/cul8ter/luauDec/Decompiler/Decompile.h:7,
from /home/cul8ter/luauDec/main.cpp:3:
/home/cul8ter/luauDec/Decompiler/BlockGen/include/BlockGen.h:34:38: error: expected ‘)’ before ‘’ token
34 | explicit BlockGen(Proto
p, std::vector<AstExpr*> subFuncs);
| ~ ^
| )
/home/cul8ter/luauDec/Decompiler/BlockGen/include/BlockGen.h:35:39: error: expected ‘)’ before ‘’ token
35 | explicit BlockGen(Proto
p);
| ~ ^
| )
make[2]: *** [CMakeFiles/luauDec.dir/build.make:76: CMakeFiles/luauDec.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:144: CMakeFiles/luauDec.dir/all] Error 2
make: *** [Makefile:121: all] Error 2

Updating Luau works, but a few other issues

I copied this repository and replaced the entire Luau folder with the new one and that surprisingly worked.
I just had to rename the JsonEncoder Header and add the Config folder to the CMake Mist. And change a few arguments on some of the Ast Constructions on luauDec's end.

However, if I manually feed Luau Bytecode in it, it errors out at some places. But the callstack lead to the files of this Repository's, before they reach the original Luau code.

Which is a good sign, but it's really hard to understand on how to fix it, without knowing what one has to do. It's related to the Ast Generation stuff.

Error When Buiding

>>> make  
[  0%] Built target Luau.Common
Consolidate compiler generated dependencies of target Luau.VM
[ 24%] Built target Luau.VM
Consolidate compiler generated dependencies of target Luau.Ast
[ 30%] Built target Luau.Ast
Consolidate compiler generated dependencies of target Luau.Compiler
[ 37%] Built target Luau.Compiler
Consolidate compiler generated dependencies of target Luau.Analysis
[ 73%] Built target Luau.Analysis
Consolidate compiler generated dependencies of target luauDec
[ 74%] Building CXX object CMakeFiles/luauDec.dir/main.cpp.o
In file included from 
luauDec-main/main.cpp:3:
In file included from 
luauDec-main/Decompiler/Decompile.h:7:
In file included from 
luauDec-main/Decompiler/BlockGen/include/BlockGen.h:7:

luauDec-main/Decompiler/BlockGen/include/../include/Lifter.h:37:18: error: use of undeclared identifier 'LOP_FORGLOOP_INEXT'; did you mean 'LOP_FORGPREP_INEXT'?
            case LOP_FORGLOOP_INEXT:
                 ^~~~~~~~~~~~~~~~~~
                 LOP_FORGPREP_INEXT

luauDec-main/Decompiler/../luau/Common/include/Luau/Bytecode.h:294:5: note: 'LOP_FORGPREP_INEXT' declared here
    LOP_FORGPREP_INEXT,
    ^
In file included from 
luauDec-main/main.cpp:3:
In file included from 
luauDec-main/Decompiler/Decompile.h:7:
In file included from 
luauDec-main/Decompiler/BlockGen/include/BlockGen.h:7:

luauDec-main/Decompiler/BlockGen/include/../include/Lifter.h:39:18: error: use of undeclared identifier 'LOP_FORGLOOP_NEXT'; did you mean 'LOP_FORGPREP_NEXT'?
            case LOP_FORGLOOP_NEXT:
                 ^~~~~~~~~~~~~~~~~
                 LOP_FORGPREP_NEXT

luauDec-main/Decompiler/../luau/Common/include/Luau/Bytecode.h:301:5: note: 'LOP_FORGPREP_NEXT' declared here
    LOP_FORGPREP_NEXT,
    ^
In file included from 
luauDec-main/main.cpp:3:
In file included from 
luauDec-main/Decompiler/Decompile.h:7:
In file included from 
luauDec-main/Decompiler/BlockGen/include/BlockGen.h:7:

luauDec-main/Decompiler/BlockGen/include/../include/Lifter.h:41:18: error: use of undeclared identifier 'LOP_JUMPIFEQK'; did you mean 'LOP_JUMPIFEQ'?
            case LOP_JUMPIFEQK:
                 ^~~~~~~~~~~~~
                 LOP_JUMPIFEQ

luauDec-main/Decompiler/../luau/Common/include/Luau/Bytecode.h:199:5: note: 'LOP_JUMPIFEQ' declared here
    LOP_JUMPIFEQ,
    ^
In file included from 
luauDec-main/main.cpp:3:
In file included from 
luauDec-main/Decompiler/Decompile.h:7:
In file included from 
luauDec-main/Decompiler/BlockGen/include/BlockGen.h:7:

luauDec-main/Decompiler/BlockGen/include/../include/Lifter.h:42:18: error: use of undeclared identifier 'LOP_JUMPIFNOTEQK'; did you mean 'LOP_JUMPIFNOTEQ'?
            case LOP_JUMPIFNOTEQK:
                 ^~~~~~~~~~~~~~~~
                 LOP_JUMPIFNOTEQ

luauDec-main/Decompiler/../luau/Common/include/Luau/Bytecode.h:202:5: note: 'LOP_JUMPIFNOTEQ' declared here
    LOP_JUMPIFNOTEQ,
    ^
In file included from 
luauDec-main/main.cpp:3:
In file included from 
luauDec-main/Decompiler/Decompile.h:7:
In file included from 
luauDec-main/Decompiler/BlockGen/include/BlockGen.h:7:

luauDec-main/Decompiler/BlockGen/include/../include/Lifter.h:41:18: error: duplicate case value 'LOP_JUMPIFEQ'
            case LOP_JUMPIFEQK:
                 ^

luauDec-main/Decompiler/BlockGen/include/../include/Lifter.h:26:18: note: previous case defined here
            case LOP_JUMPIFEQ:
                 ^

luauDec-main/Decompiler/BlockGen/include/../include/Lifter.h:42:18: error: duplicate case value 'LOP_JUMPIFNOTEQ'
            case LOP_JUMPIFNOTEQK:
                 ^

luauDec-main/Decompiler/BlockGen/include/../include/Lifter.h:29:18: note: previous case defined here
            case LOP_JUMPIFNOTEQ:
                 ^

luauDec-main/Decompiler/BlockGen/include/../include/Lifter.h:37:18: error: duplicate case value 'LOP_FORGPREP_INEXT'
            case LOP_FORGLOOP_INEXT:
                 ^

luauDec-main/Decompiler/BlockGen/include/../include/Lifter.h:36:18: note: previous case defined here
            case LOP_FORGPREP_INEXT:
                 ^

luauDec-main/Decompiler/BlockGen/include/../include/Lifter.h:39:18: error: duplicate case value 'LOP_FORGPREP_NEXT'
            case LOP_FORGLOOP_NEXT:
                 ^

luauDec-main/Decompiler/BlockGen/include/../include/Lifter.h:38:18: note: previous case defined here
            case LOP_FORGPREP_NEXT:
                 ^

luauDec-main/Decompiler/BlockGen/include/../include/Lifter.h:100:18: error: use of undeclared identifier 'LOP_JUMPIFEQK'; did you mean 'LOP_JUMPIFEQ'?
            case LOP_JUMPIFEQK:
                 ^~~~~~~~~~~~~
                 LOP_JUMPIFEQ

luauDec-main/Decompiler/../luau/Common/include/Luau/Bytecode.h:199:5: note: 'LOP_JUMPIFEQ' declared here
    LOP_JUMPIFEQ,
    ^
In file included from 
luauDec-main/main.cpp:3:
In file included from 
luauDec-main/Decompiler/Decompile.h:7:
In file included from 
luauDec-main/Decompiler/BlockGen/include/BlockGen.h:7:

luauDec-main/Decompiler/BlockGen/include/../include/Lifter.h:101:18: error: use of undeclared identifier 'LOP_JUMPIFNOTEQK'; did you mean 'LOP_JUMPIFNOTEQ'?
            case LOP_JUMPIFNOTEQK:
                 ^~~~~~~~~~~~~~~~
                 LOP_JUMPIFNOTEQ

luauDec-main/Decompiler/../luau/Common/include/Luau/Bytecode.h:202:5: note: 'LOP_JUMPIFNOTEQ' declared here
    LOP_JUMPIFNOTEQ,
    ^
In file included from 
luauDec-main/main.cpp:3:
In file included from 
luauDec-main/Decompiler/Decompile.h:7:
In file included from 
luauDec-main/Decompiler/BlockGen/include/BlockGen.h:7:

luauDec-main/Decompiler/BlockGen/include/../include/Lifter.h:100:18: error: duplicate case value 'LOP_JUMPIFEQ'
            case LOP_JUMPIFEQK:
                 ^

luauDec-main/Decompiler/BlockGen/include/../include/Lifter.h:90:18: note: previous case defined here
            case LOP_JUMPIFEQ:
                 ^

luauDec-main/Decompiler/BlockGen/include/../include/Lifter.h:101:18: error: duplicate case value 'LOP_JUMPIFNOTEQ'
            case LOP_JUMPIFNOTEQK:
                 ^

luauDec-main/Decompiler/BlockGen/include/../include/Lifter.h:93:18: note: previous case defined here
            case LOP_JUMPIFNOTEQ:
                 ^
12 errors generated.
make[2]: *** [CMakeFiles/luauDec.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/luauDec.dir/all] Error 2
make: *** [all] Error 2

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.