Viewing and Interpreting Binary Data

Peter Bubestinger-Steindl
(peter @ ArkThis.com)

November 2022

How to display raw data?

Ideas…?

Data as Text? 😒️

PNG in a text editor

Hex editing! 🤩️

Hex View of a PNG

What is “Hex”?

“Hex” is short for “Hexadecimal” (which literally means “16”), and is a
base-16 numeral system.

 

btw: To avoid confusion, hex numbers are usually prefixed with “0x”:
0xFF, 0x10, 0x12345, etc.

Comparison to Decimal

Dec Hex
0 0
1 1
2 2
8 8
9 9
Base = 10 A
11 B
12 C
13 D
14 E
15 F
16 10 = Base (16)
255 FF

Hex 💕️ Byte

Why is hexadecimal (base-16) better than decimal (base-10) for digital data?

1 pair = 1 byte

Hex View of a PNG

Hex 💕️ Byte

  • From “00” to “FF” = 0..255

  • = The value range of 1 byte.

  • Each hex digit represents 4 bits.

  • 1 Byte = 8 Bit = 256 numbers [0..255]

  • 4 Bit = 16 numbers [0..15]

  • [0..15] (dec) = [0..F] (hex)

Character encoding

ASCII Table

Text as Data?

Hex View of plain text characters

Let’s Hack in Hex!

Hex View of a WAV

Hex editor: Introduction

Hex Editor UI: Offset/Data Columns
  1. Data offset (in byte)
  2. Data view (1 hex-pair = 1 byte)
  3. Text view

Hex editor: Introduction

  1. Data offset: (in byte)
    Shows “where in the file/stream” you are.
    The last number equals the filesize in total.

  2. Data view: (1 hex-pair = 1 byte)
    This is it: These are your bytes.
    Each shown as a number: [00..FF]

  3. Text view:
    This is each byte interpreted as text, applying a certain character set.
    Non-printable (or non-alphanumeric) characters are often represented by a placeholder. Cursor position highlights the corresponding hex-value, too.

“Magic bytes”

  • .PNG
  • RIFF
  • PK..
  • JFIF
  • AIFF
  • .Eߣ
  • %PDF-
  • 8BPS

Source: List of File Signatures (Wikipedia)

Exercise

Identify the file types in the given set, using a Hexeditor and the
“Magic Byte” list on Wikipedia

Unix “file” command (1973!)

Identifying mixed file types on Linux

See Wikipedia: File (command)

Exercise / Puzzle

The file “whatami”:

  • Identify what it is?
  • Find out what is wrong with it?

MIME Type

Multipurpose Internet Mail Extensions (MIME) is an Internet standard that extends the format of email messages to support text in character sets other than ASCII, as well attachments of audio, video, images, and application programs.” Wikipedia: Media Type

MIME Type Examples

  • application/zip
  • application/pdf
  • text/html
  • text/xml
  • text/csv
  • text/plain
  • image/png
  • image/jpeg
  • image/gif
  • audio/aac
  • audio/mpeg
  • video/DV
  • video/H264
  • video/mp4

Complete List (IANA), 2019-10-16

Remember our “no suffix” file set?

“UNIX file” can show the MIME type

So where’s my audio/video/image?

Hex view of WAV file

Data Structure

Hex view of WAV header (annotated)

Header? Payload?

“header refers to supplemental data placed at the beginning of a block of data being stored or transmitted. In data transmission, the data following the header is sometimes called the payload or body.” Wikipedia: Header (computing)

Examples

BMP Image

GIF Image

JPEG Image

PNG Image

WAV Audio

WAV Header

Comments?

Questions?