Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swen90006-a2-2018
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
Model registry
Operate
Environments
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
Callum Bradshaw
swen90006-a2-2018
Commits
5f1517ca
Commit
5f1517ca
authored
Oct 14, 2018
by
Zhaolin Deng
Browse files
Options
Downloads
Patches
Plain Diff
update
parent
23b32061
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
fuzz.s
+0
-1
0 additions, 1 deletion
fuzz.s
fuzzer/Fuzzer.java
+87
-84
87 additions, 84 deletions
fuzzer/Fuzzer.java
with
87 additions
and
85 deletions
fuzz.s
+
0
−
1
View file @
5f1517ca
This diff is collapsed.
Click to expand it.
fuzzer/Fuzzer.java
+
87
−
84
View file @
5f1517ca
...
@@ -13,7 +13,7 @@ public class Fuzzer {
...
@@ -13,7 +13,7 @@ public class Fuzzer {
private
static
final
String
OUTPUT_FILE
=
"fuzz.s"
;
private
static
final
String
OUTPUT_FILE
=
"fuzz.s"
;
private
static
final
List
<
String
>
validOpcodes
=
new
ArrayList
<
String
>(
Arrays
.
asList
(
"ADD"
,
"SUB"
,
"MUL"
,
"DIV"
,
"LDR"
,
"STR"
,
"MOV"
,
"JMP"
,
"JZ"
));
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
maxRegistry
=
32
;
private
static
final
int
maxMemory
=
6553
6
;
private
static
final
int
maxMemory
=
6553
5
;
private
static
final
String
alphabet
=
"1234567890-=`~!@#$%6&*()_+q wertyuiop[]QWERTYUIOP{}|asdfghjkl;ASDFGHJKL:zxcvbnm,./ZXCVBNM<>?\"\'\\"
;
private
static
final
String
alphabet
=
"1234567890-=`~!@#$%6&*()_+q wertyuiop[]QWERTYUIOP{}|asdfghjkl;ASDFGHJKL:zxcvbnm,./ZXCVBNM<>?\"\'\\"
;
public
static
void
main
(
String
[]
args
)
throws
IOException
{
public
static
void
main
(
String
[]
args
)
throws
IOException
{
FileOutputStream
out
=
null
;
FileOutputStream
out
=
null
;
...
@@ -23,9 +23,10 @@ public class Fuzzer {
...
@@ -23,9 +23,10 @@ public class Fuzzer {
pw
=
new
PrintWriter
(
out
);
pw
=
new
PrintWriter
(
out
);
Random
rg
=
new
Random
();
Random
rg
=
new
Random
();
//----------Fuzzer Begins Here----------//
//----------Fuzzer Begins Here----------//
String
line
=
generateMemoryUnderflow
(
rg
);
System
.
out
.
println
(
"Testing line: "
+
line
);
pw
.
println
(
line
);
//----------Fuzzer Ends Here----------
//----------Fuzzer Ends Here----------
}
catch
(
Exception
e
){
}
catch
(
Exception
e
){
...
@@ -44,26 +45,25 @@ public class Fuzzer {
...
@@ -44,26 +45,25 @@ public class Fuzzer {
//-----------Generation Functions----------//
//-----------Generation Functions----------//
public
static
String
generateMemoryOverflow
(
Random
rg
)
{
public
static
String
generateMemoryOverflow
(
Random
rg
)
{
String
line
=
new
String
();
String
line
=
new
String
();
line
.
concat
(
"MOV R0 "
+
maxMemory
+
"
%
n"
)
;
line
=
line
+
"MOV R0 "
+
maxMemory
+
"
\
n"
;
line
.
concat
(
"MOV R1 1
%
n"
)
;
line
=
line
+
"MOV R1 1
\
n"
;
if
(
rg
.
nextBoolean
())
{
if
(
rg
.
nextBoolean
())
{
line
.
concat
(
"LDR R0 R1 1"
)
;
line
=
line
+
"LDR R0 R1 1"
;
}
else
{
}
else
{
line
.
concat
(
"STR R0 R1 1"
)
;
line
=
line
+
"STR R0 R1 1"
;
}
}
return
line
;
return
line
;
}
}
public
static
String
generateMemoryUnderflow
(
Random
rg
)
{
public
static
String
generateMemoryUnderflow
(
Random
rg
)
{
String
line
=
new
String
();
String
line
=
new
String
();
line
.
concat
(
"MOV R0 "
+(
maxMemory
*-
1
)+
"
%
n"
)
;
line
=
line
+
"MOV R0 "
+(
maxMemory
*-
1
)+
"
\
n"
;
line
.
concat
(
"MOV R1 1
%
n"
)
;
line
=
line
+
"MOV R1 1
\
n"
;
if
(
rg
.
nextBoolean
())
{
if
(
rg
.
nextBoolean
())
{
line
.
concat
(
"LDR R0 R1 -1"
)
;
line
=
line
+
"LDR R0 R1 -1"
;
}
else
{
}
else
{
line
.
concat
(
"STR R0 R1 -1"
)
;
line
=
line
+
"STR R0 R1 -1"
;
}
}
System
.
out
.
println
(
"line: "
+
line
);
return
line
;
return
line
;
}
}
...
@@ -85,109 +85,109 @@ public class Fuzzer {
...
@@ -85,109 +85,109 @@ public class Fuzzer {
case
(
0
):
case
(
0
):
goodRegA
=
rg
.
nextInt
(
maxRegistry
);
goodRegA
=
rg
.
nextInt
(
maxRegistry
);
goodRegB
=
rg
.
nextInt
(
maxRegistry
);
goodRegB
=
rg
.
nextInt
(
maxRegistry
);
line
.
concat
(
"ADD "
)
;
line
=
line
+
"ADD "
;
pos
=
rg
.
nextInt
(
3
);
pos
=
rg
.
nextInt
(
3
);
switch
(
pos
)
{
switch
(
pos
)
{
case
(
0
):
case
(
0
):
line
.
concat
(
"R"
+
invalidRegistry
+
" R"
+
goodRegA
+
" R"
+
goodRegB
)
;
line
=
line
+
"R"
+
invalidRegistry
+
" R"
+
goodRegA
+
" R"
+
goodRegB
;
break
;
break
;
case
(
1
):
case
(
1
):
line
.
concat
(
"R"
+
goodRegA
+
" R"
+
invalidRegistry
+
" R"
+
goodRegB
)
;
line
=
line
+
"R"
+
goodRegA
+
" R"
+
invalidRegistry
+
" R"
+
goodRegB
;
break
;
break
;
case
(
2
):
case
(
2
):
line
.
concat
(
"R"
+
goodRegB
+
" R"
+
goodRegA
+
" R"
+
invalidRegistry
)
;
line
=
line
+
"R"
+
goodRegB
+
" R"
+
goodRegA
+
" R"
+
invalidRegistry
;
break
;
break
;
}
}
return
line
;
return
line
;
case
(
1
):
case
(
1
):
goodRegA
=
rg
.
nextInt
(
maxRegistry
);
goodRegA
=
rg
.
nextInt
(
maxRegistry
);
goodRegB
=
rg
.
nextInt
(
maxRegistry
);
goodRegB
=
rg
.
nextInt
(
maxRegistry
);
line
.
concat
(
"SUB "
)
;
line
=
line
+
"SUB "
;
pos
=
rg
.
nextInt
(
3
);
pos
=
rg
.
nextInt
(
3
);
switch
(
pos
)
{
switch
(
pos
)
{
case
(
0
):
case
(
0
):
line
.
concat
(
"R"
+
invalidRegistry
+
" R"
+
goodRegA
+
" R"
+
goodRegB
)
;
line
=
line
+
"R"
+
invalidRegistry
+
" R"
+
goodRegA
+
" R"
+
goodRegB
;
break
;
break
;
case
(
1
):
case
(
1
):
line
.
concat
(
"R"
+
goodRegA
+
" R"
+
invalidRegistry
+
" R"
+
goodRegB
)
;
line
=
line
+
"R"
+
goodRegA
+
" R"
+
invalidRegistry
+
" R"
+
goodRegB
;
break
;
break
;
case
(
2
):
case
(
2
):
line
.
concat
(
"R"
+
goodRegB
+
" R"
+
goodRegA
+
" R"
+
invalidRegistry
)
;
line
=
line
+
"R"
+
goodRegB
+
" R"
+
goodRegA
+
" R"
+
invalidRegistry
;
break
;
break
;
}
}
return
line
;
return
line
;
case
(
2
):
case
(
2
):
goodRegA
=
rg
.
nextInt
(
maxRegistry
);
goodRegA
=
rg
.
nextInt
(
maxRegistry
);
goodRegB
=
rg
.
nextInt
(
maxRegistry
);
goodRegB
=
rg
.
nextInt
(
maxRegistry
);
line
.
concat
(
"MOV R"
+
goodRegB
+
" 1
%
n"
)
;
line
=
line
+
"MOV R"
+
goodRegB
+
" 1
\
n"
;
line
.
concat
(
"DIV "
)
;
line
=
line
+
"DIV "
;
pos
=
rg
.
nextInt
(
3
);
pos
=
rg
.
nextInt
(
3
);
switch
(
pos
)
{
switch
(
pos
)
{
case
(
0
):
case
(
0
):
line
.
concat
(
"R"
+
invalidRegistry
+
" R"
+
goodRegA
+
" R"
+
goodRegB
)
;
line
=
line
+
"R"
+
invalidRegistry
+
" R"
+
goodRegA
+
" R"
+
goodRegB
;
break
;
break
;
case
(
1
):
case
(
1
):
line
.
concat
(
"R"
+
goodRegA
+
" R"
+
invalidRegistry
+
" R"
+
goodRegB
)
;
line
=
line
+
"R"
+
goodRegA
+
" R"
+
invalidRegistry
+
" R"
+
goodRegB
;
break
;
break
;
case
(
2
):
case
(
2
):
line
.
concat
(
"R"
+
goodRegB
+
" R"
+
goodRegA
+
" R"
+
invalidRegistry
)
;
line
=
line
+
"R"
+
goodRegB
+
" R"
+
goodRegA
+
" R"
+
invalidRegistry
;
break
;
break
;
}
}
return
line
;
return
line
;
case
(
3
):
case
(
3
):
goodRegA
=
rg
.
nextInt
(
maxRegistry
);
goodRegA
=
rg
.
nextInt
(
maxRegistry
);
goodRegB
=
rg
.
nextInt
(
maxRegistry
);
goodRegB
=
rg
.
nextInt
(
maxRegistry
);
line
.
concat
(
"MUL "
)
;
line
=
line
+
"MUL "
;
pos
=
rg
.
nextInt
(
3
);
pos
=
rg
.
nextInt
(
3
);
switch
(
pos
)
{
switch
(
pos
)
{
case
(
0
):
case
(
0
):
line
.
concat
(
"R"
+
invalidRegistry
+
" R"
+
goodRegA
+
" R"
+
goodRegB
)
;
line
=
line
+
"R"
+
invalidRegistry
+
" R"
+
goodRegA
+
" R"
+
goodRegB
;
break
;
break
;
case
(
1
):
case
(
1
):
line
.
concat
(
"R"
+
goodRegA
+
" R"
+
invalidRegistry
+
" R"
+
goodRegB
)
;
line
=
line
+
"R"
+
goodRegA
+
" R"
+
invalidRegistry
+
" R"
+
goodRegB
;
break
;
break
;
case
(
2
):
case
(
2
):
line
.
concat
(
"R"
+
goodRegB
+
" R"
+
goodRegA
+
" R"
+
invalidRegistry
)
;
line
=
line
+
"R"
+
goodRegB
+
" R"
+
goodRegA
+
" R"
+
invalidRegistry
;
break
;
break
;
}
}
return
line
;
return
line
;
case
(
4
):
case
(
4
):
line
.
concat
(
"LDR "
)
;
line
=
line
+
"LDR "
;
goodRegA
=
rg
.
nextInt
(
maxRegistry
);
goodRegA
=
rg
.
nextInt
(
maxRegistry
);
pos
=
rg
.
nextInt
(
2
);
pos
=
rg
.
nextInt
(
2
);
val
=
rg
.
nextInt
(
maxMemory
);
val
=
rg
.
nextInt
(
maxMemory
);
switch
(
pos
)
{
switch
(
pos
)
{
case
(
0
):
case
(
0
):
line
.
concat
(
"R"
+
invalidRegistry
+
" "
+
val
+
"R"
+
goodRegA
)
;
line
=
line
+
"R"
+
invalidRegistry
+
" "
+
val
+
"R"
+
goodRegA
;
break
;
break
;
case
(
1
):
case
(
1
):
line
.
concat
(
"R"
+
goodRegA
+
" "
+
val
+
"R"
+
invalidRegistry
)
;
line
=
line
+
"R"
+
goodRegA
+
" "
+
val
+
"R"
+
invalidRegistry
;
break
;
break
;
}
}
return
line
;
return
line
;
case
(
5
):
case
(
5
):
line
.
concat
(
"STR "
)
;
line
=
line
+
"STR "
;
goodRegA
=
rg
.
nextInt
(
maxRegistry
);
goodRegA
=
rg
.
nextInt
(
maxRegistry
);
pos
=
rg
.
nextInt
(
2
);
pos
=
rg
.
nextInt
(
2
);
val
=
rg
.
nextInt
(
maxMemory
);
val
=
rg
.
nextInt
(
maxMemory
);
switch
(
pos
)
{
switch
(
pos
)
{
case
(
0
):
case
(
0
):
line
.
concat
(
"R"
+
invalidRegistry
+
" "
+
val
+
"R"
+
goodRegA
)
;
line
=
line
+
"R"
+
invalidRegistry
+
" "
+
val
+
"R"
+
goodRegA
;
break
;
break
;
case
(
1
):
case
(
1
):
line
.
concat
(
"R"
+
goodRegA
+
" "
+
val
+
"R"
+
invalidRegistry
)
;
line
=
line
+
"R"
+
goodRegA
+
" "
+
val
+
"R"
+
invalidRegistry
;
break
;
break
;
}
}
return
line
;
return
line
;
case
(
6
):
case
(
6
):
line
.
concat
(
"MOV "
)
;
line
=
line
+
"MOV "
;
goodRegA
=
rg
.
nextInt
(
maxRegistry
);
goodRegA
=
rg
.
nextInt
(
maxRegistry
);
val
=
rg
.
nextInt
(
maxMemory
);
val
=
rg
.
nextInt
(
maxMemory
);
line
.
concat
(
"R"
+
invalidRegistry
+
" "
+
val
)
;
line
=
line
+
"R"
+
invalidRegistry
+
" "
+
val
;
return
line
;
return
line
;
}
}
return
line
;
return
line
;
...
@@ -197,38 +197,38 @@ public class Fuzzer {
...
@@ -197,38 +197,38 @@ public class Fuzzer {
String
line
=
new
String
();
String
line
=
new
String
();
Boolean
positive
=
rg
.
nextBoolean
();
Boolean
positive
=
rg
.
nextBoolean
();
if
(!
positive
)
{
if
(!
positive
)
{
line
.
concat
(
"MOV R0 -70000"
)
;
line
=
line
+
"MOV R0 -70000"
;
}
else
{
}
else
{
line
.
concat
(
"MOV R0 70000"
)
;
line
=
line
+
"MOV R0 70000"
;
}
}
return
line
;
return
line
;
}
}
public
static
String
generateLineOverFlow
()
{
public
static
String
generateLineOverFlow
()
{
String
line
=
new
String
();
String
line
=
new
String
();
line
.
concat
(
"RET R0"
)
;
line
=
line
+
"RET R0"
;
for
(
int
x
=
0
;
x
<
2000
;
x
++)
{
for
(
int
x
=
0
;
x
<
2000
;
x
++)
{
line
.
concat
(
"a"
)
;
line
=
line
+
"a"
;
}
}
return
line
;
return
line
;
}
}
public
static
String
generateInstructionOverflow
()
{
public
static
String
generateInstructionOverflow
()
{
String
line
=
new
String
();
String
line
=
new
String
();
line
.
concat
(
"MOV R0 0
%
n"
)
;
line
=
line
+
"MOV R0 0
\
n"
;
line
.
concat
(
"MOV R1 1"
)
;
line
=
line
+
"MOV R1 1"
;
for
(
int
x
=
0
;
x
<
70000
;
x
++)
{
for
(
int
x
=
0
;
x
<
70000
;
x
++)
{
line
.
concat
(
"%
nADD R0 R0 R1"
)
;
line
=
line
+
"\
nADD R0 R0 R1"
;
}
}
return
line
;
return
line
;
}
}
public
static
String
generateDivideByZero
(){
public
static
String
generateDivideByZero
(){
String
line
=
new
String
();
String
line
=
new
String
();
line
.
concat
(
"MOV R0 0
%
n"
)
;
line
=
line
+
"MOV R0 0
\
n"
;
line
.
concat
(
"MOV R1 1
%
n"
)
;
line
=
line
+
"MOV R1 1
\
n"
;
line
.
concat
(
"DIV R2 R1 R0
%
n"
)
;
line
=
line
+
"DIV R2 R1 R0
\
n"
;
line
.
concat
(
"RET R2"
)
;
line
=
line
+
"RET R2"
;
return
line
;
return
line
;
}
}
...
@@ -236,23 +236,23 @@ public class Fuzzer {
...
@@ -236,23 +236,23 @@ public class Fuzzer {
String
line
=
new
String
();
String
line
=
new
String
();
for
(
int
x
=
1
;
x
<
maxRegistry
-
1
;
x
++)
{
for
(
int
x
=
1
;
x
<
maxRegistry
-
1
;
x
++)
{
line
.
concat
(
"ADD R0 R0 R"
+
x
+
"
%
n"
)
;
line
=
line
+
"ADD R0 R0 R"
+
x
+
"
\
n"
;
}
}
line
.
concat
(
"RET R0"
)
;
line
=
line
+
"RET R0"
;
return
line
;
return
line
;
}
}
public
static
String
generateDirtyMemoryRead
(
Random
rg
)
{
public
static
String
generateDirtyMemoryRead
(
Random
rg
)
{
String
line
=
new
String
();
String
line
=
new
String
();
int
attempts
=
20
;
int
attempts
=
20
;
line
.
concat
(
"MOV R0 0"
)
;
line
=
line
+
"MOV R0 0"
;
for
(
int
x
=
0
;
x
<
attempts
;
x
++)
{
for
(
int
x
=
0
;
x
<
attempts
;
x
++)
{
int
value
=
rg
.
nextInt
(
maxMemory
);
int
value
=
rg
.
nextInt
(
maxMemory
);
if
(
rg
.
nextBoolean
())
{
if
(
rg
.
nextBoolean
())
{
value
=
value
*-
1
;
value
=
value
*-
1
;
}
}
line
.
concat
(
"%
nLDR R0 "
+
value
+
" R1
%
n"
)
;
line
=
line
+
"\
nLDR R0 "
+
value
+
" R1
\
n"
;
line
.
concat
(
"ADD R2 R2 R1
%
n"
)
;
line
=
line
+
"ADD R2 R2 R1
\
n"
;
}
}
return
line
;
return
line
;
}
}
...
@@ -265,7 +265,7 @@ public class Fuzzer {
...
@@ -265,7 +265,7 @@ public class Fuzzer {
}
else
{
}
else
{
val
=
(
programLength
-
lineNumber
+
1
);
val
=
(
programLength
-
lineNumber
+
1
);
}
}
line
.
concat
(
"JMP "
+
val
)
;
line
=
line
+
"JMP "
+
val
;
return
line
;
return
line
;
}
}
...
@@ -278,24 +278,24 @@ public class Fuzzer {
...
@@ -278,24 +278,24 @@ public class Fuzzer {
}
else
{
}
else
{
val
=
(
programLength
-
lineNumber
+
2
);
val
=
(
programLength
-
lineNumber
+
2
);
}
}
line
.
concat
(
"MOV R0 0
%
n"
)
;
line
=
line
+
"MOV R0 0
\
n"
;
line
.
concat
(
"JZ R0 "
+
val
)
;
line
=
line
+
"JZ R0 "
+
val
;
return
line
;
return
line
;
}
}
public
static
String
intOverflow
()
{
public
static
String
intOverflow
()
{
String
line
=
new
String
();
String
line
=
new
String
();
line
.
concat
(
"MOV R0 65535
%
n"
)
;
line
=
line
+
"MOV R0 65535
\
n"
;
line
.
concat
(
"MUL R1 R0 R0
%
n"
)
;
line
=
line
+
"MUL R1 R0 R0
\
n"
;
line
.
concat
(
"MUL R1 R0 R0"
)
;
line
=
line
+
"MUL R1 R0 R0"
;
return
line
;
return
line
;
}
}
public
static
String
intUnderflow
()
{
public
static
String
intUnderflow
()
{
String
line
=
new
String
();
String
line
=
new
String
();
line
.
concat
(
"MOV R0 -65535
%
n"
)
;
line
=
line
+
"MOV R0 -65535
\
n"
;
line
.
concat
(
"MUL R1 R0 R0
%
n"
)
;
line
=
line
+
"MUL R1 R0 R0
\
n"
;
line
.
concat
(
"MUL R1 R0 R0"
)
;
line
=
line
+
"MUL R1 R0 R0"
;
return
line
;
return
line
;
}
}
...
@@ -305,51 +305,54 @@ public class Fuzzer {
...
@@ -305,51 +305,54 @@ public class Fuzzer {
Boolean
hasval
=
rg
.
nextBoolean
();
Boolean
hasval
=
rg
.
nextBoolean
();
int
index
=
rg
.
nextInt
(
validOpcodes
.
size
());
int
index
=
rg
.
nextInt
(
validOpcodes
.
size
());
String
opcode
=
validOpcodes
.
get
(
index
);
String
opcode
=
validOpcodes
.
get
(
index
);
line
.
concat
(
opcode
)
;
line
=
line
+
opcode
;
for
(
int
x
=
0
;
x
<
regs
;
x
++)
{
for
(
int
x
=
0
;
x
<
regs
;
x
++)
{
int
register
=
rg
.
nextInt
(
maxRegistry
);
int
register
=
rg
.
nextInt
(
maxRegistry
);
line
.
concat
(
" R"
+
register
)
;
line
=
line
+
" R"
+
register
;
}
}
if
(
hasval
)
{
if
(
hasval
)
{
int
value
=
rg
.
nextInt
(
maxMemory
);
int
value
=
rg
.
nextInt
(
maxMemory
);
line
.
concat
(
" "
+
value
)
;
line
=
line
+
" "
+
value
;
}
}
//too many arguments
//too many arguments
return
null
;
return
line
;
}
}
public
static
String
generateInvalidFunctionName
(
Random
rg
,
String
line
)
{
public
static
String
generateInvalidFunctionName
(
Random
rg
,
String
line
)
{
char
[]
charLine
=
line
.
toCharArray
();
char
[]
charLine
=
line
.
toCharArray
();
System
.
out
.
println
(
"line"
+
line
);
int
change
=
rg
.
nextInt
(
3
)+
1
;
int
change
=
rg
.
nextInt
(
3
)+
1
;
System
.
out
.
println
(
"change"
+
change
);
for
(
int
x
=
0
;
x
<
change
;
x
++)
{
for
(
int
x
=
0
;
x
<
change
;
x
++)
{
int
index
=
rg
.
nextInt
(
charLine
.
length
);
int
index
=
rg
.
nextInt
(
charLine
.
length
);
char
character
=
alphabet
.
charAt
(
rg
.
nextInt
(
alphabet
.
length
()));
char
character
=
alphabet
.
charAt
(
rg
.
nextInt
(
alphabet
.
length
()));
System
.
out
.
println
(
"char at:"
+
x
+
" is "
+
character
);
charLine
[
index
]
=
character
;
charLine
[
index
]
=
character
;
}
}
return
charLine
.
toString
(
);
return
new
String
(
charLine
);
}
}
public
static
String
generateInstructionComment
(
Random
rg
)
{
public
static
String
generateInstructionComment
(
Random
rg
)
{
String
line
=
new
String
();
String
line
=
new
String
();
line
.
concat
(
";"
)
;
line
=
line
+
";"
;
String
instr
=
generateValidReturn
(
rg
);
String
instr
=
generateValidReturn
(
rg
);
line
.
concat
(
instr
)
;
line
=
line
+
instr
;
return
line
;
return
line
;
}
}
public
static
String
generateValidReturn
(
Random
rg
)
{
public
static
String
generateValidReturn
(
Random
rg
)
{
String
line
=
new
String
();
String
line
=
new
String
();
line
.
concat
(
"RET"
)
;
line
=
line
+
"RET"
;
line
.
concat
(
" R"
+
rg
.
nextInt
(
maxRegistry
)
)
;
line
=
line
+
" R"
+
rg
.
nextInt
(
maxRegistry
);
return
line
;
return
line
;
}
}
public
static
String
generateInvalidReturn
(
Random
rg
)
{
public
static
String
generateInvalidReturn
(
Random
rg
)
{
int
invalidRegistry
;
int
invalidRegistry
;
String
line
=
new
String
();
String
line
=
new
String
();
line
.
concat
(
"RET"
)
;
line
=
line
+
"RET"
;
Boolean
overflow
=
rg
.
nextBoolean
();
Boolean
overflow
=
rg
.
nextBoolean
();
if
(
overflow
)
{
if
(
overflow
)
{
invalidRegistry
=
32
;
invalidRegistry
=
32
;
...
@@ -358,7 +361,7 @@ public class Fuzzer {
...
@@ -358,7 +361,7 @@ public class Fuzzer {
invalidRegistry
=
-
1
;
invalidRegistry
=
-
1
;
}
}
line
.
concat
(
" R"
+
invalidRegistry
)
;
line
=
line
+
" R"
+
invalidRegistry
;
return
line
;
return
line
;
}
}
...
@@ -388,10 +391,10 @@ public class Fuzzer {
...
@@ -388,10 +391,10 @@ public class Fuzzer {
case
(
"STR"
):
case
(
"STR"
):
//special case - form <REGISTER VALUE REGISTER>
//special case - form <REGISTER VALUE REGISTER>
offset
=
(
rg
.
nextInt
(
2
*
maxMemory
))-
maxMemory
;
offset
=
(
rg
.
nextInt
(
2
*
maxMemory
))-
maxMemory
;
line
.
concat
(
opcode
)
;
line
=
line
+
opcode
;
line
.
concat
(
" R"
+
rg
.
nextInt
(
maxRegistry
)
)
;
line
=
line
+
" R"
+
rg
.
nextInt
(
maxRegistry
);
line
.
concat
(
" "
+
offset
)
;
line
=
line
+
" "
+
offset
;
line
.
concat
(
" R"
+
rg
.
nextInt
(
maxRegistry
)
)
;
line
=
line
+
" R"
+
rg
.
nextInt
(
maxRegistry
);
return
line
;
return
line
;
case
(
"MOV"
):
case
(
"MOV"
):
numregs
=
1
;
numregs
=
1
;
...
@@ -408,7 +411,7 @@ public class Fuzzer {
...
@@ -408,7 +411,7 @@ public class Fuzzer {
offset
=
offset
-
lineNumber
;
offset
=
offset
-
lineNumber
;
if
(
offset
<
0
)
{
if
(
offset
<
0
)
{
offset
=
offset
-
1
;
offset
=
offset
-
1
;
line
.
concat
(
"JMP 2
%
n"
)
;
line
=
line
+
"JMP 2
\
n"
;
}
else
if
(
offset
==
0
)
{
}
else
if
(
offset
==
0
)
{
offset
=
offset
+
1
;
offset
=
offset
+
1
;
}
}
...
@@ -421,19 +424,19 @@ public class Fuzzer {
...
@@ -421,19 +424,19 @@ public class Fuzzer {
offset
=
offset
-
lineNumber
;
offset
=
offset
-
lineNumber
;
if
(
offset
<
0
)
{
if
(
offset
<
0
)
{
offset
=
offset
-
2
;
offset
=
offset
-
2
;
line
.
concat
(
"JMP 2
%
n"
)
;
line
=
line
+
"JMP 2
\
n"
;
}
else
if
(
offset
==
0
)
{
}
else
if
(
offset
==
0
)
{
offset
=
offset
+
1
;
offset
=
offset
+
1
;
}
}
break
;
break
;
}
}
line
.
concat
(
opcode
)
;
line
=
line
+
opcode
;
int
x
;
int
x
;
for
(
x
=
0
;
x
<
numregs
;
x
++){
for
(
x
=
0
;
x
<
numregs
;
x
++){
line
.
concat
(
" R"
+
rg
.
nextInt
(
maxRegistry
)
)
;
line
=
line
+
" R"
+
rg
.
nextInt
(
maxRegistry
);
}
}
if
(
offset
!=
null
){
if
(
offset
!=
null
){
line
.
concat
(
" "
+
offset
)
;
line
=
line
+
" "
+
offset
;
}
}
return
line
;
return
line
;
}
}
...
...
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