将以下代码以 Unicode 编码保存为 FixHtmlVirus.js 后,双击文件图标运行。
注意:使用前,请备份原文件。- //name: FixHtmlVirus.js
- //js codepage:ule
- //fix html codepage:utf-8
-
- main();
- function main()
- {
- FixHtmlVirus();
- };
-
-
- //修复病毒感染的Html文件
- function FixHtmlVirus()
- {
- var sInfo = '';
- var sFolder = BrowseForFolder("请选择要修复的HTML文件夹(注意自行备份文件!):"); //获取用户选择的文件夹
- if (sFolder == '')
- {
- WScript.Echo('提示:没有选择文件夹,程序退出。');
- return 0;
- }
- var aFile = ScanFolder(sFolder); //获取文件夹所有文件夹、文件列表
- for (var i=0; i<aFile.length; i++)
- {
- if (/^(.+)(\.html)$/i.test(aFile[i])) //过滤其他文件,只操作 *.html 文件
- {
- var html = ReadText(aFile[i]), html2 = ''; //以 utf-8 编码读取 .html 文件
- var aHtml = html.split('\r\n'); //将读取的内容按行(\r\n)拆分成数组
- var sEnd = '', sVir = '';
- for (var j=0; j<aHtml.length; j++)
- {
- if (aHtml[j].toLowerCase().indexOf('</html>') != -1) // .html 文件尾部标记
- {
- aHtml[j] = aHtml[j].substr(0,2000); //限制长度,提高正则速度
- sEnd = aHtml[j].replace(/^(.*<\/html>)(.*)$/igm, '$1'); //提取末行内容
- sVir = aHtml[j].replace(/^(.*<\/html>)(.*)$/igm, '$2'); //提取部分病毒内容
- aHtml[j] = sEnd; //修正末行内容
- };
- html2 += aHtml[j] + '\r\n'; //将修正后的内容提交到 html2
- if (sEnd != '') //结束行
- {
- if (sVir != '' || aHtml.length - j > 2) //找到病毒
- {
- SaveText(aFile[i], html2); //保存修正后的内容
- if (sInfo != '') sInfo += '\r\n'; //记录修正的文件路径
- sInfo += aFile[i]; //记录修正的文件路径
- };
- break;
- };
- };
- }
- }
- if (sInfo == '')
- {
- WScript.Echo('提示:没有文件需要修复。');
- } else {
- WScript.Echo('提示:以下文件已被修复:\r\n' + sInfo);
- };
- }
-
-
- //文件夹选择对话框
- function BrowseForFolder(sTips)
- {
- var BIF_returnonlyfsdirs = 0x0001;
- var BIF_editbox= 0x0010;
- var oShell = new ActiveXObject("Shell.Application")
- var oFolder = oShell.BrowseForFolder(0x0, sTips, BIF_editbox + BIF_returnonlyfsdirs)
- if (oFolder==null) {return("")} else {return(oFolder.self.path + '\\')}; //return(oFolder.items().item().path+'\\')
- }
-
-
- // 获取文件夹所有文件夹、文件列表(数组)
- function ScanFolder(strPath)
- {
- if (strPath.substr(strPath.length-1,1) != '\\') {strPath += '\\';}
- var arr=[];
- var DO_SCAN_FOLDER=function(arr,folderSpec)
- {
- try {
- var fso = new ActiveXObject('Scripting.FileSystemObject');
- var oFolder = fso.GetFolder(folderSpec);
- if (oFolder != null){
- var oFiles = new Enumerator(oFolder.files);
- for (; !oFiles.atEnd(); oFiles.moveNext()) arr.push(oFiles.item().path);
- var oSubFolders = new Enumerator(oFolder.subfolders);
- for (; !oSubFolders.atEnd(); oSubFolders.moveNext()) {
- arr.push(oSubFolders.item().path + '\\');
- DO_SCAN_FOLDER(arr, oSubFolders.item());
- }
- }
- }catch(e){};
- }
- arr.push(strPath);
- DO_SCAN_FOLDER(arr,strPath);
- return(arr);
- }
-
-
- // 使用 utf-8 编码读写文本文件
- function ReadText(FileName){ return Pfile(FileName, "utf-8", "ForReading", ""); }
- function SaveText(FileName, TextString){ return Pfile(FileName, "utf-8", "ForWriting", TextString); }
- function SaveWSH(FileName, TextString){ return Pfile(FileName, "Unicode", "ForWriting", TextString); }
- function LogText(FileName, TextString){ return Pfile(FileName, "utf-8", "ForAppending", TextString); }
- function Pfile(FileName, FileCode, strType, TextString){
- var fso = new ActiveXObject("Scripting.FileSystemObject");
- var objStream = new ActiveXObject("ADODB.Stream");
- objStream.Type = 2;
- objStream.Mode = 3;
- objStream.Charset = FileCode; //不同编码时自己换,Chinese (Simplified) (GB2312),中文 GBK ,繁体中文 Big5 ,日文 EUC-JP ,韩文 EUC-KR,charset=UTF-8(国际化编码),ANSI,Unicode,unicode big endian
- if (fso.FileExists(FileName)==true) {
- objStream.Open();
- objStream.LoadFromFile(FileName);
- if (strType=="ForReading") TextString = objStream.ReadText();
- if (strType=="ForAppending") TextString += objStream.ReadText();
- objStream.Close();
- }
- if (strType=="ForWriting" || strType=="ForAppending") {
- objStream.Open();
- objStream.WriteText(TextString);
- objStream.SaveToFile(FileName, 2);
- objStream.Close();
- }
- fso = null;
- objStream = null;
- if (strType=="ForReading"){return(TextString)};
- if (strType=="ForWriting" || strType=="ForAppending"){return(0)};
- }
复制代码
|