如何将ELF可执行文件转换为C代码?生成的C代码不必是人类可读的 [英] How to convert an ELF executable to C code? The generated C code need not be human-readable

查看:814
本文介绍了如何将ELF可执行文件转换为C代码?生成的C代码不必是人类可读的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆