diff options
Diffstat (limited to 'hexdump.py')
| -rw-r--r-- | hexdump.py | 9 |
1 files changed, 8 insertions, 1 deletions
| @@ -1,9 +1,16 @@ | |||
| 1 | import struct | 1 | import struct |
| 2 | from binascii import b2a_hex | 2 | from binascii import b2a_hex, a2b_hex |
| 3 | """ | 3 | """ |
| 4 | Simple hexdump, 16 bytes per line with offset. | 4 | Simple hexdump, 16 bytes per line with offset. |
| 5 | """ | 5 | """ |
| 6 | 6 | ||
| 7 | def unhex(data): | ||
| 8 | if type(data)==bytes: | ||
| 9 | data = data.decode('ascii') | ||
| 10 | data = data.replace(' ', '') | ||
| 11 | data = data.strip() | ||
| 12 | return a2b_hex(data) | ||
| 13 | |||
| 7 | def ashex(line): | 14 | def ashex(line): |
| 8 | return " ".join("%02x" % _ for _ in line) | 15 | return " ".join("%02x" % _ for _ in line) |
| 9 | def aschr(b): | 16 | def aschr(b): |
