趋势杀毒的后遗症
2006年7月上旬,FDT的電腦爆發病毒,趨勢殺毒后,所有的EXE文件都不能執行。雙擊后會彈出DOS窗口,一閃及過。我也沒有能幸免。
索性先研究一下:
??? 用Ultra Edit等工具打開正常的EXE文件會發現EXE文件均是以十六進制4D開頭。
???? EXE文件被修改以后,大家會發現文件大小并未改變或者只增加了1K。
???? 用Ultra Edit打開被修改后的EXE文件,發現頭被修改為00 00 00 00 00 00 00 00 00,把這部分去掉,保存文件。EXE文件就恢復了以前的面貌。
?
??? 因此可以確定,只要將文件修改后即可恢復正常使用。無需重新安裝或拷貝正常的EXE文件。
自己索性寫了個小東西:
//修復列表框里的exe文件
????? private void button1_Click(object sender, EventArgs e)
??????? {
??????????? int nFile = this.listBox1.Items.Count;
??????????? int rFile = 0;
??????????? if (this.listBox1.Items.Count < 1)
??????????? {
??????????????? MessageBox.Show("請添加需要修復的exe文件");
??????????????? return;
??????????? }
??????????? for (int i = 0; i < this.listBox1.Items.Count; i++)
??????????? {
??????????????? bool succ = repairFile(this.listBox1.Items[i].ToString());
??????????????? if (succ == true)
??????????????? {
??????????????????? this.listBox1.Items.RemoveAt(i);
??????????????????? rFile++;
??????????????? }
??????????? }
??????????? if (rFile == nFile)
??????????? {
??????????????? MessageBox.Show("修復完成");
??????????? }
??????????? else
??????????? {
??????????????? MessageBox.Show("修復過程中發生錯誤,有幾項并未修復完成,如右側列表所示");
??????????? }
??????? }
??????? /// <summary>
??????? /// 修復文件
??????? /// </summary>
??????? /// <param name="fileName">文件名稱及詳細路徑</param>
??????? /// <returns>false失敗? false 成功</returns>
??????? private bool repairFile(string fileName)
??????? {
??????????? if (File.Exists(fileName) == false)
??????????? {
??????????????? MessageBox.Show("指定的文件不存在");
??????????????? return false;
??????????? }
??????????? string bkfile = fileName.Substring(0, fileName.LastIndexOf(@"/"))? + fileName.Substring(fileName.LastIndexOf(@"/")) + ".bak";
??????????? if (File.Exists(bkfile)==true)
??????????? {
??????????????? File.Delete(bkfile);
??????????? }
??????????? try
??????????? {
??????????????? File.Copy(fileName, bkfile);
??????????? }
??????????? catch(Exception ex)
??????????? {
??????????????? MessageBox.Show("發生錯誤:" + ex.Message);
??????????????? return false;
??????????? }
??????????? byte[] tmp = new byte[1024];
??????????? bool flag = false;
??????????? FileStream fs = new FileStream(bkfile, FileMode.Open);
??????????? FileStream fs2 = new FileStream(fileName, FileMode.Open);
??????????? int time = 0;
??????????? int lng = 1024;
??????????? while (time * 1024 <= fs.Length)
??????????? {
??????????????? if (time == 0 && tmp[0].ToString("X") == "4D")
??????????????? {
??????????????????? return true;
??????????????? }
??????????????? fs.Read(tmp, 0, lng);
??????????????? time = time + 1;
??????????????? if (flag == true)
??????????????? {
??????????????????? fs2.Write(tmp, 0, tmp.Length);
??????????????????? continue;
??????????????? }
??????????????? for (int i = 0; i < tmp.Length; i++)
??????????????? {
??????????????????? string t = tmp[i].ToString("X");
??????????????????? if (t == "4D")
??????????????????? {
??????????????????????? fs2.Write(tmp, i, 1024 - i);
??????????????????????? flag = true;
??????????????????????? break;
??????????????????? }
??????????????????? Console.WriteLine(t);
??????????????? }
??????????? }
??????????? fs.Close();
??????????? fs2.Close();
??????????? return true;
??????? }
//添加要修復的文件到列表框?
??????? private void button2_Click(object sender, EventArgs e)
??????? {
??????????? this.openFileDialog1.ShowDialog();
??????????? bool flag = false;
??????????? for (int i = 0; i < this.listBox1.Items.Count; i++)
??????????? {
??????????????? if (this.listBox1.Items[i].ToString() == this.openFileDialog1.FileName.ToString())
??????????????? {
??????????????????? flag = true;
??????????????? }
??????????? }
??????????? if (flag == true)
??????????? {
??????????????? MessageBox.Show("已經添加了這個文件");
??????????? }
??????????? else
??????????? {
??????????????? this.listBox1.Items.Add(this.openFileDialog1.FileName.ToString());
??????????? }
??????? }
//選擇要修復的目錄?
?????? private void button3_Click(object sender, EventArgs e)
??????? {
??????????? this.folderBrowserDialog1.ShowDialog();
??????????? this.textBox1.Text = this.folderBrowserDialog1.SelectedPath.ToString();
??????? }
//修復整個文件夾的文件 ?
?????? private void button4_Click(object sender, EventArgs e)
??????? {
??????????? if (Directory.Exists(this.textBox1.Text) == false)
??????????? {
??????????????? MessageBox.Show("選擇的目錄不存在,請重新選擇");
??????????????? return;
??????????? }
??????????? repFoFile(this.textBox1.Text);
??????????? MessageBox.Show("修復完成,不能修復的EXE文件如列表");
??????? }
//遍歷文件夾進行修復
??????? private void repFoFile(string folder)
??????? {
??????????? DirectoryInfo myFolder = new DirectoryInfo(folder);
??????????? foreach (FileInfo NextFile in myFolder.GetFiles("*.exe"))
??????????? {
??????????????? bool succ = repairFile(NextFile.FullName);
??????????????? if (succ == false)
??????????????? {
??????????????????? this.listBox2.Items.Add(NextFile.Name);
??????????????? }
??????????? }
??????????? foreach (DirectoryInfo NextDir in myFolder.GetDirectories())
??????????? {
??????????????? repFoFile(NextDir.FullName);
??????????? }
??????? }
?
總結
- 上一篇: 注册表操作,reg脚本简单编写
- 下一篇: 一款轻量级的权限框架,轻松搞定项目权限