home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Elysian Archive
/
AmigaElysianArchive.iso
/
virus
/
sentry.lha
/
Sentry.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-03-29
|
11KB
|
503 lines
echo; /* Mar 28, 1988; Assumes you've assigned your work area as a:
lc -v -b -y -oa: Sentry.c
blink lib:cback.o,Sentry.o +
to Sentry +
library lib:amiga.lib,lib:lc.lib +
sc sd nd +
map a:map plain
quit
Just `execute Sentry.c'. Based on some weird Manx VirusX program
source by Steve Tibbett. Reprogrammed and made to compile and link on
Lattice 4.01 by Bruce Takahashi. This program doesn't need to be
`run'ed or `runback'ed. It sets up it's own process. It can be loaded
by a program icon and for those that use WorkBench only and cannot
`install dfx:' from CLI, just Click into the Window and type the
number of the drive unit to install. Be warned that writing to the
boot sectors of a disk with CUSTOM BOOT SECTORS may prevent the
program disk from ever working again.
"Wouldn't you like to play a nice game of chess?" -WOPAR
Yup. -Bruce K. Takahashi
*/
#include "exec/types.h"
#include "exec/exec.h"
#include "exec/execbase.h"
#include "intuition/intuition.h"
#include "intuition/intuitionbase.h"
#include "devices/trackdisk.h"
#define BUFSIZE 2*TD_SECTOR /* io data buffer size */
LONG _stack = 2500; /* That ol' black magic.. */
char *_procname= "Sentry0.1";
LONG _priority = 0;
LONG _BackGroundIO = 0;
void MemCleanup(){}
struct MsgPort *diskport;
struct IOExtTD *diskreq;
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct IntuiMessage *Message;
struct RastPort *RP;
void cleanup(int);
void CheckBlocks();
long DiskInserted();
void DoInstall(long);
long DisksChecked=0, DisksInstalled=0, SCAFound=0; /* for title bar info */
long ChangeCount[4]; /* TD_CHANGENUM all 4 drives */
long Virus, SCA; /* Virus flags */
long Unit, Class, Code, error, ok;
UBYTE *diskbuffer;
ULONG *sumbuffer;
UBYTE *titlebuffer;
static char TEXT1[] = "Danger: Disk in DFX:";
static char TEXT2[] = "DFX:'s disk boot sectors?";
unsigned char bootblock[] = {
'D', 'O', 'S', 0, 0xc0, 0x20, 0x0f, 0x19,
0, 0, 3, 0x70, 0x43, 0xfa, 0, 0x18,
0x4e, 0xae, 0xff, 0xa0, 0x4a, 0x80, 0x67, 0x0a, 0x20, 0x40, 0x20, 0x68,
0x00, 0x16, 0x70, 0x00, 0x4e, 0x75, 0x70, 0xff, 0x60, 0xfa, 0x64,
0x6f, 0x73, 0x2e, 0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79,0,0,0,0,0
};
struct TextAttr TxtAt_Plain = {
"topaz.font",
8,
FS_NORMAL,
FPF_ROMFONT
};
/*** Non SCA warning requester IntuiText's ***/
struct IntuiText Body2 = {
0, 1,
JAM2,
20,18,
&TxtAt_Plain,
"Nonstandard Boot Code!",
NULL
};
struct IntuiText Body1 = {
0, 1,
JAM2,
20, 8,
&TxtAt_Plain,
TEXT1,
&Body2
};
struct IntuiText Pos = {
0, 1,
JAM2,
7,3,
&TxtAt_Plain,
"Remove it",
NULL
};
struct IntuiText Neg = {
0, 1,
JAM2,
7,3,
&TxtAt_Plain,
"Ignore it",
NULL
};
/*
* SCA Danger Requester IntuiText's
*/
struct IntuiText SCABody2 = {
0, 1,
JAM2,
20,18,
&TxtAt_Plain,
"Infected with SCA Virus!!",
NULL
};
struct IntuiText SCABody = {
0, 1,
JAM2,
20, 8,
&TxtAt_Plain,
TEXT1,
&SCABody2
};
struct IntuiText SCAPos = {
0, 1,
JAM2,
7,3,
&TxtAt_Plain,
"Remove it",
NULL
};
struct IntuiText SCANeg = {
0, 1,
JAM2,
7,3,
&TxtAt_Plain,
"Ignore it",
NULL
};
/*
* Write Protect Error Requester IntuiText's
*/
struct IntuiText ERRBody2 = {
0, 1,
JAM2,
20,18,
&TxtAt_Plain,
"Disk is Write Protected",
NULL
};
struct IntuiText ERRBody = {
0, 1,
JAM2,
20, 8,
&TxtAt_Plain,
"DISK ERROR:",
&ERRBody2
};
struct IntuiText ERRPos = {
0, 1,
JAM2,
7,3,
&TxtAt_Plain,
"Retry",
NULL
};
struct IntuiText ERRNeg = {
0, 1,
JAM2,
7,3,
&TxtAt_Plain,
"Cancel",
NULL
};
/*
* Rewrite block? Really?
*/
struct IntuiText REWBody4 = {
0, 1,
JAM2,
20,33,
&TxtAt_Plain,
TEXT2,
NULL
};
struct IntuiText REWBody3 = {
0, 1,
JAM2,
20, 23,
&TxtAt_Plain,
"Are you sure you want to rewrite",
&REWBody4
};
struct IntuiText REWBody2 = {
0, 1,
JAM2,
20, 13,
&TxtAt_Plain,
"be necessary for a program disk.",
&REWBody3
};
struct IntuiText REWBody = {
0, 1,
JAM2,
20, 3,
&TxtAt_Plain,
"WARNING: CUSTOM BOOT blocks may",
&REWBody2
};
struct IntuiText REWPos = {
0, 1,
JAM2,
7,3,
&TxtAt_Plain,
"Yes",
NULL
};
struct IntuiText REWNeg = {
0, 1,
JAM2,
7,3,
&TxtAt_Plain,
"No!",
NULL
};
struct Window *LittleWindow;
struct NewWindow NewLittleWindow = {
0, 10, 400, 10, /* window position, size */
3, 2, /* Frontpen, Backpen */
DISKINSERTED
| CLOSEWINDOW
| VANILLAKEY, /* IDCMP Flags */
WINDOWDRAG
| WINDOWDEPTH
| WINDOWCLOSE
| NOCAREREFRESH
| SIMPLE_REFRESH
| RMBTRAP, /* Flags */
NULL, NULL,
NULL, /* title */
NULL, NULL,
0, 0, 0, 0,
WBENCHSCREEN
};
void _main()
{
int xx;
BOOL flag;
/* my weird type of open -BKT */
ok=0;
if(IntuitionBase=(struct IntuitionBase *) OpenLibrary("intuition.library",33L)) {
ok=1;
if(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0)) {
ok=2;
if(diskport=(struct MsgPort *)CreatePort(0,0)) {
ok=3;
if(diskreq=(struct IOExtTD *)CreateExtIO(diskport,sizeof(struct IOExtTD))) {
ok=4;
if(titlebuffer=(UBYTE *)AllocMem(64,MEMF_PUBLIC)) {
ok=5;
if(diskbuffer=(UBYTE *)AllocMem(BUFSIZE,MEMF_CHIP|MEMF_CLEAR)) {
ok=6;
if(LittleWindow = (struct Window *)OpenWindow(&NewLittleWindow)) {
RP = LittleWindow->RPort;
ok=7;
}
}
}
}
}
}
}
if(ok!=7) { cleanup(ok); return; } /* It ain't Amiga, outta here! */
for(xx=0;xx<4;xx++) ChangeCount[xx]=~0; /* forces check of all drives */
CheckBlocks();
SetAPen(RP, 1);
SetBPen(RP, 0);
SetDrMd(RP, JAM2);
flag=TRUE;
while(flag) {
sprintf(titlebuffer, " %ld disks: %ld infected; %ld cured",
DisksChecked, SCAFound, DisksInstalled);
SetWindowTitles(LittleWindow, titlebuffer, -1);
(void)WaitPort(LittleWindow->UserPort);
while(Message = (struct IntuiMessage *)GetMsg(LittleWindow->UserPort)) {
Class = Message->Class;
Code = Message->Code;
ReplyMsg(Message);
if (Class == CLOSEWINDOW) flag=FALSE;
if (Class == DISKINSERTED) CheckBlocks();
if (Class == VANILLAKEY) {
switch(Code) {
case '3':
case '2':
case '1':
case '0': DoInstall(Code-'0');
break;
}
} /* if */
}/* while */
} /* for */
cleanup(ok);
}
void CheckBlocks()
{
register long aa, Sum, LastSum;
for(;;) {
SCA = FALSE;
Virus = FALSE;
Unit=DiskInserted(); /* new disks mounted? */
if(Unit==-1) break; /* no.. just return */
error = OpenDevice(TD_NAME,Unit,diskreq,0);
if (error) continue;
diskreq->iotd_Req.io_Command = CMD_READ;
diskreq->iotd_Req.io_Data = (APTR)diskbuffer;
diskreq->iotd_Req.io_Length = BUFSIZE;
diskreq->iotd_Req.io_Offset = 0;
DoIO(diskreq); /* READ BOOT */
if(BUFSIZE!=diskreq->iotd_Req.io_Actual) {
CloseDevice(diskreq);
continue;
}
(APTR)sumbuffer=(APTR)diskbuffer;
Sum = 0;
for (aa=0; aa<256; aa++) {
LastSum = Sum;
Sum += sumbuffer[aa];
if (LastSum > Sum) Sum++;
}
diskreq->iotd_Req.io_Length = 0;
diskreq->iotd_Req.io_Command = TD_MOTOR;
DoIO(diskreq); /* turn off motor */
CloseDevice(diskreq);
DisksChecked++;
if (Sum!=0) continue; /* not bootable */
/* check specifically for SCA virus */
if (diskbuffer[8] == 'C') {
if (diskbuffer[9] == 'H') {
if (diskbuffer[10] == 'W') {
SCA = TRUE; /* CHW is part of SCA virus */
SCAFound++;
}
}
}
/* compare `standard' boot code with what was read */
for (aa=8; aa<39+8; aa++) { /* num of elements in bootblock */
if (diskbuffer[aa] != bootblock[aa]) Virus = TRUE;
}
/* a Virus! */
if (Virus == TRUE) {
TEXT1[18] = '0'+Unit; /* change text `DFX' to real drive */
if (SCA != TRUE) {
error = AutoRequest(LittleWindow, &Body1, &Pos, &Neg, 0, 0, 320, 75);
if (error == TRUE) DoInstall(Unit);
}
else {
/* a nonstandard boot block */
error = AutoRequest(LittleWindow, &SCABody, &SCAPos, &SCANeg, 0, 0, 320, 75);
if (error == TRUE) DoInstall(Unit);
}
}
}/* End of loop */
}
long DiskInserted()
{
long xx, RetVal=-1; /* return -1 as no change */
for (xx=0; xx<4; xx++) {
error = OpenDevice(TD_NAME,xx,diskreq,0);
if(error) continue; /* no drive */
/* disk changed */
diskreq->iotd_Req.io_Command = TD_CHANGENUM;
DoIO(diskreq);
if (diskreq->iotd_Req.io_Actual != ChangeCount[xx]) {
ChangeCount[xx] = diskreq->iotd_Req.io_Actual;
RetVal=xx;
CloseDevice(diskreq);
break;
}
}
return(RetVal);
}
void DoInstall(unit)
long unit; /* unit to write to */
{
register long xx;
TEXT2[2] = '0'+unit; /* change text `DFX' to real drive */
error = AutoRequest(LittleWindow,&REWBody,&REWPos,&REWNeg,0,0,320,75);
if (error != TRUE) return;
error = OpenDevice(TD_NAME, unit,diskreq,0);
if (error > 0) return;
for(;;) { /* check if disk is write protected */
diskreq->iotd_Req.io_Command = TD_PROTSTATUS;
DoIO(diskreq);
if (diskreq->iotd_Req.io_Actual == 0) break;
else { /* write protect tab is enabled */
error = AutoRequest(LittleWindow,&ERRBody,&ERRPos,&ERRNeg,0,0,320,75);
if (error == TRUE) continue; /* user chose retry */
CloseDevice(diskreq);
return; /* user chose no */
}
}
/* clear diskbuffer to zero. clean. */
for(xx=0; xx<1024; xx++) diskbuffer[xx] = 0;
/* copy boot code into buffer */
for(xx=0; xx<50; xx++) diskbuffer[xx] = bootblock[xx];
diskreq->iotd_Req.io_Data = (APTR)diskbuffer;
diskreq->iotd_Req.io_Length = 1024;
diskreq->iotd_Req.io_Offset = 0;
diskreq->iotd_Req.io_Command = CMD_WRITE;
DoIO(diskreq);
/* flush buffer to disk */
diskreq->iotd_Req.io_Command = CMD_UPDATE;
DoIO(diskreq);
error = diskreq->iotd_Req.io_Error;
/* turn off motor */
diskreq->iotd_Req.io_Length = 0;
diskreq->iotd_Req.io_Command = TD_MOTOR;
DoIO(diskreq);
CloseDevice(diskreq);
if (error > 19) {
SetWindowTitles(LittleWindow, "Error, Nothing Done.", -1);
}
else {
SetWindowTitles(LittleWindow, "Boot Cleaned", -1);
DisksInstalled++;
}
Delay(150);
for(xx=0;xx<4;xx++) ChangeCount[xx]=~0; /* forces check of all drives */
} /* endof DoInstall(unit) */
void cleanup(ok)
{
switch(ok) {
case 7: CloseWindow(LittleWindow);
case 6: FreeMem(diskbuffer,BUFSIZE);
case 5: FreeMem(titlebuffer,64);
case 4: DeleteExtIO(diskreq,sizeof(struct IOExtTD));
case 3: DeletePort((struct MsgPort *)diskport);
case 2: CloseLibrary((struct Library *)GfxBase);
case 1: CloseLibrary((struct Library *)IntuitionBase);
break;
}
}