Umberto Allievi Soluzioni Informatiche
TheHexDiff

TheHexDiff

Version 0.1.0

Binary file comparison tool with aligned hex view, built with C++20, GTK4, and libadwaita.

C++20GTK4libadwaitaCairoWinUI — soonVibe Coded
TheHexDiff screenshot

Features

Aligned Hex Diff via Myers Algorithm

Uses the Myers O(ND) diff algorithm — the same algorithm behind git diff — on raw byte sequences. Insertions and deletions are properly aligned instead of breaking the layout.

Side-by-Side Hex View

Two panels showing offset, 16 hex bytes per row, and ASCII representation. Gap rows maintain alignment when bytes are inserted or deleted in one file.

Color-Coded Differences

Yellow/amber for modified bytes, red for deleted bytes (File A side), green for inserted bytes (File B side). Matching bytes shown in the default color.

Async Computation

Diff runs on a background thread with a spinner and phase labels (loading files, computing diff, building model). The UI stays responsive even for large files.

Drag and Drop

Drop two files to load both at once, or drop a single file on the left/right half of the window to load it as File A or File B.

Diff Navigation

Jump to the next or previous difference with Ctrl+D / Ctrl+Shift+D, or use the arrow buttons in the header bar. Scroll with keyboard or mouse wheel.

Positional Fallback

When files differ by more than 2000 edit operations, falls back to byte-by-byte positional comparison. The header shows a clear message when this happens.

Keyboard Shortcuts

Ctrl+O / Ctrl+Shift+O to open files, Ctrl+D / Ctrl+Shift+D to navigate diffs, F5 to reload, Home/End/PageUp/PageDown for scrolling.

Use Cases

Comparing Binary File Versions

Load two versions of a binary file to see exactly which bytes changed, were added, or were removed — with proper alignment so surrounding data still lines up.

Analyzing Firmware or ROM Patches

Compare original and patched firmware images. The aligned view shows where patch bytes were inserted or modified without losing context.

Investigating File Format Differences

Compare files in the same format (images, documents, archives) to understand how specific format fields differ at the byte level.

Debugging Serialization Issues

Compare serialized output from two code paths to find where the byte stream diverges. The hex and ASCII columns help identify both binary and text differences.

Comparing Compiled Binaries

Diff two builds of the same program to see what changed in the compiled output. The Myers alignment handles inserted or removed code sections.

User Manual

Quick Start

  1. Launch TheHexDiff from GNOME Activities or terminal
  2. Click File A to open the first file
  3. Click File B to open the second file
  4. The diff computes automatically — a spinner is shown for large files
  5. Use Ctrl+D / Ctrl+Shift+D to jump between differences

From the command line:

the-hexdiff original.bin modified.bin

The Main Window

The window is organized into three areas:

Header Bar:

ElementDescription
File A buttonOpens a file dialog to load the first file
File B buttonOpens a file dialog to load the second file
Title / SubtitleShows "TheHexDiff" and diff statistics or status
Menu buttonOpens the application menu (About dialog)
Reload buttonReloads both files and re-runs the diff (same as F5)
Next diff buttonScrolls to the next difference (down arrow)
Previous diff buttonScrolls to the previous difference (up arrow)

Content Area: The main area displays the aligned hex view with both files side by side. When no files are loaded or while a diff is computing, a status page with a spinner is shown instead.

Status Bar: Shows File A filename and size, File B filename and size, and the count of modified, inserted, and deleted bytes.

Loading Files

There are three ways to load files:

  • File dialog: Click File A or File B in the header bar (or use Ctrl+O / Ctrl+Shift+O)
  • Drag and drop: Drop two files to load both at once, or drop a single file on the left half (File A) or right half (File B) of the window
  • Command line: the-hexdiff path/to/file_a path/to/file_b

TheHexDiff works with all file types since it operates on raw bytes.

Press F5 or click the reload button to re-read both files from disk and recompute the diff.

Understanding the Hex View

The view is split into two side-by-side panels separated by a vertical divider. Each panel has three columns:

  1. Offset — Hex offset of the first byte in the row, relative to the original file
  2. Hex Bytes — 16 bytes per row, space-separated
  3. ASCII — Same 16 bytes as printable characters (non-printable bytes shown as ·)

Row types:

Row TypeFile A PanelFile B Panel
MatchNormal bytesNormal bytes (identical)
ModifiedOriginal bytes (highlighted)Changed bytes (highlighted)
DeletedBytes present in A (red)Gap placeholders (__)
InsertedGap placeholders (__)Bytes present in B (green)

Color coding:

ColorMeaning
DefaultBytes match in both files
Yellow / AmberByte modified — different value at same logical position
Red (File A side)Byte deleted — present in A but not in B
Green (File B side)Byte inserted — present in B but not in A
DimmedGap placeholder — no actual byte at this position

Offsets on each side advance independently when insertions or deletions cause gaps.

Navigating Differences

Jump to differences:

  • Ctrl+D — Jump to the next row containing a difference
  • Ctrl+Shift+D — Jump to the previous row containing a difference

You can also use the arrow buttons in the header bar.

Scrolling:

ActionKeys
Scroll one rowUp / Down arrow
Scroll one pagePage Up / Page Down
Jump to beginningHome
Jump to endEnd

The mouse scroll wheel also works.

Keyboard Shortcuts

ShortcutAction
Ctrl+OOpen File A
Ctrl+Shift+OOpen File B
Ctrl+DJump to next difference
Ctrl+Shift+DJump to previous difference
F5Reload both files and re-diff
Up / DownScroll one row
Page Up / Page DownScroll one page
Home / EndJump to start / end

File Size Limits

TheHexDiff loads files entirely into memory for comparison.

File SizeBehavior
Up to 64 MBNormal operation
64 MB to 256 MBAccepted but may use significant memory
Over 256 MBRefused — file is too large

For two 100 MB files, expect roughly 300–400 MB of memory usage during diff computation.

Understanding the Diff Algorithm

Myers Algorithm: TheHexDiff uses the Myers O(ND) diff algorithm, the same foundational algorithm used by git diff and GNU diff. It finds the shortest edit script — the minimum number of insertions and deletions to transform File A into File B.

Edit Distance Bound: The algorithm is bounded to a maximum edit distance of 2000. If files differ by more than this, TheHexDiff falls back to positional comparison.

Positional Fallback: Bytes at the same offset are compared directly — matching bytes are equal, differing bytes are modified, extra bytes in the longer file are inserted or deleted. The header shows "Positional comparison (files too different for alignment)" when active.

Coalescing: Adjacent Delete+Insert pairs at the same logical position are displayed as "Modified" operations, since a byte changing value is more intuitive than showing separate deletion and insertion.

Troubleshooting

The spinner shows but nothing happens: For very large files (near the 256 MB limit), loading and comparison can take a long time. Wait for the computation to finish or load smaller files.

"Positional comparison" message: The files differ by more than 2000 edit operations. The alignment algorithm fell back to byte-by-byte comparison. This is normal for files that are substantially different.

No differences shown: Both files are identical. Check the status bar — it should show "0 modified, 0 inserted, 0 deleted."

File refused (too large): Files over 256 MB are refused to prevent excessive memory usage. Consider using cmp or xxd with diff for very large files.