FORUMS
Remove All Ads from XDA

[UTILITY] Lua 5.1 tools: compiler, decompiler, snippets & extendable lua.dll with SDK

1,061 posts
Thanks Meter: 879
 
Post Reply Email Thread
18th February 2009, 01:57 AM |#61  
12aon's Avatar
Retired Senior Moderator
Thanks Meter: 473
 
Donate to Me
More
Quote:
Originally Posted by sztupy

If one would do a reassembler for lua then these kind of things could be changed easily, but I've never heard of one (saw on a forum, that someone is making one, but no links/DL yet)

So no luck with the hex editor then? I wonder how people change the other lua files they do? I wish I was smart and stuff
18th February 2009, 11:14 AM |#62  
sztupy's Avatar
OP Inactive Recognized Developer
Flag London
Thanks Meter: 879
 
Donate to Me
More
Quote:
Originally Posted by 12aon

So no luck with the hex editor then? I wonder how people change the other lua files they do? I wish I was smart and stuff

you can hexedit it, but it can break things if done incorrectly.
18th February 2009, 03:58 PM |#63  
smotrs's Avatar
Senior Member
Flag So. Calif.
Thanks Meter: 0
 
More
Quote:
Originally Posted by sztupy

you can hexedit it, but it can break things if done incorrectly.

Heh, that's an understatement.
18th February 2009, 05:37 PM |#64  
pcarvalho's Avatar
Inactive Recognized Developer
Thanks Meter: 215
 
Donate to Me
More
very nice work being done here

hex editing is...#!%&%/...not easy

so any more progress in full decompiling tf3d lua? i'm waiting on this one cause then i'll be able to make the QVGA port final...and then start making new things...

thanks and keep it up
20th February 2009, 03:53 PM |#65  
sztupy's Avatar
OP Inactive Recognized Developer
Flag London
Thanks Meter: 879
 
Donate to Me
More
Quote:
Originally Posted by pcarvalho

very nice work being done here

hex editing is...#!%&%/...not easy

so any more progress in full decompiling tf3d lua? i'm waiting on this one cause then i'll be able to make the QVGA port final...and then start making new things...

thanks and keep it up

I've put that project a bit aside because of the other, but I get back to it.
20th February 2009, 07:50 PM |#66  
smotrs's Avatar
Senior Member
Flag So. Calif.
Thanks Meter: 0
 
More
Quote:
Originally Posted by sztupy

I've put that project a bit aside because of the other, but I get back to it.

Well, were looking forward to any progress you make. Keep up the good work and hope your current project is going well.
21st February 2009, 11:48 PM |#67  
sztupy's Avatar
OP Inactive Recognized Developer
Flag London
Thanks Meter: 879
 
Donate to Me
More
LuaDec beta 0.3
LuaDec beta 0.3 released

Fixed bugs:
- OP_TFORLOOP is fixed
- loop variable handing is fixed

New features:
- added command line options to handle local variables

With this version you are able to tell luadec where to declare local variables. The format is the following: -l LDS, where LDS stands for "Local Description String". It contains numbers which describe on which opcode should luadec declare a new local variable. ; separates functions and , separates registers. For example -l ;0,2 will mean to declare the first register as a local variable in the first function.

For example to decompile 4692e326_manila succesfully you have to use "-l 4,5;;0,0,10,11;0,0,8" (this will declare 5 local variables in different points of the scrfipt).

I attached some succesfully decompiled scripts (from the stock Raphael TF3D), namely:
Code:
01d9e30a_manila.lua
075987ec_manila.lua
0d465002_manila.lua
1f2972b4_manila.lua
283226d1_manila.lua
42b71610_manila.lua
4692e326_manila.lua
584477c0_manila.lua
5e085a76_manila.lua
5e8e48df_manila.lua
5f880c80_manila.lua
6efe8603_manila.lua
71552a24_manila.lua
7564a2d6_manila.lua
77faa36d_manila.lua
I also added a patch file, which will show what you have to patch to get to the (almost) correct decompilation (success rate is _very_ high if you know where to declare locals)

Because determining where to declare locals is tiresome suspected features for next version will be:
- Upvalue handling
- Heuristics to detemine where to add local variables

I've just DL'ed the leaked TP2 TF3D files, so I think I start to work on decompiling that next.
Attached Files
File Type: zip tf3d_raphael_decompile.zip - [Click for QR Code] (6.0 KB, 70 views)
23rd February 2009, 12:45 PM |#68  
12aon's Avatar
Retired Senior Moderator
Thanks Meter: 473
 
Donate to Me
More
Could you elaborate on the local variables, what are they or do they do? Where can I find what these locals are supposed to be? I didn't come across any decompiling errors, nice work man! Thanks a lot for making all this possible, 12

Edit: Maybe you could explain using the manila_file I'm trying to change (you can find a copy here here). Just tell me if I'm asking to much of you, 12
23rd February 2009, 01:48 PM |#69  
sztupy's Avatar
OP Inactive Recognized Developer
Flag London
Thanks Meter: 879
 
Donate to Me
More
Quote:
Originally Posted by 12aon

Could you elaborate on the local variables, what are they or do they do? Where can I find what these locals are supposed to be? I didn't come across any decompiling errors, nice work man! Thanks a lot for making all this possible, 12

Edit: Maybe you could explain using the manila_file I'm trying to change (you can find a copy here here). Just tell me if I'm asking to much of you, 12

usually all variables are global in lua. So for example if you have a line like

Code:
Something = 0
you assign 0 to the global variable called Something. Fortunately the names and positions of global variables are known from the compiled lua script

local variables however are simply registers in a function, and they are not stored in the compiled script explicitly, so if someone writes

Code:
local Something = 0
then this variable will not be visible in the compiled version. Unfortunately to succesfully decompile something one has to know where the original user put these local declarations. Fortunately this can be "brute-forced" out in a lot of smaller scripts, and I'm having good progress on this.


Q: what do you want to do with that manila file?
23rd February 2009, 03:58 PM |#70  
smotrs's Avatar
Senior Member
Flag So. Calif.
Thanks Meter: 0
 
More
So is there anyway to resolve the, "-- Warning: missing end command somewhere! Added here" errors or warnings? Or do they not affect the re-compiling if the variables are in place?
23rd February 2009, 04:11 PM |#71  
sztupy's Avatar
OP Inactive Recognized Developer
Flag London
Thanks Meter: 879
 
Donate to Me
More
Quote:
Originally Posted by smotrs

So is there anyway to resolve the, "-- Warning: missing end command somewhere! Added here" errors or warnings? Or do they not affect the re-compiling if the variables are in place?

if the variables are in place then most of the time there aren't any warinigs or decompilation errors. Currently I'm running a brute force decompilation on the 365 script (both embedded and separate) files from TP2's manila. 89 scripts were already processed and from them 39 have been succesfully decompiled (which means that recompiling them will result in the original file).

Because lua stores functions in the luac file separately they can be decompiled separately, but compiling the script can only be done is everything is fine. For the other scripts (50 from 89) 75% of the functions are decompiled succesfully, and the others have to be corrected manually (usual errors are missing or misaligned "end"-s and of course missing local declarations). After manual correction these scripts should recompile to the same too.

I'm doing the check whether the recompiled files are the same using the compare script I attached earlier. It uses disasm's output to check whether the disassembly of the two files are the same EXCEPT for the line numbering information (that doesn't change anything semantically). Nothing else matters. If the disassembly is the same then the script will do the same so it doesn't matter whether there are any warnings or any other decompilation "errors" in the output.
Post Reply Subscribe to Thread

Tags
lua, manila, mod, tf3d, touchflo

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes