diff --git a/fuzzer/Filler.java b/fuzzer/Filler.java
new file mode 100644
index 0000000000000000000000000000000000000000..96ada4aaa282976dead308033331a969e454a098
--- /dev/null
+++ b/fuzzer/Filler.java
@@ -0,0 +1,11 @@
+/**
+ * Filler has the responsibility of filling the arguments to the Instructions
+ * For example decides to fill the PUT Instruction at index 800 with the following
+ * "put http://sample.com fuzzer 123"
+ */
+public class Filler implements SetTransformer {
+ @Override
+ public void transformSet(InstructionSet set) {
+
+ }
+}
diff --git a/fuzzer/Fuzzer.java b/fuzzer/Fuzzer.java
index 9394bf8fd81a260984d87d9fe1aa3f3ef35fd4de..951c1dd598d168d49c5b3aed3bc2b64b613758a0 100644
--- a/fuzzer/Fuzzer.java
+++ b/fuzzer/Fuzzer.java
@@ -1,37 +1,42 @@
import java.io.IOException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
+import java.util.ArrayList;
/* a stub for your team's fuzzer */
public class Fuzzer {
private static final String OUTPUT_FILE = "fuzz.txt";
+ private static final int MAX_INSTRUCTIONS = 1024;
public static void main(String[] args) throws IOException {
- System.out.println(Instruction.getBNF());
- FileOutputStream out = null;
- PrintWriter pw = null;
- try {
- out = new FileOutputStream(OUTPUT_FILE);
- pw = new PrintWriter(out);
-
- /* We just print one instruction.
- Hint: you might want to make use of the instruction
- grammar which is effectively encoded in Instruction.java */
- pw.println("list");
-
- }catch (Exception e){
- e.printStackTrace(System.err);
- System.exit(1);
- }finally{
- if (pw != null){
- pw.flush();
- }
- if (out != null){
- out.close();
- }
- }
+ InstructionSet set = new InstructionSet(MAX_INSTRUCTIONS);
+ Segmenter segmenter = new Segmenter();
+ Orderer orderer = new Orderer();
+ Filler filler = new Filler();
+
+ System.out.println("segmenting instruction set");
+ segmenter.transformSet(set);
+ System.out.println("ordering instructions");
+ orderer.transformSet(set);
+ System.out.println("filling instructions operands");
+ filler.transformSet(set);
+
+
+ System.out.println("writing to file: "+OUTPUT_FILE);
+ writeLinesToFile(set.toString(),OUTPUT_FILE);
+
+ System.out.println("all done.");
+
+ }
+
+ /**
+ * writes the provided lines to file at filePath
+ * @param lines
+ * @param filePath
+ */
+ private static void writeLinesToFile(String lines, String filePath){
}
diff --git a/fuzzer/Instruction.java b/fuzzer/Instruction.java
index e6bb0d021d540b21e9f3d7a8a533f12b5e63723e..2cb08c5b1843ca0394d91354be69333f7ce5b495 100644
--- a/fuzzer/Instruction.java
+++ b/fuzzer/Instruction.java
@@ -1,56 +1,24 @@
-import java.util.Arrays;
import java.util.ArrayList;
-public enum Instruction {
- PUT("put",new OperandType[]{OperandType.STRING,OperandType.STRING,OperandType.STRING}),
- GET("get",new OperandType[]{OperandType.STRING}),
- REM("rem",new OperandType[]{OperandType.STRING}),
- SAVE("save",new OperandType[]{OperandType.STRING,OperandType.STRING}),
- LIST("list",new OperandType[]{}),
- MASTERPW("masterpw",new OperandType[]{OperandType.STRING});
-
- public static String getBNF(){
- String grammar = "<INSTRUCTION> ::= \n";
- Instruction[] INSTS = Instruction.values();
- boolean firstInst = true;
- for (Instruction inst : INSTS){
- if (firstInst){
- grammar += " \"";
- firstInst = false;
- }else{
- grammar += " | \"";
- }
- grammar += inst.getOpcode() + "\"";
- for (OperandType op : inst.getOperands()){
- grammar += " <" + op.toString() + ">";
- }
- grammar += "\n";
- }
- return grammar;
+public class Instruction {
+ public InstructionType getType() {
+ return type;
}
-
- private final String opcode;
- private final OperandType[] operands;
- Instruction(String opcode, OperandType[] operands){
- this.opcode = opcode;
- this.operands = operands;
+ public ArrayList<String> getParams() {
+ return params;
}
- public String getOpcode(){
- return opcode;
- }
-
- public OperandType[] getOperands(){
- return operands;
+ public void setType(InstructionType type) {
+ this.type = type;
}
- public String toString(){
- String operandsString = "";
- for (OperandType op : operands) {
- operandsString += " " + op.toString();
- }
- return "\"" + opcode + "\"" + operandsString;
+ public void setParams(ArrayList<String> params) {
+ this.params = params;
}
-
+
+ private InstructionType type;
+ private ArrayList<String> params;
+
+
}
diff --git a/fuzzer/InstructionType b/fuzzer/InstructionType
new file mode 100644
index 0000000000000000000000000000000000000000..feb92736cd6ad60b9c9f7d750704f39ccd98bed7
--- /dev/null
+++ b/fuzzer/InstructionType
@@ -0,0 +1,7 @@
+public enum InstructionType {
+ PUT,
+ GET,
+ REM,
+ SAVE,
+ RANDOM,
+}
diff --git a/fuzzer/Instruction_old.java b/fuzzer/Instruction_old.java
new file mode 100644
index 0000000000000000000000000000000000000000..68749aba89e8177c3fb5a294764f3700b4801a9a
--- /dev/null
+++ b/fuzzer/Instruction_old.java
@@ -0,0 +1,53 @@
+public enum Instruction_old {
+ PUT("put",new OperandType[]{OperandType.STRING,OperandType.STRING,OperandType.STRING}),
+ GET("get",new OperandType[]{OperandType.STRING}),
+ REM("rem",new OperandType[]{OperandType.STRING}),
+ SAVE("save",new OperandType[]{OperandType.STRING,OperandType.STRING}),
+ LIST("list",new OperandType[]{}),
+ MASTERPW("masterpw",new OperandType[]{OperandType.STRING});
+
+ public static String getBNF(){
+ String grammar = "<INSTRUCTION> ::= \n";
+ Instruction_old[] INSTS = Instruction_old.values();
+ boolean firstInst = true;
+ for (Instruction_old inst : INSTS){
+ if (firstInst){
+ grammar += " \"";
+ firstInst = false;
+ }else{
+ grammar += " | \"";
+ }
+ grammar += inst.getOpcode() + "\"";
+ for (OperandType op : inst.getOperands()){
+ grammar += " <" + op.toString() + ">";
+ }
+ grammar += "\n";
+ }
+ return grammar;
+ }
+
+ private final String opcode;
+ private final OperandType[] operands;
+
+ Instruction_old(String opcode, OperandType[] operands){
+ this.opcode = opcode;
+ this.operands = operands;
+ }
+
+ public String getOpcode(){
+ return opcode;
+ }
+
+ public OperandType[] getOperands(){
+ return operands;
+ }
+
+ public String toString(){
+ String operandsString = "";
+ for (OperandType op : operands) {
+ operandsString += " " + op.toString();
+ }
+ return "\"" + opcode + "\"" + operandsString;
+ }
+
+}
diff --git a/fuzzer/OperandType.java b/fuzzer/OperandType.java
deleted file mode 100644
index b7a95206616c4f975223042e92aea96910e2d2d6..0000000000000000000000000000000000000000
--- a/fuzzer/OperandType.java
+++ /dev/null
@@ -1,3 +0,0 @@
-public enum OperandType {
- STRING
-}
diff --git a/fuzzer/Orderer.java b/fuzzer/Orderer.java
new file mode 100644
index 0000000000000000000000000000000000000000..299419660b6d89ca437cb7f6553f2a36c3b1ecfc
--- /dev/null
+++ b/fuzzer/Orderer.java
@@ -0,0 +1,13 @@
+/**
+ * Orderer has the responsibility of ordering the instructions in the instruction set
+ * Using the methods provided by the InstructionSet like putAtPercentile
+ *
+ * example: list(put,put,put,rem,rem,list) , after transformation: list (put,rem,put,put,rem,list)
+ *
+ */
+public class Orderer implements SetTransformer {
+ @Override
+ public void transformSet(InstructionSet set) {
+
+ }
+}
diff --git a/fuzzer/Segmenter.java b/fuzzer/Segmenter.java
new file mode 100644
index 0000000000000000000000000000000000000000..3ce8cd06103830b68c74cfd20eb3c4f4184c7d11
--- /dev/null
+++ b/fuzzer/Segmenter.java
@@ -0,0 +1,12 @@
+/*
+Segmenter has the responsibility of creating and adding Instructions to the Instruction Set
+It decides how many of each instruction type should be present in the overall set
+example: 80% put, 18% rem, 1% list, ...
+When creating instructions it only specifies the Instruction's type and leaves the arguments to be filled
+later by the Filler
+ */
+public class Segmenter implements SetTransformer {
+ @Override
+ public void transformSet(InstructionSet set) {
+ }
+}
diff --git a/fuzzer/setTransformer b/fuzzer/setTransformer
new file mode 100644
index 0000000000000000000000000000000000000000..76b45d79f6ae71958a52c3c25a8ab9a60d7d7f0d
--- /dev/null
+++ b/fuzzer/setTransformer
@@ -0,0 +1,3 @@
+interface SetTransformer{
+ public abstract void transformSet(InstructionSet set);
+}
\ No newline at end of file