Monday, September 25, 2006

Interesting behavior of the strings command

I got a little frustrated with strings the other day, so I figured I'd share. strings appears to try to be "smart" about handling fat (universal) binaries by only processing the binary for the host architecture. This means that if you run strings /some/binary/file it may not actually show you all the strings in the file if the binary is fat. An alternative is to instead use cat /some/binary/file | strings or you can use the undocumented -arch option, like strings -arch all /some/binary/file.

For example:

$ cd /Applications/Camino.app/Contents/MacOS/
$ file Camino
Camino: Mach-O fat file with 2 architectures
Camino (for architecture i386): Mach-O executable i386
Camino (for architecture ppc): Mach-O executable ppc
$ strings Camino | wc -l
27224
$ strings -arch ppc Camino | wc -l
27224
$ strings -arch i386 Camino | wc -l
27654
$ strings -arch all Camino | wc -l
54878

3 comments:

Anonymous said...
This comment has been removed by a blog administrator.
Ilaiy said...

Hmm thats intresting .. Would like to check if it gives the same results in my linux box as well ..

Thanks was intresting ..

./thanks
ilaiy

Anonymous said...

An alternative to file /some/binary/:

lipo -detailed_info /Camino/Camino.app/Contents/MacOS/Camino