如何将ELF可执行文件转换为C代码?生成的C代码不必是人类可读的 [英] How to convert an ELF executable to C code? The generated C code need not be human-readable
问题描述
我有一个ELF文件,我想将其反编译为C
代码,并对生成的C
代码进行简单的更改,然后将其重建为ELF.
I have an ELF file that I would like to decompile into C
code, and make simple changes to the resulting C
code and rebuild it into an ELF.
反编译的C
代码不需要完全可读.例如,如果混淆了变量和函数名,那就可以了.
The decompiled C
code need not be fully human readable. Eg, if variables and function names come out obfuscated, it is okay.
我可以使用哪些工具在Linux上完成此任务?
Which tools can I use to accomplish this on Linux?
PS:如果无法编译为C
或将其编译为简单代码,尽管对汇编源代码进行调整对我来说非常困难,但我愿意考虑将其反汇编为汇编语言.
PS: If decompiling to C
is not possible or is not easy, I'm willing to consider decompiling to assembly language, though tweaking the assembly source will be very difficult for me.
更新:您可能会假设我正在使用以下C
程序来获取我的a.out
ELF.现在,进一步假设我已经失去了这个原始的C
源.因此,我现在想将其反编译为(可能是混淆的)C
源,在其中至少可以更改字符串"world"
,"Hello"
和"Bye"
之类的小东西,或者能够颠倒if
语句等的含义.
UPDATE: You may assume that I'm using the following C
program to get my a.out
ELF. Now, assume further that I've lost this original C
source. So, I would now like to decompile it to (a possibly obfuscated) C
source in which I'm at least able to change small things like the strings "world"
, "Hello"
, and "Bye"
, or be able to reverse the sense of the if
statement, etc.
#include <stdio.h>
#include <string.h>
char buf[256];
const char *Hello = "Hello";
const char *Bye = "Bye";
const char *Who = "world";
char * greet(const char *greeting, const char *str) {
strcpy(buf, greeting);
strcat(buf, ", ");
strcat(buf, str);
strcat(buf, "!");
return buf;
}
int main(int argc, char *argv[]) {
int sayHello = 0;
if(sayHello) {
printf("%s\n", greet(Hello, Who));
} else {
printf("%s\n", greet(Bye, Who));
}
return 0;
}
推荐答案
这将为您(几乎)提供汇编代码翻译:
This will give you (almost) an assembly code translation:
objdump --disassemble <elf file>
我之所以这样说,几乎是因为输出包含一些注释,例如二进制文件位置标记,并且不能直接用作汇编程序的输入,但是它很接近.
I say almost because the output contains some annotations like binary file position markers and can't serve directly as input to an assembler, but it's close.
这篇关于如何将ELF可执行文件转换为C代码?生成的C代码不必是人类可读的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!