#navi_header|技術| 使うたびにググってるので、いい加減、よく使うパターンについてメモ。 16進数(od, hexdump, xxd)と2進数(xxd)ダンプ出力の、よく使うコマンド例のまとめ。 (unix上でのバイナリファイルの編集については [[1118]] とか参照。) * od -v : 直前と同じ内容を持つ行も表示する。事実上、必須。 -Ax : 基数を16進数に。 -t : GNU od : -tx1z : 1バイトずつ16進数で、対応する文字を行末にまとめて表示。 BSD, Solaris : -tx1c : 1バイトずつ16進数で、対応する文字を次の行に表示。 #pre||> $ echo "abcdefghijklmnopabcdefghijklmnopqrstu" | od -Ax -tx1z 000000 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 >abcdefghijklmnop< * 000020 71 72 73 74 75 0a >qrstu.< 000026 $ echo "abcdefghijklmnopabcdefghijklmnopqrstu" | od -Ax -tx1z -v 000000 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 >abcdefghijklmnop< 000010 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 >abcdefghijklmnop< 000020 71 72 73 74 75 0a >qrstu.< 000026 $ echo "abcdefghijklmnopqrstu" | od -v -Ax -tx1c 000000 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 a b c d e f g h i j k l m n o p 000010 71 72 73 74 75 0a q r s t u \n 000016 ||< * hexdump from http://linuxjm.sourceforge.jp/html/util-linux/man1/hexdump.1.html : -C : 標準的な 16進数 + ASCII での表示。 -v : odの"-v"と似た機能。事実上、必須。 #pre||> $ echo "abcdefghijklmnopabcdefghijklmnopqrstu" | hexdump -C 00000000 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 |abcdefghijklmnop| * 00000020 71 72 73 74 75 0a |qrstu.| 00000026 $ echo "abcdefghijklmnopabcdefghijklmnopqrstu" | hexdump -C -v 00000000 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 |abcdefghijklmnop| 00000010 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 |abcdefghijklmnop| 00000020 71 72 73 74 75 0a |qrstu.| 00000026 ||< * xxd -g N : Nバイトごとにグルーピング。1バイトずつ見たいなら "-g 1" -b : 2進数表示 #pre||> $ echo "abcdefghijklmnopabcdefghijklmnopqrstu" | xxd -g 1 0000000: 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 abcdefghijklmnop 0000010: 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 abcdefghijklmnop 0000020: 71 72 73 74 75 0a qrstu. $ echo "abcdefghijklmnopabcdefghijklmnopqrstu" | xxd -g 2 0000000: 6162 6364 6566 6768 696a 6b6c 6d6e 6f70 abcdefghijklmnop 0000010: 6162 6364 6566 6768 696a 6b6c 6d6e 6f70 abcdefghijklmnop 0000020: 7172 7374 750a qrstu. $ echo "abcdefghijklmnopabcdefghijklmnopqrstu" | xxd -g 1 -b 0000000: 01100001 01100010 01100011 01100100 01100101 01100110 abcdef 0000006: 01100111 01101000 01101001 01101010 01101011 01101100 ghijkl 000000c: 01101101 01101110 01101111 01110000 01100001 01100010 mnopab 0000012: 01100011 01100100 01100101 01100110 01100111 01101000 cdefgh 0000018: 01101001 01101010 01101011 01101100 01101101 01101110 ijklmn 000001e: 01101111 01110000 01110001 01110010 01110011 01110100 opqrst 0000024: 01110101 00001010 u. ||< ---- 参考: - UNIXの部屋 コマンド検索:od (*BSD/Linux) -- http://x68000.q-e-d.net/~68user/unix/pickup?od - Linuxコマンド集 - 【 od 】 バイナリ・ファイルの内容を閲覧する:ITpro -- http://itpro.nikkeibp.co.jp/article/COLUMN/20060227/230853/ - Linux: od でちょっと見慣れた感じに表示 | Weekly Report -- http://naohisa.wordpress.com/2012/05/06/426/ - Man page of OD -- http://linuxjm.sourceforge.jp/html/gnumaniak/man1/od.1.html - odコマンドで16進ダンプを取る方法 — ディノオープンラボラトリ -- http://openlab.dino.co.jp/2007/08/23/2249177.html - Man page of HEXDUMP -- http://linuxjm.sourceforge.jp/html/util-linux/man1/hexdump.1.html #navi_footer|技術|