Decompiler Interaction
Program-Transformation.Org: The Program Transformation Wiki
In a poorly designed decompiler (including all current decompilers and also
disassemblers), a graphical user interface (GUI) or equivalent (e.g. Sourcer's
specification files) are necessary so that the user can correct the gross mistakes
made, or to implement features that the analysis simply doesn't do. For example,
in the
IDA Pro disassembler, no attempt is made to separate constants
from pointers, so the user has to do all these via the GUI. Stack depth is sometimes
calculated correctly, but when the called function doesn't have the right calling
convention, the user has to correct the stack modification amount for the function.
For a long time, these corrections will be needed. However, it doesn't hurt to dream:
what use, if any, is there for a GUI in a decompiler that has good analyses? Sure, all
analyses can fail, but in those cases, might it be better to just fix the limitation in
the decompiler, and leave it as a batch processing program (i.e. no GUI)? Or perhaps have
a GUI, but just to amuse the user and/or allow the user to browse the results before the
analysis is finished?
Well, it turns out that there are still some valid reasons to want to have a GUI anyway,
even if he analyses are very good. Many interesting questions in decompilation (and in
compilation and any other program transformation or even visualisation) are equivalent
to the halting problem, and so cannot be answered in the general case. Compilers avoid
this problem by simply not performing certain optimisations when they are not safe.
Decompilers have to make other conservative actions, such as putting a variable into
the set of address-escaped variables even if in fact nothing uses that address to change
the value of the variable unexpectedly. Such variables cannot be propagated, since
aliases may cause the propagation to change the semantics of the program. Not
propagating the variable can result in a less readable program, sometimes very
significantly so. So if the GUI can in effect tell the decompiler "this apparently
safe operation is hereby declated to be safe" (and if it is not, well the user asked for
it!).
So here is partial list of things that a GUI could be used for:
- as above, overriding conservative decisions by the analysis routines
- (obviously) meaningful names for variables and procedures, and meaningful comments
- arbitrary choices, where the result is better only in the eyes of the reader (e.g. a complex for loop verses the equivalent while loop; hex verses decimal verses octal verses character notation for a particular constant)