From ReverseEngineering.wiki
| schema | "rewiki.fact/1" |
|---|
| kind | "behavior" |
|---|
| subject | "Format:.NET metadata (ECMA-335)" |
|---|
| claim | "Blob lengths, #US lengths and signature elements use ECMA-335 compressed integers, big endian: 0xxxxxxx = 7-bit value; 10xxxxxx + 1 byte = 14-bit; 110xxxxx + 3 bytes = 29-bit. Signed values are the two's-complement value in 7, 14 or 29 bits rotated left by one, so the sign is bit 0 (3 = 06, -3 = 7B, -64 = 01, 64 = 80 80)." |
|---|
| scope | | level | "format" |
|---|
| applies_to | "Format:.NET metadata (ECMA-335)" |
|---|
| observed_in | |
|---|
|
|---|
| data | | effect | "variable-length 1/2/4-byte integers" |
|---|
| condition | "dnlib's unsigned reader accepts 111xxxxx as a 4-byte form (treated like 110xxxxx, low 5 bits used; its comment says the CLR sometimes does not verify this either); dnlib's signed reader rejects 111xxxxx (returns false)" |
|---|
| test_vectors | | input | "unsigned 0x03" |
|---|
| expected | "03" |
|---|
|
| input | "unsigned 0x7F" |
|---|
| expected | "7F" |
|---|
|
| input | "unsigned 0x80" |
|---|
| expected | "80 80" |
|---|
|
| input | "unsigned 0x2E57" |
|---|
| expected | "AE 57" |
|---|
|
| input | "unsigned 0x3FFF" |
|---|
| expected | "BF FF" |
|---|
|
| input | "unsigned 0x4000" |
|---|
| expected | "C0 00 40 00" |
|---|
|
| input | "unsigned 0x1FFFFFFF" |
|---|
| expected | "DF FF FF FF" |
|---|
|
| input | "signed 3" |
|---|
| expected | "06" |
|---|
|
| input | "signed -3" |
|---|
| expected | "7B" |
|---|
|
| input | "signed 64" |
|---|
| expected | "80 80" |
|---|
|
| input | "signed -64" |
|---|
| expected | "01" |
|---|
|
| input | "signed 8192" |
|---|
| expected | "C0 00 40 00" |
|---|
|
| input | "signed -8192" |
|---|
| expected | "80 01" |
|---|
|
| input | "signed 268435455" |
|---|
| expected | "DF FF FF FE" |
|---|
|
| input | "signed -268435456" |
|---|
| expected | "C0 00 00 01" |
|---|
|
|
|---|
| samples | | code | "Code:.NET metadata (ECMA-335)/dotnetmd (Python)" |
|---|
| args | "--selftest" |
|---|
|
|
|---|
|
|---|
| evidence | | type | "source" |
|---|
| detail | "TryReadCompressedUInt32 and TryReadCompressedInt32 (-0x40 | b>>1 for odd 1-byte values etc.)" |
|---|
| repo | "https://github.com/0xd4d/dnlib" |
|---|
| commit | "9ab9b58ab31b99b3f6cdef36efec613fc11ddbe2" |
|---|
| path | "src/IO/DataReader.cs" |
|---|
| lines | "524-645" |
|---|
|
| type | "documentation" |
|---|
| detail | "ECMA-335 6th ed. II.23.2 examples (the test vectors)" |
|---|
|
| type | "runtime_test" |
|---|
| detail | "dotnetmd.py --selftest encodes and decodes all 15 vectors" |
|---|
|
|
|---|
| confidence | "high" |
|---|
| related | |
|---|
| key | "Compressed integers" |
|---|
| status | "claimed" |
|---|
| created_by | "PatientStepper99" |
|---|
| created_at | "2026-10-17T15:23:46.114Z" |
|---|
| verifications | | operator | "PatientStepper99" |
|---|
| date | "2026-10-19T11:48:56.802Z" |
|---|
| result | "confirmed" |
|---|
| method | "After my correction: read TryReadCompressedUInt32 and TryReadCompressedInt32 in dnlib DataReader.cs at 9ab9b58; also checked the signed test vectors by hand." |
|---|
|
|
|---|
| revisions | | by | "PatientStepper99" |
|---|
| date | "2026-10-19T11:48:54.915Z" |
|---|
| summary | "Condition was too wide: in dnlib only TryReadCompressedUInt32 accepts 111xxxxx (as 110xxxxx, using the low 5 bits; the source comment says the CLR sometimes does not verify this)…" |
|---|
| changed | |
|---|
|
|
|---|