Pyhexdmp - Python hex dump module

Overview

pyhexdmp Python hex dump module

Copyright 2021

Author: Paul Melson

Author notes:

  • Accept single variable as input, plus optional config arguments

  • Detect data type of input

  • Supported data types: str, bytes, bytearray

  • Unsupported data types: complex, bool, int, float

  • Undecided (currently unsupported): list, dict, range, tuple, memoryview

  • Convert input to bytearray()

  • Print hex output format, supported optional arguments:

    • offsets: on/off, default=on, print the distance of the first byte of each line in hex notation on the left

      hexdmp(test_data, offsets='off')
    • showascii: on/off, default=on, print the ASCII characters of each byte on the right (print periods for hi/lo bytes)

      hexdmp(test_data, showascii='off')
    • start: int, manually set offsets start value

      hexdmp(test_data, start=2)
    • width: positive int, default=16, let the user set the number of bytes per line to print

      hexdmp(test_data, width=8)

Usage:

>>> from pyhexdmp import hexdmp
>>> with open('/home/paul/sample.exe', 'rb') as f:
...     raw = f.read()
... 
>>> test_data = raw[:128]
>>> hexdmp(test_data)
00000000: 4d 5a 90 00 03 00 00 00 04 00 00 00 ff ff 00 00  MZ..............
00000010: b8 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00  ........@.......
00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000030: 00 00 00 00 00 00 00 00 00 00 00 00 f8 00 00 00  ................
00000040: 0e 1f ba 0e 00 b4 09 cd 21 b8 01 4c cd 21 54 68  ........!..L.!Th
00000050: 69 73 20 70 72 6f 67 72 61 6d 20 63 61 6e 6e 6f  is program canno
00000060: 74 20 62 65 20 72 75 6e 20 69 6e 20 44 4f 53 20  t be run in DOS 
00000070: 6d 6f 64 65 2e 0d 0d 0a 24 00 00 00 00 00 00 00  mode....$.......
>>> hexdmp(test_data, offsets='off')
4d 5a 90 00 03 00 00 00 04 00 00 00 ff ff 00 00  MZ..............
b8 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00  ........@.......
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00 00 00 00 00 00 00 00 00 00 00 00 f8 00 00 00  ................
0e 1f ba 0e 00 b4 09 cd 21 b8 01 4c cd 21 54 68  ........!..L.!Th
69 73 20 70 72 6f 67 72 61 6d 20 63 61 6e 6e 6f  is program canno
74 20 62 65 20 72 75 6e 20 69 6e 20 44 4f 53 20  t be run in DOS 
6d 6f 64 65 2e 0d 0d 0a 24 00 00 00 00 00 00 00  mode....$.......
>>> hexdmp(test_data, showascii='off')
00000000: 4d 5a 90 00 03 00 00 00 04 00 00 00 ff ff 00 00
00000010: b8 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00
00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000030: 00 00 00 00 00 00 00 00 00 00 00 00 f8 00 00 00
00000040: 0e 1f ba 0e 00 b4 09 cd 21 b8 01 4c cd 21 54 68
00000050: 69 73 20 70 72 6f 67 72 61 6d 20 63 61 6e 6e 6f
00000060: 74 20 62 65 20 72 75 6e 20 69 6e 20 44 4f 53 20
00000070: 6d 6f 64 65 2e 0d 0d 0a 24 00 00 00 00 00 00 00
>>> hexdmp(test_data, start=2)
00000002: 90 00 03 00 00 00 04 00 00 00 ff ff 00 00 b8 00  ................
00000012: 00 00 00 00 00 00 40 00 00 00 00 00 00 00 00 00  ......@.........
00000022: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000032: 00 00 00 00 00 00 00 00 00 00 f8 00 00 00 0e 1f  ................
00000042: ba 0e 00 b4 09 cd 21 b8 01 4c cd 21 54 68 69 73  ......!..L.!This
00000052: 20 70 72 6f 67 72 61 6d 20 63 61 6e 6e 6f 74 20   program cannot 
00000062: 62 65 20 72 75 6e 20 69 6e 20 44 4f 53 20 6d 6f  be run in DOS mo
00000072: 64 65 2e 0d 0d 0a 24 00 00 00 00 00 00 00        de....$.......
>>> hexdmp(test_data, width=8)
00000000: 4d 5a 90 00 03 00 00 00  MZ......
00000008: 04 00 00 00 ff ff 00 00  ........
00000010: b8 00 00 00 00 00 00 00  ........
00000018: 40 00 00 00 00 00 00 00  @.......
00000020: 00 00 00 00 00 00 00 00  ........
00000028: 00 00 00 00 00 00 00 00  ........
00000030: 00 00 00 00 00 00 00 00  ........
00000038: 00 00 00 00 f8 00 00 00  ........
00000040: 0e 1f ba 0e 00 b4 09 cd  ........
00000048: 21 b8 01 4c cd 21 54 68  !..L.!Th
00000050: 69 73 20 70 72 6f 67 72  is progr
00000058: 61 6d 20 63 61 6e 6e 6f  am canno
00000060: 74 20 62 65 20 72 75 6e  t be run
00000068: 20 69 6e 20 44 4f 53 20   in DOS 
00000070: 6d 6f 64 65 2e 0d 0d 0a  mode....
00000078: 24 00 00 00 00 00 00 00  $.......
>>> hexdmp(test_data, offsets='off', showascii='off', start=16, width=32)
b8 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 f8 00 00 00 0e 1f ba 0e 00 b4 09 cd 21 b8 01 4c cd 21 54 68
69 73 20 70 72 6f 67 72 61 6d 20 63 61 6e 6e 6f 74 20 62 65 20 72 75 6e 20 69 6e 20 44 4f 53 20
6d 6f 64 65 2e 0d 0d 0a 24 00 00 00 00 00 00 00p
>>> from pyhexdmp import strhexdmp
>>> test_hexdump_string = strhexdmp(test_data)
>>> print(test_hexdump_string)
00000000: 4d 5a 90 00 03 00 00 00 04 00 00 00 ff ff 00 00  MZ..............
00000010: b8 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00  ........@.......
00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000030: 00 00 00 00 00 00 00 00 00 00 00 00 f8 00 00 00  ................
00000040: 0e 1f ba 0e 00 b4 09 cd 21 b8 01 4c cd 21 54 68  ........!..L.!Th
00000050: 69 73 20 70 72 6f 67 72 61 6d 20 63 61 6e 6e 6f  is program canno
00000060: 74 20 62 65 20 72 75 6e 20 69 6e 20 44 4f 53 20  t be run in DOS 
00000070: 6d 6f 64 65 2e 0d 0d 0a 24 00 00 00 00 00 00 00  mode....$.......

>>> 
You might also like...
Python screenshot library, replacement for the Pillow ImageGrab module on Linux.

tldr: Use Pillow The pyscreenshot module is obsolete in most cases. It was created because PIL ImageGrab module worked on Windows only, but now Linux

An ultra fast cross-platform multiple screenshots module in pure Python using ctypes.

Python MSS from mss import mss # The simplest use, save a screen shot of the 1st monitor with mss() as sct: sct.shot() An ultra fast cross-platfo

 This module is for finding the execution time of a whole python program
This module is for finding the execution time of a whole python program

exetime 3.8 This module is for finding the execution time of a whole program How to install $ pip install exetime Contents: General Information Instru

Python module to work with Magneto Database directly without using broken Magento 2 core
Python module to work with Magneto Database directly without using broken Magento 2 core

Python module to work with Magneto Database directly without using broken Magento 2 core

A module comment generator for python

Module Comment Generator The comment style is as a tribute to the comment from the RA . The comment generator can parse the ast tree from the python s

This python module allows to extract data from the RAW-file-format produces by devices from Thermo Fisher Scientific.

fisher_py This Python module allows access to Thermo Orbitrap raw mass spectrometer files. Using this library makes it possible to automate the analys

Module for working with the site dnevnik.ru with python

dnevnikru Module for working with the site dnevnik.ru with python Dnevnik object accepts login and password from the dnevnik.ru account Methods: homew

Python module for creating the circuit simulation definitions for Elmer FEM

elmer_circuitbuilder Python module for creating the circuit simulation definitions for Elmer FEM. The circuit definitions enable easy setup of coils (

A python mathematics module

A python mathematics module

Owner
null
Cross-platform MachO/ObjC Static binary analysis tool & library. class-dump + otool + lipo + more

ktool Static Mach-O binary metadata analysis tool / information dumper pip3 install k2l Development is currently taking place on the @python3.10 branc

Kritanta 301 Dec 28, 2022
Simple tools to make/dump CPC+ CPR cartridge files

Simple tools to make/dump CPC+ CPR cartridge files mkcpr.py: make a CPR file from files (one chunk per file); see notes cprdump.py: dump the chunks of

Juan J. Martínez 3 May 30, 2022
Dump Data from FTDI Serial Port to Binary File on MacOS

Dump Data from FTDI Serial Port to Binary File on MacOS

pandy song 1 Nov 24, 2021
Automatically load and dump your dataclasses 📂🙋

file dataclasses Installation By default, filedataclasses comes with support for JSON files only. To support other formats like YAML and TOML, filedat

Alon 1 Dec 30, 2021
Backup dc registry - A simple POC that abuses Backup Operator privileges to remote dump SAM, SYSTEM, and SECURITY

Backup Operator Registry Backup to Domain Compromise A simple POC that abuses Ba

Horizon 3 AI Inc 57 Dec 18, 2022
Module for remote in-memory Python package/module loading through HTTP/S

httpimport Python's missing feature! The feature has been suggested in Python Mailing List Remote, in-memory Python package/module importing through H

John Torakis 220 Dec 17, 2022
Run python scripts and pass data between multiple python and node processes using this npm module

Run python scripts and pass data between multiple python and node processes using this npm module. process-communication has a event based architecture for interacting with python data and errors inside nodejs.

Tyler Laceby 2 Aug 6, 2021
PyPIContents is an application that generates a Module Index from the Python Package Index (PyPI) and also from various versions of the Python Standard Library.

PyPIContents is an application that generates a Module Index from the Python Package Index (PyPI) and also from various versions of the Python Standar

Collage Labs 10 Nov 19, 2022
Python communism - A module for initiating the communist revolution in each of our python modules

Python communist revolution A man once said to abolish the classes or something

null 758 Jan 3, 2023
A Python module for decorators, wrappers and monkey patching.

wrapt The aim of the wrapt module is to provide a transparent object proxy for Python, which can be used as the basis for the construction of function

Graham Dumpleton 1.8k Jan 6, 2023