Public domain "strings" command
lee at unmvax.UUCP
lee at unmvax.UUCP
Sun Apr 15 18:43:03 AEST 1984
This is a public domain version of the command "strings" available
in the Berkeley distributions. It is slightly more intellgent than
the aforementioned version. It was written for a friend on a Plexus
P-40 running V7. It works on his machine, but how well does Plexus
conform to V7? I dunno, that is the only example I have. In the 4.2 man
page it says that strings reports addresses in octal. The standard command
does not, so this version does not either. Simple change if you want it to
though...
--Lee (Ward)
{ucbvax,gatech,convex}!unmvax!lee
To unarchive, remove the first line through and
including the dashed line. Then type:
% sh <thisfilename>
-------------------------------------------
: Run this with sh NOT csh!
echo extracting strings.l
cat << //*FUNKYSTUFF*// > strings.l
.TH STRINGS L "14 April 1984"
.UC
.SH NAME
strings \\- find printable strings in an object, or other file
.SH SYNOPSIS
.B strings
[
.B \\-
] [
.B \\-o
] [
\\fB\\-\\fInumber\\fR
] file ...
.SH DESCRIPTION
.I Strings
looks for ascii strings in a binary file.
A string is any sequence of 4 or more printing characters ending with
a newline or a null.
Unless the
.B \\-
flag is given,
.I strings
only looks in the initialized data space of object files.
If the
.B \\-o
flag is given, then each string is preceded by its offset in the
file (in decimal).
If the
\\fB\\-\\fInumber\\fR
flag is given then number is used as the minimum string length
rather than 4.
.SH "SEE ALSO"
od(1)
.SH AUTHOR
Lee Ward, University of New Mexico
.SH BUGS
Though the string algorithm is a bit more intelligent than the Berkeley
version, it is still pretty stupid.
//*FUNKYSTUFF*//
echo extracting strings.c
cat << //*FUNKYSTUFF*// > strings.c
/*
* Public domain strings
*
* Conforms (closely) to the Berkeley 4.2 BSD manual page.
*
* Lee Ward
* University of New Mexico
* 4/14/84
*/
# include <stdio.h>
# include <a.out.h>
# include <ctype.h>
/* Is the below right? Oh well.... */
# ifdef V7
# define N_BADMAG(x) !((x).a_magic == A_MAGIC1 || \\
(x).a_magic == A_MAGIC2 || \\
(x).a_magic == A_MAGIC3 || \\
(x).a_magic == A_MAGIC4)
# define N_TXTOFF(x) (x).a_magic == A_MAGIC2 || \\
(x).a_magic == A_MAGIC3 ? \\
8 * 1024 : sizeof(x)
# endif
int countflag = 0;
int dataflag = 0;
char *Usgstr = "[-] [-o] [-minlength] file...";
int minlength = 4;
extern int errno;
main (argc, argv)
int argc;
char *argv[];
{
int x;
char *aptr;
struct exec exhdr;
argv[argc] = NULL;
for (x = 1; argc > 1 && *(aptr = argv[x]) == '-'; x++,argc--) {
++aptr;
if (*aptr == NULL)
dataflag++;
else if (*aptr == 'o')
countflag++;
else if (isdigit(*aptr))
minlength = atoi(aptr);
else {
fprintf (stderr, "Usage: %s %s\\n", argv[0], Usgstr);
exit (1);
}
}
do {
if (argc > 1)
if (freopen(argv[x++], "r", stdin) == NULL) {
perror (argv[x - 1]);
exit (errno);
}
if (!dataflag &&
fread(&exhdr, sizeof(exhdr), 1, stdin) == 1 &&
!N_BADMAG(exhdr)) {
fseek(stdin,
(long )(N_TXTOFF(exhdr) + exhdr.a_text), 0);
strings ((long )exhdr.a_data,
(long )(N_TXTOFF(exhdr) + exhdr.a_text));
} else {
fseek(stdin, 0L, 0);
strings (-1L, 0L);
}
} while (argv[x] != NULL);
}
strings (count, loc)
long count;
long loc;
{
char c, buf[BUFSIZ];
char *bptr;
bptr = buf;
while (count--) {
c = getchar();
loc++;
if (c == NULL || c == '\\n' || bptr >= buf + BUFSIZ - 1) {
if (bptr - buf > minlength) {
*bptr = NULL;
if (countflag)
printf ("%7D\\t", loc - 1 -
(long )( bptr - buf));
printf ("%s\\n", buf);
}
bptr = buf;
} else
if (c < 0177 && c >= ' ')
*bptr++ = c;
else
bptr = buf;
if (feof(stdin) || ferror(stdin))
break;
}
}
//*FUNKYSTUFF*//
More information about the Comp.sources.unix
mailing list