yashsingh1/xdaforums huggingface dataset:
[Windows Mobile Development and Hacking General] sztupy:
LuaDec 0.4

What's new:

Corrected upvalue handling

Fixed some ewrrors when missing locals

Added luadecguess: a luadec LDS guesser

How to use luadecguess:

1. run luadecguess on a luac file, and it will try to guess the correct LDS pattern. It will take some time. After some time has elapsed (and after some luac ciompilation errors) it will print out a string that you should use with declua.

For example if you run luadecguess on 1f3be060_manila_128E8.luac it will print out: 24;0;0,6;0,0,4;0;0;0;0;0;; next you have to run luadec with this string after the -l part, so: luadec -l 24;0;0,6;0,0,4;0;0;0;0;0;; 1f3be060_manila_128E8.luac and so the script should decompile fine.

I attached 128 scripts from TouchPro2's manila, that have been decompiled succesfully. All of these scripts recompile to the original luac file they were decompiled from! I also attached the originals in case you don't believe me :)

EDIT: you can use the -d option in luadecguess to get some debug information
[Windows Mobile Development and Hacking General] smotrs:
Ok, maybe I missed something somewhere. Whats the 128E8.luac on the end of the file?

Also, you typo'd your instruction, minor as I knew what you menat and probably most people using your tools knew what you menat as well. But you say,

You obviously meant run luadec not run luadecguess.
[Windows Mobile Development and Hacking General] NisseDILLIGAF:
Hi...

I'm trying to figure out how to decompile, change a line in the file and then compile a manila file...

I looked at this post

http://xdaforums.com/showpost.php?p=3291728&postcount=14

But I cant find the file luaconv...??

I need that to Convert it to ascii and back to unicode, right?

Keep up the great work! :)
[Windows Mobile Development and Hacking General] 12aon:
Ok I now have a script that seem fully decompiled to me but when I try to import it into the m9editor (I know, but it's easier for now) it complains about the the invalidness of the lua signature, I attached the file with the changes I made. Is this file compilable or is it not fully decompiled yet, 12
[Windows Mobile Development and Hacking General] 6Fg8:
You cant import sourcecode in m9editor, you have to compile it first, and then import the output of the compiler (the p-code). A warning though: the import function is highly experimental, especially Q16.16 numbers are known to be not working correctly.
[Windows Mobile Development and Hacking General] 6Fg8:
I removed luaconv because its outdated. You may use the "convert to ANSI" function in m9editor for embedded scripts to accomplish that (export script ANSI converted for standalone scripts).
[Windows Mobile Development and Hacking General] NisseDILLIGAF:
aha .. of course :p

But if I have a lua script file and want to compile it to a functioning manila file...

...how do I do that?
[Windows Mobile Development and Hacking General] sztupy:
I usually use the bundled luac (because it handles Q16.16 numbers), then use your (outdated) luaconv utility to convert it back to unicode. This never failed for me.
[Windows Mobile Development and Hacking General] sztupy:
use luac, that is shipped with luadec0.4

run "luac -s filename.lua" and you will get a luac.out file, which is a compiled ascii lua file. Convert it to unicode (I prefer the outdated luacconv for this ;) ), and you're ready
[Windows Mobile Development and Hacking General] sztupy:
thank god I have it DL'ed... without it I can't batch process scripts :)
[Windows Mobile Development and Hacking General] sztupy:
It was an embedded script in a mode9 file. m3editor uses this filename format to extract those scripts

Oh, yep :)
[Windows Mobile Development and Hacking General] NisseDILLIGAF:
Thanx...

I found an old .zip file from 6Fg8 with luacconv :)

This worked fine...

Thanx for the help :)
[Windows Mobile Development and Hacking General] sztupy:
It compiles, but not into the original file, so it needs some tweaking. I'll look at it.
[Windows Mobile Development and Hacking General] bedoig:
Would someone mind uploading luaconv? I seem to have erased my copy when moving to a new version of m9editor.

sztupy - maybe you could add it to your latest zip? I find it more convenient not to have to use m9editor if I'm working with standalone scripts.

Thanks!
[Windows Mobile Development and Hacking General] sztupy:
Here you go. Took a while, but this will recompile to the original.
[Windows Mobile Development and Hacking General] sztupy:
added to the 0.4 zip file. hope 6fg8 doesn't mind it :)
[Windows Mobile Development and Hacking General] bedoig:
Thanks! You and 6fg8 are making this too easy :)
[Windows Mobile Development and Hacking General] sztupy:
looking at the correctly decompiled file I found some lines like this:

"\\Windows\\Gecko.lnk\0\4\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"

I don't think this was made by HTC, so it might be caused by the edits... Can you summarize what did you change and what not?
[Windows Mobile Development and Hacking General] 6Fg8:
Ah now i understand why i failed a few days before; i used the offical lua compiler and got weird results. Ok i'll add it to the m9editor thread again, be cautious though.
[Windows Mobile Development and Hacking General] 6Fg8:
no problem, you're welcome to bundle it where you like. Just wondering it doesnt throw errors, that was a really quick hack.
[Windows Mobile Development and Hacking General] sztupy:
It throws errors if you try to asciize an ascii file or unicodize an unicode file or if the file is not a compiled script (I usuallzy run it on each file in the directory, and it drops an error that it couldn't asciize manila.exe :) ). And it will hang if someone tries to unicodize a file that was NOT compiled with the "-s" option.

And I think it will break if you supply it UTF-8 encoded strings, but this is just a guess :)

It might have other bugs of course, but I hope not, because the toolset depends on it :)
[Windows Mobile Development and Hacking General] smotrs:
Ok, so do I just use lucaconv to convert the standalone _manila lua file to ascii, then run luadecguess on the ascii file? I guess what I'm missing is, what file to I pass to luadecguess?
[Windows Mobile Development and Hacking General] sztupy:
No, that's why I compiled both the compiled and the interpreter in Q16.16.

But you might want to add a "compile and import script" button, which will compile the script (with -s set), convert it to unicode and then embed it in a mode9 file :)
[Windows Mobile Development and Hacking General] sztupy:
Yes, you have to run it on the ascii compiled lua file. You might want to use the -d option to get some debug information back, for example:

luadecguess -d 5a19374f_manila.luac

where 5a19374f_manila.luac is the file I got from 12 after conversion to ascii.

It will drop a line like this:

0;0;0;;;0,15,33,52;0,0,11,12,16;0;;7,8,9;0,0,5;

which is unfortunately incorrect, but that's why there are optoins to do manually debugging :)
[Windows Mobile Development and Hacking General] 6Fg8:
ok its clear now, i was on the wrong track then.

Quite logical if i rethink it, anyway, mindstuck :)

That would be fun to do. Just have to check for return values for successful / failed compilation, to show compilation errors or continue import. Do you know if they're set?
[Windows Mobile Development and Hacking General] bedoig:
Now that would be great!
[Windows Mobile Development and Hacking General] sztupy:
luac won't output anything if something goes wrong AND will write the error to the stderr. It's return value might indicate something too, but that I haven't checked.
[Windows Mobile Development and Hacking General] 12aon:
I think that line was created by verizon when they created this landscape mode to link it to their appstore. I think it can be removed in the source file, I only need the gecko link. That and the Time management, contacts, messaging, Email, Browser and Applications text for now. I still need to do some reading before I fully get handling compiling and decompiling scripts. Will do that tonight:) Awesome work man, can't stop saying it, 12
[Windows Mobile Development and Hacking General] sztupy:
If you have a correct decompiled script, then modifying the text in it should be self-explanatory. After modification compiling is easy too:

luac -s filenname.lua
luaconv luac.out xxxxxxxx_manila asc2uni

and you get a xxxxxxxx_manila which is compatible with m9editor and/or TF3D

correct decompilation is a bit harder, but I try to ease it even more

non-correct decompilation is easy, but the file you get won't be usually recompilable to a working file
[Windows Mobile Development and Hacking General] 6Fg8:
Ok that should do for handling errors.

That luadecguess thingy is great, played around with it a bit. Once again, sztupy, congrats on your awesome work.

Just one question regarding luadecguess: i used it in the same directory where the scripts are, and it ran fine. When i called it using a long path+filename i got a syntax warning from luadisasm. Am i doing something wrong?

T:\privat\HTC\m9editor\m9edit\bin\Debug>luadecguess.exe "T:\privat\HTC\MANILAS\a
ll structured\mode9+luac\scripts\1f3be060_manila_128E8.luaA"
Lua 5 disassembler 1.2, by Mike Lankamp.
Syntax: luadisasm <src-file>

The program will read a Lua 5.0 or 5.1 object file and disassemble it to
stdout.
[Windows Mobile Development and Hacking General] sztupy:
luadecguess runs other programs (luadec, luac and luadisasm), and I think when they are run they can't find the original filenames. Gonna fix that sometime.

and it's a rubyscript2exe-ized ruby script which might cause other problems too (rs2e compressed files don't like if the actual username that is logged in contains spaces or UTF-8 characters)...

because it's a brute force application it's not really good for inclusion in m9editor, because for some scripts it might take 10+ minutes to output anything. But I think it can be useful to include a patch file, where there are MD5 hashes of files and an LDS string for each hash. If m9editor encounters such a hash it will know which LDS to use when running luadec. I'll try to modify luac too, so it will not only compile a script but print it's LDS too.
[Windows Mobile Development and Hacking General] 6Fg8:
I had something like that on my mind - calculate hashes and use previously calculated LDS during luadec. The brute force could collect LDS in background (almost) invisible to the user.

Noticed the long runtime when luadecguessing 059a6b08_manila, but the results are pleasing - hard to resist not to built in something like that :) So thanks giving that a thought.
[Windows Mobile Development and Hacking General] smotrs:
Well, the 27a13690 (main Weather lua script) has been running since about 12:00pm, now 2pm. So 10+min is for really small ones I take it. :)

Ohh, this is on a Dual 3.2Ghz Quad core system with 8GB ram. :)

It's been spitting out lines like the following this entire time,

;;;;;;13,21,92,129,138,139,140;32;;92,95,96;
[Windows Mobile Development and Hacking General] 6Fg8:
Maybe we need something like "LuaSETI" then :D

BTW nice hardware
[Windows Mobile Development and Hacking General] smotrs:
Ooohh, LuaSETI, I like that idea. :D

Yeah, hardware is my work computer, the video card alone cost almost half what the rest of the computer cost. I use SolidEdge at work, so we need plenty of power.
[Windows Mobile Development and Hacking General] 6Fg8:
OMGawd ... last time i had to do with FEM it was running on a host (20+ years ago) ... blast the budget of the average home user like me :D
[Windows Mobile Development and Hacking General] 12aon:
Ah I read wrong I changed the the VZApp.lnk into gecko.lnk and the text VZAppstore (or something like this) into GeckoApSt. That's all I managed to change by hexing. I'll attach the original the weird long code is already in there, 12

Edit: scratch that, you were right in the original it's still normal, has been in there since I started playing with it:)
[Windows Mobile Development and Hacking General] smotrs:
I hear ya there. Before I got my work hand-me-down, I was using a 333 celeron with 512mb ram. Now I have a 2Ghz with 2gb ram for my home computer. This was just 18 months ago.
[Windows Mobile Development and Hacking General] 6Fg8:
Allright, so i praise myself lucky ... after i dont know how many hardware upgrades i currently use a Q9450 quadcore 2.67 GHz with 4gb ram and 2x GeForce 9600 with currently 3 monitors attached (cant live without that :) - nice handling with fsx too :D). Far more than i've to live with at work (although 4 screens attached there). I love screen real estate.
[Windows Mobile Development and Hacking General] smotrs:
So does luadecguess report a completed time or elapsed time when it's done or anything? I'm gonna leave this thing running all night and see if it's done in the morning. Would be nice to know if it finishes 5 minutes after I leave or 5 minutes before I show up the next morning.
[Windows Mobile Development and Hacking General] smotrs:
While luadecguess is running, I see some of these popping up,

"luac: out:20: '<name>' expected near ','"​

What exactly do they mean?
[Windows Mobile Development and Hacking General] NisseDILLIGAF:
I've been running luadecguess now for ~6 hours! :eek:

I have a feeling it's stuck in a loop or something...?

all that shows are this...

luac: out:8: '<name>' expected near ','
luac: out:8: '<name>' expected near ','
luac: out:8: '<name>' expected near ','
luac: out:8: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:12: function arguments expected
luac: out:12: function arguments expected
luac: out:8: function arguments expected
luac: out:8: function arguments expected
luac: out:8: function arguments expected
luac: out:8: function arguments expected
luac: out:8: '<name>' expected near ','
luac: out:8: '<name>' expected near ','
luac: out:8: '<name>' expected near ','
luac: out:8: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','
luac: out:10: '<name>' expected near ','

And when I look at the 'out' file... it's showing pretty much the same all the time... there is changes, but it looks like it's stuck in a function or something...

-- Decompiled using luadec 0.4 by sztupy (http://winmo.sztupy.hu)
-- Command line was: -f 2 -l ;;12,29,39,89,136;8;;4;41,42,44,45;28;;20,21;26,26,57,58,59; x.luac

DecompiledFunction = function(l_2_0)
selectorDestinationPosition = selectedPositions[l_2_0]
trace("********** selectorDestinationPosition: " .. tostring(selectorDestinationPosition))
tabControl.onUpdate:connect(TabControlOnUpdate)
Navigate(URLS[navigateToBucket], delayNavFrameCount ~= 0 or navigateToBucket == nil)
navigateToBucket = nil
local , l_2_1 =
end

I will let it run a couple of hours more... :rolleyes:
[Windows Mobile Development and Hacking General] smotrs:
I was getting the same thing the first time around. So I cancelled it and started it again with the -d option which then spit out row upon row of what I posted a little bit ago. Been running since around 12pm and I left work at 4:30pm with it still running.

See what it shows in the morning. Have another one running on my home computer. Just gonna let it run all night and see what is to be seen before I leave for work.

Hopefully it's not a loop.

Edit: Ok, mine finally ended. I have a long o line with a bunch of numbers and semi-colons which I guess is what I use to decompile it. I also ended up with a bunch of these toward the end,

"luac: out:229: no loop to break near 'end'"​
[Windows Mobile Development and Hacking General] sztupy:
yes I started a guessing on all the files at work (two Quad Xeon computers used for video compressions but I told the boss not to compress anything today :) ). I hope they finish til I get there :)
[Windows Mobile Development and Hacking General] sztupy:
use -d option, then it will print out where the guessing actually is
[Windows Mobile Development and Hacking General] sztupy:
the guessing is done the following way:

first it disassembles the input and searches for places where locals can be defined.

next it goes function by function guessing all the places where locals can be.

Then for every LDS it decompiles the luac, recompile it then compares it with the original. If they are the same then it goes to the next function. If not it loads the next LDS, etc...

the errors pop up, because sometimes luadec doesn't decompiles a compilable script, so the compiler says no. This is pretty usual... And yes... for large functions, where there are a lot of places where locals can be defined it takes a looooong time to do the job. I try to improve it a bit more.

Or make a luadecguess-lite which will simply stop after around 100 steps/function, or at the first time it encounters something compilable. That should be fast enough for everyday use.
[Windows Mobile Development and Hacking General] sztupy:
Okay. I try to decompile the original then imho you should use that as a base instead of hexediting :)
[Windows Mobile Development and Hacking General] smotrs:
Is it normal for it to change all the local names? what I mean is, when looking at the LUA within m9editor, what variables it could grab looked like this

loc_0, loc_1, etc..​

after guessing and decompiling it looks like this?

l_1_0, l_1_1​

By the way, this is what I got out of the 27a13690_manila (weather lua file from Touch HD).

311,314;;240,241,242;;111,112,113,114,118;54,55,56,57,58;8,127,128,129,130;138,139,140;32;;92,95,96; 27a13690_manila.luac

looking at the luadec'd file, it looks like I still have a long way to go.
[Windows Mobile Development and Hacking General] NisseDILLIGAF:
ok .. luadecguess worked for ~10 hours then it generated an error in windows...

I had to terminate it :(

I'm on it again, lets see how it goes this time :rolleyes:

btw... the file I'm trying do decompile is manila.luac (2a3d01cc_manila) from the new TF3D 3.0 (Diamond2)
[Windows Mobile Development and Hacking General] sztupy:
if you get very large numbers that usualy means it couldn't determine the variable locations right... I try to fix some of these issues and make the app more reliable in getting the job done. The ;; sections mean however that some functions were decompiled succesfully!

I changed the local declarations from loc_registernum format ... to l_functionnum_registernum format, so they won't clash... although they are a bit more crytptic this way. But it makes refactoring local variable names very easy (serach/replace ;) )
[Windows Mobile Development and Hacking General] sztupy:
luadec sometimes crash with some LDS strings. If you use Vista/Win7 then try to disable "xxxxx has stopped working" dialog boxes using:

HKCU\software\microsoft\windows\windows Error Reporting --> dontShowUI=1
[Windows Mobile Development and Hacking General] sztupy:
LuaDec 0.5

LuaDec 0.5 released

Featuring: a new and improved luadecguess

luadecguess can now parameterized:

Options:
-d : Show debug informations
-p num : Search for maximum `num' opcodes for local declarations (default: 70)
-l num : Search for maximum `num' locals per function (default: 3)
-f num : Only guess function number `num' (0 based) (default: all)
-s num : Only take `num' steps then use the best LDS found (default: infinity)
-t type : Only search until the first LDS for which
1: 100% of the lines are the same (default)
2: 100% of the opcodes are the same
3: 75% of the lines are the same
4: 75% of the opcodes are the same
5: 50% of the lines are the same
6: 50% of the opcodes are the same
7: 25% of the lines are the same
8: 25% of the opcodes are the same
9: the script can at least be compiled

which means to get a fast guess you can for example use luadecguess -s 10

it can now guess even better, so for example for 5a19374f_manila.luac (the one from 12) it could guess the

0;0;0;;0;0,15,33,52;0,0,0,8,16;0;;14,20;0,0,4;0,0,4;0,0,9;0,0,14;0,7,9,20,23;0,7,9,20,23;0,0,4;0,0,9;0;0;0;0;0,42,49;0,0,0,12,16;0,0,0,4,11;0;0;0,9;

string in around 1 minute, and this string made a script that was around 95% identical to the original.

But usually luadecguess fails on the main body, so it is advised to use 0 as the first number (before the first ; ) unless it really finds something better.

Compare has changed too, now it can compare functions separately and give you a nice statistic about the changes in the files.

I attached the decompiled 5a19374f_manila.lua file. The luadecguess is at the usual place.
[Windows Mobile Development and Hacking General] smotrs:
Ok, tried the new version of luadecguess, this time after about 30min it gave a Windows Dr Watson type error and exited with the following on the DOS screen,

luac: temp.luatemp:14: function arguments expected near 'l_13_4'
Unable to open input file "luac.out"
0428: best: 59 57 59 2 ;;;;;;;;;;;;;0,3,6,12,22;0;14,35;;;0;0;0;;1;;;;12;0;21,29;1;;1;1;12;12;0;;;0;;42;;0;1;0;0,0,5,7;8;0;0;;;
0428: actual: 59 0 0 0 ;;;;;;;;;;;;;0,3,6,12,17,31;0;14,35;;;0;0;0;;1;;;;12;0;21,29;1;;1;1;12;12;0;;;0;;42;;0;1;0;0,0,5,7;8;0;0;;;
C:/DOCUME~1/user/eee/eee.luadecguess.exe.8/lib/compare.rb:42:in `sysread': end of file reached (EOFError)
from C:/DOCUME~1/user/eee/eee.luadecguess.exe.8/lib/compare.rb:42:in `comparedisasm'
from C:/DOCUME~1/user/eee/eee.luadecguess.exe.8/lib/compare.rb:41:in `open'
from C:/DOCUME~1/user/eee/eee.luadecguess.exe.8/lib/compare.rb:41:in `comparedisasm'
from C:\DOCUME~1\user\eee\eee.luadecguess.exe.8\app\luadecguess.rb:201
from C:\DOCUME~1\user\eee\eee.luadecguess.exe.8\bootstrap.rb:77:in `load'
from C:\DOCUME~1\user\eee\eee.luadecguess.exe.8\bootstrap.rb:77

I also attached the manila file I was using. Yesterday, beta 4, completed after about 5 hours. The final result I had at home matched the result I had on my work computer.
[Windows Mobile Development and Hacking General] sztupy:
Added a hotfix. DL link the same (beta 5)
[Windows Mobile Development and Hacking General] sztupy:
Having some progress on the decompile all scripts project. Here are 138 scripts that are fine.
[Windows Mobile Development and Hacking General] smotrs:
Ok, running again, after a while I got the error again, "luadec.exe has encountered a problem and needs to close". Hitting Don't Send closes it and it comes back on the next line in the DOS window. After about 5-9 of these, it was good for about another minute then repeated the process again.

So far, it's done it about 6 times now. Nothing really showing up i nthe DOS window except lines like the following,

0629: best: 59 57 59 2 ;;;;;;;;;;;;;0,3,6,12,22;0;14,35;;;0;0;0;;1;;;;12;0;21,29;1;;1;1;12;12;0;;;0;;42;;0;1;0;0,0,5,7;8;0;0;;;

When it's not displaying the error dialog and appears to be going through ok, it displays lines like this,

0644: actual: 59 0 0 0 ;;;;;;;;;;;;;0,3,6,12,25,31;0;14,35;;;0;0;0;;1;;;;12;0;21,29;1;;1;1;12;12;0;;;0;;42;;0;1;0;0,0,5,7;8;0;0;;;
luac: temp.luatemp:9: function arguments expected near 'local'
Unable to open input file "luac.out"
[Windows Mobile Development and Hacking General] sztupy:
read post #123