我使用过的linux命令之strings

strings命令用于输出文件中可打印的字符串。不论文件是普通文本,还是可执行文件,任何文件都可以。

最常用的选项:
-a 扫描整个文件的任何段,这是strings的默认行为,但是这种默认行为是可以改变的。所以建议加上此选项。
-f Print the name of the file before each string.
-n 字符串的最小长度。默认是4。也就是说长度小于4的字符串不会输出。

常用场景:

  1. 确定某个可执行文件的版本。
    生成的so文件的文件名往往不包含完整的版本号。
    故可以使用strings -a | grep xxx.xxx 来确认版本。
    当然,grep也可以。但是grep只能显示match与否,不能输出具体的字符串。

  2. 确认编译ko文件所使用的gcc版本

root@debian2:~/test# strings /lib/modules/4.9.0-7-686/kernel/net/netfilter/ipvs/ip_vs.ko | grep -i GCC
GCC: (Debian 6.3.0-18+deb9u1) 6.3.0 20170516
GCC: (Debian 6.3.0-18+deb9u1) 6.3.0 20170516
GCC: (Debian 6.3.0-18+deb9u1) 6.3.0 20170516
  1. 确认源文件与目标文件的对应关系
[taoge@localhost learn_c]$ strings -f * | grep "my dear"
a.out: oh, my dear, c is %d
test.c: 	printf("oh, my dear, c is %d\n", c);
[taoge@localhost learn_c]$ 

参考

  1. man strings
  2. https://blog.csdn.net/stpeace/article/details/46641069

猜你喜欢

转载自blog.csdn.net/qq_31567335/article/details/89666613