/* Program to report possible bootsector VIRUS contamination

   This program is designed to check multiple disks for executable boot sectors.
It simply looks for a boot sector with a check sum of $1234. This program will
detect all bootsector viruses. It is designed to check large quantities of
disks quickly. Just put the disk in the drive, then press any key. It will
tell you if it has found a suspect disk.

  By	David Mace			This program is on the Public Domain
	PSC 2 Box 10233			If you find it useful and feel guilty,
	APO San Francisco, CA		send me money to make yourself feel
			96367		better. I don't mind a bit.

STOP THAT DRIVE  Written July 20, 1989
QUICK STOP	 Written January 23, 1989
*/

#include <osbind.h>
#include <linea.h>

alert(string)
	char *string;
{
int r;
	r=Getrez();
	lineaa();
	if (Getrez()!=2)
		{
		Setscreen(-1L,-1L,0);
		Cconws("\007\033c\041");
		}
	Cconws("\033E\n\n\n\n\n\n");
	Cconws(string);
	Cconws("\n\n\n\n\rPress a key to continue...\007");
	Cnecin();
	if (Getrez()!=2)
		{
		Cconws("\033c\040");
		Setscreen(-1L,-1L,r);
		}
	Cconws("\033E");
	linea9();
}


/* Check drive 'D' (A, D=0; B, D=1) for executable bootsector. Returns:
	0=No problem, 1=Executable bootsector, -1=Could not read boot sector */

int check_drive(D)
	int D;
{
unsigned char buf[512];
unsigned int c,cs=0;

	if (Floprd(buf,0L,D,1,0,0,1))
		return(-1);
	else
		{
		/* Calculate check sum */
		cs=0;
		for (c=0;c<512;c+=2)
			cs+=((unsigned)(buf[c]<<8)+buf[c+1]);
		if(cs==0x1234)
			return(1);
		else
			return(0);
		}
}

main()
{
unsigned int K,D=0,r;

	Cconws("\033E\n\r\
	+------+----------+------+\n\r\
	|      |QUICK STOP|	 |\n\r\
	|      +----------+	 |\n\r\
	|     By: David Mace	 |\n\r\
	|    January 23, 1990	 |\n\r\
	|  On the Public Domain  |\n\r\
	+------------------------+\n\r");

	while(1)
		{
		Cconws("\nInsert disk in drive ");
		Cconout((char)('A'+D));
		Cconws(", then press any key.\n\r");
		Cconws("Press [A] for drive A, or [B] for drive B.\n\r");
		Cconws("Press [Esc] to quit\n\r");
		Cconws("Press any other key to read selected drive.\n\r");
		K=Cnecin();
		if((K=='A')||(K=='a'))
			D=0;
		if((K=='B')||(K=='b'))
			D=1;
		if(K==27) /* [Esc] */
			Pterm(0);

		Cconws("\n\rChecking Drive ");
		Cconout((char)('A'+D));
		Cconws("... ");

		r=check_drive(D);
		switch(r)
			{
			case -1:
				alert("\
       The boot sector on the disk      \n\r\
	     is unreadable!\n\r");
			break;
			case 1:	
				alert("\n\
            This disk shows\n\r\
 signs of possible virus contamination.\n\n\r\
    Load a better detection program\n\r\
	 for better diagnosis.\n\r");
			break;
			case 0:
				Cconws(" Bootsector harmless.\n\r");
			break;
			}
		}
}
