fkie-cad / dewolf

A research decompiler implemented as a Binary Ninja plugin.
GNU Lesser General Public License v2.1
172 stars 9 forks source link

[For-Loop Reconstruction] Follow up: Not handling "continue" instructions correctly #325

Closed fnhartmann closed 9 months ago

fnhartmann commented 1 year ago

What happened?

247 discussed the issue that a continue-statement was not handled correctly during the for-loop reconstruction. For that @ebehner mentioned two solutions:

  1. Only do for-loop reconstruction, if there is no continue in the loop body
  2. Check that the update-statement rule also holds when continuing the loop due to a continue-statement

In the previous issue the first solution was implemented to close this bug. Therefore, in this follow-up issue, we will work on the second solution to avoid skipping the reconstruction completely.

Possible Solution

To implement this, the following approach can be taken. If a continue-statement is found, the following update-statement is subtracted before it. If possible, this deduction should be calculated into the previous operation. Otherwise the inverted update-statement is inserted into the code node before the continue. In this way the update statement is equalized.

fnhartmann commented 1 year ago

/cib

github-actions[bot] commented 1 year ago

Branch issue-325-_For-Loop_Reconstruction_Follow_up_Not_handling_continue_instructions_correctly created!

fnhartmann commented 1 year ago

Possible Solution

To implement this, the following approach can be taken. If a continue-statement is found, the following update-statement is subtracted before it. If possible, this deduction should be calculated into the previous operation. Otherwise the inverted update-statement is inserted into the code node before the continue. In this way the update statement is equalized.

As discussed today, we will implement only the simple cases to perform a for-loop reconstruction if a continue-statement occurs. So the deduction will be calculated into the previous operation. If there is no operation, there will be no reconstruction.