📄 strings.c
字号:
/*
* STRINGS.C - Output printable ascii strings from a binary file.
* E.g. this can be used to locate identifier strings from .EXE-files
* or other messages.
*
* PROGRAMMER: Martti Ylikoski
* CREATED: 1.12.1990
*/
static char *VERSION= "Version 1.1. Copyright (c) Martti Ylikoski, 1990. 1991." ;
/*
*/
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <param.h>
#include <paramstd.h>
/* in MTOOLSP.LIB */
int Pageprintf(int rows, char *fmt, ...) ;
static char *progname, *fname ;
extern unsigned long pflags ;
ParamEntry pentry[12] = {
"P", &ParamSetPause, 1,
"F", &ParamSetFold, 0,
"V", &ParamSetVerbose, 0,
"R", &ParamSetReport, 0,
"S", &ParamSetSubDirs, 0,
"?", &ParamSetHelp, 1,
"H", &ParamSetHelp, 1,
"NOD", &ParamSetNoDefault, 0,
"TEST", &ParamSetTest, 0,
"Y", &ParamSetYes, 0,
"N", &ParamSetTest, 0,
"\0", NULL, 0
} ;
ParamBlock params = {
"/-", IGNORECASE | NOPRIORITY | NOTRIGGERSALLOWED ,
pentry
} ;
static int fhnd, count = 5 ;
static char *optr ;
/* local prototypes */
static int strings( char *fname ) ;
int main(int argc, char *argv[])
{
int i ;
progname = argv[0] ;
ParamHandle(¶ms, &argc, argv) ;
if( pflags & PA_HELP || argc == 1)
{
printf("%s - locate and output printable ascii strings from binary files.\n", progname) ;
puts(VERSION) ;
puts("Usage: strings [/H | /?] [/P] file -count") ;
puts("Where,") ;
puts(" /P = Pause /H,/? = Help");
return( 0 ) ;
}
for (i = 1 ; i < argc; i++)
{
if (argv[i][0] == '-' && strlen(argv[i]) > 1 )
count = atoi(&argv[i][1]) ;
}
/* allocate space for buffer to gather output chars.*/
if ((optr = calloc((size_t) 1, (size_t) max (80, count + 1) )) == NULL)
{
printf("%s: error allocating memory...\nExiting...\n", progname) ;
return( 1 ) ;
}
for (i = 1 ; i < argc; i++)
if (argv[i][0] != '-' && argv[i][0] != '/')
strings(argv[i]) ;
else
if (strcmp(argv[i], "-") == 0)
strings("-") ;
return( 0 ) ;
}
/******************************************
* strings() - locate and output printable ascii strings from an executable
* file. Strings uses a naive algorithm to output every string of printable
* chars of a given length. It uses the global identifier count as the
* requested length.
*******************************************/
static int strings( char *fname )
{
FILE *fptr ;
int i, c ;
if (strcmp(fname, "-") == 0)
fptr = stdin ;
else
/* open file */
if ((fptr = fopen(fname, "rb")) == NULL)
{
printf("%s: unable to open file %s for reading...\n", progname, fname) ;
return( 1 ) ;
}
i = 0 ;
/* read from file */
while ( (c = fgetc(fptr)) != EOF)
{
if (isprint(c) != 0)
{
optr[i] = (char) c ;
i++ ;
if (i >= max(79, count) ) /* buffer full */
{
optr[i] = '\0' ;
/*fputs(optr, stdout) ;
fputs("\n", stdout) ;*/
Pageprintf(24, "%s\n", optr) ;
i = 0 ;
}
}
else
if (i >= count ) /* matching number of chars found */
{
optr[i] = '\0' ;
/* fputs(optr, stdout) ;
fputs("\n", stdout) ;*/
Pageprintf(24, "%s\n", optr) ;
i = 0 ;
}
else
i = 0 ;
}
/* close file */
fclose (fptr ) ;
return( 0 ) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -