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/
$ 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
$ strings -arch ppc Camino | wc -l
$ strings -arch i386 Camino | wc -l
$ strings -arch all Camino | wc -l


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 ..


Anonymous said...

An alternative to file /some/binary/:

lipo -detailed_info /Camino/