C语言 逆向工程c程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2272581/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 04:30:24  来源:igfitidea点击:

reverse engineering c programs

cassemblyreverse-engineeringdisassembly

提问by shreyasva

every c program is converted to machine code, if this binary is distributed. Since the instruction set of a computer is well known, is it possible to get back the C original program?

如果此二进制文件已分发,则每个 c 程序都会转换为机器代码。既然计算机的指令集是众所周知的,那么有没有可能找回C原程序呢?

回答by Filip Ekberg

You can never get back to the exact same source since there is no meta-data about that saved with the compiled code.

您永远无法返回到完全相同的源,因为编译后的代码中没有关于该源的元数据。

But you can re-create code out from the assembly-code.

但是您可以从汇编代码中重新创建代码。

Check out this book if you are interested in these things: Reversing: Secrets of Reverse Engineering.

如果您对以下内容感兴趣,请查看这本书:逆向:逆向工程的秘密

Edit

编辑

Some compilers-101 here, if you were to define a compiler with another word and not as technical as "compiler", what would it be?

这里有一些编译器-101,如果你用另一个词来定义一个编译器,而不是像“编译器”那样技术性强,那会是什么?

Answer: Translator

答案:翻译

A compiler translates the syntax / phrases you have written into another language a C compiler translates to Assembly or even Machine-code. C# Code is translated to IL and so forth.

编译器将您编写的语法/短语翻译成另一种语言,C 编译器将其翻译成汇编甚至机器代码。C# 代码被翻译成 IL 等等。

The executable you have is just a translation of your original text / syntax and if you want to "reverse it" hence "translate it back" you will most likely not get the same structure as you had at the start.

您拥有的可执行文件只是原始文本/语法的翻译,如果您想“反转它”因此“将其翻译回来”,您很可能无法获得与开始时相同的结构。

A more real life example would be if you Translate from English to German and the from German back to English, the sentance structure will most likely be different, other words might be used but the meaning, the context, will most likely not have changed.

一个更真实的例子是,如果你从英语翻译成德语,然后从德语再翻译成英语,句子结构很可能会有所不同,可能会使用其他词,但意思和上下文很可能不会改变。

The same goes for a compiler / translator if you go from C to ASM, the logic is the same, it's just a different way of reading it ( and of course its optimized ).

如果您从 C 转到 ASM,则编译器/翻译器也是如此,逻辑是相同的,只是阅读方式不同(当然还有优化的)。

回答by Darin Dimitrov

It depends on what you mean by original C program. Things like local variable names, comments, etc... are not included in the binary, so there's no way to get the exact same source code as the one used to produce the binary. Tools such as IDA Promight help you disassemble a binary.

这取决于您所说的原始 C 程序是什么意思。诸如局部变量名称、注释等之类的东西……不包含在二进制文件中,因此无法获得与用于生成二进制文件的源代码完全相同的源代码。IDA Pro等工具可能会帮助您反汇编二进制文件。

回答by Hans Passant

I would guestimate the conversion rate of a really skilled hacker at about 1 kilobyte of machine code per day. At common Western salaries, that puts the price of, say, a 100 KB executable at about $25,000. After spending that much money, all that's gained is a chunk of C code that does exactly what yours does, minus the benefit of comments and whatnot. It is no way competitive with your version, you'll be able to deliver updates and improvements much quicker. Reverse engineering those updates is a non trivial effort as well.

我估计一个真正熟练的黑客的转换率约为每天 1 KB 的机器代码。以西方人的普通工资计算,例如 100 KB 可执行文件的价格约为 25,000 美元。在花了那么多钱之后,所获得的只是一大块 C 代码,它完全可以完成你的工作,减去评论和诸如此类的好处。它与您的版本没有任何竞争力,您将能够更快地提供更新和改进。对这些更新进行逆向工程也是一项重要的工作。

If that price tag doesn't impress you, you can arbitrarily raise the conversion cost by adding more code. Just keep in mind that skilled hackers that can tackle large programs like this have something much better to do. They write their own code.

如果那个价格标签没有给您留下深刻印象,您可以通过添加更多代码来任意提高转换成本。请记住,能够处理此类大型程序的熟练黑客有更好的事情要做。他们编写自己的代码。

回答by Ira Baxter

One of the best works on this topic that I know about is:

我所知道的关于这个主题的最好的作品之一是:

Pigs from sausages? Reengineering from assembler to C via FermaT.

来自香肠的猪?从通过费马汇编至C再造

The claim is you get back a reasonable C program, even if the original asm code was not written in C! Lots of caveats apply.

声称您得到了一个合理的 C 程序,即使原始的 asm 代码不是用 C 编写的!许多注意事项适用。

回答by joveha

The Hex-Raysdecompiler (extension to IDA Pro) can do exactly that. It's still fairly recent and upcoming but showing great promise. It takes a little getting used to but can potentially speed up the reversing process. It's not a "silver bullet" - no c decompiler is, but it's a great asset.

六角射线反编译器(扩展IDA Pro)的能做到这一点。它仍然是最近的和即将到来的,但显示出巨大的希望。这需要一点时间来适应,但可能会加快逆转过程。它不是“银弹”——没有 c 反编译器,但它是一项巨大的资产。

回答by John Bode

The common name for this procedure is "turning hamburger back into cows." It's possible to reverse engineer binary code into a functionally equivalent C program, but whether that C code bears a close resemblance to the original is an open question.

这个程序的通用名称是“把汉堡包变回奶牛”。可以将二进制代码逆向工程为功能等效的 C 程序,但该 C 代码是否与原始代码非常相似是一个悬而未决的问题。

回答by Pascal Cuoq

Working on tools that do this is a research activity. That is, it is possible to get something in the easy cases (you won't recover local variables names unless debug symbols are present, for instance). It's nearly impossible in practice for large programs or if the programmer had decided to make it difficult.

开发能够做到这一点的工具是一项研究活动。也就是说,有可能在简单的情况下得到一些东西(例如,除非存在调试符号,否则您将无法恢复局部变量名称)。对于大型程序,或者如果程序员决定让它变得困难,这在实践中几乎是不可能的。

回答by Mr. Boy

There is not a 1:1 mapping between a C program and the ASM/machine code it will produce - one C program can compile to a different result on different compilers or with different settings) and sometimes two different bits of C could produce the same machine code.

在 C 程序和它将产生的 ASM/机器代码之间没有 1:1 的映射——一个 C 程序可以在不同的编译器或不同的设置上编译成不同的结果),有时两个不同的 C 位可能产生相同的结果机器码。

You definitely cangenerate C code from a compiled EXE. You just can't know how similar in structure it will be to the original code - apart from variable/function names being lost, I assume it won't know the original way the code was split amongst many files.

您绝对可以从已编译的 EXE 生成 C 代码。您只是不知道它与原始代码在结构上有多么相似-除了丢失了变量/函数名称之外,我认为它不知道代码在许多文件中拆分的原始方式。

回答by Yuriy Y. Yermilov

You can try hex-rays.com, it has a really nice decompiler which can decompile assembly code into C with 99% accuracy.

你可以试试 hex-rays.com,它有一个非常好的反编译器,可以以 99% 的准确率将汇编代码反编译成 C。