Skip to content

Conversation

@gpotter2
Copy link
Member

@gpotter2 gpotter2 commented Jun 4, 2017

Here's the most boring part of it. That should bring neally all bytes support for the core. Contribution files will be changed later.

This PR:

  • introduces some util functions in scapy.compat.py that works on both python 2 and 3:
    -- raw(x) : returns the byte form of a string/packet/int/list of ints
    -- plain_str(x) : does exactly the opposite: bytes/int ==> str
    -- hex_bytes / bytes_hex ==> converts hex => bytes or bytes => hex
  • Remove stupid BGP bug in a test: None ==> "None" ==> "\x04". Fixed by using raw

@codecov-io
Copy link

codecov-io commented Jun 4, 2017

Codecov Report

Merging #674 into master will increase coverage by 0.01%.
The diff coverage is 80.81%.

@@            Coverage Diff             @@
##           master     #674      +/-   ##
==========================================
+ Coverage   80.69%   80.71%   +0.01%     
==========================================
  Files         137      137              
  Lines       33903    34005     +102     
==========================================
+ Hits        27357    27446      +89     
- Misses       6546     6559      +13
Impacted Files Coverage Δ
scapy/layers/all.py 83.33% <0%> (-4.91%) ⬇️
scapy/asn1/mib.py 78.47% <100%> (+0.15%) ⬆️
scapy/layers/vrrp.py 84.09% <100%> (+0.36%) ⬆️
scapy/arch/common.py 100% <100%> (ø) ⬆️
scapy/layers/tls/crypto/h_mac.py 92.06% <100%> (+0.12%) ⬆️
scapy/pton_ntop.py 97.26% <100%> (+0.2%) ⬆️
scapy/layers/tls/crypto/pkcs1.py 73.48% <100%> (+0.2%) ⬆️
scapy/dadict.py 98.71% <100%> (+0.01%) ⬆️
scapy/modules/nmap.py 97.01% <100%> (+0.04%) ⬆️
scapy/arch/__init__.py 90% <100%> (ø) ⬆️
... and 40 more

@gpotter2 gpotter2 force-pushed the fix-str-bytes branch 3 times, most recently from a14e143 to fa5c364 Compare June 27, 2017 20:31
@gpotter2 gpotter2 force-pushed the fix-str-bytes branch 2 times, most recently from 961e207 to c63a39a Compare June 28, 2017 09:52
@gpotter2 gpotter2 force-pushed the fix-str-bytes branch 9 times, most recently from 87b0e92 to dd1db1e Compare June 29, 2017 11:19
@gpotter2
Copy link
Member Author

@p-l- @guedou Calling for review.

@gpotter2 gpotter2 closed this Jun 29, 2017
@gpotter2 gpotter2 reopened this Jun 29, 2017
@gpotter2 gpotter2 force-pushed the fix-str-bytes branch 2 times, most recently from 4411665 to 718e2c2 Compare June 29, 2017 16:17
@gpotter2
Copy link
Member Author

gpotter2 commented Jun 29, 2017

Ok I'm now able to boot scapy using python 3 (windows and ubuntu)... Tons of stuff must be broken though...

@gpotter2 gpotter2 force-pushed the fix-str-bytes branch 3 times, most recently from ad6dbfd to 1abf6ea Compare July 8, 2017 20:37
@gpotter2
Copy link
Member Author

gpotter2 commented Jul 8, 2017

Rebased (apply mtury's work).

@gpotter2
Copy link
Member Author

gpotter2 commented Aug 24, 2017

Status update:

  • Squashed and rebased
  • Removed many raw() unneeded
  • Some raw() are important: when raw bytes want to be converted from str to bytes, it's required to use raw() (non-ascii str)

@gpotter2 gpotter2 force-pushed the fix-str-bytes branch 5 times, most recently from 66f503c to 85d171d Compare August 25, 2017 09:57
@guedou
Copy link
Member

guedou commented Aug 25, 2017

@gpotter2 don't forget to update the title when it its ready to be reviewed =)

@gpotter2 gpotter2 changed the title [WIP DO NOT MERGE] [Python 2 to 3] Bytes fixes [Python 2 to 3] Bytes fixes Aug 25, 2017
@gpotter2 gpotter2 force-pushed the fix-str-bytes branch 2 times, most recently from 7ac2994 to 81b8c9a Compare August 27, 2017 19:13
@gpotter2
Copy link
Member Author

@guedou @p-l- Ready to be reviewed

@gpotter2 gpotter2 force-pushed the fix-str-bytes branch 5 times, most recently from 545adc4 to 5354974 Compare August 30, 2017 10:21
@gpotter2
Copy link
Member Author

I've added python 3 launchers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really needed ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, nice catch

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the new indentation needed ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the change log is a bit messy but the code is

if six.PY2:
    def crc32(x):
        return "%08X" % (0xffffffff & zlib.crc32(x))

    def sha1(x):
         return hashlib.sha1(x).hexdigest().upper()
else:
    def crc32(x):
        return "%08X" % (0xffffffff & zlib.crc32(bytearray(x, "utf8")))

    def sha1(x):
        return hashlib.sha1(x.encode("utf8")).hexdigest().upper()

@guedou
Copy link
Member

guedou commented Aug 31, 2017

It looks good to me !

@gpotter2 gpotter2 force-pushed the fix-str-bytes branch 2 times, most recently from fc2a438 to 5e88574 Compare September 2, 2017 00:01
@p-l- p-l- merged commit 1d057bf into secdev:master Sep 14, 2017
@gpotter2 gpotter2 deleted the fix-str-bytes branch September 14, 2017 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants