Page 1 of 1

.luc decompiling

Posted: Tue Nov 18, 2014 2:26 pm
by escapem
Hello!
Anyone can take a look on this files?
It's indefinitely must be a some sort of lua compiled script, but i can't find the decompiler...
I've tried luadec, but it don't work for this files :(
These files where unpacked from Farming simulator 15

https://yadi.sk/d/y5JGcpaacnRmD
https://yadi.sk/d/bYt_hPyncnRne

Re: .luc decompiling

Posted: Tue Nov 18, 2014 9:59 pm
by shakotay2
escapem wrote:I've tried luadec, but it don't work for this files :(
... because they don't have a standard lua header.

Code: Select all

Pos   Hex Data           Description or Code
------------------------------------------------------------------------
0000                     ** source chunk: vehiclemotor-header.luc
                         ** global header start **
0000  1B4C7561           header signature: "\27Lua"
0004  51                 version (major:minor hex digits)
0005  00                 format (0=official)
0006  01                 endianness (1=little endian)
0007  04                 size of int (bytes)
0008  04                 size of size_t (bytes)
0009  04                 size of Instruction (bytes)
000A  08                 size of number (bytes)
000B  00                 integral (1=integral)
                         * number type: double
                         * x86 standard (32-bit, little endian, doubles)
                         ** global header end **
You could try replacing

Code: Select all

Offset 0  1  2  3  4  5  6  7   
00000 1B 4C 4A 02 00 47 44 3A   .LJ..GD:
(not sure, the "D:" might belong to the following path)
by

Code: Select all

Offset 0  1  2  3  4  5  6  7   8  9  A  B  C  D  E  F
00000 1B 4C 75 61 51 00 01 04  04 04 08 00 48 00 00 00   .LuaQ.......H...
(0x48 = 72 dec. is the string length of the path including the "terminating" zero.)
Not sure about the EE 08.

Code: Select all

00010 2F 63 6F 64 65 2F 6C 73  69 6D 32 30 31 35 2F 62   /code/lsim2015/b
00020 75 69 6C 64 2F 66 69 6E  61 6C 62 69 6E 2F 64 61   uild/finalbin/da
00030 74 61 53 2F 73 63 72 69  70 74 73 2F 76 65 68 69   taS/scripts/vehi
00040 63 6C 65 73 2F 56 65 68  69 63 6C 65 4D 6F 74 6F   cles/VehicleMoto
00050 72 2E 6C 75 61 EE 08 00  11 15 00 22 00 43 E0 02   r.luaî.....".Cà.
Sadly this results in an endlos decoding loop when using ChunkSpy.
Same goes for unluac:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

edit2: ok, there are differences between Lua and LuaJIT opcodes so the above simple approach can't work

edit: decompiling features/lua functions from the lucs seems to me a waste of time (didn't try harder)

My suggestion would be to search here for mods which might have the lua files/features you want:
http://www.farming-mod.com/category/far ... ator-2015/

I checked Scania R730 Forest And Trailer V 1.0 and found some lua (= plain ASCII) files contained.

btw: is there an SDK with a lua compiler to create lucs (with this strange header) from lua?
(From what I read I assume it's possible to use mods with uncompiled lua files.)

Re: .luc decompiling

Posted: Wed Nov 19, 2014 5:40 pm
by escapem
First of all, thank you for your attention!

I've found that these files are actually contains the bytecodes, compiled with LuaJIT.
If someone have an interest, here is the project page: http://luajit.org/
So, this is explanation for the unusual header.
I was able to list code from the files, here is an example:

Code: Select all

-- BYTECODE -- 0x005cbcc0:33-37
0001    GGET     1   0      ; "ipairs"
0002    TNEW     2   3
0003    VARG     3   0   1
0004    TSETM    3   0      ; 1
0005    CALL     1   4   2
0006    JMP      4 => 0013
0007 => GGET     6   1      ; "fileWrite"
0008    TGETS    7   0   2  ; "fileId"
0009    GGET     8   3      ; "tostring"
0010    MOV      9   5
0011    CALL     8   0   2
0012    CALLM    6   1   1
0013 => ITERC    4   3   3
0014    ITERL    4 => 0007
0015    RET0     0   1
shakotay2 wrote: My suggestion would be to search here for mods which might have the lua files/features you want:
http://www.farming-mod.com/category/far ... ator-2015/

I checked Scania R730 Forest And Trailer V 1.0 and found some lua (= plain ASCII) files contained.

btw: is there an SDK with a lua compiler to create lucs (with this strange header) from lua?
(From what I read I assume it's possible to use mods with uncompiled lua files.)
Actually, these files where unpacked from the game client and contain developer objects.
Looks like they was compiled for performance measures, not because of security.
In mods we can use simple lua files, written in plain text.
But i'm working on mod, that must change some developer values, and making it without understanding of what actually all these files contains is the real headache :)
So, somebody have any suggestions about how to convert this bytecode in something "human readable"?

Re: .luc decompiling

Posted: Wed Nov 19, 2014 8:01 pm
by shakotay2
escapem wrote:So, somebody have any suggestions about how to convert this bytecode in something "human readable"?
seems there are some differences between JIT and standard lua opcodes.

You could try this tutorial: http://www.progamercity.net/ghack-tut/5 ... ripts.html

After 4 min I got a little bit bored and jumped to the end of the swf video.
Seems he could reconstruct 6 lua lines or so.

Good luck. :)

Re: .luc decompiling

Posted: Wed Nov 19, 2014 8:55 pm
by escapem
This is exactly what i need!
Sadly, but looks like my mod should wait, while i trying to write some sort of re-assembler for all this stuff...
However, your assistance was really helpful, thanks again!

Re: .luc decompiling

Posted: Mon Dec 29, 2014 9:22 am
by JohnHudeski
This is what you need
Lua VM 5.1
I am currently doing this for 5.0
It is the most boring thing I have ever come across.