如何从 .so 文件中提取 C 源代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5933057/
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
How to extract C source code from .so file?
提问by Ravi
I am working on previously developed software and source code is compiled as linux shared libraries (.so) and source code is not present. Is there any tool which can extract source code from the linux shared libraries?
我正在研究以前开发的软件,源代码被编译为 linux 共享库 (.so),并且源代码不存在。有没有可以从linux共享库中提取源代码的工具?
Thanks, Ravi
谢谢,拉维
回答by cnicutar
There isn't. Once you compile your code there is no trace of it left in the binary, only machine code.
没有。一旦你编译了你的代码,二进制文件中就没有留下任何痕迹,只有机器代码。
Some may mention decompilers but those don't extract the source, they analyze the executable and produce some source that should have the same effect as the original one did.
有些人可能会提到反编译器,但那些不会提取源代码,它们会分析可执行文件并生成一些与原始文件具有相同效果的源代码。
回答by Stephen Canon
No. In general, this is impossible. Source is not packaged in compiled objects or libraries.
不。一般来说,这是不可能的。源代码未打包在已编译的对象或库中。
回答by phoxis
You can try disassembling the object code and get the machine code mnemonics.
您可以尝试反汇编目标代码并获取机器代码助记符。
objdump -D --disassembler-options intel sjt.o
to get Intel syntax assembly
objdump -D --disassembler-options intel sjt.o
获取英特尔语法汇编
objdump -D --disassembler-options att sjt.o
or objdump -D sjt.o
to get AT&T syntax assembly
objdump -D --disassembler-options att sjt.o
或objdump -D sjt.o
获取 AT&T 语法汇编
But the original source code could never be found. You might try to reverse the process by studying and reconstruct the sections. It would he hell pain.
但始终找不到原始源代码。您可以尝试通过研究和重建这些部分来扭转这个过程。他会很痛苦。
回答by Igor Skochinsky
Disclaimer: I work for Hex-Rays SA.
免责声明:我为 Hex-Rays SA 工作。
The Hex-Rays decompiler is the only commercially available decompiler I know of that works well with real-lifex86 and ARM code. It's true that you don't get the original source, but you get something which is equivalent to it. If you didn't strip your binary, you might even get the function names, or, with some luck, even types and local variables. However, even if you don't have symbol info, you don't have to stick to the first round of decompilation. The Hex-Rays decompiler is interactive- you can rename any variable or function, change variable types, create structure types to represent the structures in the original code, add comments and so on. With a little work you can recover a lot. And quite often what you need is not the whole original file, but some critical algorithm or function - and this Hex-Rays can usually provide to you.
Hex-Rays 反编译器是我所知道的唯一一个商业上可用的反编译器,它适用于现实生活中的x86 和 ARM 代码。确实,您没有获得原始来源,但您获得了与它等效的东西。如果你没有剥离你的二进制文件,你甚至可能得到函数名,或者,幸运的话,甚至可以得到类型和局部变量。但是,即使您没有符号信息,也不必坚持进行第一轮反编译。Hex-Rays 反编译器是交互式的——您可以重命名任何变量或函数、更改变量类型、创建结构类型以表示原始代码中的结构、添加注释等。只需稍加努力,您就可以恢复很多. 通常你需要的不是整个原始文件,而是一些关键的算法或函数——这个 Hex-Rays 通常可以提供给你。
Have a look at the demovideosand the comparisonpages. Still think "staring at the assembly" is the same thing?
回答by arshad
You cannot. But you can open it as an archive in 7-Zip. You can see the file type and size of each file separately in that. You can replace the files in it with your custom files.
你不能。但是您可以在 7-Zip 中将其作为存档打开。您可以在其中分别查看每个文件的文件类型和大小。您可以使用自定义文件替换其中的文件。