tags:

views:

153

answers:

6

When one reads a file lets say a dd image or we read from a hard drive itself with cat /dev/sda, the output is usually mush in some form of Hex. Since these are actually binary files is there a way to see the binary instead of the hex.

Add: So here is the output of a windows 7 dd image of a hdd. As you can see it is just hex mush. I instead would like to see the actual binary, instead of a interpretation in hex.

3<C0><8E>м^@|<8E><C0><8E><U+063E>^@|<BF>^@^F<B9>^@^B<FC><F3><A4>Ph^\^F<CB><FB><B9>^D^@<BD><BE>^G<80>~^@^@|^K^O<85>^N^A<83><C5>^P<E2><F1><CD>^X�88>V^@U<C6>F^Q^E<C6>F^P^@<B4>A<BB><AA>U<CD>^S]r^O<81><FB>U<AA>u
<F7><C1>^A^@t^C<FE>F^Pf`<80>~^P^@t&fh^@^@^@^@f<FF>h^@^@h^@|h^A^@h^P^@<B4>B
<8A>V^@<8B><F4><CD>^S<9F><83><C4>^P<9E><EB>^T<B8>^A^B<BB>^@|<8A>V^@<8A>v^A<8A>N^B<8A>n^C<CD^Sfas^\<FE>N^Qu^L<80>~^@<80>^O<84><8A>^@<B2><80> <EB><84>U2<E4><8A>V^@<CD>^S]랁<FE>}U<AA>un<FF>v^@<E8><8D>^@u^W<FA><B0><D1><E6>d<E8><83>^@<B0><DF><E6>`<E8>|^@<B0><FF><E6>d<E8>u^@<FB><B8>^@
<BB><CD>^Zf#<C0>u;f<81><FB>TCPAu2<81><F9>^B^Ar,fh^G<BB>^@^@fh^@^B^@^@f^@^@^@fSfSfUfh^@^@^@^@fh^@|^@^@fah^@^@^G<CD>^ZZ2<F6><EA>^@|^@^@<CD>^X
<A0><B7>^G<EB>^H<A0><B6>^G<EB>^C<A0><B5>^G2<E4>^E^@^G<8B><F0><AC><^@t
<BB>^G^@<B4>^N<CD>^P<EB><F2><F4><EB><FD>+<C9><E4>d<EB>^@$^B<E0><F8>$^B<C3>Invalid
partition table^@Error loading
operating system^@Missing operating
system^@^@^@c{<9A>~<8B>^V<C8>V <80>
!^@^G<FE><FF><FF>^@^H^@^@^@<E8><A7>^H^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@U
<AA>-kM-dM-^JV^@`M-;M-*UM-4AM-M^Sr6M-^AM-{UM-*u0M-vM-A^At+a`j^@j^@M-^?v
M-^?v^Hj^@h^@|j^Aj^PM-4BM-^KM-tM-M^Saas^NOt^K2M-dM-^JV^@M-M^SM-kM-VaM-yM-CInvalid
partition table^@Error loading
operating system^@Missing operating
system^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@,Dcv^Wv^W^@^@M-^@^A^A^@^GM-~M-^?M-^??^@^@^@M-^OM-^AM-'^H^
A: 

cat should dump binary. If you're really seeing printable hex then xxd -r can be used to maybe find out what's going on.

Xepoch
It does, but it comes out like I amended above. Not 1's and 0's.
Recursion
+4  A: 

Try: hd filename

Edit:

Try:

xxd -b filename

Here's a sample:

$ xxd -b /usr/bin/xxd
0000000: 01111111 01000101 01001100 01000110 00000001 00000001  .ELF..
0000006: 00000001 00000000 00000000 00000000 00000000 00000000  ......
000000c: 00000000 00000000 00000000 00000000 00000010 00000000  ......
0000012: 00000011 00000000 00000001 00000000 00000000 00000000  ......
0000018: 10110000 10001000 00000100 00001000 00110100 00000000  ....4.
000001e: 00000000 00000000 11100100 00110001 00000000 00000000  ...1..
0000024: 00000000 00000000 00000000 00000000 00110100 00000000  ....4.
000002a: 00100000 00000000 00001001 00000000 00101000 00000000   ...(.
0000030: 00011101 00000000 00011100 00000000 00000110 00000000  ......
0000036: 00000000 00000000 00110100 00000000 00000000 00000000  ..4...
Dennis Williamson
+1  A: 

Most data on a HDD is binary data not meant to represent printable characters, so if you use cat (a command meant to output text, not binary) you get meaningless "mush".

cat will dump binary, as Xepoch said, but only by assuming the bytes are printable characters. In the example you provided, the bytes are not encoding text, and the characters you see don't make much sense.

If you need output formatted in hexadecimal, use hd as Dennis suggested.

I believe the od command could be persuaded to output binary as 1s and 0s.

Correction: the od command is a predecessor of hd, I suppose. It doesn't do binary output (ie, 1s and 0s). Neither does hd.

Would output in the form of 1s and 0s make any more sense? I doubt it, and it would require too much screen real estate. Hex and Octal are close enough to binary.

pavium
Its not that I want it to make sense, I just want to see the binary output, rather than the assumption of bytes in characters,
Recursion
In which case, use `hd` and see the hex values, not the 'printable' characters.
pavium
I guess you are correct that they are good eneogh, but id still like the binary if possible. I guess I could write a app to convert on the fly.
Recursion
Since it's relatively easy to mentally convert Hex to Binary, and Hex representations are more compact, people don't usually insist on binary representations - but by all means 'roll your own'.
pavium
Read the options of the od command, which can dump in all sorts of things other than hex. I don't recall it if can be made to dump in 010010010001 really truly binary.
bmargulies
+1  A: 

If you really want a binary representation of the data, you could do it like this:

perl -ne 'printf "0x%04x %s\n", $o++, unpack("B*", substr($_, 0, 1, "")) while length;' datafile

The output will look a little like this:

0x0000 00000001
0x0001 00000010
0x0002 00110011
0x0003 00110100
0x0004 00001010

If that's not what you want, please be a little more specific about what you're expecting.

Tim
+1  A: 

You will need a rather wide terminal, but you could do something like:

#!/bin/sh
od "$@" | sed -e s/0/000/g -e s/1/001/g -e s/2/010/g -e s/3/011/g -e s/4/100/g -e s/5/101/g -e s/6/110/g -e s/7/111/g
DigitalRoss
A: 

I use a tool called hexdump. It produces a nicely formatted hex dump.

cat /dev/random |  hexdump -C
00000000  ee ae 18 a7 7f e2 a6 db  eb 2b d5 4f ec 90 7d 61  |.........+.O..}a|
00000010  83 88 b0 2f 8f 06 f8 35  b5 88 0e ca e6 0a b6 71  |.../...5.......q|
00000020  4a ff bf ab 1e 13 49 33  e0 dc 78 23 98 ca 07 a6  |J.....I3..x#....|
Jason