Ubuntu 20.04 LTS でバイナリファイルを表示

Ubuntu Desktop 20.04 LTS でバイナリファイル、または実行ファイルの文字列を表示する手順です。

バイナリファイルとは

テキストファイル以外のファイルで、メモ帳等のテキストエディタで編集できないファイルを指します。
バイナリファイルを less で実行すると以下のように表示されます。

$ less wtmp
"wtmp" may be a binary file.  See it anyway? y
^B^@^@^@^@^@^@^@~^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@~~^@^@reboot^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@5.8.0-59-ge
neric^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ESC^W<E9>`<A2>^@^L^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^G^@^@^@^N^F^@^@:0^@^@

strings コマンドについて

バイナリファイルの中には、一部テキストが含まれる場合もあり、strings コマンドは、この文字列として読める部分を表示することができます。

strings のインストール

Ubuntu 20.04 LTS に strings をインストールするには、以下を実行します。

sudo apt install binutils

stings -version コマンドでバージョンが表示されれば、インストール成功です。

$ strings -version
GNU strings (GNU Binutils for Ubuntu) 2.34
Copyright (C) 2020 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty.

バイナリファイルに strings コマンドを実行すると、文字列のみ表示します。

$ strings wtmp 
reboot
5.8.0-59-generic
runlevel
shutdown

以上

参考書籍

created by Rinker
¥4,180 (2024/04/20 11:06:58時点 楽天市場調べ-詳細)