.LUB Decompilation

Extraction and unpacking of game archives and compression, encryption, obfuscation, decoding of unknown files
lllsondowlll
Posts: 5
Joined: Mon Sep 18, 2017 5:12 am

.LUB Decompilation

Post by lllsondowlll »

About 10 years ago, a friend and I discovered how to decompile the attached lub files. Since then I had a hard drive crash and lost my backups in the move on how to perform this. I've been trying based on memory to hex edit the lub files into a format luadec could read but I keep getting stuck on how we were generating the stripped table.

From what I can remember, we were converting this luac 5.0 header to a luac 5.1 that luacdec 51 could read by changing the header, and cutting some of the data (namely the size code) near " C63E" (which can be found in every lub) and pasting it under the 51 header. There were some other steps needed such as generating a checksum which my memory is hazy on, and the data at the footer of the luac51 file which I simply cannot find out how to generate.

Luckily, I am in possession of SOME of the unpacked lubs which I've been trying to use as a comparison. I simply just need to modify this file back to a format where a decompiler can read. This is why I am reaching out as this has been taking up a LOT of my time and figured someone here could point me in the right direction. I've attached two sample files with four formats: Lub, Lua, Luac50, and Luac51.

Please, if anyone could shed some light on to this so I can get decompilers to read the original, I would be extremely grateful.
lllsondowlll
Posts: 5
Joined: Mon Sep 18, 2017 5:12 am

Re: .LUB Decompilation

Post by lllsondowlll »

Nevermind I got it figured out
Acewell
Posts: 706
Joined: Fri Aug 08, 2014 1:06 am

Re: .LUB Decompilation

Post by Acewell »

what was your solution? i would like to try what worked for you. :)
i've seen lub files from other games before and i wondered if they could be converted back to lua.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: .LUB Decompilation

Post by aluigi »

@lllsondowlll
feel free to post your code on github so other people (and you if you have another hdd crash :) ) don't have to reinvent the wheel
lllsondowlll
Posts: 5
Joined: Mon Sep 18, 2017 5:12 am

Re: .LUB Decompilation

Post by lllsondowlll »

By the time I figured out how to do it by hand, I stumbled on some source code a few days later for a patchy unluac50. I made some modifications to the code (in particular fixed a loop issue as well) to target this native luac50 format. This may be more help for people to sift through than me explaining how to do it by hand :lol:

https://sourceforge.net/u/tomy/unluac/ci/default/tree/

Here is one of the main issues with this source:
decompile\Registers.java

Code: Select all

 public Target getTarget(int register, int line) {
    if(!isLocal(register, line)) {
      throw new IllegalStateException("No declaration exists in register " + register + " at line " + line);
    }
    return new VariableTarget(decls[register][line]);
  }


and here is the "fix"

Code: Select all

  public Target getTarget(int register, int line) {
    if(!isLocal(register, line)) {
      decls[register][line] = new Declaration("_TMP_", 0, 0);
    }
    return new VariableTarget(decls[register][line]);
  }