Digital Evidence · Topic 7 of 8

Hex Encoding and File Format Analysis

Learn ASCII and Unicode encoding, offsets, hex editors, file signatures for JPEG, BMP and Office files, EXIF metadata and PDF structure for CHFI v11.

  • 5 min
In a nutshell
  • Signatures sit at offset 0, and they are a stronger indicator of file type than the extension.
  • JPEG starts FF D8 and ends FF D9. BMP starts with BM. PDF starts with %PDF. ZIP and OOXML start with PK.
  • UTF-16 has a BOM of FF FE or FE FF. UTF-8's is EF BB BF.

What it is

Every file is bytes. A hex editor shows those bytes with their position, so an investigator can identify a file by its header, spot data hidden inside it and read embedded metadata. File signatures matter because extensions can be changed while the content bytes are a stronger indicator of the real type.

The exam asks for signatures, encoding facts, offsets and what metadata a format holds.

Unknown fileHex editorview bytesRead header signatureCompare with extensionParse metadata

How it works

Character encoding

StandardFacts
ASCII7 bits, 128 characters. A is 0x41, a is 0x61, digit 0 is 0x30.
Extended ASCII8 bits, 256 values, varies by code page
UnicodeCode points for nearly all writing systems
UTF-81 to 4 bytes per character. ASCII compatible. Optional marker EF BB BF.
UTF-162 or 4 bytes. Byte order mark FF FE (little endian) or FE FF (big endian).
UTF-324 bytes per character

Windows uses UTF-16 in many places, so strings in memory and files often look like text with a zero byte between every letter.

Offset

An offset is the distance in bytes from the start of a file, a sector or a disk. A hex editor shows the offset down the left side. The first byte is offset 0. A signature "at offset 0" means the very first bytes.

Hex editors and hexadecimal notation

Hexadecimal is base 16 (digits 0 to 9 and A to F). One byte is two hex digits, such as 0xFF (255). Multi byte numbers on x86 are stored little endian: 0x12345678 appears as 78 56 34 12.

Editors include HxD, WinHex, 010 Editor, Hex Workshop and Hex Fiend. On Linux:

xxd -l 64 photo.jpg
hexdump -C -n 64 photo.jpg

Both print the first 64 bytes with offsets and ASCII.

Common file signatures

FormatHeader bytes (hex)Notes
JPEGFF D8 FFEnds with FF D9. E0 follows for JFIF, E1 for EXIF.
BMP42 4D ("BM")
PNG89 50 4E 47 0D 0A 1A 0A
GIF47 49 46 38 ("GIF8")
PDF25 50 44 46 ("%PDF")Ends with %%EOF
ZIP, DOCX, XLSX, PPTX50 4B 03 04 ("PK")
Legacy Office (DOC, XLS, PPT)D0 CF 11 E0 A1 B1 1A E1OLE compound file
Windows executable4D 5A ("MZ")
ELF7F 45 4C 46Linux executable
GZIP1F 8B
SQLite"SQLite format 3"

JPEG and BMP analysis

A JPEG is a series of markers: SOI (FF D8), application segments (APP0 FF E0, APP1 FF E1 for EXIF), quantization and Huffman tables, the frame header, the scan data and EOI (FF D9). Data after the EOI marker deserves a closer look, because it may be appended hidden content (some cameras also append legitimate data).

A BMP starts with a 14 byte file header (BM, file size, offset to pixel data), then a DIB header giving width, height and bits per pixel. BMP files are large and uncompressed, which makes them common carriers for hidden data.

EXIF data

EXIF is metadata in the APP1 segment of JPEG and in TIFF. It can hold camera make and model, DateTimeOriginal, software used, orientation, an embedded thumbnail and GPS latitude and longitude.

exiftool -Make -Model -DateTimeOriginal -GPSLatitude -GPSLongitude photo.jpg

A mismatch between the thumbnail and the main image, or a Software tag naming an editor, suggests editing. Many social platforms strip EXIF on upload, so its absence is not proof of tampering.

Hex view of other image formats

PNG is made of chunks (IHDR, IDAT, IEND), each with a length, a type and a CRC. GIF has a header, a logical screen descriptor and blocks. TIFF starts with 49 49 2A 00 (little endian) or 4D 4D 00 2A (big endian).

PDF, Word, PowerPoint and Excel

FormatStructureEvidence
PDFHeader, objects, cross reference table, trailerInfo fields such as Author, Creator, Producer and CreationDate. Incremental updates may keep earlier versions of content.
DOCX, XLSX, PPTXZIP archive of XMLdocProps/core.xml has author, created and last modified by. Embedded macros sit in vbaProject.bin.
DOC, XLS, PPTOLE compound fileMetadata and possibly deleted text fragments

Renaming a DOCX to ZIP lets an analyst open the parts directly.

Hex view of other formats

Executables begin with MZ and have a PE header. Archives start with PK, Rar!, or 37 7A BC AF 27 1C for 7-Zip. Audio and video files have their own headers, and an MP3 may begin with ID3.

A worked example

A file named report.txt is flagged. In a hex editor, offset 0 shows 25 50 44 46, and the end contains %%EOF.

The bytes indicate it is a PDF with the wrong extension. The analyst records the mismatch, hashes the file and reads its metadata with a parser.

How the exam asks about this

  • "Which hex bytes start a JPEG file?" → FF D8 FF.
  • "What does the signature 4D 5A indicate?" → A Windows executable (MZ header).
  • "Which tag in a photo can reveal where it was taken?" → The EXIF GPS latitude and longitude.

What to remember for the exam

  • Signatures sit at offset 0, and they are a stronger indicator of file type than the extension.
  • JPEG starts FF D8 and ends FF D9. BMP starts with BM. PDF starts with %PDF. ZIP and OOXML start with PK.
  • UTF-16 has a BOM of FF FE or FE FF. UTF-8's is EF BB BF.
  • EXIF is stored in the JPEG APP1 segment.
  • Little endian stores the least significant byte first.
Watch out

Absence of EXIF does not prove a photo was edited. Messaging and social platforms commonly remove it.

Common mistakes

Trusting the extension. An attacker or user can rename a file. The header decides the type.

Reading multi byte values in the wrong order. On x86 the bytes are reversed.

Treating DOCX as one binary blob. It is a ZIP of XML parts that can be examined one by one.

Check yourself

  • What is an offset?

    The distance in bytes from the start of a file or disk, where the first byte is offset 0.

  • Which bytes end a JPEG?

    FF D9, the EOI marker.

  • Why can a DOCX be opened as a ZIP file?

    Office Open XML documents are ZIP archives that contain XML parts and media.

Topic 7 of 8 in Digital Evidence

Test yourself on Digital Evidence

The full EC-Council 312-49 question bank has 900 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by EC-Council. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.