home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 169.lha / VirusX_v2.0 / VirusX.C < prev    next >
C/C++ Source or Header  |  1988-04-28  |  26KB  |  1,079 lines

  1.  
  2.  
  3. /* VirusX - by Steve Tibbett
  4.  
  5.     The complete Virus Elimination System!
  6.  
  7.         Please - if you find a new virus, Send me a copy!
  8.         (And warn me it's on the disk!).  I want to keep
  9.         this program current.  (Feel free to put something
  10.         neat on the disk also!)
  11.  
  12.  
  13. History:
  14. --------
  15.  
  16.  A few weeks ago: V1.0 written.
  17. A few days later: V1.01 released - V1.0 wrote garbage when disk was Write Prot. 
  18.        27-Mar-88: V1.2 - Added Byte Bandit RAM detection, and disk detection.  
  19.           (Actually, it's well after Midnight - make that 28-Mar-88)
  20. Just after
  21. uploading V1.2
  22.      to Amic BBS: Realized I put the wrong version in the ARC file - Had to
  23.                   rename V1.2 to V1.21...
  24.  
  25.    June 15, 1988: Created V1.3 which was just V1.21 cleaned up, made a bunch smaller.
  26.  
  27.     July 8, 1988: Recieved Revenge virus Yesterday, disassembled it,
  28.                   and added it to VirusX 1.4.  Added ViewBoot and SCA check also.
  29.  
  30.    July 24, 1988: Recieved the Byte Warrior virus, added it.  V1.5
  31.  
  32.     Aug. 1, 1988: These things are showing up Quick!  Northstar Virus
  33.                   sent to me by Dan Mosedale.  Thanks, Dan!  V1.6
  34.  
  35.    Aug. 18, 1988: Whew, after a 2 week break, got the Obelisk
  36.           Softworks Crew Virus, dealt with it within an hour.
  37.             (this is becoming a habit 8-)  1.7
  38.  
  39.  
  40.   Viruses Dealt With:
  41.  
  42.     Byte Bandit    - RAM and Disk checked, TD vector patched,
  43.               resident module destroyed, Interrupt
  44.               patched.
  45.     
  46.     SCA        - Disk checked, CoolCapture checked, fixed
  47.               if it points to a known SCA virus.
  48.  
  49.     Revenge        - DoIO patched, Interrupt patched, Disk
  50.               checked.
  51.  
  52.     Byte Warrior - 
  53.  
  54.     North Star    - Hangs around via Coolcapture, I just killed it.
  55.  
  56.     Obelisk Softworks Crew - Hangs around via CoolCapture, also
  57.                  watches reads of DoIO() (but doesn't
  58.                  infect EVERY disk - onlyt ones you boot
  59.                  off of)
  60.  
  61. */
  62.  
  63. #include <stdio.h>
  64. #include <exec/types.h>
  65. #include <intuition/intuition.h>
  66. #include <devices/bootblock.h>
  67. #include <devices/trackdisk.h>
  68. #include <exec/execbase.h>
  69. #include <libraries/dos.h>
  70.  
  71. /*  This stuff is for the detach module Manx provides, that's how
  72.     VirusX can be executed in the Startup Sequence and have the 
  73.     initial CLI window close without any problems. 
  74.  
  75.      (but not until I get a version of 1.3 that works with it)
  76.  
  77.     */
  78.  
  79. long _stack = 16000;
  80. long _priority = 0;
  81. long _BackGroundIO = 0;
  82. char *_procname = "VirusX";
  83.  
  84.  
  85. /*
  86.  
  87.     Created with Aztec C V3.6a using 32 bit ints.
  88.  
  89.     (My makefile is included in the archive)
  90.  
  91.     No longer uses Precompiled Headers, so it should compile OK.
  92.  
  93. */
  94.  
  95. char WindowBig;
  96. struct         Port         *diskport;    /* disk's port.*/
  97. struct         IOStdReq     *diskreq;    /* disk's IOStdReq */
  98. int        DisksChecked, 
  99.         DisksInstalled, 
  100.         VirusesFound;            /* for title bar info */
  101. char         titlebuffer[75];        /* Where tietie bar is kept */
  102. int VirusBase;    /* ick, whatta name! */
  103.  
  104. /* Amount of boot code we've got bwlow (approx):  */
  105. #define BSIZE 40
  106.  
  107. char TDName[] = "trackdisk.device";    /* Saves space */
  108. char copystring[] = "(Copy Count on this disk: %d)"; /* Again, saves space */
  109. char ITBodyText[80]; /* this saves mega space! */
  110. char VN_OBELISK[] = "Obelisk";
  111. char VN_NORTHSTAR[] = "North Star";
  112. char VN_SCA[] = "SCA";
  113. char VN_BYTEBANDIT[] = "Byte Bandit";
  114. char VN_BYTEWARRIOR[] = "Byte Warrior";
  115. char VN_REVENGE[] = "Revenge";
  116.  
  117. int ObeliskCount;
  118. int NorthStarCount;
  119. int SCACount;
  120. int ByteBanditCount;
  121. int ByteWarriorCount;
  122. int RevengeCount;
  123.  
  124. int ChangeCount[4];        /* TD_CHANGECOUNT for all 4 drives */
  125. int LastSum;            /* Used in the checksumming */
  126. int CheckDrives;        /* Boolean, from the command line */
  127. int error;            /* sort of a temporary variable sort of */
  128.  
  129. unsigned char diskbuffer[3*512];/* Everything ends up in here. 
  130.                    I suppose I should have AllocMem'ed this,
  131.                    but it's SO easy this way 
  132.  
  133.             Note that this is 3*512, not 2*512.  The reason
  134.             for this is that I have heard that the SCA will
  135.             attempt to rewrite itself whenever it sees a Read
  136.             request of 1024 bytes... So I read 3 blocks.
  137.             */
  138.  
  139. /* Warning messages.  These messages get modified before being displayed
  140. wack   (Unless you DO have a DF9:) */
  141.  
  142. char TEXTPTR[] = "Danger:  The disk in DF9: is";
  143. char NBCTEXT[] = "Danger:  The disk in DF9: has";  /* What a waste, eh? */
  144. char CopyText[40];
  145.  
  146. /* This is a byte by byte copy of working boot block code.  Check it
  147.    out if you like.  This is what gets written back to the disk when you
  148.    ask VirusX to fix a disk. */
  149.  
  150. unsigned char bootblock[] = { 'D', 'O', 'S', 0, 
  151. 0xc0, 0x20, 0x0f, 0x19, 0x00, 0x00, 0x03, 0x70, 0x43, 0xfa, 0x00, 0x18, 
  152. 0x4e, 0xae, 0xff, 0xa0, 0x4a, 0x80, 0x67, 0x0a, 0x20, 0x40, 0x20, 0x68, 
  153. 0x00, 0x16, 0x70, 0x00, 0x4e, 0x75, 0x70, 0xff, 0x60, 0xfa, 0x64, 0x6f,
  154. 0x73, 0x2e, 0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x00, 0x00, 0x00,
  155. 0x00, 0x00};
  156.  
  157. struct TextAttr TxtAt_Plain = {    "topaz.font", 8, FS_NORMAL, FPF_ROMFONT};
  158.  
  159.  
  160. /***  Non SCA warning requester IntuiText's ***/
  161. struct IntuiText Body2 = { 0, 1,  JAM2, 20,18, &TxtAt_Plain,
  162.     "Nonstandard Boot Code!", NULL };
  163. struct IntuiText Body1 = {
  164.    0, 1,        JAM2,          20, 8, &TxtAt_Plain,      (UBYTE *)NBCTEXT, &Body2 };
  165.  
  166.  
  167.  
  168. /*  This one says "The disk in DFx: is"  */
  169. struct IntuiText GenericFirstBody = {
  170.    0, 1,        JAM2,          20, 8, &TxtAt_Plain,      (UBYTE *)TEXTPTR, 0 };
  171.  
  172.  
  173.  
  174. /***** Generic IntuiTexts used as of V1.7 ******/
  175.  
  176. struct IntuiText GenericDiskBody = {
  177.    0, 1,     JAM2,          20,18,        &TxtAt_Plain,ITBodyText, &GenericFirstBody };
  178.  
  179. struct IntuiText SCAPos = {
  180.    0, 1,     JAM2,           7,3,        &TxtAt_Plain, "Remove it", NULL };
  181. struct IntuiText Repair = {
  182.    0, 1,     JAM2,           7,3,        &TxtAt_Plain, "Repair it", NULL };
  183. struct IntuiText SCANeg = {
  184.    0, 1,    JAM2,           7,3,        &TxtAt_Plain, "Ignore it", NULL };
  185.  
  186.  
  187.  
  188. /*  Special cases (display copy count  */
  189.  
  190. /***** BBANDIT Requester IntuiText's ******/
  191. struct IntuiText BBDiskbody2 = {
  192.    0, 1,     JAM2,          20,30,        &TxtAt_Plain, CopyText, &GenericFirstBody };
  193. struct IntuiText BBDiskbody = {
  194.    0, 1,     JAM2,          20,18,        &TxtAt_Plain, ITBodyText, &BBDiskbody2};
  195.  
  196. /***** Revenge on Disk Requester IntuiText's ******/
  197. struct IntuiText RevDiskbody3 = {
  198.    0, 1,     JAM2,          20,30,        &TxtAt_Plain, CopyText, &GenericFirstBody };
  199. struct IntuiText RevDiskbody = {
  200.    0, 1,     JAM2,          20,18,        &TxtAt_Plain,(UBYTE *) "infected with the -Revenge- VIRUS!", &RevDiskbody3};
  201.  
  202.  
  203. /***** Generic Notice - Removed from Memory ****/
  204. struct IntuiText GRB3 = {
  205.    0, 1,     JAM2,          20,18,        &TxtAt_Plain,(UBYTE *) "in memory, and is now disabled.  See the", NULL};
  206. struct IntuiText GRB2 = {
  207.    0, 1,     JAM2,          20,28,        &TxtAt_Plain,(UBYTE *) "documentation for more information!", &GRB3 };
  208. struct IntuiText GenericRAMBody = {
  209.    0, 1,     JAM2,          20,8,        &TxtAt_Plain, ITBodyText, &GRB2 };
  210. struct IntuiText BBMPos = {
  211.    0, 1,     JAM2,           7,3,        &TxtAt_Plain, " Thanks! ", NULL };
  212.  
  213. struct IntuiText Mem3 = {
  214.    0, 1,     JAM2,          20,28,        &TxtAt_Plain,(UBYTE *) "some other utility is the cause of it.", NULL};
  215. struct IntuiText Mem2 = {
  216.    0, 1,     JAM2,          20,18,        &TxtAt_Plain,(UBYTE *) "This could mean a new Virus is in RAM, or", &Mem3};
  217. struct IntuiText Mem1 = {
  218.    0, 1,     JAM2,          20,8,        &TxtAt_Plain, 0 , &Mem2};
  219.  
  220.  
  221.  
  222. /***** Write Protect Error Requester IntuiText's ******/
  223. struct IntuiText ERRBody2 = {
  224.    0, 1,     JAM2,          20,18,        &TxtAt_Plain,(UBYTE *) "Write Protected.", NULL };
  225. struct IntuiText ERRBody = {
  226.    0, 1,        JAM2,          20, 8, &TxtAt_Plain,      (UBYTE *)"DISK ERROR:  Disk is", &ERRBody2 };
  227. struct IntuiText ERRPos = {
  228.    0, 1,     JAM2,           7,3,        &TxtAt_Plain, "Retry", NULL };
  229. struct IntuiText ERRNeg = {
  230.    0, 1,    JAM2,           7,3,        &TxtAt_Plain, "Cancel", NULL };
  231.  
  232.  
  233. /***** Rewrite block?  Really? ******/
  234. struct IntuiText REWBody3 = {
  235.    0, 1,     JAM2,          20,28,        &TxtAt_Plain,(UBYTE *) "boot sectors?", NULL };
  236.  struct IntuiText REWBody2 = {
  237.    0, 1,     JAM2,          20,18,        &TxtAt_Plain,(UBYTE *) "rewrite that disk's boot", &REWBody3};
  238. struct IntuiText REWBody = {
  239.    0, 1,        JAM2,          20, 8, &TxtAt_Plain,      (UBYTE *)"Are you sure you want to", &REWBody2 };
  240. struct IntuiText REWPos = {
  241.    0, 1,     JAM2,           7,3,        &TxtAt_Plain, "Yes", NULL };
  242. struct IntuiText REWNeg = {
  243.    0, 1,    JAM2,           7,3,        &TxtAt_Plain, "No!", NULL };
  244.  
  245. struct IntuitionBase *IntuitionBase;
  246. struct GfxBase *GfxBase;
  247. struct Window *Window;
  248. struct IntuiMessage *Message;
  249.  
  250. int Keepgoing;        /* a boolean flag.  it's false when we want out. */
  251. int x, y, i;        /* left over from my using Basic */
  252.  
  253. /*** The Newwindow Structure. ***/
  254.  
  255. char TITLETEXT[] = "VirusX 2.00 by Steve Tibbett";
  256. char text[] = "DF6: Boot Sectors"; /* for display thing */
  257.  
  258. struct NewWindow NewWindow = {
  259.     128,0,    309,10,     0,1,        
  260.     DISKINSERTED | CLOSEWINDOW | VANILLAKEY | NEWSIZE | MOUSEBUTTONS,    /* IDCMP Flagz */
  261.     WINDOWDRAG | WINDOWDEPTH | RMBTRAP | WINDOWCLOSE | NOCAREREFRESH, /* Windo Flagz */    
  262.     NULL, NULL,TITLETEXT,    /* My name.  Vous Touchez mon Name, Vous dies. */
  263.     NULL,NULL,0,0,0,0,WBENCHSCREEN,    
  264.     };
  265.  
  266. struct RastPort *RP;
  267.  
  268. /*********************Da Beginnin*************************/
  269. main()
  270. {
  271.  
  272. WindowBig = FALSE;
  273.  
  274. /* Come on, folks, is intuition ever NOT going to be available???? */
  275. IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0);
  276.  
  277. /* Same with GfxBase.  If GfxBase is gone, we DESERVE to crash. */
  278. GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0);
  279.  
  280. /*  We use the same port/request through the whole program.  Works OK. */
  281. diskport = CreatePort(0,0);
  282. diskreq = CreateStdIO(diskport);
  283.  
  284. Window = OpenWindow(&NewWindow);
  285. if (Window == NULL) 
  286.     goto Quitter;    /* No memory to open little window! */
  287.  
  288. RP = Window->RPort;
  289.  
  290. /* This does some setup stuff, I guess, eh? */
  291. SetUp();
  292.  
  293. /*  Check for Byte Bandit, SCA, Revenge and ByteWarrior in RAM.  */
  294. CheckMemoryForViruses();
  295.  
  296. CheckBlock();
  297.  
  298. DoLittle();    /* The main loop.  Do Little.  Ya. */
  299.  
  300. Quitter:
  301. DeletePort(diskport);
  302. DeleteStdIO(diskreq);
  303.  
  304. CloseLibrary(GfxBase);
  305. CloseLibrary(IntuitionBase);
  306. }            
  307.  
  308. /*********************/
  309. DoLittle()
  310. {
  311. register int Code;    /* for storing our IntuiMessage stuff */
  312. register int Class;
  313. register int KG2;    /* KeepGoing 2.  Another booleean. */
  314.  
  315. KG2 = TRUE;
  316.  
  317. SetAPen(RP, 1);
  318. SetBPen(RP, 0);
  319. SetDrMd(RP, JAM2);
  320.  
  321. while (KG2 == TRUE)
  322.     {
  323.     if (WindowBig == TRUE) DoStats();
  324.  
  325.     Goober:
  326.  
  327.     WaitPort(Window->UserPort);
  328.     Message = GetMsg(Window->UserPort);
  329.  
  330.     Class = Message->Class;
  331.     Code = Message->Code;
  332.     ReplyMsg(Message);
  333.     
  334.     if (Class == CLOSEWINDOW) 
  335.         {
  336.         KG2 = FALSE;
  337.         continue;
  338.         };
  339.  
  340.     if (Class == MOUSEBUTTONS)
  341.         if (Code == MENUDOWN)
  342.             { Class = VANILLAKEY; Code = 'i'; }
  343.             else goto Goober;
  344.  
  345.     if (Class == VANILLAKEY)
  346.         {
  347.         int flag;
  348.  
  349.         if (Code == 'i')
  350.             {
  351.             if (WindowBig == TRUE) WindowBig = FALSE;
  352.                 else WindowBig = TRUE;
  353.  
  354.             if (WindowBig == TRUE) 
  355.                 {
  356.                 SizeWindow(Window, 0, 100);
  357.                 } else SizeWindow(Window, 0, -100);
  358.  
  359.             WaitForNewSize();
  360.             };
  361.  
  362.         if (Code == 'c')
  363.             {
  364.             for (x=0; x<4; x++) ChangeCount[x] = 10000;
  365.             CheckBlock();
  366.             }
  367.             else
  368.             {
  369.             flag = ShowAscii(Code);
  370.             if (flag == 1) CheckBlock();
  371.             };
  372.         };
  373.  
  374.     if (Class == DISKINSERTED) CheckBlock();
  375.     };
  376.  
  377. CloseWindow(Window);
  378. }
  379.  
  380.  
  381. /************************************************/
  382. /* Opens trackdisk, finds out who's out there,  */
  383. /* and sets Changecount up accordioningly.      */
  384. /************************************************/
  385. SetUp()
  386. {
  387. for (x = 0; x < 4; x++)    /* go thru all 4 possible drives */
  388.     {
  389.     ChangeCount[x] = 1000;
  390.     error = OpenDevice(TDName,x,diskreq,0);
  391.     if (error > 0) 
  392.         {
  393.         ChangeCount[x] = -1;
  394.         } else CloseDevice(diskreq);
  395.     };
  396.  
  397. }
  398.  
  399. /*********************************************************/
  400. /* This routine returns which drive changed disks lately */
  401. /*********************************************************/
  402. WhoChanged()
  403. {
  404. int RetVal;    /* The value we'll return */
  405.  
  406. RetVal = -1;    /* return -1 if all else fails */
  407. for (x = 0; x < 4; x++)
  408.     {
  409.     if (ChangeCount[x] == -1) continue;    /* no drive here */
  410.     error = OpenDevice(TDName,x,diskreq,0);
  411.     if (error > 0) continue;    /* no drive here */
  412.     
  413.     diskreq->io_Command = TD_CHANGESTATE;
  414.     DoIO(diskreq);
  415.     if (diskreq->io_Actual != 0) 
  416.         {
  417.         CloseDevice(diskreq);
  418.         continue;
  419.         };
  420.  
  421.     diskreq->io_Command = TD_CHANGENUM;
  422.     DoIO(diskreq);
  423.     if (diskreq->io_Actual != ChangeCount[x]) 
  424.         {
  425.         RetVal = x;
  426.         ChangeCount[x] = diskreq->io_Actual;
  427.         CloseDevice(diskreq);
  428.         goto Out;
  429.         };
  430.  
  431.     CloseDevice(diskreq);
  432.     };
  433.  
  434. Out:;
  435. return(RetVal);
  436. }
  437.  
  438. /****************************************************************/
  439. /*  Figures out which drive changed disks (using WhoChanged(),  */
  440. /*  And checks it.  Calling this after every DISKINSERTED is OK.*/
  441. /****************************************************************/
  442.  
  443. CheckBlock()
  444. {
  445. /*  How many register vars can I use, anyway? */
  446. register int Sum, Bootable, Virus;
  447. register int a, Unit;
  448. int SCA, ByteWarrior, Revenge, BBandit;
  449. int NorthStar, Obelisk;
  450. register unsigned int *iptr;
  451. unsigned int *ptr;
  452.  
  453. while ((Unit = WhoChanged()) != -1)
  454.     {
  455.     DisksChecked++;
  456.  
  457.     SCA = FALSE;
  458.     BBandit = FALSE;
  459.     Revenge = FALSE;
  460.     ByteWarrior = FALSE;
  461.     NorthStar = FALSE;
  462.     Obelisk = FALSE;
  463.  
  464.     /* Unit # to open is returned by "WhoChanged()" up above. */
  465.     if (Unit == -1) return;
  466.     error = OpenDevice(TDName,Unit,diskreq,0);
  467.     if (error > 0) return;
  468.  
  469.     error = ReadBlock();
  470.     CloseDevice(diskreq);
  471.     if (error == FALSE) return;
  472.  
  473.     ptr = diskbuffer;
  474.     iptr = diskbuffer;
  475.  
  476.     if (iptr[0] != ID_DOS_DISK) return;    /* No DOS/0 */
  477.  
  478.     Sum = 0;
  479.     for (a=0; a<256 /*1024/4 cuz we're dealing with ptr math now*/  ; a++)
  480.         {
  481.         LastSum = Sum;
  482.         Sum = Sum + ptr[a];
  483.         if (LastSum > Sum) Sum++;    /* took me a while to figger this out */
  484.         }
  485.  
  486.     if (Sum != 0) 
  487.         {
  488.         return;    /* if it's not bootable, we DONT want it! */
  489.         };
  490.  
  491.     ptr = &diskbuffer[4];
  492.  
  493.     if (diskbuffer[0x34] == 100)
  494.         if (diskbuffer[0xc4] == 48)
  495.             if (diskbuffer[0xb] == 89)
  496.                 if (diskbuffer[0xf1] == 7)
  497.                     {
  498.                     VirusesFound++;
  499.                     ByteWarriorCount++;
  500.                     ByteWarrior = TRUE;
  501.                     };
  502.  
  503.     if (diskbuffer[0x2b] == '9')
  504.         if (diskbuffer[0x2c] == '.')
  505.             if (diskbuffer[0x2d] == '8')
  506.                 if (diskbuffer[0x2e] == '7')
  507.                     {
  508.                     VirusesFound++;
  509.                     ByteBanditCount++;
  510.                     BBandit = TRUE;    /* 9.87 is part of BBandit Virus */
  511.                     };
  512.  
  513.     /* check specifically for SCA virus */
  514.     if (diskbuffer[8] == 'C')
  515.         if (diskbuffer[9] == 'H')
  516.             if (diskbuffer[10] == 'W')
  517.                     {
  518.                     SCA = TRUE;    /* CHW is part of SCA virus */
  519.                     SCACount++;
  520.                     VirusesFound++;
  521.                     };
  522.  
  523.     if (diskbuffer[0xe] == 'I')
  524.         if (diskbuffer[0xf] == 'D')
  525.             if (diskbuffer[0x10] == '9')
  526.                 if (diskbuffer[0x1a6] == 'f')
  527.                     {
  528.                     Revenge= TRUE;
  529.                     RevengeCount++;
  530.                     VirusesFound++;
  531.                     };
  532.  
  533.     if (diskbuffer[0x12] == 78)
  534.         if (diskbuffer[0x13c] == 68)        
  535.             if (diskbuffer[0x18] = 83)
  536.                 if (diskbuffer[0x19] == 116)
  537.                     {
  538.                     NorthStar = TRUE;
  539.                     NorthStarCount++;
  540.                     VirusesFound++;
  541.                     };
  542.  
  543.  
  544.     if (diskbuffer[0x38] == 71)
  545.         if (diskbuffer[0xbc] == 83)
  546.             if (diskbuffer[0x1fb] == 100)
  547.                 if (diskbuffer[0x2d] == 80)
  548.                     {
  549.                     Obelisk = TRUE;
  550.                     ObeliskCount++;
  551.                     VirusesFound++;
  552.                     };
  553.  
  554.     /* compare boot block with real boot block.  If it's not, notify God. */
  555.     Virus = FALSE;
  556.  
  557.     for (x = 0; x < 39; x++) /* num of bytes in bootblock */
  558.         {
  559.         if (diskbuffer[8+x] != bootblock[8+x])
  560.             {    
  561.             Virus = TRUE;
  562.             };
  563.         };
  564.  
  565.     /* Oh no, a Virus! */
  566.     if (Virus == TRUE) 
  567.         {
  568.         NBCTEXT[23] = '0'+Unit; /* change DF9: to real drive in text */
  569.         TEXTPTR[23] = '0'+Unit;
  570.         error = FALSE;
  571.  
  572.         if (SCA == TRUE)
  573.             {
  574.             /* OH NOOOOO, an SCA virus.  Wimpo virus, compared to BBandit 
  575.                but it's a lot nicer code to read. */
  576.             error = MyRequest(VN_SCA, 1);
  577.             }
  578.         else if (BBandit == TRUE)
  579.             {
  580.             /* The Byte Bandit Virus.  Tricky bugger, he WAS. Cheats, tho. */
  581.             sprintf(CopyText, copystring, (diskbuffer[74]*256)+diskbuffer[75]);
  582.             BuildITBodyText(VN_BYTEBANDIT, 1);
  583.             error = AutoRequest(Window, &BBDiskbody, &SCAPos, &SCANeg, 0, 0, 380, 80);
  584.             }
  585.         else if (Revenge == TRUE)
  586.             {
  587.             /* Revenge virus.  X rated bugger, lot like Byte Bandit. */
  588.             sprintf(CopyText, copystring, (diskbuffer[0x3f6]*256)+diskbuffer[0x3f7]);
  589.             BuildITBodyText(VN_REVENGE, 1);
  590.             error = AutoRequest(Window, &RevDiskbody, &SCAPos, &SCANeg, 0, 0, 380, 80);
  591.             }
  592.         else if (ByteWarrior == TRUE)
  593.             {
  594.             /* Byte Warrior.  Very 'friendly' virus.  Ez to get rid of.  */
  595.             error = MyRequest(VN_BYTEWARRIOR, 1);
  596.             }
  597.         else if (NorthStar == TRUE)
  598.             {
  599.             /* NorthStar.  Nice virus - alerts you to others, ez to get rid of */
  600.             MyRequest(VN_NORTHSTAR, 1);
  601.             }
  602.         else if (Obelisk == TRUE)
  603.             {
  604.             /* At least these guys are getting creative with their Graphics! */
  605.             error = MyRequest(VN_OBELISK, 1);
  606.             }
  607.         else 
  608.             {
  609.             /* Probably just a custom boot block (or a new virus...) */
  610.             error = AutoRequest(Window, &Body1, &SCAPos, &SCANeg, 0, 0, 320, 70);
  611.             }
  612.         if (error == TRUE) DoInstall(Unit); /* user wants it neutered. */
  613.         };
  614.     };  /* End of While Whochanged */
  615. }
  616.  
  617. /********************************************/
  618. /* This is where the boot code gets changed */
  619. /********************************************/
  620. DoInstall(un)
  621. int un;    /* unit to write to */
  622. {
  623. register int x;
  624. register int Sum;
  625. register int err, a;
  626.  
  627. /* Rewrite disk?  Really?  */
  628. error = AutoRequest(Window, &REWBody, &REWPos, &REWNeg, 0, 0, 320, 75);
  629. if (error != TRUE) return;    /* user changed his brain. */
  630.  
  631. DisksInstalled++;
  632.  
  633. error = OpenDevice(TDName, un,diskreq,0);
  634. if (error > 0) return;
  635.  
  636. trygain:
  637.  
  638. diskreq->io_Command = TD_PROTSTATUS;
  639. DoIO(diskreq);        /* check if disk is write protected */
  640.  
  641. if (diskreq->io_Actual != 0)
  642.     {
  643.     error = AutoRequest(Window, &ERRBody, &ERRPos, &ERRNeg, 0, 0, 280, 75);
  644.     if (error == TRUE) /* error is true or false, depending on user */
  645.         {
  646.         goto trygain;
  647.         };
  648.     CloseDevice(diskreq);
  649.     return;    /* unrecoverable write protect error!!!!!!!!! */
  650.     };
  651.  
  652.  
  653. for (x = 0; x < 1024; x++)
  654.     diskbuffer[x] = 0;    /* clear diskbuffer to zero.  clean. */
  655.  
  656. CopyMem(bootblock, diskbuffer, 50); /* Copy it over */
  657.  
  658. /* Write it ! */
  659.  
  660.     {
  661.     error = 0;
  662.     diskreq->io_Length = 1024; /* here we go! */
  663.     diskreq->io_Data = &diskbuffer[0];  
  664.     diskreq->io_Command = CMD_WRITE;
  665.     diskreq->io_Offset = 0L;
  666.     DoIO(diskreq);
  667.     error = diskreq->io_Error;
  668.     };
  669.  
  670. if (error < 19)
  671.     {
  672.     diskreq->io_Command = CMD_UPDATE;    /* flush buffer to disk */
  673.     DoIO(diskreq);
  674.     error = diskreq->io_Error;
  675.     };
  676.  
  677. if (error < 19) 
  678.     {
  679.     diskreq->io_Length = 0;
  680.     diskreq->io_Command = ETD_MOTOR;
  681.     DoIO(diskreq);                /* turn off motor */
  682.     error = diskreq->io_Error;
  683.     };
  684.  
  685. CloseDevice(diskreq);
  686.  
  687. if (error > 19) 
  688.     {
  689.     SetWindowTitles(Window, "Error, Nothing Done.", -1);
  690.     } 
  691.     else
  692.     {
  693.     SetWindowTitles(Window, "Disk Healed.", -1);
  694.     };
  695.  
  696. Delay(150);
  697. SetWindowTitles(Window, TITLETEXT, -1);
  698. }
  699.  
  700.  
  701. /************************/
  702.  
  703. CheckMemoryForViruses()
  704. {
  705. int Temp;
  706. struct ExecBase *ExecBase;
  707. unsigned int *LongMemPointer;    /* Used for reading FROM memory */
  708. unsigned short *loc;
  709. unsigned int *ptr;
  710. char linebuffer[80];
  711.  
  712. ExecBase = OpenLibrary("exec.library", 0);
  713.  
  714.  
  715. /**************- Check for Byte Bandit (look at TD Vector) *************/
  716. /*  (Byte Bandit isn't at a fixed location.  Depends on your RAM.      */
  717.  
  718. /* LongMemPointer = &trackdisk.device */
  719. LongMemPointer = FindName(&ExecBase->DeviceList, TDName);
  720. Temp = LongMemPointer;
  721. Temp = Temp - 0x1c;
  722. LongMemPointer = Temp; 
  723. VirusBase = (*LongMemPointer) - 0x1b8;
  724. LongMemPointer = VirusBase;
  725.  
  726. if (*LongMemPointer == ID_DOS_DISK)    /* klugo */
  727.     {
  728.     /* Ok, so we don't really remove it from memory, but we DO render
  729.            it harmless. */
  730. #asm
  731.     xdef _VirusBase
  732.     xref _geta4
  733.     xref _LVODisable
  734.     xref _LVOEnable
  735.  
  736.     jsr _geta4
  737.  
  738.     move.l 4,a6
  739.     jsr _LVODisable(a6)
  740.  
  741.     move.l _VirusBase,a0
  742.  
  743.     move.w #$4e71,d0
  744.  
  745.     move.w d0,$aa(a0)    ; noops
  746.     move.w d0,$ac(a0)    
  747.     move.w d0,$ae(a0)
  748.     move.w d0,$b0(a0)
  749.  
  750.     move.w #$6000,$1c2(a0)    ; change bxx to bra
  751.  
  752.     move.w #$6000,$2d2(a0)
  753.  
  754.     move.w #$4e75,$388(a0)
  755.     move.w #0,$3ea(a0)
  756.     move.w #0,(a0)
  757.  
  758.     jsr _LVOEnable(a6)
  759.  
  760. #endasm
  761.     MyRequest(VN_BYTEBANDIT, 2);
  762.     };
  763.  
  764. /****************- Look for Revenge Virus (at $7e000) ****************/
  765. if (ExecBase->CoolCapture == 516192)
  766.     {
  767.     /* Fix the CoolCapture vector */
  768.     ExecBase->CoolCapture = 0;
  769.  
  770. #asm
  771.     xref _LVODisable
  772.     xref _LVOEnable
  773.  
  774.     move.l 4,a6
  775.     jsr _LVODisable(a6)
  776.     
  777.     ; Get rid of his DOS\0 in memory 
  778.     lea $7e000,a0
  779.     move.l #0,(a0)
  780.  
  781.     ; Patch his DoIO() wedge 
  782.     move.w #$4ef9,$1e0(a0)
  783.     move.w #$7,$1e2(a0)
  784.     move.w #$e066,$1e4(a0)
  785.  
  786.     ; Patch his Interrupt wedge
  787.     move.w #$4ef9,$2da(a0)
  788.     move.w #$7,$2dc(a0)
  789.     move.w #$e06c,$2de(a0)
  790.  
  791.     jsr _LVOEnable(a6)
  792. #endasm
  793.  
  794.     MyRequest(VN_REVENGE, 2);
  795.     };
  796.  
  797. /******************** See if SCA is in RAM ***************************/
  798. if (ExecBase->CoolCapture == 0x7ec3e)
  799.     {
  800.     ExecBase->CoolCapture = 0;
  801.     MyRequest(VN_SCA, 2);
  802.     };
  803.     
  804. /***************** Check for Obelisk  *******************************/
  805. if (ExecBase->CoolCapture == 0x7e86c)
  806.     {
  807.     ExecBase->CoolCapture = 0;
  808.     ptr = 0x7e88a;
  809.     Forbid();
  810.     ptr[0] = 10;
  811.     Permit();
  812.     MyRequest(VN_OBELISK, 2);
  813.     };
  814.  
  815. /******************** How about North Star? **************************/
  816. if (ExecBase->CoolCapture == 0x7ec0e)
  817.     {
  818.     ExecBase->CoolCapture = 0;
  819.     MyRequest(VN_NORTHSTAR, 2);
  820.     };
  821.  
  822. /********************* Check for Byte Warrior ************************/
  823. ptr = 0x7f800;
  824. if (ptr[0] == ('D'<<24) + ('O'<<16) + ('S'<<8))
  825.     {
  826.     ptr = 0x7f954;
  827.     if (ptr[0] == 0x4afc)
  828.         {
  829.         ptr[0] = 0;        /* Kill resident matchtag */
  830.         
  831. #asm
  832.     xref    _LVOForbid
  833.     xref    _LVOPermit
  834.     xref    _Window
  835.     xref     _BBMPos
  836.     xref    _LVOAutoRequest
  837.  
  838.         move.l 4,a6
  839.         jsr _LVOForbid(a6)
  840.  
  841.         lea $7f972,a0
  842.         move.w #$4ef9,(a0)
  843.         move.w #$fc,2(a0)
  844.         move.w #$6dc,4(a0)
  845.         ; jump right into the 1.2 ROMs. Ow.
  846.         
  847.         lea $7f800,a0
  848.         move.l #0,(a0)
  849.         jsr _LVOPermit(a6)
  850.  
  851. #endasm
  852.         MyRequest(VN_BYTEWARRIOR, 2);
  853.         };
  854.     };
  855.  
  856. if (ExecBase->CoolCapture != 0)
  857.     {
  858.     sprintf(linebuffer, "CoolCapture is pointing at $%x", ExecBase->CoolCapture);
  859.     if (MyRequest(linebuffer, 3) == TRUE) ExecBase->CoolCapture = 0;
  860.     }
  861.  
  862. if (ExecBase->ColdCapture != 0)
  863.     {
  864.     sprintf(linebuffer, "ColdCapture is pointing at $%x", ExecBase->ColdCapture);
  865.     if (MyRequest(linebuffer, 3) == TRUE) ExecBase->ColdCapture = 0;
  866.     }
  867.  
  868. if (ExecBase->WarmCapture != 0)
  869.     {
  870.     sprintf(linebuffer, "WarmCapture is pointing at $%x", ExecBase->WarmCapture);
  871.     if (MyRequest(linebuffer, 3) == TRUE) ExecBase->WarmCapture = 0;
  872.     }
  873.  
  874.  
  875. CloseLibrary(ExecBase);
  876. }
  877.  
  878.  
  879. /**************************************************************/
  880. /*  This is the routine that displauys a block as ASCII text. */
  881. /**************************************************************/
  882. ShowAscii(key)
  883. int key;
  884. {
  885. char linebuffer[80];
  886. int drive;
  887. int x,y;
  888. int deltax, deltay;
  889. int a,b;
  890. int FLAG=0;
  891.  
  892. struct RastPort *RP;
  893. RP = Window->RPort;
  894.  
  895. drive = key - '0';
  896.  
  897. if ((drive < 0) || (drive > 3) || (ChangeCount[drive] == -1)) return;
  898.  
  899. error = OpenDevice(TDName,drive,diskreq,0);
  900. if (error > 0) return;
  901.  
  902. error = ReadBlock();
  903.  
  904. CloseDevice(diskreq);
  905.  
  906. if (error == FALSE) return;
  907.  
  908. /* save the amount we moved the window */
  909. deltax = Window->LeftEdge;
  910. deltay = Window->TopEdge;
  911.  
  912. MoveWindow(Window, -deltax, -deltay);
  913.  
  914. if (WindowBig == FALSE) SizeWindow(Window, 278, 160);
  915.     else SizeWindow(Window, 278, 60);
  916.  
  917. WaitForNewSize();
  918.  
  919. SetAPen(RP, 3);
  920. Move(RP, 14+(12*8), 165);
  921. Text(RP, "Block 0", 7);
  922. Move(RP, 324+(12*8), 165);
  923. Text(RP, "Block 1", 7);
  924. SetAPen(RP, 1);
  925.  
  926. text[2] = key;
  927. SetWindowTitles(Window, text, -1);
  928.  
  929. x=0; y=0;
  930.  
  931. SetAPen(RP, 1);
  932. SetDrMd(RP, JAM2);
  933.  
  934. for (a=0; a<512; a=a+32)
  935.     {
  936.     Move(RP, 10+(x*8), 20+(y*9));
  937.     Text(RP, &diskbuffer[a], 32);
  938.  
  939.     Move(RP, 320+(x*8), 20+(y*9));
  940.     Text(RP, &diskbuffer[a+512], 32);
  941.     y++;
  942.     };
  943.  
  944. Wait(1<<Window->UserPort->mp_SigBit);
  945. Message = GetMsg(Window->UserPort);
  946.  
  947. /*  If a disk was inserted, we want CheckBlock() to happen later on some time */
  948. if (Message->Class == DISKINSERTED) FLAG=1;
  949. ReplyMsg(Message);
  950.  
  951. returner:
  952. if (WindowBig == FALSE)
  953.     SizeWindow(Window, -278, -160);
  954.     else SizeWindow(Window, -278, -60);
  955.  
  956. SetWindowTitles(Window, TITLETEXT, -1);
  957. WaitForNewSize();
  958.  
  959. /* deltas plus current position, in case dude moved the window */
  960. MoveWindow(Window, deltax+(-Window->LeftEdge), deltay+(-Window->TopEdge));
  961. Delay(2);
  962. return(FLAG);
  963. }
  964.  
  965.  
  966. /*  
  967.  When you do a SizeWindow() command, you have to wait for a NEWSIZE
  968.  IntuiMessage before drawing in it.  That's all this routine does.
  969.  */
  970. WaitForNewSize()
  971. {
  972. while (TRUE)
  973.     {
  974.     WaitPort(Window->UserPort);
  975.     Message = GetMsg(Window->UserPort);
  976.     if (Message->Class != NEWSIZE)
  977.         {
  978.         ReplyMsg(Message);
  979.         continue;
  980.         };
  981.     ReplyMsg(Message);
  982.     break;
  983.     };
  984. }
  985.  
  986. /*
  987.     type:
  988.  
  989.         1 == "is infected with the xxxx VIRUS!"
  990.         2 == "somethin about virus in ram"
  991.         3 == virus in cold/cool/warm capture 
  992. */
  993.  
  994. BuildITBodyText(text, type)
  995. char *text;
  996. int type;
  997. {
  998. switch (type)
  999.     {
  1000.     case 1:
  1001.         strcpy(ITBodyText, "infected with the `");
  1002.         strcat(ITBodyText, text);
  1003.         strcat(ITBodyText, "' VIRUS!");
  1004.         break;
  1005.     case 2:
  1006.         strcpy(ITBodyText, "NOTICE:  The `");
  1007.         strcat(ITBodyText, text);
  1008.         strcat(ITBodyText, "' VIRUS was found");
  1009.         break;
  1010.     };
  1011. }
  1012.  
  1013. /***** an attempt to save space *********/
  1014. MyRequest(string, type)
  1015. char *string;
  1016. int type;
  1017. {
  1018. if (type != 3)
  1019.     {
  1020.     BuildITBodyText(string, type);
  1021.     } else
  1022.     {
  1023.     Mem1.IText = string;
  1024.     };
  1025.  
  1026. if (type == 1) return(AutoRequest(Window, &GenericDiskBody, &SCAPos, &SCANeg, 0, 0, 380, 80));
  1027. if (type == 2) return(AutoRequest(Window, &GenericRAMBody, &BBMPos, &BBMPos, 0, 0, 395, 78));
  1028. if (type == 3) return(AutoRequest(Window, &Mem1, &Repair, &SCANeg, 0, 0, 395, 78));
  1029. }
  1030.  
  1031.  
  1032. /********* DoStats() **********/
  1033. DoStats()
  1034. {
  1035. char linebuffer[80];
  1036. char numbuf[30];
  1037.  
  1038. SetAPen(RP, 0);
  1039. RectFill(RP, 2, 11, 303, 107);
  1040. SetAPen(RP, 1);
  1041.  
  1042. sprintf(linebuffer, "  Disks Checked: %d", DisksChecked);
  1043. Out(20, linebuffer);
  1044.  
  1045. sprintf(linebuffer, "Disks Installed: %d", DisksInstalled);
  1046. Out(29, linebuffer);
  1047.  
  1048. Out(43, "    Viruses Found:");
  1049.  
  1050. PV(52, VN_SCA, SCACount);
  1051. PV(61, VN_BYTEBANDIT, ByteBanditCount);
  1052. PV(70, VN_NORTHSTAR, NorthStarCount);
  1053. PV(79, VN_BYTEWARRIOR, ByteWarriorCount);
  1054. PV(88, VN_REVENGE, RevengeCount);
  1055. PV(97, VN_OBELISK, ObeliskCount);
  1056. }
  1057.  
  1058. /****************** Ok, we're REALLY being chintzy here. */
  1059. PV(num, name, howmany)
  1060. int num;
  1061. char *name;
  1062. int howmany;
  1063. {
  1064. register int x;
  1065. char linebuffer[80];
  1066.  
  1067. sprintf(linebuffer, "%-12s: %d", name, howmany);
  1068. Out(num, linebuffer);
  1069. }
  1070.  
  1071. /********************* Cheap?  Me?  Nooooo....     */
  1072. Out(num, name)
  1073. int num;
  1074. char *name;
  1075. {
  1076. Move(RP, 20, num);
  1077. Text(RP, name, strlen(name));
  1078. }
  1079.