Skip to content

Commit d1115ca

Browse files
gg-gvaladonguedou
authored andcommitted
Object saving/loading removed
1 parent 29d7360 commit d1115ca

File tree

3 files changed

+3
-87
lines changed

3 files changed

+3
-87
lines changed

doc/scapy/usage.rst

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -991,41 +991,6 @@ We can reimport the produced binary string by selecting the appropriate first la
991991
\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e
992992
\x1f !"#$%&\'()*+,-./01234567' |>>>>
993993

994-
Base64
995-
^^^^^^
996-
997-
Using the ``export_object()`` function, Scapy can export a base64 encoded Python data structure representing a packet::
998-
999-
>>> pkt
1000-
<Ether dst=00:50:56:fc:ce:50 src=00:0c:29:2b:53:19 type=0x800 |<IP version=4L
1001-
ihl=5L tos=0x0 len=84 id=0 flags=DF frag=0L ttl=64 proto=icmp chksum=0x5a7c
1002-
src=192.168.25.130 dst=4.2.2.1 options='' |<ICMP type=echo-request code=0
1003-
chksum=0x9c90 id=0x5a61 seq=0x1 |<Raw load='\xe6\xdapI\xb6\xe5\x08\x00\x08\t\n
1004-
\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f
1005-
!"#$%&\'()*+,-./01234567' |>>>>
1006-
>>> export_object(pkt)
1007-
eNplVwd4FNcRPt2dTqdTQ0JUUYwN+CgS0gkJONFEs5WxFDB+CdiI8+pupVl0d7uzRUiYtcEGG4ST
1008-
OD1OnB6nN6c4cXrvwQmk2U5xA9tgO70XMm+1rA78qdzbfTP/lDfzz7tD4WwmU1C0YiaT2Gqjaiao
1009-
bMlhCrsUSYrYoKbmcxZFXSpPiohlZikm6ltb063ZdGpNOjWQ7mhPt62hChHJWTbFvb0O/u1MD2bT
1010-
WZXXVCmi9pihUqI3FHdEQslriiVfWFTVT9VYpog6Q7fsjG0qRWtQNwsW1fRTrUg4xZxq5pUx1aS6
1011-
...
1012-
1013-
The output above can be reimported back into Scapy using ``import_object()``::
1014-
1015-
>>> new_pkt = import_object()
1016-
eNplVwd4FNcRPt2dTqdTQ0JUUYwN+CgS0gkJONFEs5WxFDB+CdiI8+pupVl0d7uzRUiYtcEGG4ST
1017-
OD1OnB6nN6c4cXrvwQmk2U5xA9tgO70XMm+1rA78qdzbfTP/lDfzz7tD4WwmU1C0YiaT2Gqjaiao
1018-
bMlhCrsUSYrYoKbmcxZFXSpPiohlZikm6ltb063ZdGpNOjWQ7mhPt62hChHJWTbFvb0O/u1MD2bT
1019-
WZXXVCmi9pihUqI3FHdEQslriiVfWFTVT9VYpog6Q7fsjG0qRWtQNwsW1fRTrUg4xZxq5pUx1aS6
1020-
...
1021-
>>> new_pkt
1022-
<Ether dst=00:50:56:fc:ce:50 src=00:0c:29:2b:53:19 type=0x800 |<IP version=4L
1023-
ihl=5L tos=0x0 len=84 id=0 flags=DF frag=0L ttl=64 proto=icmp chksum=0x5a7c
1024-
src=192.168.25.130 dst=4.2.2.1 options='' |<ICMP type=echo-request code=0
1025-
chksum=0x9c90 id=0x5a61 seq=0x1 |<Raw load='\xe6\xdapI\xb6\xe5\x08\x00\x08\t\n
1026-
\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f
1027-
!"#$%&\'()*+,-./01234567' |>>>>
1028-
1029994
Sessions
1030995
^^^^^^^^
1031996

scapy/utils.py

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import argparse
1717
import array
18-
import base64
1918
import collections
2019
import decimal
2120
import difflib
@@ -25,7 +24,6 @@
2524
import locale
2625
import math
2726
import os
28-
import pickle
2927
import random
3028
import re
3129
import shutil
@@ -1221,39 +1219,9 @@ def __repr__(self):
12211219
return "<%s>" % self.__dict__.get("name", self.__name__)
12221220

12231221

1224-
###################
1225-
# Object saving #
1226-
###################
1227-
1228-
1229-
def export_object(obj):
1230-
# type: (Any) -> None
1231-
import zlib
1232-
print(base64.b64encode(zlib.compress(pickle.dumps(obj, 2), 9)).decode())
1233-
1234-
1235-
def import_object(obj=None):
1236-
# type: (Optional[str]) -> Any
1237-
import zlib
1238-
if obj is None:
1239-
obj = sys.stdin.read()
1240-
return pickle.loads(zlib.decompress(base64.b64decode(obj.strip())))
1241-
1242-
1243-
def save_object(fname, obj):
1244-
# type: (str, Any) -> None
1245-
"""Pickle a Python object"""
1246-
1247-
fd = gzip.open(fname, "wb")
1248-
pickle.dump(obj, fd)
1249-
fd.close()
1250-
1251-
1252-
def load_object(fname):
1253-
# type: (str) -> Any
1254-
"""unpickle a Python object"""
1255-
return pickle.load(gzip.open(fname, "rb"))
1256-
1222+
##################
1223+
# Corrupt data #
1224+
##################
12571225

12581226
@conf.commands.register
12591227
def corrupt_bytes(data, p=0.01, n=None):

test/regression.uts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -993,17 +993,6 @@ zerofree_randstring(4) in [b"\xd2\x12\xe4\x5b", b'\xd3\x8b\x13\x12']
993993
= Test strand function
994994
assert strand(b"AC", b"BC") == b'@C'
995995

996-
= Test export_object and import_object functions
997-
from unittest import mock
998-
def test_export_import_object():
999-
with ContextManagerCaptureOutput() as cmco:
1000-
export_object(2807)
1001-
result_export_object = cmco.get_output(eval_bytes=True)
1002-
assert result_export_object.startswith("eNprYPL9zqUHAAdrAf8=")
1003-
assert import_object(result_export_object) == 2807
1004-
1005-
test_export_import_object()
1006-
1007996
= Test tex_escape function
1008997
tex_escape("$#_") == "\\$\\#\\_"
1009998

@@ -1024,12 +1013,6 @@ assert sane(corrupt_bytes("ABCDE", n=3)) in ["A.8D4", ".2.DE"]
10241013
assert corrupt_bits("ABCDE") in [b"EBCDE", b"ABCDG"]
10251014
assert sane(corrupt_bits("ABCDE", n=3)) in ["AF.EE", "QB.TE"]
10261015

1027-
= Test save_object and load_object functions
1028-
import tempfile
1029-
fd, fname = tempfile.mkstemp()
1030-
save_object(fname, 2807)
1031-
assert load_object(fname) == 2807
1032-
10331016
= Test whois function
10341017
~ netaccess
10351018

0 commit comments

Comments
 (0)