0?前言
在使用Linux的過程中,有時我們需要在obj文件或二進制文件中查找可打印的字符串,那么可以strings命令。
1. strings命令?的功能、格式和選項說明
我們可以使用命令 strings --help 來查看strings命令的幫助信息。
pupleEndurer @ bash ~ $ strings --help
Usage: strings [option(s)] [file(s)]
?Display printable strings in [file(s)] (stdin by default)
?The options are:
? -a - --all ? ? ? ? ? ? ? ?Scan the entire file, not just the data section [default]
? -d --data ? ? ? ? ? ? ? ? Only scan the data sections in the file
? -f --print-file-name ? ? ?Print the name of the file before each string
? -n --bytes=[number] ? ? ? Locate & print any NUL-terminated sequence of at
? -<number> ? ? ? ? ? ? ? ? ? least [number] characters (default 4).
? -t --radix={o,d,x} ? ? ? ?Print the location of the string in base 8, 10 or 16
? -w --include-all-whitespace Include all whitespace as valid string characters
? -o ? ? ? ? ? ? ? ? ? ? ? ?An alias for --radix=o
? -T --target=<BFDNAME> ? ? Specify the binary file format
? -e --encoding={s,S,b,l,B,L} Select character size and endianness:
? ? ? ? ? ? ? ? ? ? ? ? ? ? s = 7-bit, S = 8-bit, {b,l} = 16-bit, {B,L} = 32-bit
? -s --output-separator=<string> String used to separate strings in output.
? @<file> ? ? ? ? ? ? ? ? ? Read options from <file>
? -h --help ? ? ? ? ? ? ? ? Display this information
? -v -V --version ? ? ? ? ? Print the program's version number
strings: supported targets: elf64-x86-64 elf32-i386 elf32-iamcu elf32-x86-64 a.out-i386-linux pei-i386 pei-x86-64 elf64-l1om elf64-k1om elf64-little elf64-big elf32-little elf32-big plugin srec symbolsrec verilog tekhex binary ihex
Report bugs to <http://bugzilla.redhat.com/bugzilla/>
?
1.1 strings命令的功能
顯示文件中可打印的字符串。
1.2?strings命令的格式
strings [選項(s)] [文件(s)]
?1.3 strings命令的選項說明?
選項 | 說明 |
---|---|
-a --all - | 掃描整個文件而不是只掃描目標文件初始化和裝載段 |
-d --data | 僅打印文件中已初始化、加載的數據段中的字符串,這可能會減少輸出中的垃圾量 |
-e <encoding> --encoding=<s,S,b,l,B,L> | 選擇字符編碼與字節序。可取值: s=7bits的ASCII, S=8bits的Latin1, {b,l}=16bits寬字符大小端編碼, {B,L}=32bits寬字符大小端編碼。其中b,B代表bigendian,l,L代表littleendian |
-f –-print-file-name | 在顯示字符串前先顯示文件名 |
--help | 顯示幫助信息 |
-<min-len> -n <min-len> --bytes=<min-len> | 指定可打印字符序列的最小長度,不指定則默認是4個字符 |
-o | 類似 --radix=o |
-t <radix> --radix=<radix> | 輸出字符串在文件中的偏移位置,radix可取值o(octal,八進制)、d(decimal,十進制)或者x(hexadecimal,十六進制) |
-T <bfdname> --target=<bfdname> | 指定二進制文件格式 |
-v -V --version | 顯示版本信息 |
-w --include-all-whitespace | 默認情況下,Tab和空格字符包含在字符串中,但其他空白字符除外,比如換行符和回車符等字符不是。-w使所有的空白字符被認為是字符串的一部分 |
@<file> | 從指定的文件file總讀取命令行選項 |
字符串: 支持的目標: elf64-x86-64 elf32-i386 elf32-iamcu elf32-x86-64 a.out-i386-linux pei-i386 pei-x86-64 elf64-l1om elf64-k1om elf64-little elf64-big elf32-little elf32-big plugin srec symbolsrec verilog tekhex binary ihex
2 strings命令使用實例
我們先用echo命令創建一個用來演示命令用法的文件a.txt
pupleEndurer @ bash ~ $ echo -e "Hello \t world. \n\r I am PurpleEnduer :-P \a\b ..." > a.txt
然后我們使用cat命令查看文件a.txt的內容
pupleEndurer @ bash ~ $ cat a.txt
Hello ? ?world.?
?I am PurpleEnduer :-P ...
2.1 strings?文件名:查看文件中的可打印字符
pupleEndurer @ bash ~ $ strings a.txt
Hello ? ?world.?
?I am PurpleEnduer :-P?
?...
pupleEndurer @ bash ~ $?
?
2.2 strings -f?文件名:在顯示字符串前先顯示文件名
pupleEndurer @ bash ~ $ strings -f a.txt
a.txt: Hello ? ? world.?
a.txt: ?I am PurpleEnduer :-P?
a.txt: ?...
pupleEndurer @ bash ~ $?
2.3 strings -t x?文件名:以16進制輸出字符串在文件中的偏移位置
pupleEndurer @ bash ~ $ strings -t x a.txt
? ? ? 0 Hello ? ?world.?
? ? ?11 ?I am PurpleEnduer :-P?
? ? ?2a ?...
pupleEndurer @ bash ~ $?
2.4 strings -e?字符編碼與字節序 文件名:輸出符合指定字符編碼與字節序的可打印字符串
?pupleEndurer @ bash ~ $ strings -e S a.txt
Hello ? ?world.?
?I am PurpleEnduer :-P?
?...
pupleEndurer @ bash ~ $ strings -e{b,l} a.txt
pupleEndurer @ bash ~ $ strings -e{B,L} a.txt
pupleEndurer @ bash ~ $ strings -es a.txt
Hello ? ?world.?
?I am PurpleEnduer :-P?
?...
pupleEndurer @ bash ~ $?