The default output of the Hex-Rays decompiler tries to strike a balance between conciseness and readability. However, everyone has different preferences so it offers a few options to control the layout and formatting of the pseudocode.
Accessing the options
Because of its origins as a third-party plugin for IDA, the decompiler options are accessible not through IDA’s Options menu, but via Edit > Plugins > Hex-Rays Decompiler, Options button
Pseudocode formatting options
Formatting options are available on the main page of the options dialog.
- Comment indent: starting position for regular (end-of-line) comments. Obviously, for longer lines the comment will be shifted further to the right. Block comments are aligned to the statement they’re attached to so this setting does not apply to them.
- Block indent: indentation for nested statements, e.g. inside
- Right margin: the decompiler tries to keep the pseudocode line length under the specified length. For example, it will try to split a function call with many arguments by putting them on separate lines:
Note that in some cases you may still see lines longer than the specified margin because it’s not always possible to break a long line so that it remains valid C.
- Max strlit len: maximum length of a string constant displayed directly (inline) in the pseudocode. A constant longer than this value will be replaced by a name referring to it.
- Max commas: how many comma operators the decompiler can use in one expression to make the code more compact. By reducing this value, you should see simpler expressions at the cost of more lines of code: more/deeper nested
ifstatements, extra variables for intermediate results, or even additional
For example, here’s a fragment of pseudocode with a comma statement inside the
After changing max commas to 1, the comma disappears at the cost of additional
Changing the defaults
When changing the settings from inside IDA using the UI described above, they apply only to the current database. To change the defaults for all new databases, either edit
cfg/hexrays.cfg in IDA’s install directory, or create one in the user directory with the options you want to override.
Extra empty lines can be added to the pseudocode to improve readability. This feature was described in the tip #43 (Annotating the decompiler output).