Skip to main content

Basic tools to read, filter, format and display hex values

Project description

Description

Basic tools to read, format, filter and display hex values

Installation

pip install hexlib

Usage

  • The class HexTwin is a hexadecimal representation of a file
    • HexTwin reads a file in 16 byte chunks
    • Each of this chunks is saved as as tuple together with the following information:
      • tuple[0] = Offset
      • tuple[1] = A bytearray containing the 16 bytes
      • tuple[2] = A boolean indicating if the bytes are all zero
      • tuple[3] = A boolean indicating if the bytes are all non ASCII values
  • The class Hexdump format and prints HexTwin instances

Example

from hexlib.HexTwin import HexTwin
from hexlib.Hexdump import Hexdump

# 1.) HexTwin instance
twin = HexTwin("path/to/file/test.txt")
dump = Hexdump()

# Activates filtering for zero rows
dump.filter(filterZeroRows=True) 
dump.printTwin("path/to/result.txt", twin)

# Activates filtering for non-ascii rows (Includes also zero rows)
dump.filter(filterNonAsciiRows=True) 
dump.printTwin("path/to/result.txt", twin)

# 2.) Create HexTwin from bytes (Filtering can also be used here)
f = open("path/to/file", "rb")
twinFromBytes = HexTwin.fromBytes(f.read(16))
dumpFromBytes = Hexdump()

dumpfromBytes.printTwin("path/to/bytes-result.txt", twinFromBytes)

# 3.) Create a HexTwin from a offset reading x bytes (Filtering can also be used here)
twinFromOffset = HexTwin.fromOffset("path/to/file.txt", offset=50, noOfBytes=10)
dumpFromOffset = Hexdump()

dumpFromOffset.printTwin("path/to/offset-result.txt", twinFromOffset)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hexlib-2.0.3.tar.gz (4.2 kB view hashes)

Uploaded Source

Built Distribution

hexlib-2.0.3-py3-none-any.whl (5.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page