home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware 1 2 the Maxx
/
sw_1.zip
/
sw_1
/
VIRUS
/
VIRLIST1.ZIP
/
VIRLIST.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-30
|
6KB
|
260 lines
/* VIRLIST V1.0
*
* Read McAfee's VIRLIST.TXT file and display viruses
* with selected characteristics.
*
* Program: VIRLIST Version 1.0
* Platform: IBM PC/Turbo C V2.0
* Author: Jason Mathews
* Date: 2/24/92
*
* Copyright (C) 1992 by Jason Mathews. Permission is granted to any
* individual or institution to use, copy or redistribute this software so long
* as it is not sold for profit, provided this copyright notice is retained.
*/
#include <stdio.h>
#include "virlist.h"
void main (int argc, char **argv)
{
FILE *fp = fopen (VIRLIST_FILE, "r");
if (fp==0)
{
fprintf(stderr, "Cannot file virus list '%s'\n", VIRLIST_FILE);
fputs("Please copy this file into the appropriate directory.\n", stderr);
exit(1);
}
CheckArgs(argc, argv); /* Check arguments */
SkipHeader(fp);
while (fgets(buffer, 1024, fp))
{
if (*buffer == '\n') break;
if (GetRecord(buffer) > 0) PrintRecord();
}
fclose(fp);
Legend();
} /** main **/
/* CheckArgs:
* Check program flags & options
*/
void CheckArgs (int argc, char **argv)
{
int i, offset;
boot = data = format = links = ops = program = variable = 0;
if (argc == 1) Help();
puts("Program options:");
for (i=1; i<argc; i++)
{
if (*argv[i] == '-')
{
for (offset=1; argv[i][offset] != 0; offset++)
switch(argv[i][offset])
{
case 'B': SetField(boot, 1);
case 'C': SetField(program, 2);
case 'D': SetField(data, 3);
case 'F': SetField(format, 4);
case 'L': SetField(links, 5);
case 'O': SetField(ops, 6);
case 'V': SetField(variable, 8);
case '1': SetFlag(1, 9);
case '2': SetFlag(2, 10);
case '3': SetFlag(3, 11);
case '4': SetFlag(4, 12);
case '5': SetFlag(5, 13);
case '6': SetFlag(6, 14);
case '7': SetFlag(7, 15);
case '8': SetFlag(8, 16);
case '9': SetFlag(9, 17);
case 'P': SetFlag(10, 7);
case 'h':
case '?': Help();
default:
printf("invalid option/flag: %c\n", argv[i][offset]);
break;
} /* switch */
} /* if */
} /* for */
puts(messages[0]); /* show a dashed line */
} /** CheckArgs **/
/* CheckCode:
* Check if code is set for entry and print its corresponding letter
* or a blank.
*/
void CheckCode (int code, char letter)
{
putchar( (virus.codes[code-1]) ? letter : '.');
putchar(' ');
} /** CheckCode **/
/* GetRecord:
* Get fields from virlist entry and fill in record
*/
int GetRecord (char *buf)
{
int i, len;
char tmp[20];
int match = 0;
Copy(name, 26);
buf += 26;
Copy(disinfector, 9);
buf += 13;
for (i=0; i<10; i++)
{
if (*buf == 'x')
{
virus.codes[i] = 1;
if (flags[i]) match++;
}
else virus.codes[i] = 0;
/* if (i < 9)*/ buf += 2;
}
/* check virus size */
if (strncmp(buf, "Overwrite", 9) == 0) virus.size = -1;
else if (strncmp(buf+2, "varies", 6) == 0)
{
virus.size = -2;
if (variable) match++;
}
else if (strncmp(buf+4, "N/A", 3) == 0) virus.size = -3;
else
{
strcpy(tmp, buf, 7);
tmp[7] = 0;
virus.size = atol(tmp);
}
buf += 11;
/* reset damage flags for virlist entry */
virus.boot = virus.data = virus.format = virus.links =
virus.ops = virus.program = 0;
/* Check damage fields */
while (*buf != 0)
{
switch( *buf)
{
case 'B': Damage(boot);
case 'D': Damage(data);
case 'F': Damage(format);
case 'L': Damage(links);
case 'O': Damage(ops);
case 'P': Damage(program);
} /* switch */
buf++;
}
return match;
} /** GetRecord **/
/* Help:
* Show program options
*/
void Help()
{
int i;
puts("Usage:\n\tvirlist [-BCDFLOP1234567890]\n");
puts("Options:\n");
for (i=1; i < MSG_NUM; i++)
printf("\t%s\n", messages[i]);
exit(1);
} /** Help **/
/* Legend:
* Show code legend
*/
void Legend()
{
int i;
putchar('\n');
puts(messages[0]);
puts("Legend:");
for (i=1; i < MSG_NUM; i++)
{
/* check for start of number codes to insert a new line */
if (i==9) putchar('\n');
printf("\t%s\n", messages[i]);
}
} /** Legend **/
/* PrintRecord:
* Print virlist record
*/
void PrintRecord()
{
printf("%s ", virus.name);
CheckCode(1, '1');
CheckCode(2, '2');
CheckCode(3, '3');
CheckCode(4, '4');
CheckCode(5, '5');
CheckCode(6, '6');
CheckCode(7, '7');
CheckCode(8, '8');
CheckCode(9, '9');
CheckCode(10, 'P');
switch(virus.size)
{
case -1:
printf("Overwrites");
break;
case -2:
printf(" varies ");
break;
case 0:
printf(" ");
break;
case -3:
printf(" N/A ");
break;
default:
printf("%7ld ", virus.size);
}
if (virus.boot) printf(" B");
if (virus.data) printf(" D");
if (virus.format) printf(" F");
if (virus.links) printf(" L");
if (virus.ops) printf(" O");
if (virus.program) printf(" C");
putchar('\n');
} /** PrintRecord **/
/* SkipHeader:
* Read past 'virlist.txt' header, which is all dashes (-)
* The file location should be at the beginning of the virlist entries.
*/
void SkipHeader (FILE *fp)
{
while (fgets(buffer, 1024, fp))
{
if (strncmp(buffer, "------", 6) == 0) return;
}
} /** SkipHeader **/