home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-10-10 | 3.1 KB | 155 lines | [TEXT/CWIE] |
- char RepairApp(short rev);
- Boolean DamagedApp(short rev);
- void DeadFile(void);
- void WriteString(short fie, uchar *str);
-
-
- extern FSSpec *lantana;
- extern Boolean check_only, prevent_moves;
-
- /* Returns 1 is/was infected, 0 for repaired, 1 not repairable */
- char RepairApp(short rev)
- {
- Handle mdh, menuh;
- Str255 stoop;
- ulong ule;
- long mdlen, mdglobs, l, mdencend, menusz;
- short nmdf, i, menid, mdid, j;
- uchar obka;
-
-
- UseResFile(rev);
-
- nmdf=Count1Resources('MDEF');
- if(!nmdf) return 0;
-
- for(i=0;i<nmdf;i++)
- {
- mdh=Get1IndResource('MDEF',i+1);
- if(!mdh) continue;
-
- if( ((short*)(*mdh))[4] == 'JS' ) break;
- }
-
- if(i==nmdf) return 0;
-
- GetResInfo(mdh,&mdid,&ule,stoop);
- // WE don't give a Str63 or whatever the virus gives for the name arg in its call!
-
- /* OK, we have a definitely infected app now */
-
- if(check_only) return 1;
-
- /* First find the char it's obfuscated with, and unobfuscate it */
- mdlen=GetHandleSize(mdh);
- mdglobs=mdlen-0x1E2;
- obka=*(mdglobs + 0x2A + *mdh);
-
- mdencend=*(short*)(2+*mdh) + 2;
- for(l=0x0A;l<mdencend;l++) (*mdh)[l]^=obka;
-
- /* now get the affected MENU id */
- menid=*(short*)(0x0A + *mdh);
-
- /* make sure that menu is still there and full of f's ... more than it checks too */
- menuh=Get1Resource('MENU',menid);
- if(!menuh || *(long*)(*menuh)!='ffff')
- {
- DeadFile();
- return -1;
- }
-
- /* now copy the proper data back into it */
- menusz=GetHandleSize(menuh);
- BlockMoveData(0x0A+*mdh,*menuh,menusz);
- ChangedResource(menuh);
-
- /* Now find the lowest-ID menu which was using the virus MDEF as their MDEF and
- set them back to 0. There is a small chance this will make a menu using a custom
- MDEF which is in another file go back to using the std MDEF (if it installed at
- this ID), but these apps would have stuffed up completely when run as infected. */
-
- nmdf=Count1Resources('MENU');
- menid=0x7FFF; // works for them
- for(i=1;i<=nmdf;i++)
- {
- menuh=Get1IndResource('MENU',i);
- if(!menuh) continue;
-
- if( ((short*)*menuh)[3]!=mdid )
- {
- // HPurge(menuh);
- // we don't call HPurge any more as the resource might be in use.
- continue;
- }
-
- GetResInfo(menuh,&j,&ule,stoop);
- if(menid>j) menid=j;
- }
-
- if(menid<0x7FFF) // just ignore it if we didn't find one I think...
- {
- menuh=Get1Resource('MENU',menid);
- ((short*)*menuh)[3]=0;
- ChangedResource(menuh);
- }
-
- /* And finally, it's time to say goodbye to our favourite resource... */
- RemoveResource(mdh);
- DisposeHandle(mdh);
- UpdateResFile(rev);
- /* Good riddance! */
-
- return 1;
- }
-
- /* This should be called after RepairApp has given it a clean bill of health */
- Boolean DamagedApp(short rev)
- {
- Handle meh;
- short nmnu, i;
-
-
- UseResFile(rev);
-
- nmnu=Count1Resources('MENU');
- if(!nmnu) return 0;
-
- for(i=0;i<nmnu;i++)
- {
- meh=Get1IndResource('MENU',i+1);
- if(!meh) continue;
-
- /* Found one homeless corrupted menu.... */
- if(*(long*)(*meh) == 'ffff')
- {
- if(!check_only) DeadFile();
- return 1;
- }
- }
-
- return 0;
- }
-
- void DeadFile(void)
- {
- Str63 nuname;
-
- if(prevent_moves) return;
-
- BlockMoveData(lantana->name,nuname,64);
- BlockMoveData(".bad",&nuname[nuname[0]+1],4); nuname[0]+=4;
- FSpRename(lantana,nuname);
- }
-
-
- void WriteString(short fie, uchar *str)
- {
- long sz;
-
- if(!fie || fie==-1) return;
-
- sz=str[0];
- FSWrite(fie,&sz,str+1);
- }
-