Jak przeglądać pliki binarne z bash?

Chciałbym wyświetlić zawartość pliku w bieżącym katalogu, ale w formacie binarnym z linii poleceń. Jak mogę to osiągnąć?

Author: adam_0, 2009-11-19

12 answers

xxd robi zarówno binarne, jak i szesnastkowe.

Bin:

xxd -b file

Hex:

xxd file
 540
Author: Emilio Bool,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-04-10 08:47:10
hexdump -C yourfile.bin

Chyba, że chcesz to oczywiście edytować. Większość dystrybucji Linuksa ma domyślnie hexdump (ale oczywiście nie wszystkie).

 189
Author: tyranid,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-06-02 00:29:47
vi your_filename

Hit esc

Wpisz :%!xxd Aby wyświetlić ciągi szesnastkowe, n :%!xxd -r aby powrócić do normalnej edycji.

 71
Author: Duck,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-12-06 11:45:56

Jako alternatywa zawsze jest od -xc filename

 29
Author: Jim Garrison,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-11-19 18:07:16

sudo apt-get install bless

Bless to narzędzie GUI, które może przeglądać, edytować, przeglądać i wiele więcej. Jego bardzo lekka waga.
 11
Author: siddiq,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-11-03 09:06:03

Jeśli chcesz otworzyć pliki binarne (w CentOS 7):

strings <binary_filename>
 11
Author: Raju,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-10-03 06:57:33
 3
Author: intgr,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-11-19 18:08:36
$ echo -n 'Hello world!' | hd
00000000  48 65 6c 6c 6f 20 77 6f  72 6c 64 21              |Hello world!|
0000000c
 2
Author: Aalex Gabi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-07-30 15:40:47

Możesz otworzyć emacs (w trybie terminalowym, używając na przykład emacs -nw), a następnie użyć trybu Hexl: M-x hexl-mode.

Https://www.gnu.org/software/emacs/manual/html_node/emacs/Editing-Binary-Files.html

 2
Author: dividebyzero,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-04-11 15:11:15

Aby przekonwertować plik na jego kody binarne (reprezentacja szesnastkowa) mówimy:

xxd filename                                         #

Np:

xxd hello.c                                          #

Aby zobaczyć całą zawartość i kody w pliku binarnym, możemy użyć komend takich jak readelf i objdump, hexdump ,... .

Na przykład, jeśli chcemy zobaczyć wszystkie konwertowanie całej zawartości pliku binarnego (wykonywalne, biblioteki współdzielone, pliki obiektowe) mówimy:

hexdump binaryfilename

Np.

hexdump /bin/bash

Ale readelf jest najlepszym narzędziem do analizy elf(wykonywalnego i linkującego format) plików. więc jeśli powiemy:

readelf -a /bin/bash

Cała zawartość w pliku binarnym bash będzie nam pokazana, również możemy dostarczyć różne flagi dla readelf, aby zobaczyć wszystkie sekcje i nagłówki pliku elf osobno, na przykład, jeśli chcemy zobaczyć tylko nagłówek elf mówimy:

readelf -h /bin/bash

Do odczytu wszystkich segmentów pliku:

readelf -l /bin/bash

Do odczytu wszystkich sekcji pliku:

readelf -S /bin/sh

Ale znowu jako podsumowanie, do czytania normalnego pliku typu " hello.c " i binarny plik jak bash w path / bin / bash w Linuksie mówimy:

xxd hello.c

readelf -a /bin/bash
 1
Author: Mgh Gh,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-09-09 01:55:31

Formaty Hexyl: sudo apt install hexyl

Tutaj wpisz opis obrazka

 0
Author: caduceus,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-10-21 08:39:42

Możesz użyć pliku binarnego hexdump

sudo apt-get install hexdump

hexdump -C yourfile.bin
 -1
Author: craken,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-05-24 16:49:27