neobrain / nihstro

3DS shader assembler and disassembler
BSD 3-Clause "New" or "Revised" License
83 stars 35 forks source link

Failed to disassemble Luigi's Mansion: Dark Moon shader code #70

Open iliasHDZ opened 1 week ago

iliasHDZ commented 1 week ago

The disassembler crashes here:

000000dc [--------] ComputeSkinMatrix:
000000dc [0727dc96]     dp3      r9.___w       c93.yyyy    r9.xyzw   16 addr:0;      temp_9 <- const_93, temp_9
000000e0 [3b21901b]     rcp      r9.___w        r9.wwww              1b addr:0;      temp_9 <- temp_9
000000e4 [23219ca3]     mul      r9.xyzw        r9.xyzw    r9.wwww   23 addr:0;      temp_9 <- temp_9, temp_9
000000e8 [48018004]     mova             r8.xyyy               4 addr:0;      out.pos <- temp_8
000000ec [23aaaca4]     mul     r13.xyzw  c10[a0.x].xyzw    r9.xxxx   24 addr:1;      temp_d <- (?), temp_9
000000f0 [23cabca4]     mul     r14.xyzw  c11[a0.x].xyzw    r9.xxxx   24 addr:1;      temp_e <- (?), temp_9
000000f4 [23eacca4]     mul     r15.xyzw  c12[a0.x].xyzw    r9.xxxx   24 addr:1;      temp_f <- (?), temp_9
000000f8 [fdb2aba5]     mad
000000fc [feb2afc5]     mad
00000100 [ffb2b3e5]     mad

I was able to kindof fix it but I don't think i fixed it correctly.

Here's the shader code: shadercode.zip

neobrain commented 1 week ago

Could you provide more information about the crash? Where does it crash? What does the stack trace look like? What did you do to fix it?

iliasHDZ commented 1 week ago

It crashes right here: https://github.com/neobrain/nihstro/blob/f4d8659decbfe5d234f04134b5002b82dc515a44/src/disassembler.cpp#L211 The instr.common.operand_desc_id was some invalid number which is why it crashed. I fixed it by checking if it was a valid index. If not, it skips to the next instruction. There is probably alot of stuff that I'm missing but I don't know much about this code so this was the quick and dirty approach I took.