Skip to content

Add pretty print to hexdump#155

Merged
Schamper merged 6 commits into
fox-it:mainfrom
JSCU-CNI:pretty-hexdump
Apr 29, 2026
Merged

Add pretty print to hexdump#155
Schamper merged 6 commits into
fox-it:mainfrom
JSCU-CNI:pretty-hexdump

Conversation

@JSCU-CNI
Copy link
Copy Markdown
Contributor

This PR aims to provide a stub for pretty colors as described in #80. Currently only null bytes are 'greyed-out' and ASCII printable characters are whitened.

image

Perhaps we can look at some of these resources to determine what other coloring rules we would like to apply here:

Some things that come to mind:

  • Should we show difference between certain printable ASCII characters (letters, numbers, capitalization, etc.)?
  • Should we color white space characters (0x09-0x0D, 0x20, etc.)?
  • What about non-ASCII (0x80-0xFF)?

The current implementation does not change the default behavior of hexdump, using the pretty argument is required.

@yunzheng
Copy link
Copy Markdown
Member

Nice! I’m a pretty big fan of HexFiend on macOS which also added hex coloring based on hexyl, see this PR:

HexFiend/HexFiend#181

Think if we base the coloring rules and scheme on that it would already be very nice.

@JSCU-CNI
Copy link
Copy Markdown
Contributor Author

JSCU-CNI commented Apr 28, 2026

Think if we base the coloring rules and scheme on that it would already be very nice.

Thanks for the input @yunzheng, I have applied some rules from HexFriend in 9fa9977. I feel the white color of printable ASCII is somewhat calmer to read than a blue color. What do you think? Perhaps we could make this user customizable in the future, but for simplicity's sake for now I think we should settle on one coloring scheme.

For example, a small PE file is now rendered like this:

image

@JSCU-CNI JSCU-CNI changed the title Add pretty option to hexdump Add pretty print to hexdump Apr 28, 2026
@yunzheng
Copy link
Copy Markdown
Member

That looks awesome, yes looking at the Hexyl example I think the white is much better on the eyes!

Comment thread dissect/cstruct/utils.py Outdated
Comment thread dissect/cstruct/utils.py Outdated
Comment thread dissect/cstruct/utils.py Outdated
Comment thread dissect/cstruct/utils.py
Comment thread dissect/cstruct/utils.py Outdated
JSCU-CNI and others added 3 commits April 29, 2026 11:20
Co-authored-by: Erik Schamper <1254028+Schamper@users.noreply.github.com>
@JSCU-CNI JSCU-CNI requested a review from Schamper April 29, 2026 09:37
Comment thread dissect/cstruct/utils.py Outdated
Comment thread dissect/cstruct/utils.py
@JSCU-CNI JSCU-CNI requested a review from Schamper April 29, 2026 14:47
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 29, 2026

Codecov Report

❌ Patch coverage is 0% with 48 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (edf9f8e) to head (40f71db).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
dissect/cstruct/utils.py 0.00% 48 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #155   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files         21      21           
  Lines       2438    2470   +32     
=====================================
- Misses      2438    2470   +32     
Flag Coverage Δ
unittests 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 29, 2026

Merging this PR will not alter performance

✅ 12 untouched benchmarks


Comparing JSCU-CNI:pretty-hexdump (40f71db) with main (edf9f8e)

Open in CodSpeed

@Schamper Schamper merged commit 29652dd into fox-it:main Apr 29, 2026
24 checks passed
@JSCU-CNI JSCU-CNI deleted the pretty-hexdump branch April 29, 2026 15:42
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.

3 participants