It is possible to read an object file?
Asked Answered
B

3

14

I was curious about .obj files: I pretty much don't know what they are (or what they contain), so I opened them with Vim text editor and what I found inside was an Alien like language...

Is there any way to understand what they represent and what is their content Also, for what are they being used ?

Thanks.

Basalt answered 22/12, 2011 at 5:15 Comment(1)
An object file is the output of a compiler. It's generally in binary and is meant to be understood by a linker, not by a human being. Why would wou want to open one?Hypoglycemia
K
10

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...

Kokoschka answered 22/12, 2011 at 5:25 Comment(2)
I dont use visual studio I rather prefer CodeBlocks what I could do?Basalt
+1 for the link! The article provides a great deal of information regarding the elf format!Sorely
H
7

The .obj files used by link.exe has MS COFF format.

You can find "Microsoft PE and COFF Specification" here, and parse .obj file according to it.

Or, you can use existing tool like dumpbin.

Hysterogenic answered 22/12, 2011 at 7:49 Comment(0)
C
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.

Close answered 22/12, 2011 at 5:25 Comment(2)
Very good response but im doing this on windows and I doubt it has those console optionsBasalt
Ahl yes, readelf really is for ELF files. Not so useful on Windows unless you're cross-compiling.Close

© 2022 - 2024 — McMap. All rights reserved.