diff --git a/fuzzer/Fuzzer.java b/fuzzer/Fuzzer.java index e4207e3b9b31712e3d75b3296d1f5df724b28901..5e70d18bbf72dd6551897d81ccb271a47e9434a4 100644 --- a/fuzzer/Fuzzer.java +++ b/fuzzer/Fuzzer.java @@ -14,6 +14,7 @@ public class Fuzzer { private static final List<String> validOpcodes = new ArrayList<String>(Arrays.asList("ADD","SUB","MUL","DIV","LDR","STR","MOV","JMP","JZ")); private static final int maxRegistry = 32; private static final int maxMemory = 65535; + private static final int maxPadding = 40000; private static final String alphabet = "1234567890-=`~!@#$%6&*()_+q wertyuiop[]QWERTYUIOP{}|asdfghjkl;ASDFGHJKL:zxcvbnm,./ZXCVBNM<>?\"\'\\"; public static void main(String[] args) throws IOException { FileOutputStream out = null; @@ -23,7 +24,33 @@ public class Fuzzer { pw = new PrintWriter(out); Random rg = new Random(); //----------Fuzzer Begins Here----------// + //-----Decide Strategy-----// + /*** + * 0 - Valid Termination + * 1 - Memory Overflow + * 2 - Registry Overflow + * 3 - Offset Overflow + * 4 - Line Overflow + * 5 - EOF Overflow + * 6 - Dirty Read Registry + * 7 - Dirty Read Memory + * 8 - Pc Overflow + * 9 - Int Overflow + * 10 - Invalid + */ + //-----Decide Strategy-----// + //-----Init-----// + int paddingLines = rg.nextInt(maxPadding); + pw.println(generateDivideByZero()); + pw.println(generateInstructionComment(rg)); + for(int x=0;x<paddingLines;x++){ + pw.println(generateValidString(rg,paddingLines-x+3,x+3)); + } + //-----Init-----// + //-----Terminate-----// + + //-----Terminate-----// @@ -43,6 +70,21 @@ public class Fuzzer { } } + //-----------Strategy Functions----------// + public static PrintWriter functionTerminate(PrintWriter pw,Random rd){ + return pw; + } + public static PrintWriter createPadding(Random rg,PrintWriter pw,int paddinglines){ + + return pw; + } + public static PrintWriter invalidStringTerminate(PrintWriter pw){ + return pw; + } + public static PrintWriter dirtyRead(PrintWriter pw){ + return pw; + } + //-----------Generation Functions----------// public static String generateMemoryOverflow(Random rg) { String line = new String(); @@ -229,14 +271,13 @@ public class Fuzzer { line = line +"MOV R0 0\n"; line = line +"MOV R1 1\n"; line = line +"DIV R2 R1 R0\n"; - line = line +"RET R2"; return line; } public static String generateDirtyRegistyRead() { String line = new String(); - for(int x=1;x<maxRegistry-1;x++) { + for(int x=1;x<maxRegistry;x++) { line = line +"ADD R0 R0 R"+x+"\n"; } line = line +"RET R0"; @@ -252,19 +293,20 @@ public class Fuzzer { if(rg.nextBoolean()) { value = value*-1; } - line = line +"\nLDR R0 "+value+" R1\n"; + line = line +"\nLDR R1 R0 "+value+"\n"; line = line +"ADD R2 R2 R1\n"; } + line = line+"RET R2"; return line; } - public static String jmpOverflow(int programLength,int lineNumber,Random rg) { + public static String jmpOverflow(Random rg) { String line = new String(); int val; if(rg.nextBoolean()) { - val = -1*(lineNumber+2); + val = -1*maxMemory; } else { - val = (programLength-lineNumber+1); + val = maxMemory; } line = line +"JMP "+val; return line; @@ -275,9 +317,9 @@ public class Fuzzer { String line = new String(); int val; if(rg.nextBoolean()) { - val = -1*(lineNumber+2); + val = -1*maxMemory; } else { - val = (programLength-lineNumber+2); + val = maxMemory; } line = line +"MOV R0 0\n"; line = line +"JZ R0 "+val;