3 ms·
Eleven or twelve years ago, I was presenting a paper at the European Joint Conferences on Theory and Practice of Software; I went to a talk while I was there by
by saurik 11y ago
Eleven or twelve years ago, I was presenting a paper at the European Joint Conferences on Theory and Practice of Software; I went to a talk while I was there by Gogul Balakrishnan, and spent some time talking to him about decompilation: I remember him telling me that the problem you describe is simply not possible to solve for x86.
FWIW, jumping into the middle of an instuction is not actually a problem (even though I do realize it trips up a number of disassemblers: I actually publishef a proof-of-concept obfuscating assembler that was designed to specifically break all the best disassemblers at the time, and leaned heavily on that), as you just need to build your own graph of the execution of the program: don't try to mark regions of memory, as that will screw you.
What really gets you quickly are computed jumps: even super popular disassemblers often hiccup on simple switch tables, as there is no way to really know for sure all the cases that were proven to be impossible by the compiler and left out of the checks. And one could imagine a case where a jump is computer based on the output of a potentially undesirable function... you essentially need to be able to prove things about programs to even ask the question, and those proofs almost always fail due to incompleteness :(.
- jacquesm 11y agoAh yes, switches, I totally forgot about that bit but you're absolutely right, those were impossible to get right, especially with the optimizer on. The end result that best matched the code would be a jumble of ifs and gotos rather than a switch and because you don't know the bounds you're going to have to make a bunch of assumptions about the contents of the addresses of the jump table. Bad luck to you if one of the jump tables (you can get more of them for disjoint sets of case statements that cluster together) happens to be shorter than you think and is followed by other address pointers. Decompilation for C is a very hard problem. Conceptually super easy but extremly hard if not impossible to implement. The java folks have it so much easier in this respect.
- drakenot 11y agoSo has the Hex-Rays made significant breakthroughs in this area or does their decompiler have the same issues?
- jacquesm 11y agoIt works for relatively easy switch statements: https://www.hex-rays.com/products/decompiler/compare_vs_disassembly.shtml https://www.hex-rays.com/products/decompiler/compare_vs_disa... It requires compiler generated code as input (which I don't find a huge restriction, but any assembly code will screw up the output).
- saurik 11y agoWow, two semi-important (and one silly) typos I see in this comment I typed in the middle of the night on my iPhone ;P. computer based -> computed based undesirable -> uncomputable publishef -> published
- jacquesm 11y agoThe only one that had me stumped for a bit was 'undesirable' but even there it left only one possibility. The rest I didn't even notice, I read what you meant and now that you point them out I see them. Funny thing, the brain. I have a rule when I write reports: don't send it on the same day. Let it sit for a day and then re-read it, from paper if possible. That's when I spot the typos and the weird sentences. If I proofread right away I just read what I think it should say rather than what it really says. Frustrating!