表示用了很久的linux(其实并没有+_+),strings指令还是最近为了识别动态库版本才发现的,在此做一个汇总。
首先当然是查看帮助文档了,输入strings --help。
alex@alex:~$ 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 pe-x86-64 pe-bigobj-x86-64 pe-i386 plugin srec symbolsrec verilog tekhex binary ihex
Report bugs to <http://www.sourceware.org/bugzilla/>
alex@alex:~$
可知该指令功能是将文件中的可打印字符串显示出来,默认会以标准输出显示在控制台上(但我一直对什么是“可打印字符串”不理解)。文档内容并不多,不过很多参数都不理解,这里只对指令用法做个记录。
前面提到,当初是为了识别动态库的版本才用的这个指令。因为最近动态库迭代次数过多,很容易搞混,因此考虑用日期和编译时间作为版本,方便查看和控制。在编译成库的代码中增加一行:
其中"lib_version"是为了作为tag,方便用strings时进行筛选。对封装的库进行查看:strings xxx.so|grep "lib_version",就可以显示出版本号了。
很多人会把密码或敏感信息直接写死在程序中,其实很容易被strings指令查询出来。