Git Product home page Git Product logo

luadec51's Introduction

Overview

LuaDec for Lua 5.1 is a Lua decompiler targeting lua versions 5.1.x

It is based on Hisham Muhammad's luadec which targeted lua 5.0.x

LuaDec51 is free software and uses the same license as the original LuaDec

It currently has the following functionality:

  • Full support for Lua 5.1 opcodes
  • Added support for files with debug informations stripped
  • Includes a heuristic that tries to determine where locals have been declared
  • When it encounters something undecompilable it tries to continue with the decompilation
  • It has a built in disassembler, with easy to read disassembly
  • It includes two ruby based tool that help further correction of the decompiled scripts

Status

Current version is 2.0

Currently luadec51 can decompile most constructs of lua scripts, including scripts that have debug informations stripped. It still has some shortcomings:

  • Complex conditional expressions usually break the output
  • while and repeat..until loops are unhandled
  • The local decalration guesser usually guesses locals declaring NEWTABLE and SETLIST opcodes wrong

Planned for luadec 3.0:

  • A new conditional handling engine

Usage

To use luadec you have to compile it first. Read the following sections for more information

To use the ruby based tools compare and luadecguess you need to have ruby version 1.8 installed on your computer as well

To simply decompile a script run luadec as following:

luadec filename.luac > filename.lua

This should decompile filename.luac to filename.lua

To disassemble a file use the -dis option:

luadec -dis filename.luac

There are some more options, usually for debug purposes, or for cases where the built in local guesser guesses wrong. Use -h to get a complete list of usable parameters

Download

The source code of LuaDec 5.1 and windows binaries can be downloaded from the GitHub page. You can find windows binaries under the Releases tab. You might need to have the Visual Studio 2013 C++ redistributables installed for the project to work.

Compiling

You need to download a version of lua you want to use, and put it into the lua directory. After that you can use the Makefile in the build directory to compile both projects. Alternatively there is also an MSVC directory which contains a Visual Studio 2013 project file you can use to compile luadec.

There is also a set up luadec project for MSVC++ 2008, that uses a modified lua 5.1.4 version with unicode support at http://winmo.sztupy.hu/luadec.html. Do not use this project tree for usage with generic lua files, because it won't work (it will expect numerals in Q24.8 format, and strings in unicode)

Binaries

There are currently two separate binaries provided for lua 5.1. Both are windows binaries, and both contain lua 5.1.4 binaries (intperpreter and compiler) too

The generic lua 5.1 version can be found at the project's download page The unicode mobile version used in HTC phones can be found at http://winmo.sztupy.hu/luadec.html If you have compiled luadec for some other lua 5.1 version or operating system, then feel free to contact me, so I can add them to the project

Changelog

LuaDec 2.0.2 [4/Dec/2014]

  • Minor fixes for the {...} construct
  • Makefile for generic builds

LuaDec 2.0.1 [17/May/2012]

  • Fixes for handling unknown upvalues

LuaDec 2.0 [10/Mar/2009]

  • LuaDec has now a built-in heuristic to determine local declaration and releases
  • Luadec has an option to output the LDS2 string of a file

LuaDec 1.9

  • Some changes regarding LDS(2) strings and for loops (it's still a bit unstable)
  • LuaDec has a new option to disassemble instead of decompile

LuaDec 1.0

  • fixed OP_TFORLOOP handling
  • added LDS2 functionality to luadec

LuaDec beta 6

  • fixed a crash where luadec encounters unhandled boolean constructs
  • luadecguess has now a new heuristic called "fast guess" for large scripts

LuaDec beta 5

  • luadecguess can now be parameterized, and is more powerful

LuaDec beta 4

  • fixed upvalue handling
  • fixed some local variable handlings
  • added luadecguess: a local variable declaration place guesser

LuaDec beta 3

  • fixed OP_TFORLOOP
  • fixed loop variable handings
  • added command line options to handle local variable declarations (LDS strings)

LuaDec beta 2

  • added some workarounds for the crashes. Luadec might output lots of garbage lua code, but it tries not crashing
  • fixed OP_TEST (hopefully)

LuaDec beta 1

  • Corrected OP_FORPREP - OP_FORLOOP
  • Added some more warnings
  • Added automatic local variable declarations where possible

alpha 2

  • Fixed constant loading errors
  • fixed function variables
  • Added handlers to the new opcodes
  • Some changes to OP_TEST

alpha 1

  • Initial Version

Credits

LuaDec51 is based on Hisham Muhammad's luadec

The internals of Lua5.1 was learned from Kein-Hong Man's A No-Frills Introduction to Lua 5.1 VM Instructions

Also thanks to anyone involved in helping me on XDA

Contact us

Contact information at http://winmo.sztupy.hu

luadec51's People

Contributors

sztupy 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  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  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

luadec51's Issues

It will appear when interpreting large files Segmentation fault

Core was generated by `./luadec /root/login.lua'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:62
62 ../sysdeps/x86_64/multiarch/strlen-avx2.S: No such file or directory.
(gdb) where
#0 __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:62
#1 0x00007f3546003e3e in __GI___strdup (s=0x0) at strdup.c:41
#2 0x000055d603efc78a in ProcessCode (f=0x55d6043e0c40, indent=0) at ../luadec/../luadec/ldprint.c:1969
#3 0x000055d603efd920 in ProcessCode (f=0x55d6043df860, indent=0) at ../luadec/../luadec/ldprint.c:2250
#4 0x000055d603efe031 in luaU_decompile (f=0x55d6043df860, dflag=0) at ../luadec/../luadec/ldprint.c:2342
#5 0x000055d603ef44d5 in main (argc=1, argv=0x7fff33670fd0) at ../luadec/../luadec/luadec.c:410

Crash in AddToTable

i try to decompile a file. but crash at

void AddToTable(Function* F, DecTable * tbl, char *value, char *key)
{
   DecTableItem *item;
   List *type;
   int index;
   if (key == NULL) {
      type = &(tbl->numeric);
      index = tbl->topNumeric;
      tbl->topNumeric++;
   } else {
      type = &(tbl->keyed);
      tbl->used++;
      index = 0;
   }
   item = NewTableItem(value, index, key);  <-- Crach at this
   AddToList(type, (ListItem *) item);
   // FIXME: should work with arrays, too
   if (tbl->keyedSize == tbl->used && tbl->arraySize == 0) {
      PrintTable(F, tbl->reg, 0);
      if (error)
         return;
   }
}

because CloseTable delete a table so index is invaild.

void CloseTable(Function * F, int r)
{
   DecTable *tbl = (DecTable *) PopFromList(&(F->tables));
   if (tbl->reg != r) {
      SET_ERROR(F,"Unhandled construct in table");
      return;
   }
   DeleteTable(tbl);
   F->Rtabl[r] = 0;
}

i upload a file. you can test it.

issue compiling on a mac

I made an xcode proj for a mac "Terminal project" and used the language "C"
I downloaded the lua source files and drag/drop it to the Source files subdir in xcode and pressed ok
took the lua 5.1 source code and dragged and dropped it in the Source files subdir in xcode
build and run
screenie http://qs.lc/cx3
debug log http://pastebin.com/dNyMJhwu

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.