Washi1337 / OldRod

An automated KoiVM disassembler and devirtualisation utility
GNU General Public License v3.0
345 stars 80 forks source link

`Shr_Un`, `Div_Un`, `Rem_Un` leave behind a mess of flag updates. #45

Open ElektroKill opened 2 years ago

ElektroKill commented 2 years ago

Describe the bug OldRod currently recompiles all REM, SHR, and DIV instructions to the CIL *_Un variants. This works well enough when Shr, Div, and Rem are virtualized since KoiVM doesn't emit any additional code for them. However, if Shr_Un, Div_Un, or Rem_Un are virtualized KoiVM emits a store to the FL register to set the UNSIGNED flag. When this occurs OldRod does not properly handle this flag and rather messy code is produced.

To Reproduce Devirtualize the same sample file from issue #44.

Expected behavior OldRod should recompile REM, SHR, and DIV instructions to the regular CIL variants (Rem, Shr, Div). If the UNSIGNED flag is set in FL register before the operation the instructions should be recompiled to the *_Un variants.

Screenshots image image image

Washi1337 commented 2 years ago

Note: This will most likely require the addition of extra edges in the DFG to link instructions to others that update the flags register.