home *** CD-ROM | disk | FTP | other *** search
/ Shareware 1 2 the Maxx / sw_1.zip / sw_1 / VIRUS / VIRLIST1.ZIP / VIRLIST.C < prev    next >
C/C++ Source or Header  |  1992-04-30  |  6KB  |  260 lines

  1. /*  VIRLIST V1.0
  2.  *
  3.  *  Read McAfee's VIRLIST.TXT file and display viruses
  4.  *  with selected characteristics.
  5.  *
  6.  *      Program:    VIRLIST Version 1.0
  7.  *      Platform:    IBM PC/Turbo C V2.0
  8.  *      Author:    Jason Mathews
  9.  *      Date:     2/24/92
  10.  *
  11.  *  Copyright (C) 1992 by Jason Mathews.  Permission is granted to any
  12.  *  individual or institution to use, copy or redistribute this software so long
  13.  *  as it is not sold for profit, provided this copyright notice is retained.
  14.  */
  15.  
  16. #include <stdio.h>
  17. #include "virlist.h"
  18.  
  19. void main (int argc, char **argv)
  20. {
  21.     FILE *fp = fopen (VIRLIST_FILE, "r");
  22.  
  23.     if (fp==0)
  24.     {
  25.         fprintf(stderr, "Cannot file virus list '%s'\n", VIRLIST_FILE);
  26.         fputs("Please copy this file into the appropriate directory.\n", stderr);
  27.         exit(1);
  28.     }
  29.  
  30.     CheckArgs(argc, argv);    /* Check arguments */
  31.  
  32.     SkipHeader(fp);
  33.     while (fgets(buffer, 1024, fp))
  34.     {
  35.         if (*buffer == '\n') break;
  36.             if (GetRecord(buffer) > 0) PrintRecord();
  37.     }
  38.     fclose(fp);
  39.  
  40.     Legend();
  41. }  /** main **/
  42.  
  43.  
  44. /* CheckArgs:
  45.  *  Check program flags & options
  46.  */
  47. void CheckArgs (int argc, char **argv)
  48. {
  49.     int i, offset;
  50.     boot = data = format = links = ops = program = variable = 0;
  51.  
  52.     if (argc == 1) Help();
  53.  
  54.     puts("Program options:");
  55.     for (i=1; i<argc; i++)
  56.     {
  57.         if (*argv[i] == '-')
  58.         {
  59.         for (offset=1; argv[i][offset] != 0; offset++)
  60.             switch(argv[i][offset])
  61.             {
  62.  
  63.             case 'B': SetField(boot, 1);
  64.             case 'C': SetField(program, 2);
  65.             case 'D': SetField(data, 3);
  66.             case 'F': SetField(format, 4);
  67.             case 'L': SetField(links, 5);
  68.             case 'O': SetField(ops, 6);
  69.             case 'V': SetField(variable, 8);
  70.  
  71.             case '1': SetFlag(1, 9);
  72.             case '2': SetFlag(2, 10);
  73.             case '3': SetFlag(3, 11);
  74.             case '4': SetFlag(4, 12);
  75.             case '5': SetFlag(5, 13);
  76.             case '6': SetFlag(6, 14);
  77.             case '7': SetFlag(7, 15);
  78.             case '8': SetFlag(8, 16);
  79.             case '9': SetFlag(9, 17);
  80.             case 'P': SetFlag(10, 7);
  81.  
  82.             case 'h':
  83.             case '?': Help();
  84.  
  85.             default:
  86.                 printf("invalid option/flag: %c\n", argv[i][offset]);
  87.                 break;
  88.             } /* switch */
  89.         } /* if */
  90.     } /* for */
  91.  
  92.     puts(messages[0]);  /* show a dashed line */
  93. }  /** CheckArgs **/
  94.  
  95.  
  96. /* CheckCode:
  97.  *  Check if code is set for entry and print its corresponding letter
  98.  *  or a blank.
  99.  */
  100. void CheckCode (int code, char letter)
  101. {
  102.     putchar( (virus.codes[code-1]) ? letter : '.');
  103.     putchar(' ');
  104. }  /** CheckCode **/
  105.  
  106.  
  107. /* GetRecord:
  108.  *   Get fields from virlist entry and fill in record
  109.  */
  110. int GetRecord (char *buf)
  111. {
  112.     int i, len;
  113.     char tmp[20];
  114.     int match = 0;
  115.  
  116.     Copy(name, 26);
  117.     buf += 26;
  118.     Copy(disinfector, 9);
  119.     buf += 13;
  120.     for (i=0; i<10; i++)
  121.     {
  122.         if (*buf == 'x')
  123.         {
  124.             virus.codes[i] = 1;
  125.             if (flags[i]) match++;
  126.         }
  127.         else virus.codes[i] = 0;
  128.         /* if (i < 9)*/ buf += 2;
  129.     }
  130.  
  131.     /* check virus size */
  132.  
  133.     if (strncmp(buf, "Overwrite", 9) == 0) virus.size = -1;
  134.     else if (strncmp(buf+2, "varies", 6) == 0)
  135.     {
  136.         virus.size = -2;
  137.         if (variable) match++;
  138.     }
  139.     else if (strncmp(buf+4, "N/A", 3) == 0) virus.size = -3;
  140.     else
  141.     {
  142.         strcpy(tmp, buf, 7);
  143.         tmp[7] = 0;
  144.         virus.size = atol(tmp);
  145.     }
  146.     buf += 11;
  147.  
  148.     /* reset damage flags for virlist entry */
  149.     virus.boot = virus.data = virus.format = virus.links =
  150.     virus.ops = virus.program = 0;
  151.  
  152.     /* Check damage fields */
  153.     while (*buf != 0)
  154.     {
  155.         switch( *buf)
  156.         {
  157.           case 'B': Damage(boot);
  158.           case 'D': Damage(data);
  159.           case 'F': Damage(format);
  160.           case 'L': Damage(links);
  161.           case 'O': Damage(ops);
  162.           case 'P': Damage(program);
  163.         } /* switch */
  164.         buf++;
  165.     }
  166.  
  167.     return match;
  168. }  /** GetRecord **/
  169.  
  170.  
  171. /* Help:
  172.  *   Show program options
  173.  */
  174. void Help()
  175. {
  176.     int i;
  177.     puts("Usage:\n\tvirlist [-BCDFLOP1234567890]\n");
  178.     puts("Options:\n");
  179.     for (i=1; i < MSG_NUM; i++)
  180.         printf("\t%s\n", messages[i]);
  181.     exit(1);
  182. }  /** Help **/
  183.  
  184.  
  185. /* Legend:
  186.  *  Show code legend
  187.  */
  188. void Legend()
  189. {
  190.     int i;
  191.     putchar('\n');
  192.     puts(messages[0]);
  193.     puts("Legend:");
  194.     for (i=1; i < MSG_NUM; i++)
  195.     {
  196.         /* check for start of number codes to insert a new line */
  197.         if (i==9) putchar('\n');
  198.         printf("\t%s\n", messages[i]);
  199.     }
  200. }  /** Legend **/
  201.  
  202.  
  203. /* PrintRecord:
  204.  *  Print virlist record
  205.  */
  206. void PrintRecord()
  207. {
  208.     printf("%s  ", virus.name);
  209.  
  210.     CheckCode(1, '1');
  211.     CheckCode(2, '2');
  212.     CheckCode(3, '3');
  213.     CheckCode(4, '4');
  214.     CheckCode(5, '5');
  215.     CheckCode(6, '6');
  216.     CheckCode(7, '7');
  217.     CheckCode(8, '8');
  218.     CheckCode(9, '9');
  219.     CheckCode(10, 'P');
  220.  
  221.     switch(virus.size)
  222.     {
  223.     case -1:
  224.         printf("Overwrites");
  225.         break;
  226.     case -2:
  227.         printf("  varies  ");
  228.         break;
  229.     case 0:
  230.         printf("          ");
  231.         break;
  232.     case -3:
  233.         printf("    N/A   ");
  234.         break;
  235.     default:
  236.         printf("%7ld   ", virus.size);
  237.     }
  238.  
  239.     if (virus.boot) printf(" B");
  240.     if (virus.data) printf(" D");
  241.     if (virus.format) printf(" F");
  242.     if (virus.links) printf(" L");
  243.     if (virus.ops) printf(" O");
  244.     if (virus.program) printf(" C");
  245.     putchar('\n');
  246. }  /** PrintRecord **/
  247.  
  248.  
  249. /* SkipHeader:
  250.  *    Read past 'virlist.txt' header, which is all dashes (-)
  251.  *    The file location should be at the beginning of the virlist entries.
  252.  */
  253. void SkipHeader (FILE *fp)
  254. {
  255.     while (fgets(buffer, 1024, fp))
  256.     {
  257.         if (strncmp(buffer, "------", 6) == 0) return;
  258.     }
  259. }  /** SkipHeader **/
  260.