home *** CD-ROM | disk | FTP | other *** search
- /*
- >> Kill WDEF-virus INIT
- */
- #include <SetUpA4.h>
-
- #define GetResourceNum 0x9A0
-
- int ActiveFlag;
- char dtstr[]="\PFinder 1.0"; /* Ugly, ugly, ugly... */
-
- void KillWDEF() /* Called when finder does GetResource('WDEF',0); */
- { /* Remove suspect WDEF 0 resources. */
- Handle theWDEF;
- Handle DesktopString;
- int i;
- char *rdtstr;
-
- SetUpA4();
- /* Find out if current res file is Desktop */
- if(0==(DesktopString=Get1Resource('STR ',0))) return;
- if(GetHandleSize(DesktopString)!=dtstr[0]+1) return;
- rdtstr=*DesktopString;
- for(i=0;i<=dtstr[0];i++)
- { if(dtstr[i]!=rdtstr[i]) return;
- }
-
- theWDEF=Get1Resource('WDEF',0); /* Find out if WDEF is in DeskTop */
- if(theWDEF) /* If it is, beep three times */
- { SysBeep(10);
- SysBeep(10);
- SysBeep(10);
- RmveResource(theWDEF); /* And remove the resource! */
- }
- RestoreA4();
- }
- void InstallGetResourcePatch() /* Install patch to GetResource */
- { /* This code look weird, but it works fine.*/
- long OldGetResource;
- long NewGetResource;
-
- OldGetResource=NGetTrapAddress(GetResourceNum,ToolTrap);
- asm {
- lea @OldGetResource,A0
- move.l OldGetResource,(A0)
- lea @NewGetResource,A0
- move.l A0,NewGetResource
- }
- NSetTrapAddress(NewGetResource,GetResourceNum,ToolTrap);
- return; /* Installation ends here */
- asm {
- @NewGetResource
- cmp.l #'WDEF',6(sp) /* Is someone trying to get a WDEF? */
- beq.s @LookOut /* If so, look into it. */
- @ItsOk
- move.l @OldGetResource,A0 /* No, just a plain old GetResource. */
- jmp (A0)
- @LookOut
- cmp.w #0,4(sp) /* Is someone trying to get WDEF 0? */
- bne.s @ItsOk /* No, just some other WDEF. */
- lea FinderName,A0 /* Is the finder name */
- lea CurApName,A1 /* equal to the current application name? */
- clr.l D0
- move.b (A0)+,D0
- swap.w D0
- move.b (A1)+,D0
- _CmpString MARKS
- tst.b D0
- bne.s @ItsOk /* No, Finder is not running. */
- movem.l D0-D7/A2-A4,-(sp)
- jsr KillWDEF /* Finder is loading a WDEF 0. */
- movem.l (sp)+,D0-D7/A2-A4
- bra.s @ItsOk
- @OldGetResource
- dc.l 0
- }
- }
- void main()
- {
- RememberA0();
- SetUpA4();
- asm {
- move.l A4,A0
- _RecoverHandle /* Find handle of this code resource. */
- move.l A0,-(SP) /* Detach it. It's already locked in the */
- _DetachResource /* system heap, because of res flags. */
- }
- InstallGetResourcePatch(); /* Patch GetResource to look for virus. */
- RestoreA4(); /* Done! */
- }