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
55df7f97
Commit
55df7f97
authored
7 years ago
by
gpotter2
Browse files
Options
Downloads
Patches
Plain Diff
Fix overwritten imports
parent
359b0930
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
scapy/autorun.py
+6
-3
6 additions, 3 deletions
scapy/autorun.py
scapy/layers/all.py
+10
-3
10 additions, 3 deletions
scapy/layers/all.py
scapy/main.py
+11
-6
11 additions, 6 deletions
scapy/main.py
scapy/tools/UTscapy.py
+8
-7
8 additions, 7 deletions
scapy/tools/UTscapy.py
with
35 additions
and
19 deletions
scapy/autorun.py
+
6
−
3
View file @
55df7f97
...
...
@@ -7,7 +7,7 @@
Run commands when the Scapy interpreter starts.
"""
import
code
,
sys
import
code
,
sys
,
importlib
from
scapy.config
import
conf
from
scapy.themes
import
*
from
scapy.error
import
Scapy_Exception
...
...
@@ -36,13 +36,16 @@ class ScapyAutorunInterpreter(code.InteractiveInterpreter):
return
code
.
InteractiveInterpreter
.
showtraceback
(
self
,
*
args
,
**
kargs
)
def
autorun_commands
(
cmds
,
my_globals
=
None
,
verb
=
0
):
def
autorun_commands
(
cmds
,
my_globals
=
None
,
ignore_globals
=
None
,
verb
=
0
):
sv
=
conf
.
verb
import
__builtin__
try
:
try
:
if
my_globals
is
None
:
my_globals
=
__import__
(
"
scapy.all
"
).
all
.
__dict__
my_globals
=
importlib
.
import_module
(
"
.all
"
,
"
scapy
"
).
__dict__
if
ignore_globals
:
for
ig
in
ignore_globals
:
my_globals
.
pop
(
ig
,
None
)
conf
.
verb
=
verb
interp
=
ScapyAutorunInterpreter
(
my_globals
)
cmd
=
""
...
...
This diff is collapsed.
Click to expand it.
scapy/layers/all.py
+
10
−
3
View file @
55df7f97
...
...
@@ -7,15 +7,22 @@
All layers. Configurable with conf.load_layers.
"""
import
__builtin__
from
scapy.config
import
conf
from
scapy.error
import
log_loading
import
logging
import
logging
,
importlib
ignored
=
list
(
__builtin__
.
__dict__
.
keys
())
+
[
"
sys
"
]
log
=
logging
.
getLogger
(
"
scapy.loading
"
)
__all__
=
[]
def
_validate_local
(
x
):
global
ignored
return
x
[
0
]
!=
"
_
"
and
not
x
in
ignored
def
_import_star
(
m
):
mod
=
__import__
(
m
,
globals
(),
locals
()
)
mod
=
importlib
.
import_module
(
"
.
"
+
m
,
"
scapy.layers
"
)
if
'
__all__
'
in
mod
.
__dict__
:
# only import the exported symbols in __all__
for
name
in
mod
.
__dict__
[
'
__all__
'
]:
...
...
@@ -24,7 +31,7 @@ def _import_star(m):
else
:
# import all the non-private symbols
for
name
,
sym
in
mod
.
__dict__
.
iteritems
():
if
name
[
0
]
!=
'
_
'
:
if
_validate_local
(
name
)
:
__all__
.
append
(
name
)
globals
()[
name
]
=
sym
...
...
This diff is collapsed.
Click to expand it.
scapy/main.py
+
11
−
6
View file @
55df7f97
...
...
@@ -11,8 +11,10 @@ import os,sys
import
glob
import
types
import
gzip
import
importlib
import
cPickle
import
__builtin__
ignored
=
list
(
__builtin__
.
__dict__
.
keys
())
from
scapy.error
import
*
...
...
@@ -35,6 +37,9 @@ def _read_config_file(cf):
except
Exception
,
e
:
log_loading
.
exception
(
"
Error during evaluation of config file [%s]
"
%
cf
)
def
_validate_local
(
x
):
global
ignored
return
x
[
0
]
!=
"
_
"
and
not
x
in
ignored
DEFAULT_PRESTART_FILE
=
_probe_config_file
(
"
.scapy_prestart.py
"
)
DEFAULT_STARTUP_FILE
=
_probe_config_file
(
"
.scapy_startup.py
"
)
...
...
@@ -58,7 +63,7 @@ from scapy.themes import DefaultTheme
def
_load
(
module
):
try
:
mod
=
__
import_
_
(
module
,
globals
(),
locals
(),
"
.
"
)
mod
=
importlib
.
import_module
(
module
)
if
'
__all__
'
in
mod
.
__dict__
:
# import listed symbols
for
name
in
mod
.
__dict__
[
'
__all__
'
]:
...
...
@@ -66,7 +71,7 @@ def _load(module):
else
:
# only import non-private symbols
for
name
,
sym
in
mod
.
__dict__
.
iteritems
():
if
name
[
0
]
!=
'
_
'
:
if
_validate_local
(
name
)
:
__builtin__
.
__dict__
[
name
]
=
sym
except
Exception
,
e
:
log_interactive
.
error
(
e
)
...
...
@@ -79,7 +84,7 @@ def load_layer(name):
def
load_contrib
(
name
):
try
:
__
import_
_
(
"
scapy.contrib.
"
+
name
)
importlib
.
import_
module
(
"
scapy.contrib.
"
+
name
)
_load
(
"
scapy.contrib.
"
+
name
)
except
ImportError
:
# if layer not found in contrib, try in layers
...
...
@@ -180,11 +185,11 @@ def init_session(session_name, mydict=None):
global
session
global
globkeys
scapy_builtins
=
__
import_
_
(
"
all
"
,
globals
(),
locals
(),
"
.
"
).
__dict__
scapy_builtins
=
importlib
.
import_
module
(
"
.
all
"
,
"
scapy
"
).
__dict__
for
name
,
sym
in
scapy_builtins
.
iteritems
():
if
name
[
0
]
!=
'
_
'
:
if
_validate_local
(
name
)
:
__builtin__
.
__dict__
[
name
]
=
sym
globkeys
=
scapy_builtins
.
keys
()
globkeys
=
list
(
scapy_builtins
.
keys
()
)
globkeys
.
append
(
"
scapy_session
"
)
scapy_builtins
=
None
# XXX replace with "with" statement
if
mydict
is
not
None
:
...
...
This diff is collapsed.
Click to expand it.
scapy/tools/UTscapy.py
+
8
−
7
View file @
55df7f97
...
...
@@ -7,7 +7,7 @@
Unit testing infrastructure for Scapy
"""
import
sys
,
getopt
,
imp
,
glob
import
sys
,
getopt
,
imp
,
glob
,
importlib
import
bz2
,
base64
,
os
.
path
,
time
,
traceback
,
zlib
,
sha
from
scapy.consts
import
WINDOWS
...
...
@@ -355,17 +355,17 @@ def remove_empty_testsets(test_campaign):
#### RUN CAMPAIGN #####
def
run_campaign
(
test_campaign
,
get_interactive_session
,
verb
=
3
):
def
run_campaign
(
test_campaign
,
get_interactive_session
,
verb
=
3
,
ignore_globals
=
None
):
if
WINDOWS
:
# Add a route to 127.0.0.1 and ::1
from
scapy.arch.windows
import
route_add_loopback
route_add_loopback
()
passed
=
failed
=
0
if
test_campaign
.
preexec
:
test_campaign
.
preexec_output
=
get_interactive_session
(
test_campaign
.
preexec
.
strip
())[
0
]
test_campaign
.
preexec_output
=
get_interactive_session
(
test_campaign
.
preexec
.
strip
()
,
ignore_globals
=
ignore_globals
)[
0
]
for
testset
in
test_campaign
:
for
t
in
testset
:
t
.
output
,
res
=
get_interactive_session
(
t
.
test
.
strip
())
t
.
output
,
res
=
get_interactive_session
(
t
.
test
.
strip
()
,
ignore_globals
=
ignore_globals
)
the_res
=
False
try
:
if
res
is
None
or
res
:
...
...
@@ -607,7 +607,7 @@ def usage():
#### MAIN ####
def
execute_campaign
(
TESTFILE
,
OUTPUTFILE
,
PREEXEC
,
NUM
,
KW_OK
,
KW_KO
,
DUMP
,
FORMAT
,
VERB
,
ONLYFAILED
,
CRC
,
autorun_func
,
pos_begin
=
0
):
FORMAT
,
VERB
,
ONLYFAILED
,
CRC
,
autorun_func
,
pos_begin
=
0
,
ignore_globals
=
None
):
# Parse test file
test_campaign
=
parse_campaign_file
(
TESTFILE
)
...
...
@@ -637,7 +637,7 @@ def execute_campaign(TESTFILE, OUTPUTFILE, PREEXEC, NUM, KW_OK, KW_KO, DUMP,
# Run tests
test_campaign
.
output_file
=
OUTPUTFILE
result
=
run_campaign
(
test_campaign
,
autorun_func
[
FORMAT
],
verb
=
VERB
)
result
=
run_campaign
(
test_campaign
,
autorun_func
[
FORMAT
],
verb
=
VERB
,
ignore_globals
=
None
)
# Shrink passed
if
ONLYFAILED
:
...
...
@@ -672,6 +672,7 @@ def resolve_testfiles(TESTFILES):
def
main
(
argv
):
import
__builtin__
ignore_globals
=
list
(
__builtin__
.
__dict__
.
keys
())
+
[
"
sys
"
]
# Parse arguments
...
...
@@ -815,7 +816,7 @@ def main(argv):
output
,
result
,
campaign
=
execute_campaign
(
open
(
TESTFILE
),
OUTPUTFILE
,
PREEXEC
,
NUM
,
KW_OK
,
KW_KO
,
DUMP
,
FORMAT
,
VERB
,
ONLYFAILED
,
CRC
,
autorun_func
,
pos_begin
)
CRC
,
autorun_func
,
pos_begin
,
ignore_globals
)
runned_campaigns
.
append
(
campaign
)
pos_begin
=
campaign
.
end_pos
if
UNIQUE
:
...
...
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