home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / trojanpr / nobrains.arc / debrain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-29  |  23.3 KB  |  781 lines

  1. /****************************************************************
  2. Program:   DEBRAIN
  3. Date:      June 17, 1988
  4. Descript:  Program "cures" diskettes infected with the "Brain" virus.
  5.  
  6. Language:  Turbo C
  7.  
  8. Operation: Run it by typing:  x> DEBRAIN  DRV:  [0/1]
  9.            where DRV: is the drive containing the "infected" diskette.
  10.            The option 0 or 1 is for verbose mode where it dumps contents
  11.            of infected sectors, steps being performed, etc. to display.
  12.            If specified and non-zero, verbose occurs.
  13.  
  14.            The program first checks to see if the machine itself is
  15.            infected.  If so, you are asked if you want the machine
  16.            "cleansed".  If yes, it is and the program proceeds.  If no,
  17.            the program aborts.  You cannot leave the machine infected
  18.            but proceed with curing the diskettes.
  19.  
  20.            If it thinks the diskette is infected, then just before the
  21.            cure is effected, a confirmation will be asked for.
  22.            You can leave the diskette infected if desired.
  23.  
  24.  
  25.     The Brain virus appears to have been hacked into a more
  26. virulent strain by persons unknown... New version should catch
  27. both strains.
  28.  
  29. ***************************************************************/
  30. #include <stdio.h>
  31. #include <dos.h>
  32. /*        Error Message Definitions                   */
  33. #define noarg  1
  34. #define invadr 2
  35. #define nofixd 3
  36.  
  37. /*        Misc Definitions                */
  38. #define byte unsigned char
  39. #define word unsigned int
  40. #define TRUE    1
  41. #define FALSE    0
  42. #define GOOD    1
  43. #define BAD     0
  44. #define FOUND_BAD_CLUSTERS    1
  45.  
  46. char *boot_strings[] = {         "Non-System disk or disk error",
  47.                              "Replace and strike any key when ready",
  48.                                  "Disk Boot failure",
  49.                                  "IBMBIO  COMIBMDOS  COM" };
  50.  
  51. int  num_boot_strings = 4;
  52.  
  53. int     bogus_clus,
  54.     bogus_side,
  55.     bogus_sect,        
  56.     bogus_trk,    
  57.     bogus_dls;    /* dls = dos logical sector */
  58.  
  59. int  pc_infected=FALSE;
  60.  
  61. typedef struct {
  62.     byte junk1[3];
  63.     char sysid[8];
  64.     word sectsize;
  65.     byte clustsize;
  66.     word resvsects;
  67.     byte FATcopies;
  68.     word rootdirentries;
  69.     word totalsects;
  70.     byte idbyte;
  71.     word FATsects;
  72.     word trksects;
  73.     word heads;
  74.     word resvspecial;     } BiosParmBlock;
  75.  
  76.  
  77. struct direntry {
  78.     char fname[8];
  79.     char ext[3];
  80.     byte attrib;
  81.     byte resvd[10];
  82.     word xtime;
  83.     word xdate;
  84.     word startFAT;
  85.     long fsize; };
  86.  
  87. union REGS rreg,sreg;
  88. struct SREGS segs;
  89. struct direntry directory[1024];
  90. int drv;
  91. unsigned char FAT[10*512];    /* allow for 10 sectors though only 4 */
  92.                             /* are needed for D-9 diskettes */
  93. BiosParmBlock *bootinfo;          /* so we can try to work with different types */
  94. int dispflag= 0;
  95. /*    Assume not Infected */
  96. int brain_infected = FALSE;
  97. int infected_bad_secs = FALSE;
  98. int infected_vol_lab = FALSE;
  99.  
  100.  /*        Function Definitions                        */
  101. int copyvec();
  102. int checkvec();
  103. word gettim();
  104. word getdat();
  105. int findlabel();
  106. int changelabel();
  107. int getFATentry();
  108. int setFATentry();
  109. int dlstoclus();
  110. int str_scan();
  111. int errorout();
  112. int diskerror();
  113. int diskread();
  114. int diskwrite();
  115. int displayraw();
  116. int homecursor();
  117. int clearscreen();
  118. int AbortCure(BiosParmBlock *);
  119. int checkbootinfo(BiosParmBlock *);
  120.  
  121. /************************************************************/
  122. /*        Main Program Starts Here            */
  123. /************************************************************/
  124.  
  125. main(argc,argv)
  126.     int argc;
  127.     char *argv[];
  128. {
  129.     int idbyte,sect,i,nsects,dirsize,dirstart;
  130.  
  131.     char drvlet, ans[20];
  132.     unsigned char bufr[1024],bootrec[512],orig_bootrec[512],virus[6*512];
  133.     int bogus_lable = FALSE;
  134.  
  135.     clearscreen();
  136. printf("Debrain.exe                                                 V1.3\n\n");
  137.  
  138.     if (argc<2) {
  139.  
  140.         printf("This program is used to eradicate the Brain virus.\n");
  141.         printf("    Usage:  DEBRAIN drive:    [ 1 ]\n\n");
  142.         printf("    Where drive is the disk drive containing the infected diskette.\n");
  143.         printf("    And 1 is an optional flag that will dump the sectors to the screen\n\n");
  144.         leave();
  145.  
  146.     } else {
  147.  
  148.         drvlet = *argv[1];
  149.         drv = toupper(drvlet) - 'A' + 1;    /* A=1, B=2 */
  150.         if (drv<1 || drv>2) {
  151.  
  152.             printf("   Error:  Only drive A: or B: may be specified!\n");
  153.             leave();
  154.         }
  155.         dispflag = (argc>2);
  156.     }
  157.  
  158.  /* OK lets do some work */
  159.  
  160.     if (pc_infected=((checkvec(0x13)) || (checkvec(0x24)) || (checkvec(0x25)))){
  161.  
  162.         printf("\nWARNING! This machine has itself been infected and thus\n");
  163.         printf("         so has the \"cure\" diskette in all likelihood.\n");
  164.         printf("         You can proceed but will probably need to  inoculate\n");
  165.         printf("         the \"cure\" diskette too.\7\n");
  166.         printf("\n      VACCINATE machine itself (Y/N) ?");
  167.         scanf("%s",ans);
  168.  
  169.         if (toupper(ans[0])=='Y') {
  170.             printf("\n      Inoculating the PC...\n");
  171.             copyvec(0x6D,0x13);
  172.         } else {
  173.             printf("\n   Cannot \"cure\" diskettes on an infected machine...");
  174.             printf("\n   Aborting cure....\n");
  175.             leave();
  176.         } /* else */
  177.     } /* if */
  178.  
  179.     printf("\n\nAttempting cure on Drive %c:....            :-)\n",'A'+drv-1);
  180.  
  181.  
  182. /* Get directory table */
  183.  
  184.     if (dispflag) printf("\nGetting directory entry...\n");
  185.  
  186.     dirstart = 1 + 4;        /* boot sector + FAT size */
  187.     dirsize = 7;            /* D-9 diskettes have 7 sectors of dir entries */
  188.     diskread(drv,dirstart,dirsize,directory);
  189.  
  190.     if (!(bogus_lable=findlabel())) {
  191.  
  192.         printf("\n   The Virus label was not found on this diskette!\n");
  193.     }
  194.  
  195. /* Get boot record */
  196.  
  197.      if (dispflag) printf("\nGetting Boot Record...\n");
  198.    
  199.      diskread(drv,0,1,bootrec) ;
  200.      
  201.      if (dispflag) displayraw(bootrec,1);
  202.  
  203.      if ( check_boot_rec( bootrec ) == BAD ){
  204.  
  205.           if ( checkFATpointer( bootrec ) == FOUND_BAD_CLUSTERS ){
  206.  
  207.                if ( dispflag ) printf( "\nGetting original boot record...\n");
  208.  
  209.                diskread( drv, bogus_dls - 1, 1, orig_bootrec );
  210.  
  211.                if (dispflag) displayraw(orig_bootrec,1);
  212.  
  213.                if ( check_boot_rec( orig_bootrec ) == GOOD ) {
  214.                
  215.                /* this is an infected disk...  Repair everything */
  216.  
  217.                    printf("\nThis appears to be an infected diskette. \n\n");
  218.                    printf("   VACCINATE it (Y/N) ?");
  219.                    scanf("%s",ans);
  220.                    if (toupper(ans[0])=='Y') {
  221.                        printf("\n      Inoculating the Drive...\n");
  222.  
  223.                        diskwrite(drv,0,1,orig_bootrec);            /* Replace boot rec */              
  224.  
  225.                        setFATentry(bogus_clus,0);                    /* Update FAT */
  226.                        setFATentry(bogus_clus+1,0);
  227.                        setFATentry(bogus_clus+2,0);
  228.  
  229.                        diskwrite(drv,1,4,FAT);                        /* Write updated FAT */                     
  230.  
  231.                        if (bogus_lable) {
  232.                             changelabel(bogus_lable);
  233.                             diskwrite(drv,dirstart,dirsize,directory);    /* Write updated direct */
  234.  
  235.                        }
  236.                       /* zero out virus sectors */
  237.      
  238.                        for(i = 0; i < 512 * 6; i++ ) virus[i] = 0x00;
  239.                        diskwrite(drv,bogus_dls-1,6,virus);
  240.                        printf("\n\n     Your diskette should now be \"cured\"!\n\n");
  241.  
  242.                    } else {
  243.                        printf("\nOK...  Aborting!");
  244.                        leave();
  245.                    }
  246.                } else {  /* can't find good boot rec */
  247.  
  248.                          printf("\n\nThis disk appears to be infected by a Brain type virus, but a good");
  249.                          printf("\nboot record was not found. ");
  250.                          printf("\nSuggest you copy the files that you need (data files only!) and forward");
  251.                          printf("\nthis disk to the Computer Science Center.");
  252.                          leave();
  253.                }
  254.          
  255.           } else {    /* bad boot sector but no virus sectors */
  256.  
  257.                printf("\n\nThis disk does not seem to be infected, but an invalid");
  258.                printf("\nboot record was found.");
  259.                printf("\nThis may be due to a non DOS format program or it is just a bad disk!");
  260.                leave();
  261.           }
  262.  
  263.      }
  264.      else {
  265.           printf("\nThis is a good disk!");
  266.           leave();
  267.      }
  268. }/* main */
  269. /********************************************************************/
  270. leave()
  271. {
  272.     if (pc_infected) {
  273.         printf("\nREMEMBER!   This PC was infected.  Be sure to inoculate\n");
  274.         printf("            the vaccine diskette in case it was infected!\n");
  275.     }
  276.      exit();
  277. }
  278.  
  279. /***********************************************************************/     
  280.                
  281. checkFATpointer( byte * bootrec )
  282. {
  283.  
  284.      unsigned int *p,f1,f2,f3;
  285.  
  286. /* check for brain virus string and confirmation on signature */
  287.  
  288.      p = (unsigned int)&bootrec[4];
  289.      if ( *p != 0x1234 ) 
  290.           return ( FALSE );
  291.  
  292. /* this is a Brain Infected Disk  */
  293.  
  294.     bogus_side = bootrec[6];
  295.     bogus_sect = bootrec[7];
  296.     bogus_trk = bootrec[8];
  297.  
  298.     bogus_dls = bogus_trk*9*2 + bogus_side*9 + bogus_sect;
  299.  
  300. /* Get FAT table read in */
  301.  
  302.     if (dispflag) printf("\nGetting FAT table...\n");
  303.     diskread(drv,1,4,FAT);
  304.  
  305.     bogus_clus = dlstoclus(bogus_dls);
  306.  
  307.     f1 = getFATentry(bogus_clus);
  308.     f2 = getFATentry(bogus_clus+1);
  309.     f3 = getFATentry(bogus_clus+2);
  310.  
  311.     if (dispflag) {
  312.         printf("   Bogus DLS = %d (%XH)\n",bogus_dls,bogus_dls);
  313.         printf("   FAT entry for cluster %d (%xH) = %d (%xH)\n",
  314.             bogus_clus,bogus_clus,f1,f1);
  315.         printf("   FAT entry for cluster %d (%xH) = %d (%xH)\n",
  316.             bogus_clus+1,bogus_clus+1,f2,f2);
  317.         printf("   FAT entry for cluster %d (%xH) = %d (%xH)\n",
  318.             bogus_clus+2,bogus_clus+2,f3,f3);
  319.     }
  320.  
  321.     if (f1==0xFF7 && f2==0xFF7 && f3==0xFF7) {
  322.           
  323.           return( FOUND_BAD_CLUSTERS );
  324.      }
  325.      else return (FALSE );
  326.  
  327.  
  328. }/* checkFATpointer */
  329.  
  330. /********************************************************/
  331. int checkvec(vec)
  332.     int vec;
  333. {
  334.     unsigned int vec_ip,vec_cs,orgvec_ip,orgvec_cs,highmem;
  335.     int bad, mem;
  336.  
  337.     bad = 0;                        /* assume "good" to start */
  338.     vec_ip = peek( 0, 4*vec );            /* check if disk vector was altered */
  339.     vec_cs = peek( 0, 4*vec+2 );
  340.     if (dispflag) printf("vec_cs = %x    vec_ip = %x\n", vec_cs, vec_ip);
  341.     if (vec_cs < 0xA000) {
  342.         highmem=peek( 0,0x413);        /* check max mem to allow for "funny", */
  343.                                     /* legitimate disk drivers */
  344.         if (dispflag)printf("highmem = %x\n", highmem );
  345.         for (mem=64,bad=0; mem<=640; mem+=64) {
  346.             if (highmem==(mem-7)) {
  347.                 bad=1;                /* if max mem value off by 7K => bad */
  348.                 break;
  349.             } /* if */
  350.         } /* for */
  351.     } /* if */
  352.     return(bad);
  353. } /* checkvec */
  354.  
  355. /********************************************************/
  356. int copyvec(src,dst)
  357.     int src;
  358.     int dst;
  359. {
  360.     word vec_ip,vec_cs,highmem;
  361.  
  362.     vec_ip = peek( 0, 4*src );        /* get original vector */
  363.     vec_cs = peek( 0, 4*src+2 );
  364.     poke( 0, 4*dst, vec_ip );
  365.     poke( 0, 4*dst+2, vec_cs );
  366.     highmem=peek( 0, 0x413 );        /* adjust max mem limit while at it */
  367.     highmem += 7;                /* get back 7K virus hid in */
  368.     poke( 0, 0x413, highmem );
  369.     return;
  370. } /* copyvec */
  371. /********************************************************/
  372. int changelabel(entry)
  373.     int entry;
  374. {
  375.     int i;
  376.     char c;
  377.     char newlabel[11] = "           ",*p, ans[80];
  378.     char null_label[] = { 0xe5, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00 };
  379.  
  380.     printf( "\nInput a new volume label:" );
  381.  
  382.     ans[0] = 11;                  /* max vol lable length */
  383.     cgets( ans );
  384.     strncpy( newlabel, &ans[2], ans[1] );
  385.     if (strlen( newlabel ) > 0){
  386.         for (i=0,p=newlabel; i<11; i++)
  387.             directory[entry].fname[i] = *(p+i);
  388.         directory[entry].attrib = 8;
  389.         for (i=0; i<10; i++) directory[entry].resvd[i] = 0;
  390.         directory[entry].xdate = getdat();
  391.         directory[entry].xtime = gettim();
  392.         directory[entry].startFAT = 0;
  393.         directory[entry].fsize = 0L;
  394.     }
  395.     else{
  396.         strcpy( directory[entry].fname, null_label );   /* delete vol lab */
  397.     }
  398. } /* changelabel */
  399.  
  400. /********************************************************/
  401. int findlabel()
  402. {
  403.     int i;
  404.  
  405. printf("\nfindlable:");
  406.  
  407.     for (i=0; i<112; i++) {                    /* max 112 entries in D-9 disk */
  408.         if (!directory[i].fname[0]) break;
  409.         if (   (directory[i].attrib & 0x08) &&
  410.                ( str_scan( directory[i].fname, 12, "Brain ")) ) {
  411.              if (!i) {            /* label should not be able to be 1st */
  412.                  printf("\nThis should not occur!  Label First!  Abort!\n");
  413.                  leave();
  414.                     return( FALSE );/* this is just to get the compiler to shut up */
  415.              }
  416.              return(i);
  417.         } /* if */
  418.     } /* for */
  419.     return(FALSE);
  420. } /* findlabel */
  421.  
  422. /********************************************************/
  423. word gettim()
  424. {
  425.     word time;
  426.  
  427.     sreg.x.ax = 0x2C00;
  428.     intdos(&sreg,&rreg);
  429.     time = ( ((rreg.x.cx>>8)<<11) | ((rreg.x.cx&0xFF)<<5) | (rreg.x.dx>>9) );
  430. /*    printf("\nch=%d   cl=%d   dh=%d   time=%x\n",
  431.         rreg.x.cx>>8 , rreg.x.cx&0xFF, rreg.x.dx>>8 , time); */
  432.     return(time);
  433. } /* gettime */
  434.  
  435. /********************************************************/
  436.  
  437. word getdat()
  438. {
  439.     word idate;
  440.  
  441.     sreg.x.ax = 0x2A00;
  442.     intdos(&sreg,&rreg);
  443.     idate = ( ((rreg.x.cx-1980)<<9) | ((rreg.x.dx>>8)<<5) | (rreg.x.dx&0xFF) );
  444. /*    printf("\ncx = %d   dx= %x    dh= %d   dl= %d    date= %x \n",
  445.         rreg.x.cx, rreg.x.dx, (rreg.x.dx>>8), (rreg.x.dx&0xFF), idate); */
  446.     return(idate);
  447. } /* getdate */
  448.  
  449. /********************************************************/
  450.  
  451. str_scan( char * start, int len, char * str )
  452. {
  453.      int found = 0,i = 0;
  454.      char * p = start;
  455.  
  456.      while ( !found ) {
  457.  
  458.           while (( *p != str[ 0 ]) && ( p < (start + len )))
  459.                p++;
  460.           if ( p == start + len ) {
  461.                if (dispflag) printf("Couldn't find string %s\n\r", str );
  462.                return( FALSE );
  463.           }
  464.           while(( *(++p) == str[ ++i ]) && ( i < strlen( str )))
  465.  
  466.                /* empty */ ;
  467.  
  468.           if( i == strlen( str )){
  469.                p = p - ( start + i );
  470.                if (dispflag) printf("Found string \"%s\" at %d (%xH) of sector.\n\r", str, p,p);
  471.                return( TRUE );
  472.           }
  473.           i = 0; /* start scanning again */
  474.      }
  475.      return( FALSE );
  476. }
  477.  
  478. /********************************************************/
  479.  
  480. int dlstoclus(dls)
  481.     int dls;
  482. {
  483.     return(dls/2-4);
  484. } /* dlstoclus */
  485.  
  486. /********************************************************/
  487. int getFATentry(clus)
  488.     int clus;
  489. {
  490.     int index,entry;
  491.     unsigned int *p;
  492.  
  493.     index = clus*3/2;
  494.     p = (unsigned int *)&FAT[index];
  495.     entry = (clus%2)? *p >> 4 : *p & 0xFFF;
  496.     return(entry);
  497. } /* getFATentry */
  498.  
  499. /********************************************************/
  500. int setFATentry(clus,val)
  501.     int clus;
  502.     unsigned int val;
  503. {
  504.     int index,entry;                /* On a D-9 diskette, FAT is 4 sectors */
  505.     unsigned int *p;
  506.  
  507. /* Primary copy of FAT */
  508.     index = clus*3/2;                /* 1st 2 sectors of FAT */
  509.     p = (unsigned int *)&FAT[index];
  510.     *p = (clus%2)? (*p & 0xF) | (val << 4) : (*p & 0xF000) | (val & 0xFFF);
  511.  
  512. /* Secondary copy of FAT */
  513.     index = clus*3/2 + 512*2;        /* Last 2 sectors of FAT */
  514.     p = (unsigned int *)&FAT[index];
  515.     *p = (clus%2)? (*p & 0xF) | (val << 4) : (*p & 0xF000) | (val & 0xFFF);
  516.  
  517.     return;
  518. } /* setFATentry */
  519.  
  520. /********************************************************/
  521. int errorout(errcode)
  522.    int errcode;
  523. {
  524.    printf("\n    ");
  525.    switch (errcode) {
  526.       case invadr:
  527.              printf("* Invalid disk address format!");
  528.        break;
  529.       case nofixd:
  530.              printf("* This function only applies to Floppy Disk Drives!");
  531.        break;
  532.       default:
  533.              printf("* Unknown Error Encountered!");
  534.    } /* switch */
  535.    printf("\n\n\7");
  536. } /* errorout */
  537.  
  538. /********************************************************/
  539. int diskerror(intrpt, status)
  540.     unsigned int intrpt,status;
  541. {
  542.     printf("\n    ");
  543.     switch (intrpt) {
  544.     case 0x25:
  545.     case 0x26:
  546.         printf("* DOS Disk Read/Write Error!\n");
  547.         printf("\t\tCode = %4x\n",status);
  548.             break;
  549.     case 0x13:
  550.         printf("* ROM-BIOS Disk Read/Write Error!\n");
  551.         printf("\t\tCode = %2x\n",status);
  552.             break;
  553.     } /* switch */
  554.     printf("\n\n\7");
  555. } /* diskerror */
  556.  
  557. /********************************************************/
  558. int diskread(drive, dossectr, nsectrs, buffer)
  559.     int drive, dossectr, nsectrs;
  560.     unsigned char buffer[];
  561. {
  562.     union REGS rreg,sreg;
  563.     int i;
  564.     unsigned retval;
  565.  
  566. /*    segread(&segs);*/
  567.     for (i=0; i < 512 * nsectrs; i++) buffer[i] = 0;
  568. /*    sreg.x.ds = segs.ds;*/
  569.     sreg.x.cx = nsectrs;
  570.     sreg.x.dx = dossectr;
  571.     sreg.x.bx = buffer;
  572.     sreg.x.ax = drive-1;                    /* A=0, B=1 */
  573.  
  574. disklabel:
  575.     retval = int86(0x25,&sreg,&rreg);
  576.     if (rreg.x.cflag !=0x00){
  577.         if ((retval & 0x00ff) == 0x0002) {
  578.             printf("Disk not ready! \n");
  579.             printf("Press any key to continue...\n");
  580.             while (!kbhit());
  581.             getch();
  582.             goto disklabel;
  583.         }
  584.         else{
  585.                 diskerror(0x25,retval);
  586.             leave();
  587.         }
  588.     }
  589.     return( !(retval) );
  590. } /* diskread */
  591.  
  592. /********************************************************/
  593.  
  594. /********************************************************/
  595. int diskwrite(drive, dossectr, nsectrs, buffer)
  596.     int drive, dossectr, nsectrs;
  597.     unsigned char buffer[];
  598. {
  599.     union REGS rreg,sreg;
  600.     int i;
  601.     unsigned flags;
  602.  
  603. /*    segread(&segs);*/
  604. /*    sreg.x.ds = segs.ds;*/
  605.     sreg.x.cx = nsectrs;
  606.     sreg.x.dx = dossectr;
  607.     sreg.x.bx = buffer;
  608.     sreg.x.ax = drive-1;                    /* A=0, B=1 */
  609.     flags = int86(0x26,&sreg,&rreg);
  610.     if (flags&0x001) diskerror(0x26,rreg.x.ax);
  611.     return( !(flags&0x001) );
  612. } /* diskwrite */
  613.  
  614.  
  615. /********************************************************/
  616. int displayraw(buffer,nsectrs)
  617.     unsigned char buffer[];
  618.     int nsectrs;
  619. {
  620.     int p,i;
  621.     char ascstr[80],ch;
  622.  
  623.     for (i=0; i<(512*nsectrs); i++) {
  624.         if (!(i%16)) {
  625.         if (i) {
  626.                 printf("|%s|",ascstr);
  627.         }
  628.         printf("\n%3d: ",i);
  629.         ascstr[p=0] = '\0';
  630.     }
  631.  
  632.     printf("%2x ",buffer[i]);
  633.     ch = (buffer[i]>=' ' && buffer[i]<='~') ? buffer[i] : '.';
  634.     ascstr[p++] = ch;
  635.     ascstr[p] = '\0';
  636.     }
  637.     printf("|%s|",ascstr);
  638.     printf("\n\n");
  639. } /* displayraw */
  640.  
  641. /********************************************************/
  642. int homecursor()
  643. {
  644.     union REGS rreg,sreg;
  645.  
  646.     sreg.x.ax = 0x0200;        /* cursor position service */
  647.     sreg.x.bx = 0x0000;        /* display page number */
  648.     sreg.x.dx = 0x0000;        /* row and column position */
  649.     int86(0x10,&sreg,&rreg);
  650. }
  651.  
  652. /********************************************************/
  653. int clearscreen()
  654. {
  655.     union REGS rreg,sreg;
  656.  
  657.     sreg.x.ax = 0x0600;        /* service plus blank code */
  658.     sreg.x.bx = 0x0700;        /* bh = attrib byte */
  659.     sreg.x.cx = 0x0000;        /* upper left corner of window */
  660.     sreg.x.dx = (24<<8) + 79;    /* lower right corner of window */
  661.     int86(0x10,&sreg,&rreg);
  662.     homecursor();
  663.  
  664. }
  665.  
  666. /*************************************************************************/
  667.  
  668. check_boot_rec( byte * bootrec )
  669. {
  670.      int i;
  671.  
  672.      if (checkBPB((BiosParmBlock *)bootrec) == BAD)
  673.           return( BAD );
  674.      else {
  675.           for ( i = 0; i < num_boot_strings ; i++)
  676.              if (str_scan(bootrec,512,boot_strings[i])== FALSE)
  677.                     return( BAD );
  678.      }
  679.      return( GOOD );    
  680. } /* check Boot rec */
  681.  
  682.  
  683. /**********************************************************************/
  684.  
  685. checkBPB( BiosParmBlock *BPB)
  686. {
  687.  
  688.     
  689.     if (dispflag) printf("Checking boot info...\n");
  690.  
  691.         /* check JMP instruction */
  692.  
  693.     if (( BPB->junk1[0] == 0xe9) ||
  694.         (( BPB->junk1[0] == 0xeb) && (BPB->junk1[2] == 0x90))){
  695.         /* this is good...this is coded weired caus it make more sense
  696.             this way...this is an empty staement */
  697.         if (dispflag) printf("JMP instruction = %x %x %x ... GOOD\n", BPB->junk1[0],
  698.             BPB->junk1[1], BPB->junk1[2]);
  699.     }
  700.     else {
  701.         if (dispflag) printf("JMP instruction = %x %x %x ... BAD\n", BPB->junk1[0],
  702.             BPB->junk1[1], BPB->junk1[2]);
  703.         return( BAD );
  704.     }            
  705.     /* check OEM info */
  706.     /*
  707.         put code here
  708.     */
  709.  
  710.     /* check  sector size ... has to be greater than 128 */
  711.  
  712.     if ( BPB->sectsize < 128){
  713.         if (dispflag) printf("Sector size = %d (%xH) ... BAD\n", BPB->sectsize, BPB->sectsize );
  714.         return( BAD );
  715.     }
  716.     else {
  717.         if (dispflag) printf("Sector size = %d (%xH) ... GOOD\n", BPB->sectsize, BPB->sectsize );
  718.     }
  719.  
  720.     /* check cluster size ... for floppy 0 < x < 3*/
  721.  
  722.     if (( BPB->clustsize == 0) || ( BPB->clustsize > 2)){
  723.         if (dispflag) printf("Cluster size = %d (%xH) ... BAD\n", BPB->clustsize, BPB->clustsize );
  724.         return( BAD );
  725.     }
  726.     else {
  727.         if (dispflag) printf("Cluster size = %d (%xH) ... GOOD\n", BPB->clustsize, BPB->clustsize );        
  728.         }
  729.     /* check number of FATs */
  730.  
  731.     if (( BPB->FATcopies == 0) || ( BPB->FATcopies > 4)){
  732.         if (dispflag) printf("Number of FAT copies = %d ... BAD\n", BPB->FATcopies);
  733.         return( BAD );
  734.     }
  735.     else {
  736.         if (dispflag) printf("Number of FAT copies = %d ... GOOD\n", BPB->FATcopies);
  737.     }
  738.  
  739.     /* check rootdir entries */
  740.  
  741.     if( BPB->rootdirentries < 32 ){
  742.         if (dispflag) printf("Number of root directory entries = %d (%xH) ... BAD\n",
  743.             BPB->rootdirentries, BPB->rootdirentries );
  744.         return( BAD );
  745.     }
  746.     else {
  747.         if (dispflag) printf("Number of root directory entries = %d (%xH) ... GOOD\n",
  748.             BPB->rootdirentries, BPB->rootdirentries );
  749.         }
  750.         /* check media descripter byte */
  751.  
  752.     if ( BPB->idbyte < 0xf0 ){
  753.         if (dispflag) printf("Media descripter byte = %xH ... BAD\n",BPB->idbyte );
  754.         return( BAD );
  755.     }
  756.     else {
  757.         if (dispflag) printf("Media descripter byte = %xH ... GOOD\n",BPB->idbyte );        
  758.         }
  759.     /* Hey!! if we made it this far without returning then this should be
  760.         a valid BIOS paramiter Block */
  761.     if (dispflag) printf("Valid Bios parameter Block\n");
  762.  
  763.     return( GOOD );
  764. }
  765.         
  766. /**********************************************************************/
  767.  
  768. AbortCure(BiosParmBlock * BPB)
  769. {
  770.     if ( checkBPB( BPB ) == GOOD){
  771.         printf("This appeares to be a good disk!\n\n");
  772.         leave();
  773.         }
  774.         else{
  775.             printf("This disk has been corrupted by somthing other than\n");
  776.             printf("the (c) Brain virus!\n");
  777.             printf("\n\nUSE AT YOUR OWN RISK!\n");
  778.         leave();
  779.     }
  780. }
  781.