Category : Utilities for DOS and Windows Machines
Archive   : MORE13.ZIP
Filename : STRINGS.C

 
Output of file : STRINGS.C contained in archive : MORE13.ZIP
/* Strings.C
*
* Displays a list of all strings in a file read from a file that
* are entirely ASCII -- that is, between 32 and 126. Must be at least four
* characters long, or however many as specified by an argument to the
* program.
*
* Syntax: strings [] [/X]
*/

#include
#include
#include
#include

#define SYNMSG "strings: syntax [] [/X]"
#define NOPMSG "strings: unable to open file"
#define NOSTOR "strings: unable to allocate storage"

char copyright[] = "STRINGS v1.1 dated " __DATE__ ", Copyright 1990 by "
"Daniel Sachs.";

void main(int argc, char *argv[])
{
int min_chars;
int cur_char;
unsigned long pos;
unsigned long beg;
FILE *fp;
char *tmp;
char c;
int printed;
int hexflag;

if( (argc < 2) || (argc > 4) )
{
printf(SYNMSG);
exit(2);
}

if( argc == 2 && !stricmp(argv[1],"/C") )
{
printf(copyright);
exit(0);
}

if( argc == 3 && stricmp(argv[2],"/X") )
min_chars = atoi(argv[2]);
else
min_chars = 4;

if( argc == 4 )
min_chars = atoi(argv[2]);

if( min_chars == 0 )
{
printf(SYNMSG);
exit(2);
}

if( !stricmp(argv[argc-1],"/X") )
hexflag = 1;
else
hexflag = 0;

if( argc == 4 && !hexflag)
{
printf(SYNMSG);
exit(2);
}

fp = fopen(argv[1],"rb");

if( fp == NULL )
{
printf(NOPMSG);
exit(2);
}

tmp = malloc(min_chars+1);

if( tmp == NULL )
{
printf(NOSTOR);
exit(2);
}

printf("Offset\tString\n");

cur_char = 0;
beg = 0;
printed = 0;

for(pos = 0;;pos++)
{
fread(&c,1,1,fp);

if( feof(fp) )
break;

else
{
if( (c > 31) && (c < 127) )
{
cur_char++;
if (cur_char > min_chars)
putchar(c);
if (cur_char == min_chars)
{
printf(hexflag ? "%lX\t%s%c" :
"%li\t%s%c", beg, tmp, c);
printed = 1;
}
if (cur_char < min_chars)
{
*(tmp + (cur_char-1)) = c;
*(tmp + cur_char ) = 0;
}
if (cur_char == 1)
beg = pos;
}
else
{
if( cur_char != 0 )
{
cur_char = 0;
if (printed)
{
printf("\n");
printed = 0;
}
}
}
}
}
}


  3 Responses to “Category : Utilities for DOS and Windows Machines
Archive   : MORE13.ZIP
Filename : STRINGS.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/