I would like to learn more about whether it is possible and how to write a program that decompiles executable binary (an object file) to the C source. I'm not asking exactly 'how', but rather how this can be achieved.
Given the following hello.c
file (as example):
#include <stdio.h>
int main() {
printf("Hello World!");
}
Then after compilation (gcc hello.c
) I've got the binary file like:
$ hexdump -C a.out | head
00000000 cf fa ed fe 07 00 00 01 03 00 00 80 02 00 00 00 |................|
00000010 0f 00 00 00 b0 04 00 00 85 00 20 00 00 00 00 00 |.......... .....|
00000020 19 00 00 00 48 00 00 00 5f 5f 50 41 47 45 5a 45 |....H...__PAGEZE|
00000030 52 4f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |RO..............|
00000040 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 |................|
00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000060 00 00 00 00 00 00 00 00 19 00 00 00 d8 01 00 00 |................|
00000070 5f 5f 54 45 58 54 00 00 00 00 00 00 00 00 00 00 |__TEXT..........|
$ wc -c hello.c a.out
60 hello.c
8432 a.out
For the learning dataset, I assume I'll have to have thousands of source code files along with its binary representation, so the algorithm can learn about moving parts on certain changes.
How would you tackle this problem?
My concerns (and sub-questions) are:
Does my algorithm need to be aware of the header file, or it's "smart" enough to figure it out?
If it needs to know about the header, how do I tell my algorithm "here is the header file"?
What should be input/output mapping (whether some section to section or file to file)?
Do I need to divide my source code into some sections?
Do I need to know exactly how decompilers work or AI can figure it out for me?
Should I have two neural networks, one for header, another for body it-self?
or more separate neural networks, each one for each logical component (e.g. byte->C tag, etc.)