Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown capture type 1 when decoding specific Alan Wake 2 *.binlua files (1.0.8 alpha) #27

Open
riverence opened this issue Jan 11, 2024 · 15 comments
Labels
bug Something isn't working

Comments

@riverence
Copy link

When decoding .binlua files (quite literally luau renamed to binlua, thanks Remedy) simple scripts will work and output something right, but on a good chunk the decompiler will produce this error;

[20:01:12 FTL] Decompilation error Unluau.DecompilerException: Unknown capture type 1 at Unluau.Lifter.LiftBlock(Function function, Registers registers, Int32 pcStart, Int32 pcStop) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Lifter\Lifter.cs:line 528 at Unluau.Lifter.LiftProgram() in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Lifter\Lifter.cs:line 36 at Unluau.Decompiler.Decompile() in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Decompiler.cs:line 48 at Unluau.CLI.Program.RunOptions(Options options) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau.CLI\Program.cs:line 119

Is this an issue regarding support of for loops?

@atrexus
Copy link
Owner

atrexus commented Jan 11, 2024

No, I don't this has anything to do with for loops at all. There seems to be an issue regarding capture types in closures, specifically Reference capture types.

Would it be possible for you to send me the binary that you were trying to decompile? If you are unable to, the disassembly will be just fine.

Thanks for finding this bug, I must of overlooked it.

@riverence
Copy link
Author

Sure, I'll include two files; one that works (weapon_balancing_data.binlua), and one that doesn't (flashlight.binlua).
binlua.zip

@riverence
Copy link
Author

riverence commented Jan 11, 2024

I also get another different error on different files;
[21:40:25 FTL] Unexpected error; please report here: https://github.com/atrexus/unluau/issues System.NullReferenceException: Object reference not set to an instance of an object. at Unluau.IfElse.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Lifter\Statements\IfElse.cs:line 28 at Unluau.Statement.WriteSequence(Output output, IList 1 statements) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Lifter\Statements\Statement.cs:line 20 at Unluau.Block.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Lifter\Statements\Block.cs:line 33 at Unluau.Closure.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Lifter\Expressions\Closure.cs:line 47 at Unluau.Assignment.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Lifter\Statements\Assignment.cs:line 30 at Unluau.Statement.WriteSequence(Output output, IList 1 statements) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Lifter\Statements\Statement.cs:line 20 at Unluau.OuterBlock.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Lifter\Statements\OuterBlock.cs:line 24 at Unluau.Decompiler.Decompile() in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Decompiler.cs:line 53 at Unluau.CLI.Program.RunOptions(Options options) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau.CLI\Program.cs:line 119
playable_character_selector.zip

@atrexus
Copy link
Owner

atrexus commented Jan 11, 2024

@riverence Thank you for all of the bugs, I will get to them as soon as possible.

@atrexus
Copy link
Owner

atrexus commented Jan 11, 2024

Sure, I'll include two files; one that works (weapon_balancing_data.binlua), and one that doesn't (flashlight.binlua). binlua.zip

After doing some debugging I was able to fix this issue, but another one arose. I noticed that flashlight.binlua is trying to load a closure (function) with upvalues, but then doesn't capture any of them.

I will continue to look into this issue, but I think the bytecode is flawed.

@riverence
Copy link
Author

Not sure why that would be happening, only thing I can think of that has a slight chance of being the reason is the dependency on the currently-missing bigfish.lua. This has popped up as a requirement in most decompiled scripts I've seen from this game, but isn't actually present, atleast not as a separate script.

@atrexus
Copy link
Owner

atrexus commented Jan 11, 2024

Not sure why that would be happening, only thing I can think of that has a slight chance of being the reason is the dependency on the currently-missing bigfish.lua. This has popped up as a requirement in most decompiled scripts I've seen from this game, but isn't actually present, atleast not as a separate script.

Ok. I was wrong originally. After debugging for a bit more I saw that the script is creating a new closure (OP_NEWCLOSURE) and then it captures only one upvalue. The target closure has a requirement of two upvalues. I am not sure if this is allowed in Luau bytecode, but if you got this from a Roblox game, then this is most likely something on my end. I will take a look at the VM to see if they handle situations like this.

Thanks again for finding this, I had not accounted for this previously.

@riverence
Copy link
Author

I actually didn't get this from a Roblox game; this is from Alan Wake 2. The game uses Luau for it's scripts (which is one of the first examples of a game other than Roblox using it). Thanks for looking into this!

@atrexus atrexus added the bug Something isn't working label Jan 12, 2024
@riverence
Copy link
Author

I also get another different error on different files; [21:40:25 FTL] Unexpected error; please report here: https://github.com/atrexus/unluau/issues System.NullReferenceException: Object reference not set to an instance of an object. at Unluau.IfElse.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Lifter\Statements\IfElse.cs:line 28 at Unluau.Statement.WriteSequence(Output output, IList 1 statements) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Lifter\Statements\Statement.cs:line 20 at Unluau.Block.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Lifter\Statements\Block.cs:line 33 at Unluau.Closure.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Lifter\Expressions\Closure.cs:line 47 at Unluau.Assignment.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Lifter\Statements\Assignment.cs:line 30 at Unluau.Statement.WriteSequence(Output output, IList 1 statements) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Lifter\Statements\Statement.cs:line 20 at Unluau.OuterBlock.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Lifter\Statements\OuterBlock.cs:line 24 at Unluau.Decompiler.Decompile() in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Decompiler.cs:line 53 at Unluau.CLI.Program.RunOptions(Options options) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau.CLI\Program.cs:line 119 playable_character_selector.zip

Now that the capture issue has been fixed, while it has opened up my scope on the scripts I can actually decompile, I'm getting more variations on this specific error. They don't always produce the same traceback either, which makes me think it's gonna be horrible to actually look into on a consistent basis. On some occasions, it'll actually produce output in the specified file, but it always cuts off at strange locations, like in the middle of a function. I've attached a zip file containing a few files that don't work.
objectnotset.zip

@atrexus
Copy link
Owner

atrexus commented Jan 14, 2024

I also get another different error on different files; [21:40:25 FTL] Unexpected error; please report here: https://github.com/atrexus/unluau/issues System.NullReferenceException: Object reference not set to an instance of an object. at Unluau.IfElse.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Lifter\Statements\IfElse.cs:line 28 at Unluau.Statement.WriteSequence(Output output, IList 1 statements) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Lifter\Statements\Statement.cs:line 20 at Unluau.Block.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Lifter\Statements\Block.cs:line 33 at Unluau.Closure.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Lifter\Expressions\Closure.cs:line 47 at Unluau.Assignment.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Lifter\Statements\Assignment.cs:line 30 at Unluau.Statement.WriteSequence(Output output, IList 1 statements) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Lifter\Statements\Statement.cs:line 20 at Unluau.OuterBlock.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Lifter\Statements\OuterBlock.cs:line 24 at Unluau.Decompiler.Decompile() in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau\Decompiler.cs:line 53 at Unluau.CLI.Program.RunOptions(Options options) in C:\Users\infur\Documents\unluau-1.0.8-alpha\src\Unluau.CLI\Program.cs:line 119 playable_character_selector.zip

Now that the capture issue has been fixed, while it has opened up my scope on the scripts I can actually decompile, I'm getting more variations on this specific error. They don't always produce the same traceback either, which makes me think it's gonna be horrible to actually look into on a consistent basis. On some occasions, it'll actually produce output in the specified file, but it always cuts off at strange locations, like in the middle of a function. I've attached a zip file containing a few files that don't work. objectnotset.zip

Take at look at the most recent version, I added a few more things.

@riverence
Copy link
Author

riverence commented Jan 14, 2024

Take at look at the most recent version, I added a few more things.

Unfortunately, after building and testing 1.0.9, I'm still getting the object error, specifically on white_light_zone_system.binlua in my previous attachment.
[07:51:00 FTL] Unexpected error; please report here: https://github.com/atrexus/unluau/issues System.NullReferenceException: Object reference not set to an instance of an object. at Unluau.NameIndex.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.9-alpha (2)\src\Unluau\Lifter\Expressions\NameIndex.cs:line 27 at Unluau.LocalExpression.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.9-alpha (2)\src\Unluau\Lifter\Expressions\LocalExpression.cs:line 32 at Unluau.FunctionCall.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.9-alpha (2)\src\Unluau\Lifter\Expressions\FunctionCall.cs:line 40 at Unluau.LocalExpression.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.9-alpha (2)\src\Unluau\Lifter\Expressions\LocalExpression.cs:line 32 at Unluau.IfElse.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.9-alpha (2)\src\Unluau\Lifter\Statements\IfElse.cs:line 28 at Unluau.Statement.WriteSequence(Output output, IList 1 statements) in C:\Users\infur\Documents\unluau-1.0.9-alpha (2)\src\Unluau\Lifter\Statements\Statement.cs:line 20 at Unluau.Block.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.9-alpha (2)\src\Unluau\Lifter\Statements\Block.cs:line 33 at Unluau.IfElse.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.9-alpha (2)\src\Unluau\Lifter\Statements\IfElse.cs:line 31 at Unluau.Statement.WriteSequence(Output output, IList 1 statements) in C:\Users\infur\Documents\unluau-1.0.9-alpha (2)\src\Unluau\Lifter\Statements\Statement.cs:line 20 at Unluau.Block.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.9-alpha (2)\src\Unluau\Lifter\Statements\Block.cs:line 33 at Unluau.Closure.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.9-alpha (2)\src\Unluau\Lifter\Expressions\Closure.cs:line 47 at Unluau.Assignment.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.9-alpha (2)\src\Unluau\Lifter\Statements\Assignment.cs:line 30 at Unluau.Statement.WriteSequence(Output output, IList 1 statements) in C:\Users\infur\Documents\unluau-1.0.9-alpha (2)\src\Unluau\Lifter\Statements\Statement.cs:line 20 at Unluau.OuterBlock.Write(Output output) in C:\Users\infur\Documents\unluau-1.0.9-alpha (2)\src\Unluau\Lifter\Statements\OuterBlock.cs:line 24 at Unluau.Decompiler.Decompile() in C:\Users\infur\Documents\unluau-1.0.9-alpha (2)\src\Unluau\Decompiler.cs:line 53 at Unluau.CLI.Program.RunOptions(Options options) in C:\Users\infur\Documents\unluau-1.0.9-alpha (2)\src\Unluau.CLI\Program.cs:line 1

@strawbberrys
Copy link

strawbberrys commented Jan 15, 2024

I'm on v1.0.9-alpha and also getting the same error on two other scripts while using Client encoding.

code.luau.txt
code2.luau.txt

The error seems to be the same as above on code.luau but code2.luau appears to error from the lifer.

> ./src/Unluau.CLI/bin/Debug/net6.0/linux-x64/Unluau.CLI --encoding Client code.luau

local var0 = upval2[[13:30:07 FTL] Unexpected error; please report here: https://github.com/atrexus/unluau/issues
System.NullReferenceException: Object reference not set to an instance of an object.
  at Unluau.ExpressionIndex.Write(Output output) in /home/strawberrys/unluau/src/Unluau/Lifter/Expressions/ExpressionIndex.cs:line 28

> ./src/Unluau.CLI/bin/Debug/net6.0/linux-x64/Unluau.CLI --encoding Client code2.luau

[13:33:24 FTL] Unexpected error; please report here: https://github.com/atrexus/unluau/issues
System.NullReferenceException: Object reference not set to an instance of an object.
  at Unluau.Lifter.LiftBlock(Function function, Registers registers, Int32 pcStart, Int32 pcStop) in /home/strawberrys/unluau/src/Unluau/Lifter/Lifter.cs:line 543

@atrexus
Copy link
Owner

atrexus commented Jan 15, 2024

Just pushed a new change that should fix a few scripts. Not all.

@atrexus
Copy link
Owner

atrexus commented Feb 3, 2024

Just wanted to check in quickly. I have been rewriting Unluau for the past weeks and am adding an IL to facilitate control flow analysis. Hopefully this set up will resolve most issues the alpha version faces.

@riverence
Copy link
Author

nice! hopefully this can help me get through all of the scripts from alan wake 2 c:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants