Skip to content

Improved hexdump output #1094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 25, 2018
Merged

Improved hexdump output #1094

merged 4 commits into from
Jan 25, 2018

Conversation

dimos
Copy link
Contributor

@dimos dimos commented Jan 11, 2018

I refactored some code of hexdump_iter function.
The output is now better and also added the group size option.

Before

>>> print hexdump('A'*20)
00000000  41 41 41 41  41 41 41 41  41 41 41 41  41 41 41 41  │AAAA│AAAA│AAAA│AAAA│
00000010  41 41 41 41                                         │AAAA││
00000014
>>> 
>>> s = 'A'*9 + '\x00'+'B'
>>> print hexdump(s, width=8)
00000000  41 41 41 41  41 41 41 41   │AAAA│AAAA│
00000008  41 00 42                  │A·B│
0000000b
>>> print hexdump('A' + s, width=8)
00000000  41 41 41 41  41 41 41 41   │AAAA│AAAA│
00000008  41 41 00 42               │AA·B││
0000000c
>>> 
>>> print hexdump('ABCDEFGH', width=2)
00000000  41 42    │AB│
00000002  43 44    │CD│
00000004  45 46    │EF│
00000006  47 48    │GH│
00000008

After

>>> print hexdump('A'*20)
00000000  41 41 41 41  41 41 41 41  41 41 41 41  41 41 41 41  │AAAA│AAAA│AAAA│AAAA│
00000010  41 41 41 41                                         │AAAA│
00000014
>>> 
>>> s = 'A'*9 + '\x00'+'B'
>>> print hexdump(s, width=8)
00000000  41 41 41 41  41 41 41 41  │AAAA│AAAA│
00000008  41 00 42                  │A·B│
0000000b
>>> print hexdump('A' + s, width=8)
00000000  41 41 41 41  41 41 41 41  │AAAA│AAAA│
00000008  41 41 00 42               │AA·B│
0000000c
>>> 
>>> print hexdump('ABCDEFGH', width=2)
00000000  41 42  │AB│
00000002  43 44  │CD│
00000004  45 46  │EF│
00000006  47 48  │GH│
00000008
>>> 
>>> s = 'A'*8 + 'B'*8 + 'C'*8
>>> print hexdump(s, width=16, groupsize=8)
00000000  41 41 41 41 41 41 41 41  42 42 42 42 42 42 42 42  │AAAAAAAA│BBBBBBBB│
00000010  43 43 43 43 43 43 43 43                           │CCCCCCCC│
00000018
>>> 
>>> s = 'A'*10 + '\x00'+'B'*4
>>> print hexdump(s, width=9, groupsize=3)
00000000  41 41 41  41 41 41  41 41 41  │AAA│AAA│AAA│
00000009  41 00 42  42 42 42            │A·B│BBB│
0000000f
>>> 
>>> with open('/dev/urandom', 'r') as f:
...     print hexdump(f.read(8*16), groupsize=-1)
... 
00000000  91 e7 7b d9 99 64 ae 97 be 6a 19 02 a8 31 fb 62  │··{··d···j···1·b│
00000010  24 e2 ad 57 4b a0 a7 a3 05 14 7c 64 80 a7 c1 43  │$··WK·····|d···C│
00000020  5a b2 d7 20 bb 2d 0f e0 68 93 fb 76 92 b6 13 c5  │Z·· ·-··h··v····│
00000030  2f 5d c8 9b 53 84 45 c4 10 cc 8d 3d 64 48 0b 49  │/]··S·E····=dH·I│
00000040  98 f8 7e d7 d4 cb 5e 39 94 46 bb 2b 69 6f fc c9  │··~···^9·F·+io··│
00000050  b8 72 27 da ef bf d4 86 1e 3e 2c 97 f3 4d ba f0  │·r'······>,··M··│
00000060  6a 80 a2 08 2f ba d9 1a 73 de 42 a1 b3 ca 2c 24  │j···/···s·B···,$│
00000070  23 20 80 47 87 24 68 77 54 c4 32 d5 81 8f bc c0  │# ·G·$hwT·2·····│
00000080

@zachriggle
Copy link
Member

Overall looks good to me except that the parameter ordering was changed. Can you add the new parameter last? Thanks!

@dimos
Copy link
Contributor Author

dimos commented Jan 11, 2018

@zachriggle done. 👍

@zachriggle
Copy link
Member

Thanks for this! Tests pass and you added some new ones, merging :)

@zachriggle zachriggle merged commit c7c5019 into Gallopsled:dev Jan 25, 2018
@dimos dimos deleted the hexdumpfix branch February 18, 2018 13:44
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.

2 participants