You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hexdump -h
Usage:
hexdump [options] <file>...
Display file contents in hexadecimal, decimal, octal, or ascii.
Options:
-b, --one-byte-octal one-byte octal display
-c, --one-byte-char one-byte character display
-C, --canonical canonical hex+ASCII display
-d, --two-bytes-decimal two-byte decimal display
-o, --two-bytes-octal two-byte octal display
-x, --two-bytes-hex two-byte hexadecimal display
-L, --color[=<mode>] interpret color formatting specifiers
colors are enabled by default
-e, --format <format> format string to be used for displaying data
-f, --format-file <file> file that contains format strings
-n, --length <length> interpret only length bytes of input
-s, --skip <offset> skip offset bytes from the beginning
-v, --no-squeezing output identical lines
-h, --help display this help
-V, --version display version
Arguments:
<length> and <offset> arguments may be followed by the suffixes for
GiB, TiB, PiB, EiB, ZiB, and YiB (the "iB" is optional)
For more details see hexdump(1).
-C, --canonical
Canonical hex+ASCII display. Display the input offset in
hexadecimal, followed by sixteen space-separated, two-column,
hexadecimal bytes, followed by the same sixteen bytes in %_p
format enclosed in | characters. Invoking the program as hd
implies this option.
0000000 211 P N G \r \n 032 \n \0 \0 \0 \r I H D R
0000010 \0 \0 001 D \0 \0 001 036 \b 006 \0 \0 \0 362 377 l
0000020 W \0 \0 002 ) i T X t X M L : c o m
0000030 . a d o b e . x m p \0 \0 \0 \0 \0 <
0000040 ? x p a c k e t b e g i n = "
The text was updated successfully, but these errors were encountered:
YumaInaura
changed the title
Linux - Docker Ubuntu – バイナリファイルをHEX (16進数) で出力する
Linux - Docker Ubuntu – hexdumpコマンドでバイナリファイルをHEX ( 16進数 ) で出力する
May 8, 2024
YumaInaura
changed the title
Linux - Docker Ubuntu – hexdumpコマンドでバイナリファイルをHEX ( 16進数 ) で出力する
Linux - Docker Ubuntu – hexdumpコマンドでバイナリファイルをHEX ( 16進数 ) で標準出力する
May 8, 2024
docker Ubutu で試してみる
ホストマシンでdockerを起動する
カレントディレクトリにバイナリファイル ( この例では
test.png
) を置いておいて、dockerコンテナ の/home/
にマウントしておく以下dockerの操作
これで hexdump コマンドが使えるようになる
次にdocker上でバイナリファイルのあるディレクトリに移動しておく
今回利用したサンプルのバイナリファイル ( 画像 )
ものすごくてきとうに作ったファイルなので文字が見切れている変な画像だが、以下を利用した (
test.png
)hexdump コマンドのヘルプ
概要
デフォルト実行 ( 2バイト 16進数 )
hexdump test.png | head -n 5
デフォルトでは
--two-bytes-hex
オプションを付けたときと同じで「2バイトの16進数」が標準出力されるようだ。オプションに
--two-bytes-hex
を指定すると何故かタブ幅だけが違ったが、同じ内容が出力されるhexdump --two-bytes-hex test.png | head -n 5
なお 一番左の列の
0000000
0000010
とかいう部分はオフセットといい、各行の表示位置を示すようだ標準的な出力 ( canonical – hex+ASCII )
canonical オプション (
canonical hex+ASCII display
)を指定して実行してみるすると
.PNG........IHDR
のような部分 ) が出力されるということが分かる
hexdump --canonical test.png | head -n 5
ではこのHEXはデフォルト実行 ( 2バイト 16進数 ) とは何が違うのか?
よく見るとデフォルト実行では
5089
だった部分が89 50
と表示されていたりと、すべて逆順になっているのが分かるこの Canonical とは何なのか?
どうやらバイナリ表示をする時の標準的なフォーマットらしい
https://man7.org/linux/man-pages/man1/hexdump.1.html
hexdump の短縮形の hd コマンドでも同じ結果が返ってくるので、こちらが「標準」のようだ
フォーマット
自由にフォーマットもできるようだ
参考:
https://www.baeldung.com/linux/convert-binary-to-hexadecimal
Hexを1行につなげる
以下コマンドで16進数を1行につなげた値が得られた
参考 - Canonical 以外
Canonical以外のフォーマットを並べてみると以下のようになる
hexdump --one-byte-octal test.png | head -n 5
hexdump --one-byte-char test.png | head -n 5
hexdump --two-bytes-decimal test.png | head -n 5
hexdump --two-bytes-octal test.png | head -n 5
hexdump --two-bytes-hex test.png | head -n 5
他、参考
【 hexdump 】コマンド――ファイルを8進数や16進数でダンプする
https://atmarkit.itmedia.co.jp/ait/articles/1810/26/news039.html
基礎用語 バイナリファイルの解析
https://digitaltravesia.jp/usamimihurricane/webhelp/_RESOURCE/words/words9.html
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。
https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ
プロフィール・経歴
https://github.com/YumaInaura/YumaInaura
The text was updated successfully, but these errors were encountered: