Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fuzzBackEnd
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钱炳权
fuzzBackEnd
Commits
356c9ddd
Commit
356c9ddd
authored
Apr 22, 2024
by
钱炳权
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enhance code robustness
parent
df2e1715
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
10 deletions
+31
-10
spring.log
fuzzbackend/log/spring.log
+0
-0
TestControler.java
...va/com/example/fuzzControll/controller/TestControler.java
+6
-3
TestServiceImpl.java
...om/example/fuzzControll/service/impl/TestServiceImpl.java
+3
-0
CmdTools.java
...rc/main/java/com/example/fuzzControll/tools/CmdTools.java
+22
-7
No files found.
fuzzbackend/log/spring.log
View file @
356c9ddd
This diff is collapsed.
Click to expand it.
fuzzbackend/src/main/java/com/example/fuzzControll/controller/TestControler.java
View file @
356c9ddd
package
com
.
example
.
fuzzControll
.
controller
;
import
com.example.fuzzControll.exception.AflnetException
;
import
com.example.fuzzControll.pojo.vo.AjaxResult
;
import
com.example.fuzzControll.pojo.vo.CmdStartParams
;
import
com.example.fuzzControll.service.TestService
;
...
...
@@ -28,14 +29,15 @@ public class TestControler {
@RequestMapping
(
value
=
"/testStart"
,
method
=
RequestMethod
.
POST
)
public
AjaxResult
list
(
@RequestBody
final
CmdStartParams
cmdStartParams
)
{
try
{
//todo 加个同步锁,执行到特征点就返回数据
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
service
.
testStart
(
cmdStartParams
);
}
}).
start
();
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
());
}
catch
(
Aflnet
Exception
e
)
{
log
.
error
(
e
.
get
Default
Message
());
return
AjaxResult
.
error
(
"测试启动失败!"
);
}
return
AjaxResult
.
success
(
"测试启动成功!"
);
...
...
@@ -48,7 +50,8 @@ public class TestControler {
public
AjaxResult
testStop
()
{
try
{
service
.
testStop
();
}
catch
(
Exception
e
)
{
}
catch
(
AflnetException
e
)
{
log
.
error
(
e
.
getDefaultMessage
());
return
AjaxResult
.
error
(
"测试停止失败!"
);
}
return
AjaxResult
.
success
(
"测试停止成功!"
);
...
...
fuzzbackend/src/main/java/com/example/fuzzControll/service/impl/TestServiceImpl.java
View file @
356c9ddd
...
...
@@ -9,9 +9,11 @@ import com.example.fuzzControll.pojo.vo.CmdStartParams;
import
com.example.fuzzControll.service.TestService
;
import
com.example.fuzzControll.tools.CmdTools
;
import
com.example.fuzzControll.tools.TestControlTools
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
@Service
(
"testService"
)
@Slf4j
public
class
TestServiceImpl
implements
TestService
{
KittyProperties
kittyProperties
=
(
KittyProperties
)
SpringContextUtil
.
getBean
(
"kittyProperties"
);
...
...
@@ -30,5 +32,6 @@ public class TestServiceImpl implements TestService {
@Override
public
void
testStop
()
{
TestControlTools
.
setIsRunning
(
false
);
log
.
info
(
"Aflnet has been stopped ! "
);
}
}
fuzzbackend/src/main/java/com/example/fuzzControll/tools/CmdTools.java
View file @
356c9ddd
...
...
@@ -20,11 +20,12 @@ import java.util.*;
public
class
CmdTools
{
Boolean
send
=
false
;
WebSocket
socket
=
(
WebSocket
)
SpringContextUtil
.
getBean
(
"WebSocket"
);
Boolean
show
=
true
;
/**
* 运行不需要后台运行cmd
*/
public
List
<
String
>
runCmd
(
String
cmd
,
String
caller
)
throws
CmdException
{
public
List
<
String
>
runCmd
(
String
cmd
,
String
caller
)
throws
CmdException
{
List
<
String
>
result
=
new
ArrayList
<
String
>();
try
{
Process
process
=
Runtime
.
getRuntime
().
exec
(
cmd
);
...
...
@@ -33,7 +34,7 @@ public class CmdTools {
process
.
waitFor
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
CmdException
(
caller
+
" run cmd failed!"
);
throw
new
CmdException
(
caller
+
" run cmd failed!"
);
}
return
result
;
...
...
@@ -45,14 +46,16 @@ public class CmdTools {
* 运行需要后台运行cmd
* 通过websocket返回数据
*/
public
void
runProgramCmd
(
String
cmd
)
{
public
void
runProgramCmd
(
String
cmd
)
throws
AflnetException
{
try
{
Process
process
=
Runtime
.
getRuntime
().
exec
(
cmd
);
printMessageToWeb
(
process
.
getInputStream
()
,
process
);
printMessageToWeb
(
process
.
getInputStream
());
printMessage
(
process
.
getErrorStream
(),
new
ArrayList
<
String
>());
process
.
waitFor
();
log
.
info
(
"Aflnet cmd have been run."
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
AflnetException
(
"Aflnet run error"
);
}
}
...
...
@@ -118,7 +121,8 @@ public class CmdTools {
return
result
;
}
private
void
printMessageToWeb
(
final
InputStream
input
,
Process
process
)
throws
IOException
{
private
void
printMessageToWeb
(
final
InputStream
input
)
throws
IOException
,
AflnetException
{
show
=
true
;
Reader
reader
=
new
InputStreamReader
(
input
);
BufferedReader
bf
=
new
BufferedReader
(
reader
);
String
line
=
null
;
...
...
@@ -127,12 +131,23 @@ public class CmdTools {
makeReturnEntity
(
line
,
returnEntity
);
if
(
send
)
{
String
data
=
JSONObject
.
toJSONString
(
returnEntity
);
try
{
socket
.
appointSending
(
"backend"
,
"web"
,
data
);
}
catch
(
Exception
ignored
)
{
}
}
}
}
private
TestReturnEntity
makeReturnEntity
(
String
line
,
TestReturnEntity
returnEntity
)
{
if
(
line
.
contains
(
"All set and ready to roll!"
)
||
line
.
contains
(
"american fuzzy"
)
||
line
.
contains
(
"process timing overall results"
))
{
show
=
false
;
}
else
if
(
line
.
contains
(
"PROGRAM ABORT"
))
{
throw
new
AflnetException
(
"Aflnet run failed !"
);
}
if
(
show
)
{
log
.
info
(
line
);
}
if
(
line
.
contains
(
"run time"
))
{
send
=
false
;
int
run_time
=
line
.
indexOf
(
":"
);
...
...
@@ -222,8 +237,8 @@ public class CmdTools {
return
returnEntity
;
}
public
String
parse
(
CmdStartParams
cmdStartParams
)
throws
AflnetException
{
if
(
cmdStartParams
==
null
)
{
public
String
parse
(
CmdStartParams
cmdStartParams
)
throws
AflnetException
{
if
(
cmdStartParams
==
null
)
{
throw
new
AflnetException
(
"CmdStartParams is null!"
);
}
StringBuilder
cmd
=
new
StringBuilder
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment