Skip to content
Snippets Groups Projects
Commit 50b39771 authored by Hongyang Lyu's avatar Hongyang Lyu
Browse files

fuzzer.java for single fuzz.txt

parent e07557a6
No related branches found
No related tags found
No related merge requests found
Pipeline #58840 passed
...@@ -6,6 +6,7 @@ import java.util.Random; ...@@ -6,6 +6,7 @@ import java.util.Random;
/* a stub for your team's fuzzer */ /* a stub for your team's fuzzer */
public class Fuzzer { public class Fuzzer {
private static final String OUTPUT_FILE = "fuzz.txt";
private static Instruction[] INSTRUCTIONS = Instruction.values(); private static Instruction[] INSTRUCTIONS = Instruction.values();
private static PrintWriter pw = null; private static PrintWriter pw = null;
private static final int MAX_LINE_LENGTH = 1022; private static final int MAX_LINE_LENGTH = 1022;
...@@ -13,39 +14,15 @@ public class Fuzzer { ...@@ -13,39 +14,15 @@ public class Fuzzer {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
System.out.println(Instruction.getBNF()); 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; FileOutputStream out = null;
PrintWriter pw = null; PrintWriter pw = null;
try { try {
out = new FileOutputStream(OUTPUT_FILE); out = new FileOutputStream(OUTPUT_FILE);
pw = new PrintWriter(out); 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(); Instruction instruction = getRandomInstruction();
String outputString = instruction.getOpcode(); String outputString = instruction.getOpcode();
if (instruction.equals(Instruction.PUSH) || instruction.equals(Instruction.LOAD) if (instruction.equals(Instruction.PUSH) || instruction.equals(Instruction.LOAD)
...@@ -69,7 +46,6 @@ public class Fuzzer { ...@@ -69,7 +46,6 @@ public class Fuzzer {
} }
pw.println(outputString); pw.println(outputString);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(System.err); e.printStackTrace(System.err);
System.exit(1); System.exit(1);
...@@ -81,6 +57,7 @@ public class Fuzzer { ...@@ -81,6 +57,7 @@ public class Fuzzer {
out.close(); out.close();
} }
} }
} }
public static Instruction getRandomInstruction() { public static Instruction getRandomInstruction() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment