yashsingh1/xdaforums huggingface dataset:
[Windows Mobile Development and Hacking General] sztupy:
"-1.#QNAN" is a number which means Not a Number. Negative numbers in Q16 form will break the double things. Don't worry about them. Usually don't worry about numbers in the disassembled output, they are represented fine in the decompiled output.

Closures are function definitions. If you find somewhere a CLOSURE command there you have to find a "function()" declaration in the decompiled output. If this function is an inline function (so not declared in the main block), then in the disassembly and in the output of compare it's contents will be after the complete disassembly of the function you're working on.
[Windows Mobile Development and Hacking General] smotrs:
Ok, so if I'm understanding that right, the following,

function()
SwitchMode("CityPicker")
end

should be entered after the function I'm working on (after the last end), not in the middle of it as it's currently shown in the luadec version and represented in the disassembly?
[Windows Mobile Development and Hacking General] sztupy:
no. I meant whenewer you create a function lua (and so the disassembler too) will put the function AFTER the function you're working on and put a CLOSURE in the place where you have defined the function. So you have to keep it there, but in the disassembly it will show up after the function.
[Windows Mobile Development and Hacking General] smotrs:
So the following would be correct?

; Function #1:
;
; Name:
; Defined at line: 47
; #Upvalues: 0
; #Parameters: 1 (R0)
; Is_vararg: 0
; Max Stack Size: 8
;
; No locals information
; No upvalues

1 [-]: GETGLOBAL R1 K0 ; R1 := EasterEggRunning
2 [-]: EQ 0 R1 K1 ; if R1 != 1 then PC := 5
3 [-]: JMP 5
4 [-]: RETURN R0 1 ; return
5 [-]: GETGLOBAL R1 K2 ; R1 := navigatingOut
6 [-]: EQ 0 R1 K1 ; if R1 != 1 then PC := 9
7 [-]: JMP 9
8 [-]: RETURN R0 1 ; return
9 [-]: GETGLOBAL R1 K3 ; R1 := URL
10 [-]: LOADK R2 K4 ; R2 := "Manila://Confirmation.dialog"
11 [-]: CALL R1 2 2 ; R1 := R1(R2)
12 [-]: GETTABLE R2 R1 K5 ; R2 := R1["Parameters"]
13 [-]: SELF R2 R2 K6 ; R3 := R2; R2 := R2["AddParameter"]
14 [-]: LOADK R4 K7 ; R4 := "Title"
15 [-]: GETGLOBAL R5 K8 ; R5 := Locale
16 [-]: SELF R5 R5 K9 ; R6 := R5; R5 := R5["GetString"]
17 [-]: LOADK R7 K10 ; R7 := "IDS_YOU_ARE_ROAMING"
18 [-]: CALL R5 3 0 ; R5,... := R5(R6,R7)
19 [-]: CALL R2 0 1 ; R2(R3,...)
20 [-]: GETTABLE R2 R1 K5 ; R2 := R1["Parameters"]
21 [-]: SELF R2 R2 K6 ; R3 := R2; R2 := R2["AddParameter"]
22 [-]: LOADK R4 K11 ; R4 := "ContentString"
23 [-]: GETGLOBAL R5 K8 ; R5 := Locale
24 [-]: SELF R5 R5 K9 ; R6 := R5; R5 := R5["GetString"]
25 [-]: LOADK R7 K12 ; R7 := "IDS_UPDATE_NOW_DLG_MSG"
26 [-]: CALL R5 3 0 ; R5,... := R5(R6,R7)
27 [-]: CALL R2 0 1 ; R2(R3,...)
28 [-]: GETGLOBAL R2 K13 ; R2 := _application
29 [-]: GETTABLE R2 R2 K14 ; R2 := R2["DialogManager"]
30 [-]: SELF R2 R2 K15 ; R3 := R2; R2 := R2["GetDialog"]
31 [-]: MOVE R4 R1 ; R4 := R1
32 [-]: CALL R2 3 2 ; R2 := R2(R3,R4)
33 [-]: GETTABLE R3 R2 K16 ; R3 := R2["OnExit"]
34 [-]: SELF R3 R3 K17 ; R4 := R3; R3 := R3["connect"]
35 [-]: CLOSURE R5 0 ; R5 := closure(Function #1.0,R5)
36 [-]: MOVE R0 R0 ; R0 := R0
37 [-]: CALL R3 3 1 ; R3(R4,R5)
38 [-]: SELF R3 R2 K18 ; R4 := R2; R3 := R2["Show"]
39 [-]: CALL R3 2 1 ; R3(R4)
40 [-]: RETURN R0 1 ; return

; Function #1.0:
;
; Name:
; Defined at line: 62
; #Upvalues: 1
; #Parameters: 1 (R0)
; Is_vararg: 0
; Max Stack Size: 4
;
; No locals information
; No upvalues

1 [-]: GETGLOBAL R1 K0 ; R1 := OnShowUpdateNowConfirmationDialogReturned
2 [-]: MOVE R2 R0 ; R2 := R0
3 [-]: GETUPVAL R3 0 ; R3 := U0
4 [-]: CALL R1 3 1 ; R1(R2,R3)
5 [-]: RETURN R0 1 ; return

with a LUA that looks like this

ShowUpdateNowConfirmationDialog = function(l_2_0)
if EasterEggRunning == true then
return
end
if navigatingOut == true then
return
end
local l_2_1 = URL("Manila://Confirmation.dialog")
l_2_1.Parameters:AddParameter("Title", Locale:GetString("IDS_YOU_ARE_ROAMING"))
l_2_1.Parameters:AddParameter("ContentString", Locale:GetString("IDS_UPDATE_NOW_DLG_MSG"))
local l_2_2 = _application.DialogManager:GetDialog(l_2_1)
-- internal function below this line
l_2_2.OnExit:connect(function(l_1_0)
OnShowUpdateNowConfirmationDialogReturned(l_1_0, l_2_0)
end)
l_2_2:Show()
end
[Windows Mobile Development and Hacking General] sztupy:
yes, it looks fine to me
[Windows Mobile Development and Hacking General] sztupy:
I've got the even newer Rhodium Manila package from xboxmod, so I started upgrading my freshly decompiled scripts :) 303 scripts are already fine (including all embedded scripts and manila.lua), and I'm working on the others too. I'm now releasing them in "kitchen format" for easier usage, which means both the mode9 files and lua files are in source form, and there are three batch files to automatically

compile them

embed them into mode9 files and compile them too

hash all of them to get package

this is not the complete kitchen, only the files needed for lua development and "mass hashing".

http://winmo.sztupy.hu/temp/rhodium2_src.zip
[Windows Mobile Development and Hacking General] sztupy:
http://winmo.sztupy.hu/temp/rhodium2_src.zip

EDIT: updated the above file with 20 scripts, including all calendar, album and home scripts
[Windows Mobile Development and Hacking General] sztupy:
Decomp Frenzy!

370 files from the even newer Touch Pro2 decomp'd and ready to use. only 40 remaining :)

http://winmo.sztupy.hu/temp/rhodium2_src.zip
[Windows Mobile Development and Hacking General] smotrs:
Hate to bother you again, but I'm having the same problem as before with another file where the LDS string is wrong. I'm not quite understanding the whole adjustment to that string. Specially since the last file you had a bunch of weird numbers in there.

-l2 361-368,364-368;;11,32;;17,38;;;;;;;1;;3,6,16,26;34;14,35;;;;;;;49,100,101;;8-145,11-145,17-145,59-145,223-260,226-260;;;;21,29;;;;;;;;;;;;;;1,2,8;1;;5;8;;;;; 27a13690_manila.luac

361-368, 364-368, 8-145, 11-145, etc.. I have no idea where they came from. :)

The file I'm trying to convert now is the original raphael version of the 27a13690 so I can compare to the HD version I finished decompiling the other day.
[Windows Mobile Development and Hacking General] smotrs:
Thanks, it definitely took a bit of time, but as you mentioned in a previous post. The longer your working on decompiling scripts, the faster you get at figuring out how it's supposed to read.

That makes perfect sense. Glad you explained it.

No problem, this was great information and I'm glad you took the time to explain it as you did.

Ok, that makes sense I think. So if I take my script and run the command like this,

luadec -d -l ;;0,11,32;;0,17,38;;;;;;;5;;0,3,6,16,26;;14,35;;;;;49,74,195;0,0,185;;;;;;;;;;;;;;;;;;19;;0,0,5;8;;;;; \lua\27a13690_manila.TP.luac

Would it be written like this for LDS2?

luadec -d -l2 ;;11,32;;17,38;;;;;;;5;;3,6,16,26;;14,35;;;;;49,74,195;185;;;;;;;;;;;;;;;;;;19;;5;8;;;;; \lua\27a13690_manila.TP.luac

When I tried this string, it didn't give me any crash or debug message like the first one did, just scrolled all sorts of what looked like decompiled code until it stopped.

Anyway, with the first one a whole bunch of text goes scrolling across the screen and it finally stops (or crashes) with the following,

----------------------------------------------
98 CLOSURE 0 10
----------------------------------------------
1 LOADK 0 0
SET_CTR(Tpend) = 0

next bool: 0
locals(0):
vpend(0):
tpend(1): 0{""}
()

----------------------------------------------
2 GETGLOBAL 1 1
SET_CTR(Tpend) = 1

next bool: 0
locals(0):
vpend(0):
tpend(2): 0{""} 1{cityListSize}
()

----------------------------------------------
3 LE 0 258 1

next bool: 0
locals(0):
vpend(0):
tpend(1): 0{""}
()

----------------------------------------------
4 JMP 0 1

next bool: 1
locals(0):
vpend(0):
tpend(1): 0{""}
()

----------------------------------------------
5 LOADK 0 3

next bool: 1
locals(1): 0{l_11_0}
vpend(0):
tpend(1): 0{l_11_0}
()
-- DECOMPILER ERROR: Overwrote pending register. Missing locals? Creating them

local l_11_0 = ""

----------------------------------------------
6 GETGLOBAL 1 4

Exps(0): at 3 dest 6 neg 1 (cityListSize < 10) cpd -1

Stored at endif list: <6>

is that what your referring to when you say it crashes and gives you a clue as to where to look for the crash?

If so, does that mean it crashed at opcode 6 or function #6 (or is that function #7 because it starts at 0?)

How often do these come about?
[Windows Mobile Development and Hacking General] smotrs:
Quick confirmation, when you say the 11th function (10+1) you mean within the LDS string using luadec, it's still the 10th function within the dissasembler?

I ask, because on the next instance where it crashes, I get the following,

----------------------------------------------
184 CLOSURE 0 38
----------------------------------------------
1 LOADK 0 0
SET_CTR(Tpend) = 0

next bool: 0
locals(0):
vpend(0):
tpend(1): 0{""}
()

(...)
----------------------------------------------
19 CONCAT 0 5 6
SET_CTR(Tpend) = 0

next bool: 1
locals(1): 0{l_39_0}
vpend(1): 0{l_39_0=l_39_0 .. ","}
tpend(0):
()
if cityListSize >= 1 then
-- WARNING: pending registers. Declaring locals.
local l_39_0 = ""
for i = 1, cityListSize do
l_39_0 = l_39_0 .. cityList[i].accuweatherCode

Exps(0): at 15 dest 20 neg 0 (i < cityListSize) cpd -1

Stored at endif list: <20> 21
----------------------------------------------
20 FORLOOP 1 -12

I located the 39th (38+1) function in the LDS string and it said 19, which is where it crashed above. When I went to the disassembly and looked for the 39th (38+1) function, I was shown a function that ended at opcode 16. Whereas the 38th function, in the disassembly went to opcode 40 and also referenced 'cityListSize, cityList, accuweatherCode' as shown above.

Looking at this function, the register referenced at opcode 19 was first created at opcode 1. So changing the LDS string at the 39th (38+1) function position to 1 fixes that part of the code.

To check just that function with luadec, I had to use the -f like the following,

luadec -d -f 39 -l ;;0,11,32;;0,17,38;;;;;;;1;;0,3,6,16,26;;14,35;;;;;49,74,195;0,0,185;;;;;;;;;;;;;;;;;;1;;0,0,5;8;;;;; .\lua\27a13690_manila.TP.luac

So to me, it looks like when using luadec it's always X+1 but with the disassembly output it's just X.
[Windows Mobile Development and Hacking General] smotrs:
Also, I fixed the normal LDS string and output it to a LUA file so I can start going through it. I then went back and changed it to an LDS2 string

luadec -l ;;0,11,32;;0,17,38;;;;;;;1;;0,3,6,16,26;;14,35;;;;;49,74,195;0,0,185;;;;;;;;;;;;;;;;;;1;;0,0,5;8;;;;; .\lua\27a13690_manila.TP.luac > .\lua\27a13690_manila.TP.luac.lua

luadec -l2 ;;11,32;;17,38;;;;;;;1;;3,6,16,26;;14,35;;;;;49,74,195;185;;;;;;;;;;;;;;;;;;1;;5;8;;;;; .\lua\27a13690_manila.TP.luac > .\lua\27a13690_manila.TP.luac.lua2

Then ran a compare on both files and they have close to a dozen differences.

Maybe I did something wrong? Anyway, I attached them both so you can see if you would like too.
[Windows Mobile Development and Hacking General] 12aon:
Hey stup thanks for decompiling, and for the nice ordering. I have a decomp request. I'm working on the world clock, which is a lot harder to port than I thought. Especially the touch area's, nice that they are practically have a different name in every script. I have the alarm clock page resized but I cannot locate the touch area there, so I think it might be in the regular alarmview lua or possibly the alarm edit lua (I don't thinks so but in landscape it has to the onoff buttons, which I'm trying to fix). I intend to fix the entire world clock and would therefore also need clockview and possibly radiobuttoncontrol (saw a reference in the wolrdclock mode9). I am getting bolder in lua editing I created my first if landscape then, else if function :), your efforts are and will be appreciated, 12
[Windows Mobile Development and Hacking General] sztupy:
You're doing fine. If you compare the two files, you can see that the LDS1 version has a lot of garbage outputted, like

Í^RWx
(forecastMinutes)

while the LDS2 variant had less. The LDS1 version was in an "almost-crash" state, that's why it had output random tidbits of your memory, while the LDS2 variant didn't do any bad memory management, just told you about the undeclared locals. If you use a diff command to compare the two, you can see that the only differences are in two functions, with the LDS2 variant outputting a better (but actually still useless) output. I would consider checking the disassembly of these two functions (20 and 21), and see where those pesky locals are declared :)
[Windows Mobile Development and Hacking General] sztupy:
Yes, it was the case. But not anymore:

LuaDec 2.0 pre-release

this is a pre-release version of the new luadec which will hopefully have a built-in local guesser, to ease decompiling.

But until I'm ready with it, I also added a disassembler to luadec, which will interpret numbers correctly, and will number the functions the same (#1 instead of #0 for the first function) :) I also changed luadecguess and compare so they're now using "luadec -dis" instead of "luadisasm" (you can remove it if you want)

The version in the attachment has the disassembler already built in. It has almost the same output as the luadisasm had. The guesser is not yet included, I'm working on it to get it finished till monday.
[Windows Mobile Development and Hacking General] sztupy:
Hi!

I unfortunately get used to decomp using two monitors, so I'll work on this on monday at work :) I'm currently standing at the last few people scripts, but next time I'll start with the worldclock ones and upload them when I'm finished with them.

But until monday I want to finish a new luadec to help me finish decompiling all scripts on monday.

Btw. I'm glad to hear you guys have success using luadec / working with lua files. This means I'm not that bad teacher after all :)
[Windows Mobile Development and Hacking General] 12aon:
Actually Xbox made a kitchen with a couple of great batch files that might go great with your kitchen. He made a batch file to automatically install and restart the recompiled files and one batch file with an option to automatically recompile a recompile scrip, real nice. Thanks for all the work you put into this, 12
[Windows Mobile Development and Hacking General] smotrs:
Yeah, I did notice it looked cleaner in the LDS2 version. What appeared to be missing bits of code in the LDS2 version were actually because it appears the LDS2 version was able to correctly build that portion of the code without resorting to creating variables for everything which is what appeared to happen in the LDS1 version.

I also noticed that I lost some special characters or something else. But all the instances where a degree existed appear to have been changed to a ? (question mark) within the decompiled LUA's. Both my versions as well as the TP2 version you did.

I only detected it because I added it too my phone.

EDIT: Darn, tried to insert the degree symbol back in place of the ? and recompile but now no character shows up where the degree symbol should be. Any ideas on how to fix special characters like that? What the correct character string should be maybe?
[Windows Mobile Development and Hacking General] sztupy:
It might be because of code page conversions. TP lua uses UCS-16LE (Unicode), while luaconv will convert it to ascii, which will strip them (so no unicode characters) instead of UTF-8, which would keep those characters. I think this may be the problem. Could please send me the files (the unicode luac, the ascii luac, and the decompiled script) with some comments where to find this bug, so I can look at whether this is really the case.
[Windows Mobile Development and Hacking General] smotrs:
Which file would be the unicode luac? I got the ascii luac and the decompiled script. Is the unicode luac the original file or the final compiled file?
[Windows Mobile Development and Hacking General] sztupy:
the very original (the one on the phone)
[Windows Mobile Development and Hacking General] smotrs:
Got it, here they are.

The HD in the filename is only so I can distinguish between the two versions I'm messing with, HD and TP versions (not TP2).

Edit: Forgot to mention, do a search for 'incorrect symbol for degree' for all error instances.

EDIT2: removed attachment, taking up space.
[Windows Mobile Development and Hacking General] sztupy:
Just as I thought. The problem is with luaconv, that converts to ascii instead of UTF-8. I've already started creating a hotfix.
[Windows Mobile Development and Hacking General] sztupy:
LuaDec 1.9

LuaDec 1.9 released

This is a major release, and the last in the 1.x series.

Major changes:

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

The provided lua package (lua, luac and luadec) is now unicode compilant, it will read and write the unicode variants of the scripts instead of the ascii variants.

This version will only work with the original, unicode (non-converted using luaconv) variants of the compiled luac files. It won't load (or write) ascii variants any more!

Let's see from top to bottom:

1. Although there may be still some errors, LDS2 strings declaring locals in a for loop won't break the decompilation with unneded local declarations.

2. You can use luadec -dis to get a disassembly of the input file. Compare and luadecguess also uses luadec from now on to the decompilation, so luadisasm is no more needed

3. LuaDec (and every other member of the package) now use the file format of HTC's unicode lua variant instead of the original. This means luadec, luac and lua can now work (and will only work!) on the lua files that are native to Manila3D, and there is no more need to use luaconv to convert them to ascii and back to unicode. It also has some minor fixes to Q16.16 handling of numbers, so some of the undecompilable Q16.16 numbers can now be fixed.

Internally lua* didn't change, only the way it loads and saves binary chunks. Internally the representation of strings have changed to UTF-8 (luadec will use iconv to convert between UTF-8 and UTF-16LE), so this means you can use any utf-8 characters in the input file, they will be converted to their correct unicode counterparts during compilation. But don't forget that luac is not UTF-8 aware, so if you use an editor that adds the UTF-8 BOM (\EF\EE\EB) to the beginning of the file (like notepad.exe, and many others), then lua* might tell you that the file is corrupt. Use an editor where you can set whether you want the BOM or not (like notepad++, SciTe, gVim, etc.), and always say, that you don't need it :)

The other tidbit about UTF-8 charactes are that during decompilation luadec will treat them as binary characters, so instead of "°" you will get "\194\176", which is of course the same (check this page at line "194 176"), so you can replace them with "°" if you want (after compilation you'll get back the same string), or keep them the escaped way.

DL link: http://winmo.sztupy.hu/luadec.html
[Windows Mobile Development and Hacking General] smotrs:
Would you recommend I re-decompile the original file, make the changes to the new uni-LUA file that I made to the asc-LUA file to guarantee I have the correct uni-coding in place?

EDIT: never mind, almost done duplicating what I did before. Doing a diff compare to see where my changes are and duplicating them on the new file. Going by really quick.

EDIT: It works, all the degree symbols came across perfectly.
[Windows Mobile Development and Hacking General] smotrs:
Found a problem with the compare program. When running compare against the original manila lua file, it errors with the following,

C:\Documents and Settings\user1\My Documents\My Software\Mobile Software\lua51_tf3d_1.9> compare .\lua\27a13690_manila.TP .\lua\27a13690_manila.TP.lua
luadec: unrecognized option `-dis'
usage: luadec [options] [filename]. Available options are:
- process stdin
-d output information for debugging the decompiler
-- stop handling options
luadec: unrecognized option `-dis'
usage: luadec [options] [filename]. Available options are:
- process stdin
-d output information for debugging the decompiler
-- stop handling options
Main block:
Same

Global:
Opcodes in original: 0
C:\DOCUME~1\user1\eee\eee.compare.exe.42\app\compare.rb:176:in `to_i': NaN (FloatDomainError)
from C:\DOCUME~1\user1\eee\eee.compare.exe.42\app\compare.rb:176:in `comparedisasm'
from C:\DOCUME~1\user1\eee\eee.compare.exe.42\app\compare.rb:198
from C:\DOCUME~1\user1\eee\eee.compare.exe.42\bootstrap.rb:77:in `load'
from C:\DOCUME~1\user1\eee\eee.compare.exe.42\bootstrap.rb:77

Also, I assume we run our lua scripts against the original compiled lua file? Didn't see any other way to do it.
[Windows Mobile Development and Hacking General] sztupy:
This luadec version compare finds and runs isn't the latest that's for sure. It seems to be a very, very old version (according to the parameter list it prints out it don't even have LDS support, so it might be 0.1 or 0.2). Do you have the latest luadec.exe besides compare.exe? Or is an old luadec.exe be found somewhere along the %PATH%?

Of course. I have to modify some of my other tools so they won't use luaconv, and I think 6Fg8 will modify his program to support luadec1.9 too.
[Windows Mobile Development and Hacking General] smotrs:
Was out dirt biking all day. What a ride.

Your right, I had the open source LUA installed as well, and I think when compare was attempting to access luadec, it was grabbing that version instead of the one in the current directory. :rolleyes:

oops :D

Wanna see something really cool. :)

C:\Documents and Settings\user1\My Documents\My Software\Mobile Software\lua51_tf3d_1.9>compare .\lua\27a13690_manila.HD .\lua\27a13690_manila.HD.lua
Main block:
Same
Function 1:
Same
Function 2:
Same
Function 3:
Same
Function 4:
Same
Function 5:
Same
Function 6:
Same
Function 7:
Same
Function 8:
Same
Function 9:
Same
Function 10:
Same
Function 11:
Same
Function 12:
Same
Function 13:
Same
Function 14:
Same
Function 15:
Same
Function 16:
Same
Function 17:
Same
Function 18:
Same
Function 19:
Same
Function 20:
Same
Function 21:
Same
Function 22:
Same
Function 23:
Same
Function 24:
Same
Function 25:
Same
Function 26:
Same
Function 27:
Same
Function 28:
Same
Function 29:
Same
Function 30:
Same
Function 31:
Same
Function 32:
Same
Function 33:
Same
Function 34:
Same
Function 35:
Same
Function 36:
Same
Function 37:
Same
Function 38:
Same
Function 39:
Same
Function 40:
Same
Function 41:
Same
Function 42:
Same
Function 43:
Same
Function 44:
Same
Function 45:
Same
Function 46:
Same
Function 47:
Same
Function 48:
Same
Function 49:
Same
Function 50:
Same

Global:
Opcodes in original: 3311
Same lines in both files: 3311 100%
Same opcodes in files: 3311 100%

C:\Documents and Settings\user1\My Documents\My Software\Mobile Software\lua51_tf3d_1.9>
[Windows Mobile Development and Hacking General] mun_rus:
Thanx man! That's wht im waiting for.

So no need to use string.char(param1+1040) to get russian letters:)) great:)!
[Windows Mobile Development and Hacking General] sztupy:
You could have asked it earlier :)

Btw. I thought that using ascii is not that bad, considering you can always use Locale:GetString("IDS_SOMETHING") to get something unicode :), but now it doesn't matter.
[Windows Mobile Development and Hacking General] sztupy:
3311 lines of opcodes. You're doing great! :)