Commit e47c4040 by 钱炳权

aflnet日志文件和kitty日志结果文件下载功能完成

parent e8313a6d
package com.example.fuzzControll.constents;
public enum ServerClassEnum {
}
......@@ -38,7 +38,6 @@ public class KittyFuzzPersistenceServiceImpl implements KittyFuzzPersistenceServ
if (files.size() > 3) {
log.error("kittyLogs backup failed!");
}
System.out.println("1");
List<String> logFiles = null;
try {
logFiles = files.stream().filter(file -> file.contains("pcap")).collect(Collectors.toList());
......@@ -46,9 +45,7 @@ public class KittyFuzzPersistenceServiceImpl implements KittyFuzzPersistenceServ
log.error("There is no file!");
e.printStackTrace();
}
System.out.println("2");
logFiles.forEach(System.out::println);
System.out.println("3");
//todo 需要传入任务id
KittyPackageFile kittyPackageFile = new KittyPackageFile(missionId, "", "",
new byte[1],
......@@ -56,8 +53,6 @@ public class KittyFuzzPersistenceServiceImpl implements KittyFuzzPersistenceServ
// KittyPackageFile kittyPackageFile = new KittyPackageFile(missionId, logFiles.get(0), logFiles.get(1),
// fileTools.fileReadAndTranstoBytes(kittyProperties.getLogOutPath(), logFiles.get(0)),
// fileTools.fileReadAndTranstoBytes(kittyProperties.getLogOutPath(), logFiles.get(1)));
System.out.println(kittyPackageFile);
System.out.println("4");
return kittyMapper.kittyPackagesBackup(kittyPackageFile);
}
......
......@@ -41,7 +41,7 @@ public class TestServiceImpl implements TestService {
Date date = new Date();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss-");
String outputFileName = df.format(date)+cmdStartParams.getProtopcol()+"-output";
String finalCmd = CmdConstent.RUN_AFLNET_BEFORE + outputFileName + CmdConstent.RUN_AFLNET_AFTER + cmd + aflnetProperties.getAflnetPath() + "live555/testProgs/testOnDemandRTSPServer 8554";
String finalCmd = CmdConstent.RUN_AFLNET_BEFORE + outputFileName + CmdConstent.RUN_AFLNET_AFTER + cmd + aflnetProperties.getAflnetPath() + "live555/testProgs/"+"testOnDemandRTSPServer 8554";
GlobalParameters.aflnetData.put("aflnetName", outputFileName);
log.info("The cmd is [{}]",finalCmd);
cmdTools.runProgramCmd(finalCmd, outputFileName + ".zip");
......@@ -62,6 +62,10 @@ public class TestServiceImpl implements TestService {
String fileZipName = fileName + ".zip";
cmdTools.runCmd(CmdConstent.RUN_ZIP_FILE + fileZipName + " " + fileName, "zip file in testStart");
List<String> files = cmdTools.runCmd(CmdConstent.GET_FILE_NAME + aflnetProperties.getOutputPath(), "getSeedFiles");
files.stream().forEach(System.out::println);
if(!files.contains(fileZipName)){
log.error("File zip error!");
}
while (files.contains(fileZipName) && flag == 0) {//当前存在压缩包才存入
flag = aflnetPersistenceService.aflnetResultBackup(fileZipName,GlobalParameters.aflnetData.get("missionName"));
}
......@@ -74,7 +78,7 @@ public class TestServiceImpl implements TestService {
log.error("file delete failed!");
}
log.info("kittyLog has been backuped!");
log.info("Aflnet Logs has been backuped!");
}
}).start();
} catch (Exception e) {
......
......@@ -35,10 +35,12 @@ public class CmdTools {
public List<String> runCmd(String cmd, String caller) throws CmdException {
List<String> result = new ArrayList<String>();
try {
log.info(caller+" is running!");
Process process = Runtime.getRuntime().exec(cmd);
printMessage(process.getInputStream(), result);
printMessage(process.getErrorStream(), new ArrayList<String>());
process.waitFor();
log.info(caller+" end!");
} catch (Exception e) {
e.printStackTrace();
throw new CmdException(caller + " run cmd failed!");
......@@ -262,37 +264,37 @@ public class CmdTools {
}
StringBuilder cmd = new StringBuilder();
if (cmdStartParams.getNetinfo() != "" && cmdStartParams.getNetinfo() != null) {
cmd.append(" -N " + cmdStartParams.getNetinfo());
cmd.append(" -N " + cmdStartParams.getNetinfo()+ " ");
} else {
log.error("There is no netinfo !");
throw new AflnetException("There is no netinfo !");
}
if (cmdStartParams.getProtopcol() != "") {
cmd.append(" -P " + cmdStartParams.getProtopcol());
cmd.append(" -P " + cmdStartParams.getProtopcol()+ " ");
}
if (cmdStartParams.getWaiting() != 0) {
cmd.append(" -D " + cmdStartParams.getWaiting());
cmd.append(" -D " + cmdStartParams.getWaiting()+ " ");
}
if (cmdStartParams.getNsname() != "") {
cmd.append(" -e " + cmdStartParams.getNsname());
cmd.append(" -e " + cmdStartParams.getNsname()+ " ");
}
if (cmdStartParams.getKill()) {
cmd.append(" -K ");
}
if (cmdStartParams.getAwareMode()) {
cmd.append(" -E ");
cmd.append(" -E "+ " ");
}
if (cmdStartParams.getRegionMutationOperators()) {
cmd.append(" -R ");
cmd.append(" -R "+ " ");
}
if (cmdStartParams.getFalseNegativeMode()) {
cmd.append(" -F ");
cmd.append(" -F "+ " ");
}
if (cmdStartParams.getScript() != "") {
cmd.append(" -c " + cmdStartParams.getScript());
cmd.append(" -c " + cmdStartParams.getScript()+ " ");
}
if (cmdStartParams.getStateSelectionAlgo() != 0) {
cmd.append(" -q " + cmdStartParams.getStateSelectionAlgo());
cmd.append(" -q " + cmdStartParams.getStateSelectionAlgo()+ " ");
}
if (cmdStartParams.getSeedSelectionAlgo() != 0) {
cmd.append(" -s " + cmdStartParams.getSeedSelectionAlgo() + " ");
......
......@@ -49,16 +49,13 @@ public class FileTools {
FileInputStream inputStream = new FileInputStream(file);
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);) {
System.out.println("1-2");
if (file.length() > Integer.MAX_VALUE && file.length() <= 0) {
log.error("KittyLogFile is too long or has no content!");
}
System.out.println("1-3");
int bytesRead;
while ((bytesRead = bufferedInputStream.read(buffer)) != -1) {
System.out.println(buffer.length);
}
System.out.println("1-5");
} catch (Exception e) {
e.printStackTrace();
}
......
......@@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.*;
*/
@Slf4j
@RestController
@RequestMapping("/test")
@RequestMapping("/aflnet")
@CrossOrigin
public class TestController {
@Autowired
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment