Are there any good ways of splitting up a very long for loop or if statement in IDA into larger chunks to make it more readable? Disabling use fast structure analysis in the Hex Rays decompiler options did not help. Nor did setting the Max commas option to 1, as explained by Rolf Rolles in this Twitter post.

for ( i = four - 1; file_size > i + tmp + 1 && match_buffer(&buf[tmp], i + 1, buf_num, idx) != -1; ++i )

What I am trying to achieve is getting this on multiple lines. For reference I am using IDA Free v7.7 for Linux.

The equivalent in Ghidra looks like this and I was hoping to get the same result in IDA:

for (i = four - 1; tmp + i + 1 < file_size; i += 1) {
    var1 = match_buffer(buf + tmp,i + 1,buf + num,tmp - num); // == match_buffer(buf[tmp], i + 1, buf[num], tmp - num);
    if (var1 == -1) 

Sadly, Hex-Rays control flow structuring algorithms are a black box with exactly two knobs on the outside of it: the two options that you listed. If those two knobs don't improve the behavior you're experiencing, then there's nothing you can do as a user. Not even writing a plugin; control flow structuring is only mentioned once in the SDK, and none of the relevant data structures are defined in the headers. You're going to have to live with whatever Hex-Rays gives you, unfortunately.

(More technically: the behavior you're seeing with combining the two if-statements into a compound is very fundamental to the way that Hex-Rays structures control flow, and there's nothing you can do to influence it short of reverse engineering the control flow structuring implementation and reimplementing it. Even if you do that (which I have), you only have very limited influence to prevent the compound from being re-created during the next phase of ctree analysis.)

  • Thank you very much for the informative and technical feedback, Rolf! Perhaps we will see and update on this in the future. It definitely would be nice to have some options to control this for readability. I'll stick to primarily using IDA as it works most great most of the time, but will continue to use Ghidra second hand if I encounter similar control flow structures in the future (until impemented in IDA and the Hex-Rays decompiler). Jan 13 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.