r2dec-js icon indicating copy to clipboard operation
r2dec-js copied to clipboard

Handle for loops

Open wargio opened this issue 6 years ago • 0 comments

for loops are easy to detect:

do {
    ops
    ops
    ops
    [...]
// can be here an if or a label, if there's one
// then there could be a for loop.
    add // incrementer
    sub // decrementer
} while(cond);

Edits goes only under controlflow.js. Probably is possible to only edit the while detection code in order to enhance it to support for logic.

the algorithm should be like for the while:

[...]
type is do-while
if jumps into do-while loop then type is while;
if between previous jump-label and while-jump there are math or calls ops that (no compare ops) then type is for-loop (with or without iterators, e.g. c++ iterators) 

wargio avatar Aug 14 '18 13:08 wargio