Binary File Inspector
Build a C tool that looks inside any file, a picture, a program or a document, and shows what it's made of: its size, a hexadecimal and text view of the bytes (like the hexdump and xxd commands), how often each byte value appears, the file's likely type from its first bytes (its magic number, such as the %PDF at the start of a PDF), and an entropy score that hints whether the data is compressed or encrypted. It reads files in chunks, so even huge files are fine. It's a good first C project: you'll learn reading binary files with fread, arrays for counting, printf formatting in hexadecimal, command-line options with getopt, a little math with math.h, and building with Make.
- Estimate
- ~7h
- Steps
- 6
- Completed by
- 0
- Proposed by
- codeseed.app
Make · POSIX
Project roadmap
- 01
Define the output
~1hWrite README.md: the command (binspect [-n BYTES] [-s OFFSET] [-f] [-t] FILE), where the default shows the size and a hex preview, -f shows byte frequencies, -t shows the detected type and entropy, and -s and -n choose which part to preview. Include example output for a small file. Set up a Makefile with -Wall -Wextra and -lm. Done when: README.md shows the options and example output.
- 02
Show a hex preview
~1.5hOpen the file with fopen in binary mode and read it with fread in chunks. Print lines of 16 bytes: the offset in hexadecimal (%08zx), the bytes as two hex digits separated by spaces, and the same bytes as text, with non-printable bytes shown as a dot (using isprint). Stop after -n bytes, starting at -s (using fseek). Done when: the preview matches xxd for the same file.
- 03
Count byte frequencies
~1hCount how many times each of the 256 byte values appears, reading the whole file in chunks into an array of 256 counters (size_t). With -f, print the 16 most common bytes with their count and percentage, and how many different byte values appear. Done when: the counts add up to the file size.
- 04
Detect the type and measure entropy
~1.5hCompare the first bytes with a table of known signatures (such as PNG, JPEG, PDF, ZIP, GZIP and ELF) to guess the file type. Compute the Shannon entropy from the frequencies (the sum of -p × log2(p), between 0 and 8 bits per byte) and explain it: low for text, close to 8 for compressed or encrypted data. Done when: the type and entropy are sensible for a text file, an image and a zip file.
- 05
Handle errors and edge cases
~1hHandle a missing file or no permission (with strerror(errno)), an empty file, an offset beyond the end of the file, invalid option values, and folders passed instead of files. Exit with a non-zero code on errors. Done when: each case prints a clear message.
- 06
Test it
~1hWrite a test script that creates small files with known content (with printf), and compares your tool's preview with xxd, the size with stat, and the frequencies and entropy with values you calculated (such as 0 for a file of one repeated byte). Run it under valgrind. Done when: all comparisons pass with no memory errors.
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack