How can I see the 0s and 1s / machine code from a executable file / object file?
Asked Answered
F

5

5

I already tried this, I opened a a.out file with a text editor but I get only a bunch of characters with some instructions in it like:

üÙ

Foolish answered 25/1, 2011 at 16:57 Comment(1)
possible duplicate of Viewing File in Binary in TerminalHanna
A
5

Try hexdump. Something like:

$ hexdump -X a.out

It will give you just that: an hexadecimal dump of the file.

Having said that, another possibility might include using GDB's disassemble command.

Archeozoic answered 25/1, 2011 at 17:1 Comment(0)
W
3

Lookup your local friendly Hex Editor.

Wilkerson answered 25/1, 2011 at 17:2 Comment(0)
F
0

To see the disassembly (with opcode bytes) of the code only, not including any file headers:

objdump -d a.aot
Fictionist answered 25/1, 2011 at 17:7 Comment(0)
I
0

Executable files come in several formats. For Unix/Linux it's ELF: http://en.wikipedia.org/wiki/Executable_and_Linkable_Format

For Windows it's PE: http://en.wikipedia.org/wiki/Portable_Executable

Use the objdump tools to see the opcodes as others have pointed out

Interpose answered 25/1, 2011 at 17:19 Comment(0)
M
0

when you open a binary file you would see unreadable characters, the reason is that ascii encoding uses 7 bits , therefore all the characters that have a code point from 128 to 255 won't be recognized by the editor and therefore you see unknown characters.

if you want to see all the contents of a binary file , you could use programs like hexdump,objdump and readelf, for example lets say we want to dissect /bin/bash as a binary file in linux(elf) into its bytes in hexadecimal representation, so we say:

hexdump /bin/bash

but the best tool for these kind of files is: readelf

if we want to see all the contents of a binary file in a more human-readable format than the hexdump output we could just say:

readelf -a /bin/bash

and we would see all different sections of the binary file (elf header, program header , sections header and data).

also using other flags we could see only one header at a time, or we could just disassemble the .text sections in the file and so on.

Maiolica answered 8/9, 2020 at 21:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.