Hexdump Comprehensive Cheatsheet
Installation Instructions
# Using Chocolatey
choco install hexdump
# Using MSYS2
pacman - S util- linux
sudo apt-get update
sudo apt-get install bsdmainutils
# Using Homebrew
brew install hexdump
# Already installed by default on macOS
Basic Hexdump
Canonical Hex+ASCII Display
Two-byte Hex Display
One-byte Octal Display
Custom Format
hexdump -e ' 16/1 "%02X " "\n"' file
Format with ASCII
hexdump -e ' 16/1 "%02X " " |" 16/1 "%_p" "|\n"' file
Four-byte Words
hexdump -e ' 4/4 "%08X " "\n"' file
Skip Bytes
Limit Length
Custom Offset Format
hexdump -e ' "0x%08.8_ax " 16/1 "%02X " "\n"' file
Search for Pattern
hexdump -C file | grep " pattern"
Compare Files
cmp <( hexdump file1) <( hexdump file2)
Extract Specific Bytes
hexdump -s offset -n length -C file
Custom Byte Grouping
hexdump -e ' 8/1 "%02X " " " 8/1 "%02X " "\n"' file
Include Decimal Values
hexdump -e ' 4/1 "%3d " "\n"' file
Mixed Hex and ASCII
hexdump -e ' "%08.8_ax " 8/1 "%02X " " " 8/1 "%02X "' -e ' " |" 16/1 "%_p" "|\n"' file
Find String Patterns
hexdump -C file | grep -A1 -B1 " text"
Analyze File Headers
Check File Type
Analyze Executable Headers
hexdump -n 64 -C executable
Extract Sections
hexdump -s section_offset -n section_size -C file
Find Null Sequences
hexdump -C file | grep " 00 00 00 00"
Memory Dump Analysis
Network Packet Analysis
Firmware Analysis
Pattern Matching Script
#! /bin/bash
hexdump -C " $1 " | grep -A2 -B2 " $2 "
Binary Diff Script
#! /bin/bash
diff <( hexdump -C " $1 " ) <( hexdump -C " $2 " )
32-bit Integer Format
hexdump -e ' 4/4 "0x%08x " "\n"' file
Float Format
hexdump -e ' 4/4 "%f " "\n"' file
Mixed Format
hexdump -e ' "%-8_ad " 8/1 " %02x" " " 8/1 " %02x" " |" 16/1 "%_p" "|\n"' file
PDF Header Analysis
hexdump -n 32 -C file.pdf
ZIP File Analysis
hexdump -C file.zip | grep " PK"
Image File Analysis
hexdump -n 8 -C image.jpg
String Extraction
hexdump -C malware.bin | grep -i " http"
Signature Detection
hexdump -C file | grep -A4 " MZ"
Find File Headers
hexdump -C disk.img | grep -A16 -B16 " PDF"
Carve File Boundaries
hexdump -C disk.img | grep -A32 " FFD8"
Large File Handling
# Use dd to split large files
dd if=large_file bs=1M count=1 | hexdump -C
Efficient Searching
hexdump -C file | grep --color=auto pattern
Initial Assessment
# Quick file overview
head -c 512 file | hexdump -C
Detailed Analysis
# Full file with custom format
hexdump -e ' "%08.8_ax " 16/1 "%02X " " |" 16/1 "%_p" "|\n"' file
Common Issues and Solutions
File Encoding
# Handle different encodings
iconv -f utf-16 -t utf-8 file | hexdump -C
Large Files
# Split analysis
split -b 1M file chunk_
for f in chunk_* ; do hexdump -C " $f " ; done
Automated Analysis
#! /bin/bash
for file in * .bin; do
echo " Analyzing $file ..."
hexdump -C " $file " | grep -A4 -B4 " pattern"
done
Format Conversion
#! /bin/bash
hexdump -e ' 16/1 "%02X" "\n"' file > file.hex