Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scapy
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor 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
CodeLinaro
public-release-test-restored
platform
external
scapy
Commits
e658e64c
Commit
e658e64c
authored
8 years ago
by
gpotter2
Committed by
Pierre Lalet
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[Windows/coverage] Fix and Support automaton (#496)
parent
59b16b45
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
appveyor.yml
+1
-1
1 addition, 1 deletion
appveyor.yml
scapy/automaton.py
+55
-18
55 additions, 18 deletions
scapy/automaton.py
test/regression.uts
+15
-5
15 additions, 5 deletions
test/regression.uts
test/run_tests.bat
+1
-1
1 addition, 1 deletion
test/run_tests.bat
with
72 additions
and
25 deletions
appveyor.yml
+
1
−
1
View file @
e658e64c
...
@@ -24,7 +24,7 @@ test_script:
...
@@ -24,7 +24,7 @@ test_script:
-
set PATH="%APPVEYOR_BUILD_FOLDER%;C:\Program Files\Wireshark\;%PATH%"
-
set PATH="%APPVEYOR_BUILD_FOLDER%;C:\Program Files\Wireshark\;%PATH%"
# Main unit tests
# Main unit tests
-
"
%PYTHON%
\\
python
-m
coverage
run
-a
bin
\\
UTscapy
-f
text
-t
test
\\
regression.uts
-F
-K
automaton
-K
mock_read_routes6_bsd
||
exit
/b
42"
-
"
%PYTHON%
\\
python
-m
coverage
run
-a
bin
\\
UTscapy
-f
text
-t
test
\\
regression.uts
-F
-K
mock_read_routes6_bsd
||
exit
/b
42"
-
'
del
test\regression.uts'
-
'
del
test\regression.uts'
# Secondary unit tests
# Secondary unit tests
...
...
This diff is collapsed.
Click to expand it.
scapy/automaton.py
+
55
−
18
View file @
e658e64c
...
@@ -10,13 +10,14 @@ Automata with states, transitions and actions.
...
@@ -10,13 +10,14 @@ Automata with states, transitions and actions.
import
types
,
itertools
,
time
,
os
,
sys
,
socket
,
traceback
import
types
,
itertools
,
time
,
os
,
sys
,
socket
,
traceback
from
select
import
select
from
select
import
select
from
collections
import
deque
from
collections
import
deque
import
thread
import
thread
ing
from
scapy.config
import
conf
from
scapy.config
import
conf
from
scapy.utils
import
do_graph
from
scapy.utils
import
do_graph
from
scapy.error
import
log_interactive
from
scapy.error
import
log_interactive
from
scapy.plist
import
PacketList
from
scapy.plist
import
PacketList
from
scapy.data
import
MTU
from
scapy.data
import
MTU
from
scapy.supersocket
import
SuperSocket
from
scapy.supersocket
import
SuperSocket
from
scapy.consts
import
WINDOWS
class
ObjectPipe
:
class
ObjectPipe
:
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -24,13 +25,18 @@ class ObjectPipe:
...
@@ -24,13 +25,18 @@ class ObjectPipe:
self
.
queue
=
deque
()
self
.
queue
=
deque
()
def
fileno
(
self
):
def
fileno
(
self
):
return
self
.
rd
return
self
.
rd
def
checkRecv
(
self
):
return
len
(
self
.
queue
)
!=
0
def
send
(
self
,
obj
):
def
send
(
self
,
obj
):
self
.
queue
.
append
(
obj
)
self
.
queue
.
append
(
obj
)
os
.
write
(
self
.
wr
,
"
X
"
)
os
.
write
(
self
.
wr
,
"
X
"
)
def
write
(
self
,
obj
):
self
.
send
(
obj
)
def
recv
(
self
,
n
=
0
):
def
recv
(
self
,
n
=
0
):
os
.
read
(
self
.
rd
,
1
)
os
.
read
(
self
.
rd
,
1
)
return
self
.
queue
.
popleft
()
return
self
.
queue
.
popleft
()
def
read
(
self
,
n
=
0
):
return
self
.
recv
(
n
)
class
Message
:
class
Message
:
def
__init__
(
self
,
**
args
):
def
__init__
(
self
,
**
args
):
...
@@ -319,7 +325,25 @@ class Automaton_metaclass(type):
...
@@ -319,7 +325,25 @@ class Automaton_metaclass(type):
s
+=
"
}
\n
"
s
+=
"
}
\n
"
return
do_graph
(
s
,
**
kargs
)
return
do_graph
(
s
,
**
kargs
)
def
select_objects
(
inputs
,
remain
):
if
WINDOWS
:
r
=
[]
def
search_select
():
while
len
(
r
)
==
0
:
for
fd
in
inputs
:
if
isinstance
(
fd
,
ObjectPipe
)
or
isinstance
(
fd
,
Automaton
.
_IO_fdwrapper
):
if
fd
.
checkRecv
():
r
.
append
(
fd
)
else
:
raise
OSError
(
"
Not supported type of socket:
"
+
str
(
type
(
fd
)))
break
t_select
=
threading
.
Thread
(
target
=
search_select
)
t_select
.
start
()
t_select
.
join
(
remain
)
return
r
else
:
r
,
_
,
_
=
select
(
inputs
,[],[],
remain
)
return
r
class
Automaton
:
class
Automaton
:
__metaclass__
=
Automaton_metaclass
__metaclass__
=
Automaton_metaclass
...
@@ -340,6 +364,13 @@ class Automaton:
...
@@ -340,6 +364,13 @@ class Automaton:
## Utility classes and exceptions
## Utility classes and exceptions
class
_IO_fdwrapper
:
class
_IO_fdwrapper
:
def
__init__
(
self
,
rd
,
wr
):
def
__init__
(
self
,
rd
,
wr
):
if
WINDOWS
:
# rd will be used for reading and sending
if
isinstance
(
rd
,
ObjectPipe
):
self
.
rd
=
rd
else
:
raise
OSError
(
"
On windows, only instances of ObjectPipe are externally available
"
)
else
:
if
rd
is
not
None
and
type
(
rd
)
is
not
int
:
if
rd
is
not
None
and
type
(
rd
)
is
not
int
:
rd
=
rd
.
fileno
()
rd
=
rd
.
fileno
()
if
wr
is
not
None
and
type
(
wr
)
is
not
int
:
if
wr
is
not
None
and
type
(
wr
)
is
not
int
:
...
@@ -348,9 +379,15 @@ class Automaton:
...
@@ -348,9 +379,15 @@ class Automaton:
self
.
wr
=
wr
self
.
wr
=
wr
def
fileno
(
self
):
def
fileno
(
self
):
return
self
.
rd
return
self
.
rd
def
checkRecv
(
self
):
return
self
.
rd
.
checkRecv
()
def
read
(
self
,
n
=
65535
):
def
read
(
self
,
n
=
65535
):
if
WINDOWS
:
return
self
.
rd
.
recv
(
n
)
return
os
.
read
(
self
.
rd
,
n
)
return
os
.
read
(
self
.
rd
,
n
)
def
write
(
self
,
msg
):
def
write
(
self
,
msg
):
if
WINDOWS
:
return
self
.
rd
.
send
(
msg
)
return
os
.
write
(
self
.
wr
,
msg
)
return
os
.
write
(
self
.
wr
,
msg
)
def
recv
(
self
,
n
=
65535
):
def
recv
(
self
,
n
=
65535
):
return
self
.
read
(
n
)
return
self
.
read
(
n
)
...
@@ -368,11 +405,11 @@ class Automaton:
...
@@ -368,11 +405,11 @@ class Automaton:
def
recv
(
self
,
n
=
None
):
def
recv
(
self
,
n
=
None
):
return
self
.
rd
.
recv
(
n
)
return
self
.
rd
.
recv
(
n
)
def
read
(
self
,
n
=
None
):
def
read
(
self
,
n
=
None
):
return
self
.
rd
.
recv
(
n
)
return
self
.
recv
(
n
)
def
send
(
self
,
msg
):
def
send
(
self
,
msg
):
return
self
.
wr
.
send
(
msg
)
return
self
.
wr
.
send
(
msg
)
def
write
(
self
,
msg
):
def
write
(
self
,
msg
):
return
self
.
wr
.
send
(
msg
)
return
self
.
send
(
msg
)
class
AutomatonException
(
Exception
):
class
AutomatonException
(
Exception
):
...
@@ -438,7 +475,7 @@ class Automaton:
...
@@ -438,7 +475,7 @@ class Automaton:
external_fd
=
kargs
.
pop
(
"
external_fd
"
,{})
external_fd
=
kargs
.
pop
(
"
external_fd
"
,{})
self
.
send_sock_class
=
kargs
.
pop
(
"
ll
"
,
conf
.
L3socket
)
self
.
send_sock_class
=
kargs
.
pop
(
"
ll
"
,
conf
.
L3socket
)
self
.
recv_sock_class
=
kargs
.
pop
(
"
recvsock
"
,
conf
.
L2listen
)
self
.
recv_sock_class
=
kargs
.
pop
(
"
recvsock
"
,
conf
.
L2listen
)
self
.
started
=
thread
.
allocate_l
ock
()
self
.
started
=
thread
ing
.
L
ock
()
self
.
threadid
=
None
self
.
threadid
=
None
self
.
breakpointed
=
None
self
.
breakpointed
=
None
self
.
breakpoints
=
set
()
self
.
breakpoints
=
set
()
...
@@ -457,6 +494,8 @@ class Automaton:
...
@@ -457,6 +494,8 @@ class Automaton:
extfd
=
external_fd
.
get
(
n
)
extfd
=
external_fd
.
get
(
n
)
if
type
(
extfd
)
is
not
tuple
:
if
type
(
extfd
)
is
not
tuple
:
extfd
=
(
extfd
,
extfd
)
extfd
=
(
extfd
,
extfd
)
elif
WINDOWS
:
raise
OSError
(
"
Tuples are not allowed as external_fd on windows
"
)
ioin
,
ioout
=
extfd
ioin
,
ioout
=
extfd
if
ioin
is
None
:
if
ioin
is
None
:
ioin
=
ObjectPipe
()
ioin
=
ObjectPipe
()
...
@@ -508,13 +547,11 @@ class Automaton:
...
@@ -508,13 +547,11 @@ class Automaton:
self
.
debug
(
2
,
"
%s [%s] not taken
"
%
(
cond
.
atmt_type
,
cond
.
atmt_condname
))
self
.
debug
(
2
,
"
%s [%s] not taken
"
%
(
cond
.
atmt_type
,
cond
.
atmt_condname
))
def
_do_start
(
self
,
*
args
,
**
kargs
):
def
_do_start
(
self
,
*
args
,
**
kargs
):
threading
.
Thread
(
target
=
self
.
_do_control
,
args
=
(
args
),
kwargs
=
kargs
).
start
()
thread
.
start_new_thread
(
self
.
_do_control
,
args
,
kargs
)
def
_do_control
(
self
,
*
args
,
**
kargs
):
def
_do_control
(
self
,
*
args
,
**
kargs
):
with
self
.
started
:
with
self
.
started
:
self
.
threadid
=
thread
.
get_
ident
()
self
.
threadid
=
thread
ing
.
currentThread
().
ident
# Update default parameters
# Update default parameters
a
=
args
+
self
.
init_args
[
len
(
args
):]
a
=
args
+
self
.
init_args
[
len
(
args
):]
...
@@ -622,7 +659,7 @@ class Automaton:
...
@@ -622,7 +659,7 @@ class Automaton:
remain
=
next_timeout
-
t
remain
=
next_timeout
-
t
self
.
debug
(
5
,
"
Select on %r
"
%
fds
)
self
.
debug
(
5
,
"
Select on %r
"
%
fds
)
r
,
_
,
_
=
select
(
fds
,[],[],
remain
)
r
=
select
_objects
(
fds
,
remain
)
self
.
debug
(
5
,
"
Selected %r
"
%
r
)
self
.
debug
(
5
,
"
Selected %r
"
%
r
)
for
fd
in
r
:
for
fd
in
r
:
self
.
debug
(
5
,
"
Looking at %r
"
%
fd
)
self
.
debug
(
5
,
"
Looking at %r
"
%
fd
)
...
@@ -709,7 +746,7 @@ class Automaton:
...
@@ -709,7 +746,7 @@ class Automaton:
with
self
.
started
:
with
self
.
started
:
# Flush command pipes
# Flush command pipes
while
True
:
while
True
:
r
,
_
,
_
=
select
([
self
.
cmdin
,
self
.
cmdout
],
[],[],
0
)
r
=
select
_objects
([
self
.
cmdin
,
self
.
cmdout
],
0
)
if
not
r
:
if
not
r
:
break
break
for
fd
in
r
:
for
fd
in
r
:
...
...
This diff is collapsed.
Click to expand it.
test/regression.uts
+
15
−
5
View file @
e658e64c
...
@@ -858,19 +858,29 @@ class ATMT8(Automaton):
...
@@ -858,19 +858,29 @@ class ATMT8(Automaton):
self.res += "s"
self.res += "s"
return self.res
return self.res
if WINDOWS:
r = w = ObjectPipe()
else:
r,w = os.pipe()
r,w = os.pipe()
def writeOn(w, msg):
if WINDOWS:
w.write(msg)
else:
os.write(w, msg)
a=ATMT8(external_fd={"extfd":r}, ll=lambda: None, recvsock=lambda: None)
a=ATMT8(external_fd={"extfd":r}, ll=lambda: None, recvsock=lambda: None)
a.run(wait=False)
a.run(wait=False)
os.write(w,"ra")
writeOn(w,"ra")
os.write(w,"nu")
writeOn(w,"nu")
a.run()
a.run()
assert( _ == "Uranus" )
assert( _ == "Uranus" )
a.restart()
a.restart()
a.run(wait=False)
a.run(wait=False)
os.
write(w,"ra")
write
On
(w,"ra")
os.
write(w,"nu")
write
On
(w,"nu")
a.run()
a.run()
assert( _ == "Uranus" )
assert( _ == "Uranus" )
...
...
This diff is collapsed.
Click to expand it.
test/run_tests.bat
+
1
−
1
View file @
e658e64c
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
set
MYDIR
=
%cd%
\..
set
MYDIR
=
%cd%
\..
set
PYTHONPATH
=
%MYDIR%
set
PYTHONPATH
=
%MYDIR%
if
[
%
1
]==[]
(
if
[
%
1
]==[]
(
python
"
%MYDIR%
\scapy\tools\UTscapy.py"
-t
regression
.uts
-K
automaton
-K
mock_read_routes6_bsd
-f
html
-o
scapy_regression_test_
%date
:
~
6
,
4
%_%
date
:
~
3
,
2
%_%
date
:
~
0
,
2
%
.html
python
"
%MYDIR%
\scapy\tools\UTscapy.py"
-t
regression
.uts
-K
mock_read_routes6_bsd
-f
html
-o
scapy_regression_test_
%date
:
~
6
,
4
%_%
date
:
~
3
,
2
%_%
date
:
~
0
,
2
%
.html
)
else
(
)
else
(
python
"
%MYDIR%
\scapy\tools\UTscapy.py"
%
@
python
"
%MYDIR%
\scapy\tools\UTscapy.py"
%
@
)
)
...
...
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