Excerpt from: http://blog.csdn.net/stpeace/article/details/46641069
Introduction to Strings commands in Linux
In Linux under the software development of friends, almost no do not know the strings command. Let's take a look at the man strings first:
Strings-print the strings of printable characters in files. This means that the printable characters in the file are printed. Let me add that this file can be a text file (test.c), an executable file (test), a dynamic link library (TEST.O), a static link library (TEST.A) that is out of the code and not actually validated, not my style. Let's get some code under the menu (code exists in test.c):
1#include <stdio.h>2 3 intAddintXinty)4 {5 returnX +y;6 }7 8 intMain ()9 {Ten intA =1; One intb =2; A intc =Add (A, b); -printf"Oh, my dear, C is%d\n", c); - the return 0; -}
Let's take a look at the results of strings test.c:
1 [email protected] learn_c]$ strings test.c2#include <stdio.h>3 intAddintXinty)4 returnX +y;5 intMain ()6 intA =1;7 intb =2;8 intc =Add (A, b);9printf"Oh, my dear, C is%d\n", c);Ten return 0; One[Email protected] learn_c]$
As you can see, many of the characters in test.c are actually printed out. Below, let's try the executable file with strings, as follows:
1 [email protected] learn_c]$ gcc test.c2[Email protected] learn_c]$ strings A. out 3/lib/ld-linux.so.24=$TsU5 __gmon_start__6Libc.so.67 _io_stdin_used8 printf9 __libc_start_mainTenGlibc_2.0 One PTRh A[^_] -Oh, my dear, C is%D -[Email protected] learn_c]$
To see, print out a lot of characters in a.out. In fact, if you have a target file, a static library, or a dynamic library, you can also print with the strings command. Let's take a look at: Xxx.h file:
1 void print ();
1 #include <stdio.h>2"xxx.h"34void print () 5 {6 printf ("rainy days\n"); 7 }
Then, let's look at how to make a static, dynamic library (detailed in the next blog post):
1 [[email protected] learn_strings]$ ls2 xxx.c xxx.h3[Email protected] learn_strings]$ gcc-C xxx.c4 [email protected] learn_strings]$ ar RCS libxxx.a xxx.o5[Email protected] learn_strings]$ Gcc-shared-fpic-o libxxx.so xxx.o6 [[email protected] learn_strings]$ ls7 libxxx.a libxxx.so xxx.c xxx.h xxx.o8 [email protected] learn_strings]$ strings XXX.O9 Rainy DaysTen [email protected] learn_strings]$ strings LIBXXX.A One!<arch> A/1437887339 0 0 0 - ` - Rprint -xxx.o/1437887333 501 502 100664 848 ` the Rainy Days -GCC: (GNU)4.4.4 20100726(Red Hat4.4.4- -) - . Symtab - . Strtab + . Shstrtab - . Rel.text + . Data A . BSS at . Rodata - . Comment -. Note. gnu-Stack - xxx.c - Print - puts in [email protected] learn_strings]$ - [email protected] learn_strings]$ to [email protected] learn_strings]$ strings libxxx.so + __gmon_start__ - _init the _fini * __cxa_finalize $ _jv_registerclassesPanax Notoginseng Print - puts theLibc.so.6 + _edata A __bss_start the _end +Glibc_2.1.3 -Glibc_2.0 $ Rainy Days $[Email protected] learn_strings]$
See it. The strings command is simple and looks like nothing, but it actually has a lot of use. Here, let me give you an example. in large-scale software development, suppose there are 100. c/.cpp files, and this. cpp file eventually generates 10. So libraries, so how can you quickly know if a. c/.cpp file is compiled into the. So library? Of course, you may have to say, see Makefile don't know. Yes, look makefile certainly can, but the following method is better, directly with the command: strings-f "*.so" | grep "xxxxxx" If you don't understand it, use the applet above as an example to illustrate, but here we consider all the files, as follows:
1 " My dear " 2 A. out are%D3 test.c: printf ("Oh, my dear, C is%d\n< /c11>", c); 4
You can see that the source file test.c and executable files are all "my dear" string, all of a sudden found the corresponding file, clear it. If a. c/.cpp file is compiled into the. So library, then, strings-f * | grep "My dear" must be able to find the corresponding. So file, where "my dear" is a log string in the. c/.cpp file (for example, print in printf). Strings of the role of the first introduction to this, is a very familiar with the strings bar.
Introduction to Strings commands in Linux