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:APK Signing Block

From ReverseEngineering.wiki
Format
Platforms Platform:Android
Magic "APK Sig Block 42" (last 16 bytes of the block)
Endianness little-endian
On this wiki Facts · Code · Notes · Topics

Block of ID-value pairs between the last ZIP entry and the central directory of an APK, ending with the 16-byte magic "APK Sig Block 42"; holds the v2 and v3 signatures; the v4 signature is a separate .idsig file.

Layout

uint64 size_of_block            (excludes this field)
repeated: uint64 pair_len; uint32 id; byte value[pair_len-4]
uint64 size_of_block            (same value)
char   magic[16] = "APK Sig Block 42"

Find it: locate the ZIP EOCD (50 4B 05 06) at the file end, read the central directory offset, check that the 16 bytes before that offset are the magic, read the second size field and go back size+8 bytes to the first one. Both size fields must match. Unknown ids are ignored by the installer. The block sits in the gap before the central directory, invisible to ordinary ZIP tools, so re-zipping an APK destroys the v2/v3 signatures.

IDs

0x7109871A v2 signature, 0xF05368C0 v3 signature, 0x42726577 verity padding (pads the block so the central directory is 4096-aligned), 0xBEEFF00D v2 stripping-protection attribute. See the enum fact. Unverified from the sources read: v3.1 (0x1B93AD61) and source-stamp (0x2B09189E / 0x6DFF800D) ids; check apksig.

Signed data

v2/v3 value: length-prefixed sequences of signers; each signer has signed data (digests per signature algorithm id, DER X.509 certificates, additional attributes; v3 adds minSdk/maxSdk and a rotation lineage), signatures and a public key. Digests are computed over 1 MiB chunks of the ZIP entries, the central directory and the EOCD (its central directory offset treated as the signing block offset): leaf digest over byte 0xA5 + chunk length + chunk, root digest over byte 0x5A + chunk count + leaf digests.

v4

The v4 scheme (Android 11) is the separate file <apk>.apk.idsig (see the struct fact).

v1

JAR signing in META-INF is independent and can coexist.

Tools: apksigner, apk-parser, androguard.