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
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CodeLinaro
public-release-test-restored
platform
external
scapy
Commits
c41c2867
Commit
c41c2867
authored
7 years ago
by
gpotter2
Browse files
Options
Downloads
Patches
Plain Diff
Small improvements
parent
1998f2f6
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scapy/automaton.py
+1
-1
1 addition, 1 deletion
scapy/automaton.py
scapy/pipetool.py
+48
-36
48 additions, 36 deletions
scapy/pipetool.py
with
49 additions
and
37 deletions
scapy/automaton.py
+
1
−
1
View file @
c41c2867
...
...
@@ -335,7 +335,7 @@ def select_objects(inputs, remain, customTypes=()):
r
=
[]
def
look_for_select
():
for
fd
in
inputs
:
if
isinstance
(
fd
,
ObjectPipe
)
or
isinstance
(
fd
,
Automaton
.
_IO_fdwrapper
)
or
(
isinstance
(
fd
,
customTypes
)
)
:
if
isinstance
(
fd
,
(
ObjectPipe
,
Automaton
.
_IO_fdwrapper
)
+
customTypes
):
if
fd
.
checkRecv
():
r
.
append
(
fd
)
else
:
...
...
This diff is collapsed.
Click to expand it.
scapy/pipetool.py
+
48
−
36
View file @
c41c2867
...
...
@@ -62,6 +62,8 @@ class PipeEngine:
raise
AttributeError
(
attr
)
def
checkRecv
(
self
):
"""
As select.select is not available, we check if there
is some data to read by using a list that stores pointers.
"""
return
len
(
self
.
__fd_queue
)
>
0
def
fileno
(
self
):
...
...
@@ -493,46 +495,56 @@ class TermSink(Sink):
self
.
opened
=
False
if
self
.
openearly
:
self
.
start
()
def
start
(
self
):
def
_start_windows
(
self
):
if
not
self
.
opened
:
self
.
opened
=
True
if
WINDOWS
:
self
.
__f
=
get_temp_file
()
self
.
name
=
"
Scapy
"
if
self
.
name
is
None
else
self
.
name
# Start a powershell in a new window and print the PID
cmd
=
"
$app = Start-Process PowerShell -ArgumentList
'
-command &{$host.ui.RawUI.WindowTitle=
\\\"
%s
\\\"
;Get-Content
\\\"
%s
\\\"
-wait}
'
-passthru; echo $app.Id
"
%
(
self
.
name
,
self
.
__f
.
replace
(
"
\\
"
,
"
\\\\
"
))
print
([
conf
.
prog
.
powershell
,
cmd
])
_p
=
subprocess
.
Popen
([
conf
.
prog
.
powershell
,
cmd
],
stdout
=
subprocess
.
PIPE
)
_output
,
_stderr
=
_p
.
communicate
()
# This is the process PID
self
.
__p
=
int
(
_output
)
print
(
"
PID:
"
+
str
(
self
.
__p
))
else
:
self
.
__r
,
self
.
__w
=
os
.
pipe
()
cmd
=
[
"
xterm
"
]
if
self
.
name
is
not
None
:
cmd
.
extend
([
"
-title
"
,
self
.
name
])
if
self
.
keepterm
:
cmd
.
append
(
"
-hold
"
)
cmd
.
extend
([
"
-e
"
,
"
cat 0<&%i
"
%
self
.
__r
])
self
.
__p
=
subprocess
.
Popen
(
cmd
,
shell
=
True
,
executable
=
"
/bin/bash
"
)
os
.
close
(
self
.
__r
)
def
stop
(
self
):
self
.
__f
=
get_temp_file
()
self
.
name
=
"
Scapy
"
if
self
.
name
is
None
else
self
.
name
# Start a powershell in a new window and print the PID
cmd
=
"
$app = Start-Process PowerShell -ArgumentList
'
-command &{$host.ui.RawUI.WindowTitle=
\\\"
%s
\\\"
;Get-Content
\\\"
%s
\\\"
-wait}
'
-passthru; echo $app.Id
"
%
(
self
.
name
,
self
.
__f
.
replace
(
"
\\
"
,
"
\\\\
"
))
_p
=
subprocess
.
Popen
([
conf
.
prog
.
powershell
,
cmd
],
stdout
=
subprocess
.
PIPE
)
_output
,
_stderr
=
_p
.
communicate
()
# This is the process PID
self
.
__p
=
int
(
_output
)
print
(
"
PID:
"
+
str
(
self
.
__p
))
def
_start_unix
(
self
):
if
not
self
.
opened
:
self
.
opened
=
True
self
.
__r
,
self
.
__w
=
os
.
pipe
()
cmd
=
[
"
xterm
"
]
if
self
.
name
is
not
None
:
cmd
.
extend
([
"
-title
"
,
self
.
name
])
if
self
.
keepterm
:
cmd
.
append
(
"
-hold
"
)
cmd
.
extend
([
"
-e
"
,
"
cat 0<&%i
"
%
self
.
__r
])
self
.
__p
=
subprocess
.
Popen
(
cmd
,
shell
=
True
,
executable
=
"
/bin/bash
"
)
os
.
close
(
self
.
__r
)
def
start
(
self
):
if
WINDOWS
:
return
self
.
_start_windows
()
else
:
return
self
.
_start_unix
()
def
_stop_windows
(
self
):
if
not
self
.
keepterm
:
self
.
opened
=
False
if
not
WINDOWS
:
os
.
close
(
self
.
__w
)
self
.
__p
.
kill
()
self
.
__p
.
wait
()
else
:
# Recipe to kill process with PID
# http://code.activestate.com/recipes/347462-terminating-a-subprocess-on-windows/
import
ctypes
PROCESS_TERMINATE
=
1
handle
=
ctypes
.
windll
.
kernel32
.
OpenProcess
(
PROCESS_TERMINATE
,
False
,
self
.
__p
)
ctypes
.
windll
.
kernel32
.
TerminateProcess
(
handle
,
-
1
)
ctypes
.
windll
.
kernel32
.
CloseHandle
(
handle
)
# Recipe to kill process with PID
# http://code.activestate.com/recipes/347462-terminating-a-subprocess-on-windows/
import
ctypes
PROCESS_TERMINATE
=
1
handle
=
ctypes
.
windll
.
kernel32
.
OpenProcess
(
PROCESS_TERMINATE
,
False
,
self
.
__p
)
ctypes
.
windll
.
kernel32
.
TerminateProcess
(
handle
,
-
1
)
ctypes
.
windll
.
kernel32
.
CloseHandle
(
handle
)
def
_stop_unix
(
self
):
if
not
self
.
keepterm
:
self
.
opened
=
False
os
.
close
(
self
.
__w
)
self
.
__p
.
kill
()
self
.
__p
.
wait
()
def
stop
(
self
):
if
WINDOWS
:
return
self
.
_stop_windows
()
else
:
return
self
.
_stop_unix
()
def
_print
(
self
,
s
):
if
self
.
newlines
:
s
+=
"
\n
"
...
...
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