Skip to content
Snippets Groups Projects
Commit 755c39f7 authored by Jane Hoh's avatar Jane Hoh
Browse files

1/4 chance of maximising or minimising the string length

parent 466491ea
No related branches found
No related tags found
2 merge requests!16Brownian motion fuzzer,!13Fuzzer
This commit is part of merge request !16. Comments created here will be created in the context of that merge request.
...@@ -8,15 +8,17 @@ import java.util.Random; ...@@ -8,15 +8,17 @@ import java.util.Random;
public class Fuzzer { public class Fuzzer {
private static final String OUTPUT_FILE = "fuzz.txt"; private static final String OUTPUT_FILE = "fuzz.txt";
private static final String CHAR_LOWER = "abcdefghijklmnopqrstuvwxyz"; private static final String CHAR_LOWER = "abcdefghijklmnopqrstuvwxyz";
private static final String CHAR_UPPER = CHAR_LOWER.toUpperCase(); private static final String CHAR_UPPER = CHAR_LOWER.toUpperCase();
private static final String NUMBER = "0123456789"; private static final String NUMBER = "0123456789";
private static final int MAX_STRING_LENGTH = 1014;
private static final int MAX_LINE_LENGTH = 1022;
private static final int MAX_URL_LENGTH = 300; private static final int MAX_URL_LENGTH = 300;
private static final int numInputLines = 1024; //Indicates the number of inputs we wish to generate in one file private static final int numInputLines = 1024; //Indicates the number of inputs we wish to generate in one file
private static ArrayList<String> savedURLs = new ArrayList<String>(); private static ArrayList<String> savedURLs = new ArrayList<String>(); //save put urls here for get and rem
private static final String DATA_FOR_RANDOM_STRING = CHAR_LOWER + CHAR_UPPER + NUMBER; private static final String DATA_FOR_RANDOM_STRING = CHAR_LOWER + CHAR_UPPER + NUMBER; //specifies which characters can be in a string
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());
...@@ -91,7 +93,8 @@ public class Fuzzer { ...@@ -91,7 +93,8 @@ public class Fuzzer {
input += " "+ url; input += " "+ url;
}else if(op.equals(OperandType.STRING)) { }else if(op.equals(OperandType.STRING)) {
input += " "+generateRandomString(MAX_STRING_LENGTH); int maxStringLength = MAX_LINE_LENGTH - input.length() - ((inst.getOperands().length-index)*2);
input += " "+generateRandomString(maxStringLength);
} }
index++; index++;
} }
...@@ -115,14 +118,26 @@ public class Fuzzer { ...@@ -115,14 +118,26 @@ public class Fuzzer {
* and modified*/ * and modified*/
public static String generateRandomString(int maxlength) { public static String generateRandomString(int maxlength) {
if (maxlength < 1) throw new IllegalArgumentException(); if (maxlength < 1) throw new IllegalArgumentException();
Random random = new Random();
int minLength = 1;
int length;
//make a 1/4 chance of picking the max length and a 1/4 chance of picking the min length
int chance = random.nextInt(4);
if(chance == 1) {
length = maxlength;
}else if(chance == 2) {
length = minLength;
}else {
length = random.nextInt(maxlength)+1;
}
int length = new Random().nextInt(maxlength)+1;
StringBuilder sb = new StringBuilder(length); StringBuilder sb = new StringBuilder(length);
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
// 0-62 (exclusive), random returns 0-61 // 0-62 (exclusive), random returns 0-61
int rndCharAt = new Random().nextInt(DATA_FOR_RANDOM_STRING.length()); int rndCharAt = random.nextInt(DATA_FOR_RANDOM_STRING.length());
char rndChar = DATA_FOR_RANDOM_STRING.charAt(rndCharAt); char rndChar = DATA_FOR_RANDOM_STRING.charAt(rndCharAt);
sb.append(rndChar); sb.append(rndChar);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment