DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Analyze Binary File in Linux


On Linux there are some utility to analyze binary files, such as xxd, od, hexdump, which are much convenient and powerful than UltraEdit on Windows.

$ cat test
abcdefg
hijklmn
opq
rst
uvw
xyz

$ xxd test
0000000: 6162 6364 6566 670a 6869 6a6b 6c6d 6e0a  abcdefg.hijklmn.
0000010: 6f70 710a 7273 740a 7576 770a 7879 7a0a  opq.rst.uvw.xyz.

$ xxd -b test
0000000: 01100001 01100010 01100011 01100100 01100101 01100110  abcdef
0000006: 01100111 00001010 01101000 01101001 01101010 01101011  g.hijk
000000c: 01101100 01101101 01101110 00001010 01101111 01110000  lmn.op
0000012: 01110001 00001010 01110010 01110011 01110100 00001010  q.rst.
0000018: 01110101 01110110 01110111 00001010 01111000 01111001  uvw.xy
000001e: 01111010 00001010                                      z.

$ xxd -b -s 10 test
000000a: 01101010 01101011 01101100 01101101 01101110 00001010  jklmn.
0000010: 01101111 01110000 01110001 00001010 01110010 01110011  opq.rs
0000016: 01110100 00001010 01110101 01110110 01110111 00001010  t.uvw.
000001c: 01111000 01111001 01111010 00001010                    xyz.

$ xxd -b -s 0x10 test
0000010: 01101111 01110000 01110001 00001010 01110010 01110011  opq.rs
0000016: 01110100 00001010 01110101 01110110 01110111 00001010  t.uvw.
000001c: 01111000 01111001 01111010 00001010                    xyz.

$ xxd -b -s 3 -l 10 test
0000003: 01100100 01100101 01100110 01100111 00001010 01101000  defg.h
0000009: 01101001 01101010 01101011 01101100                    ijkl

$ xxd -b -s 3 -l 10 -c 1 test
0000003: 01100100  d
0000004: 01100101  e
0000005: 01100110  f
0000006: 01100111  g
0000007: 00001010  .
0000008: 01101000  h
0000009: 01101001  i
000000a: 01101010  j
000000b: 01101011  k
000000c: 01101100  l

$ xxd -p -s 3 -l 10 test
646566670a68696a6b6c

Compare hex and binary files line by line:

$ xxd -b -c 2 binaryfile > o1
$ xxd -c 2 binaryfile > o2
$ paste o1 o2
0000000: 11001101 11001101  ..  0000000: cdcd  ..
0000002: 00000000 00101110  ..  0000002: 002e  ..
0000004: 10011000 00000011  ..  0000004: 9803  ..
0000006: 11101011 00100000  .   0000006: eb20  . 
0000008: 00000010 10001011  ..  0000008: 028b  ..
000000a: 01000011 00111000  C8  000000a: 4338  C8
000000c: 00001011 10111111  ..  000000c: 0bbf  ..
000000e: 10011011 01100101  .e  000000e: 9b65  .e
0000010: 10000111 00001111  ..  0000010: 870f  ..
0000012: 00100000 00100000      0000012: 2020    
0000014: 00000010 00011100  ..  0000014: 021c  ..
0000016: 01111001 00000001  y.  0000016: 7901  y.
0000018: 01110110 01011100  v\  0000018: 765c  v\
000001a: 00000000 00011011  ..  000001a: 001b  ..
000001c: 00101100 01111101  ,}  000001c: 2c7d  ,}
000001e: 00010001 00011011  ..  000001e: 111b  ..
0000020: 01100101 10001111  e.  0000020: 658f  e.
0000022: 10100010 01010100  .T  0000022: a254  .T
0000024: 10101000 01011011  .[  0000024: a85b  .[
0000026: 00101100 10010011  ,.  0000026: 2c93  ,.
0000028: 11100101 01110100  .t  0000028: e574  .t
000002a: 00100010 11011001  ".  000002a: 22d9  ".
000002c: 01100000 01100000  ``  000002c: 6060  ``
000002e: 11101001 00011111  ..  000002e: e91f  ..
0000030: 00000000 00000000  ..  0000030: 0000  ..


Published

Apr 29, 2014

Last Updated

Apr 29, 2014

Category

Tech

Tags

  • binary 2
  • file 6
  • linux 158

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor