4.2 判断病毒是否存在,如果存在病毒,分离路径,删除病毒
病毒如果存在,就会在autorun.inf文件中有所体现,会产生类似OPEN=XXX.EXE或者SHELLEXECUTE=XXX.EXE的条目,如果存在这些特征,我们就可以检测它,从而定位病毒并删除。
|
procedure killvirus(str:string); var n:integer; T: Textfile; //文件变量,用来读取autorun.inf文件 path,S: String; procedure delvirus(str,content:string);//删除病毒过程 begin FileSetAttr(str+':\autorun.inf',faArchive);//取消autorun.inf的只读属性 deletefile(str+':\autorun.inf'); //删除文件 path:=str+':\'+copy(content,pos('=',content )+1,pos('.',content)-pos('=',content)+3) ; //得到包含病毒的路径 if FileExists(path) then begin FileSetAttr(path,faArchive);//取消只读属性 deletefile(path ); //删除文件 end; end; begin if FileExists(str+':\autorun.inf') then begin AssignFile(T, str+':\autorun.inf'); //文件变量与文件名关联 Reset(T); while not EoF(T) do begin //如果不是到文件末 ReadLn(T, S);//读取一行文件 n:=Pos('open=',lowerCase(s)); //定位第一个病毒特征 if n<>0 then //如果存在 begin CloseFile(T); //关闭文件变量 delvirus(str,s); //调用删除病毒过程 exit; end; n:=Pos('shellexecute=',lowerCase(S)); //定位第二个病毒特征 if n<>0 then //如果存在 begin CloseFile(T); delvirus(str,s); //调用删除病毒过程 exit; end; end; CloseFile(T); //关闭文件变量 end; end;
|
上述内容仅向你提供了预防这种类型病毒的通用方法。用这种与特定病毒无关的通用检测方式,使检查未知病毒十分有效且易于软件实现。但是这种方法其中还存在很多问题,如怎样区别正常程序利用Autorun.inf或是病毒的引导文件,这将影响到用户对系统的正常使用,还有待于解决。