Opt Snagger 0.01a
David Goldsmith <dhg@dec.net>
http://www.dec.net/~dhg
-

o WHAT IT DOES

This is application allows you to dump all available command line options
in most UNIX applications.  This is very handy when the documentation
on an application is less than satisfactory or if you don't have any
documentation at all.  While a lot of applications will have a -h, -?
or --help option, some still do not.

Another use of this program is to try and find hidden command line options
that were either neglected from the man page or intentionally hidden.

o HOW DO I INSTALL IT

Well, either get the tar file or the RPM file.  If you want to compile
it, just run make <systype> and then a make install as root.  It will install 
two files: /usr/local/lib/libosnag.so.1 and /usr/local/bin/grabargs.

o HOW DO I USE IT

Simply run grabargs program-name.  Here is a sample run of the program:

$ grabargs ls
Opt Snagger 0.01a
optstring = abcdfgiklmnopqrstuw:xABCDFGI:LNQRST:UX1
--all 
--escape 
--directory 
--dired 
--full-time 
--inode 
--kilobytes 
--numeric-uid-gid 
--no-group 
--hide-control-chars 
--reverse 
--size 
--width=
--almost-all 
--ignore-backups 
--classify 
--file-type 
--ignore=
--dereference 
--literal 
--quote-name 
--recursive 
--format=
--sort=
--tabsize=
--time=
--help 
--version 
--color[=]

In optstring, letters that have a ':' after them take an additional argument.

On the long options( the ones that begin with -- ), if the option ends in
an =, then that option demands an additional argument.  If the option
ends in an '[=]' then that option takes an optional additional argument.

o HOW IT DOES IT

By preloading libosnag, we intercept all calls to the getopt() family
that normally reside in libc.so.  When libosnag's getopt()s get called,
it will dump all of the options and then BAIL out of the program using
exit().  This may change in the future, but it is usually not dangerous,
as very little gets set up in most programs before getopt() is called.

o WHEN WONT IT WORK

There are two conditions where this technique will not work.  The first
is when the application in question is compiled statically.  Since it
was compiled statically it will never load libosnag.  You can run ldd
to determine if a program is compiled statically or dynamically:

$ ldd /usr/bin/nc
        statically linked (ELF)
$ ldd /usr/bin/w
        libc.so.5 => /lib/libc.so.5.3.12

The second is when the application handles command line parsing without
getopt().  This has been more common than the first, but still pretty rare.
You might be able to use nm on a program to figure out if it uses getopt:

$ nm /usr/bin/archie | grep getopt
00003d1c T __getopt_internal
000044dc T _getopt
000044fc T _getopt_long
0000452c T _getopt_long_only
00003aec t getopt.o
000044fc t getopt1.o
$

However, this wont work on a binary that has been strip'd.

One final tip.  If you are sure that it is using getopt and that it is
dynamic, and you are still getting problems, try running grabargs with
a random option ( like  grabargs --this_cant_be_an_option ).

o WHAT NOW

I am open to suggestions.  So far it does what I want.  I might have it 
continue execution of the program, and probably clean up the output.

Please send any patches, awards, medals, suggestions, contracts to:

David Goldsmith
dhg@dec.net

