13

我对文件很好奇.obj:我几乎不知道它们是什么(或它们包含什么),所以我用 Vim 文本编辑器打开它们,我发现里面是一种类似外星人的语言......

有什么方法可以理解它们代表什么以及它们的内容是什么另外,它们的用途是什么?

谢谢。

4

3 回答 3

9

Sure.

But every different platform has a different object format. On Windows, you could use a tool like dumpbin (dumpbin comes with Visual Studio). On Linux, you could use "dumpobj", or disassemble the program.

Here's a good link for Linux:

http://www.linuxjournal.com/article/1060

PS: objdump also lets you disassemble the object. Like you used to be able to do with "debug" on DOS PCs...

于 2011-12-22T05:25:04.593 回答
7

使用的.obj文件link.exe具有 MS COFF 格式。

您可以在此处找到“Microsoft PE 和 COFF 规范” ,并据此解析.obj文件。

或者,您可以使用现有的工具,例如dumpbin.

于 2011-12-22T07:49:17.010 回答
5

The readelf tool is good at showing you some details on the data:

$ readelf -a /usr/bin/readelf
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Advanced Micro Devices X86-64
...

Some of its abilities to inspect specific sections of the executable can come in handy too:

$ readelf -p .rodata /usr/bin/readelf | more

String dump of section '.rodata':
  [     4]  R_IA64_IMM14
  [    11]  R_IA64_NONE
  ...
  [  1f58]    Personality routine: 
  [  1f70]  __gcc_personality_v0
  [  1f85]  __gxx_personality_v0
  [  1f9a]  __gcj_personality_v0
  [  1faf]  __gnu_objc_personality_v0
  ...

Actually disassembling the code is a bit of a stretch; if you compile your code with -g for debugging symbols, you can use readelf --debug-dump to read the program source, type information, etc.

于 2011-12-22T05:25:33.313 回答