Skip to content

Add autoskip option to hexdump and dumpstruct#158

Merged
yunzheng merged 1 commit into
mainfrom
hexdump-autoskip
May 19, 2026
Merged

Add autoskip option to hexdump and dumpstruct#158
yunzheng merged 1 commit into
mainfrom
hexdump-autoskip

Conversation

@yunzheng
Copy link
Copy Markdown
Member

@yunzheng yunzheng commented May 19, 2026

This PR adds a autoskip argument to the hexdump() and dumpstruct() functions. When autoskip=True it will collapse all consecutive NULL bytes on a hexdump line to a single *. This mimics the --autoskip feature of xxd:

$ xxd -a /bin/ls | head
00000000: cafe babe 0000 0002 0100 0007 0000 0003  ................
00000010: 0000 4000 0000 bc00 0000 000e 0100 000c  ..@.............
00000020: 8000 0002 0001 0000 0001 5c00 0000 000e  ..........\.....
00000030: 0000 0000 0000 0000 0000 0000 0000 0000  ................
*
00004000: cffa edfe 0700 0001 0300 0000 0200 0000  ................
00004010: 1200 0000 c806 0000 8500 2000 0000 0000  .......... .....
00004020: 1900 0000 4800 0000 5f5f 5041 4745 5a45  ....H...__PAGEZE
00004030: 524f 0000 0000 0000 0000 0000 0000 0000  RO..............
00004040: 0000 0000 0100 0000 0000 0000 0000 0000  ................

and with dissect hexdump autoskip=True:

image

Note that I have also changed the hexdump() function signature to be kwargs only starting from the second argument. I think this is much cleaner and less error prone. I'm doubting if we should do the same for dumpstruct().

@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

❌ Patch coverage is 0% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (29652dd) to head (aae286d).

Files with missing lines Patch % Lines
dissect/cstruct/utils.py 0.00% 17 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #158   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files         21      21           
  Lines       2470    2482   +12     
=====================================
- Misses      2470    2482   +12     
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 May 19, 2026

Merging this PR will improve performance by 19.46%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

#### 🎉 Hooray! `pytest-codspeed` just leveled up to 5.0.2!

A heads-up, this is a breaking change and it might affect your current performance baseline a bit. But here's the exciting part - it's packed with new, cool features and promises improved result stability 🥳!
Curious about what's new? Visit our releases page to delve into all the awesome details about this new version.

⚡ 5 improved benchmarks
✅ 7 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
test_benchmark_basic[compiled] 81.2 µs 73.3 µs +10.7%
test_benchmark_getattr_typedefs 27.5 µs 24.3 µs +12.97%
test_benchmark_getattr_types 27 µs 23.8 µs +13.68%
test_benchmark_getattr_constants 17 µs 13.5 µs +26.28%
test_benchmark_attribute_access 15.3 µs 11.3 µs +35.53%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing hexdump-autoskip (aae286d) with main (29652dd)

Open in CodSpeed

@yunzheng
Copy link
Copy Markdown
Member Author

@codspeedbot explain why this is faster

Copy link
Copy Markdown
Member

@Schamper Schamper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NUL or NULL?

@yunzheng
Copy link
Copy Markdown
Member Author

NUL or NULL?

xxd calls it NUL in the man page:

       -a | -autoskip
              Toggle autoskip: A single '*' replaces NUL-lines.  Default off.

Also it's not very clear in the man page, but it always leaves the first NUL(L) line intact.

@Schamper
Copy link
Copy Markdown
Member

I'm doubting if we should do the same for dumpstruct().

Probably, yes. But that has bigger changes with #156. Perhaps we can do that in that PR.

@yunzheng
Copy link
Copy Markdown
Member Author

I'm doubting if we should do the same for dumpstruct().

Probably, yes. But that has bigger changes with #156. Perhaps we can do that in that PR.

roger

@yunzheng yunzheng merged commit 9f12b1e into main May 19, 2026
24 checks passed
@yunzheng yunzheng deleted the hexdump-autoskip branch May 19, 2026 17:19
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