Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swen90006-a2-2020
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arman Arethna
swen90006-a2-2020
Commits
2f086c36
Commit
2f086c36
authored
Oct 22, 2020
by
ehuang32
Browse files
Options
Downloads
Patches
Plain Diff
addDynamicProb
parent
fa00d99c
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
fuzzer/Fuzzer.java
+23
-3
23 additions, 3 deletions
fuzzer/Fuzzer.java
fuzzer/Instruction.java
+10
-6
10 additions, 6 deletions
fuzzer/Instruction.java
with
33 additions
and
9 deletions
fuzzer/Fuzzer.java
+
23
−
3
View file @
2f086c36
...
...
@@ -38,6 +38,11 @@ public class Fuzzer {
private
static
ArrayList
<
String
>
vars
=
new
ArrayList
<>();
// Instruction Count Array
private
static
int
[]
counts
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
// Instruction Added Probability Array
private
static
int
[]
addProb
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
public
static
void
main
(
String
[]
args
)
throws
IOException
{
System
.
out
.
println
(
Instruction
.
getBNF
());
FileOutputStream
out
=
null
;
...
...
@@ -65,8 +70,20 @@ public class Fuzzer {
}
}
}
/*
* Given an instruction, adds the instruction count to the global array
* and adds probability to the other instructions
*/
private
static
void
addCountProb
(
Instruction
instruction
)
{
int
index
=
instruction
.
ordinal
();
counts
[
index
]
+=
1
;
addProb
[
index
]
+=
instruction
.
getProbability
();
}
/***
* Generates a list of different inputs for the program
*
...
...
@@ -112,20 +129,23 @@ public class Fuzzer {
if
(
correct
)
{
while
(
counter
<
numInstructions
)
{
Instruction
newInstr
=
Instruction
.
getRandomInstruction
(
stackSize
);
Instruction
newInstr
=
Instruction
.
getRandomInstruction
(
stackSize
,
addProb
);
stackSize
=
stackSize
+
newInstr
.
getStackChange
();
result
.
append
(
completeInstruction
(
true
,
newInstr
));
addCountProb
(
newInstr
);
counter
+=
1
;
}
}
else
{
while
(
counter
<
numInstructions
)
{
Instruction
newInstr
;
if
(
rand
.
nextInt
(
100
)
<
LINE_ERROR_PERCENTAGE
){
newInstr
=
Instruction
.
getRandomInstruction
(
2
);
newInstr
=
Instruction
.
getRandomInstruction
(
2
,
addProb
);
result
.
append
(
completeInstruction
(
false
,
newInstr
));
addCountProb
(
newInstr
);
}
else
{
newInstr
=
Instruction
.
getRandomInstruction
(
stackSize
);
newInstr
=
Instruction
.
getRandomInstruction
(
stackSize
,
addProb
);
result
.
append
(
completeInstruction
(
true
,
newInstr
));
addCountProb
(
newInstr
);
}
stackSize
=
stackSize
+
newInstr
.
getStackChange
();
if
(
stackSize
<
0
){
...
...
This diff is collapsed.
Click to expand it.
fuzzer/Instruction.java
+
10
−
6
View file @
2f086c36
...
...
@@ -82,9 +82,9 @@ public enum Instruction {
// Returns a random instruction based on the stack size to prevent repeated
// requests
public
static
Instruction
getRandomInstruction
(
int
max
)
{
public
static
Instruction
getRandomInstruction
(
int
max
,
int
[]
addProb
)
{
// Check if cumlative probabilities have been calculated
checkProbability
();
checkProbability
(
addProb
);
ArrayList
<
Instruction
>
instructions
;
ArrayList
<
Integer
>
instCumlProbs
;
...
...
@@ -120,26 +120,26 @@ public enum Instruction {
// Called before doing probability calculations to check if the clumulative
// probabilities have been calculated
private
static
void
checkProbability
()
{
private
static
void
checkProbability
(
int
[]
addProb
)
{
// Check if cumlative probabilities have been calculated. If not, do so.
if
(
Instruction
.
ALL_MAX_CUML_PROB
==
0
)
{
Integer
cumProb
=
0
;
for
(
Instruction
instruction
:
ALL_INSTRUCTIONS
)
{
cumProb
+=
instruction
.
probability
;
cumProb
+=
instruction
.
probability
+
addProb
[
instruction
.
ordinal
()]
;
ALL_CUML_PROB
.
add
(
cumProb
);
}
ALL_MAX_CUML_PROB
=
cumProb
;
cumProb
=
0
;
for
(
Instruction
instruction
:
MAX_ZERO_INSTRUCTIONS
)
{
cumProb
+=
instruction
.
probability
;
cumProb
+=
instruction
.
probability
+
addProb
[
instruction
.
ordinal
()]
;
ZERO_CUML_PROB
.
add
(
cumProb
);
}
ZERO_MAX_CUML_PROB
=
cumProb
;
cumProb
=
0
;
for
(
Instruction
instruction
:
MAX_ONE_INSTRUCTIONS
)
{
cumProb
+=
instruction
.
probability
;
cumProb
+=
instruction
.
probability
+
addProb
[
instruction
.
ordinal
()]
;
ONE_CUML_PROB
.
add
(
cumProb
);
}
ONE_MAX_CUML_PROB
=
cumProb
;
...
...
@@ -169,4 +169,8 @@ public enum Instruction {
}
return
"\""
+
opcode
+
"\""
+
operandsString
;
}
public
Integer
getProbability
()
{
return
this
.
probability
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment