Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:Debian package

From ReverseEngineering.wiki
Format
Magic !<arch>\n then a member named debian-binary
Extensions .deb, .udeb, .ddeb
On this wiki Facts · Code · Notes · Topics

The .deb package of Debian, Ubuntu and derivatives: an ar archive with exactly three leading members, debian-binary ("2.0"), control.tar[.gz/.xz/.zst] and data.tar[.gz/.xz/.zst/.bz2/.lzma].

Structure

A .deb is an Format:ar archive (magic !<arch> and a linefeed). Per the Debian deb(5) manual page (dpkg-dev 1.21.22) there are three required members that must occur in this exact order; extra members after data.tar should be ignored, and members that older tools may skip start with an underscore:

  1. debian-binary: text lines; currently one line, the format version 2.0. A changed major number means an incompatible format.
  2. control.tar with an optional compression suffix: uncompressed, .gz, .xz or .zst. It holds control (mandatory: name, version, architecture, dependencies...) and optionally md5sums, conffiles, triggers, shlibs, symbols and the maintainer scripts preinst, postinst, prerm, postrm.
  3. data.tar with an optional suffix: uncompressed, .gz, .xz, .zst, .bz2 or .lzma. This is the file tree installed under /.

The tar variants allowed are v7, pre-POSIX ustar, a GNU subset and POSIX ustar. Only the common ar format is supported (no long-name extension), so names such as control.tar.zst fit in the 16-byte name field with the trailing /.

Getting at the binaries

  • ar t file.deb lists members; ar x file.deb extracts them; or dpkg-deb -x file.deb dir and dpkg-deb -e file.deb dir.
  • The compression of a member is told by its name suffix; also check magic: gzip 1F 8B, xz FD 37 7A 58 5A 00, zstd 28 B5 2F FD, bzip2 BZh (see Format:Gzip, Format:XZ, Format:Zstandard, Format:Bzip2).
  • Debug symbols ship separately as -dbgsym packages (.ddeb). They place build-id named files under /usr/lib/debug/.build-id/: debhelper's dh_strip extraction routine builds the path usr/lib/debug/.build-id/<first byte>/<rest>.debug from the build-id and records the ids in a dbgsym-build-ids file (Debian/debhelper, dh_strip, around line 292).
  • Unverified: Depends/Architecture fields in control identify the target CPU (amd64, arm64, armhf, i386...) without opening any binary.

Sources

Debian deb(5) manual page (documentation, read online). The dpkg source (GPL) was not read for this page.