简体   繁体   English

如何打开 .o 文件?

[英]How to open .o file?

After compiling a C program, you get a .o file.编译一个 C 程序后,你会得到一个 .o 文件。 I know it's a file consisting of '0's and '1's and if formed after successful compilation of a program.我知道这是一个由“0”和“1”组成的文件,并且是在成功编译程序后形成的。 But I want to see what is in the file!但我想看看文件里有什么!

you've got a couple of choices here.你在这里有几个选择。

Firstly (and easiest) is to use something that decodes the file to show you what it is.首先(也是最简单的)是使用解码文件的东西来显示它是什么。 objdump on linux does this. linux 上的 objdump 就是这样做的。

gcc -c test.c

gives you test.o给你 test.o

objdump -D test.o

will decode the file and show you what's in it on standard output (so pipe it to less or similar) Objdump output shows you the unlinked object file.将解码文件并在标准输出中向您显示其中的内容(因此将其传送到更少或类似的内容) Objdump 输出向您显示未链接的目标文件。 The addresses aren't valid and have to be fixed up by the linker.地址无效,必须由链接器修复。
the format is first a line number then some number of bytes that are the cpu instruction, these are shown in hexadecimal.eg 14 means 00010100 next comes the instruction that these byes represent格式首先是行号,然后是作为 cpu 指令的一些字节数,这些以十六进制显示。例如 14 表示 00010100 接下来是这些字节表示的指令

   0:   14 00                   adc    $0x0,%al

so above we have line 0 of the function - it's unlinked) 14 00 - these are the bytes they mean add with carry 0 to the al register storing the result in al所以在上面我们有函数的第 0 行 - 它没有链接)14 00 - 这些是它们的意思的字节加上进位 0 到 al 寄存器,将结果存储在 al 中

Another alternative is to use a hex editor and try and work out what 14 00 means without any assistance.另一种选择是使用十六进制编辑器,并在没有任何帮助的情况下尝试找出 14 00 的含义。

Good luck.祝你好运。

You can use hexdump command from the terminal to display the content.您可以从终端使用hexdump命令来显示内容。

Syntax : $ hexdump <filename>.o语法: $ hexdump <filename>.o

It will show you the content in hexadecimal form.它将以hexadecimal形式向您显示内容。

just use a hex editor. 只需使用十六进制编辑器。 It Allows you to find data patterns in multi-gigabyte files in seconds. 它使您可以在几秒钟内找到数GB的文件中的数据模式。 It's powerful. 功能强大。 Supports regular expression search across the files. 支持跨文件的正则表达式搜索。 It's handy. 很方便 Allows you to make file patches in just one click. 一键制作文件补丁。 It's smart. 很聪明 It's flexible. 它很灵活。 It's efficient. 效率很高。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM