diff --git a/fuzzer/Fuzzer.java b/fuzzer/Fuzzer.java index 55658e75d253c3eb882400f43f55fd074bfa2336..ffd1b0e0a8d777c2fb3172d0de5e2f65df5afcd8 100644 --- a/fuzzer/Fuzzer.java +++ b/fuzzer/Fuzzer.java @@ -6,7 +6,6 @@ import java.util.Random; /* a stub for your team's fuzzer */ public class Fuzzer { - private static final String OUTPUT_FILE = "fuzz.txt"; private static Instruction[] INSTRUCTIONS = Instruction.values(); private static PrintWriter pw = null; private static final int MAX_LINE_LENGTH = 1022; @@ -14,15 +13,39 @@ public class Fuzzer { public static void main(String[] args) throws IOException { System.out.println(Instruction.getBNF()); - int instructionCount = getRandomInt(0, MAX_INSTRUCTIONS); + //int instructionCount = getRandomInt(0, MAX_INSTRUCTIONS); + try{ + boolean hasPoc = false; + for(int i = 0; i<300;i++){ + generateCorpus(hasPoc); + hasPoc = true; + } + + }catch(Exception e){ + System.out.println("Error during generating corpus..."); + } + } + public static void generateCorpus(boolean hasPoc) throws Exception{ + String OUTPUT_FILE = "..\\tests\\fuzz"+System.currentTimeMillis()+".txt"; FileOutputStream out = null; PrintWriter pw = null; - try { out = new FileOutputStream(OUTPUT_FILE); pw = new PrintWriter(out); - for (int i = 0; i < instructionCount; i++) { + + int maxLenth = MAX_INSTRUCTIONS; + if(!hasPoc){ + //special command combination + String pocStr135 = "push "+ getRandomInt(0, MAX_LINE_LENGTH - "push ".length())+"\n"+"store "+getRandomName(MAX_LINE_LENGTH - "store ".length(), false); + String pocStr2 = "push "+ getRandomInt(0, MAX_LINE_LENGTH - "push ".length())+"\n"+"+"+"\n"+"print"; + String pocStr4 = "push "+ getRandomInt(0, MAX_LINE_LENGTH - "push ".length())+"\n"+"-"+"\n"+"print"; + pw.println(pocStr135); + pw.println(pocStr2); + pw.println(pocStr4); + maxLenth = MAX_INSTRUCTIONS-8; + } + for (int i = 0; i < maxLenth; i++) { Instruction instruction = getRandomInstruction(); String outputString = instruction.getOpcode(); if (instruction.equals(Instruction.PUSH) || instruction.equals(Instruction.LOAD) @@ -46,6 +69,7 @@ public class Fuzzer { } pw.println(outputString); } + } catch (Exception e) { e.printStackTrace(System.err); System.exit(1); @@ -57,7 +81,6 @@ public class Fuzzer { out.close(); } } - } public static Instruction getRandomInstruction() {