RAR Archive (.rar)

WinRAR archive in RAR4 and RAR5 variants.

Overview

RAR4 files are a sequence of blocks (marker, archive header, file headers, end) with 2-byte CRCs. RAR5 uses variable-length integers and typed headers with 32-bit CRCs. File data can be solid, encrypted (AES) and split into multiple volumes. Compression uses LZ variants with filters (E8/E8E9, Delta, RGB, audio) and PPMd in RAR3.

Where it is used

  • Software and media distribution, especially on file-sharing sites.
  • Multi-volume backups.

History

  • Created by Eugene Roshal in 1993; RAR5 was introduced with WinRAR 5.0 (2013).

Status today

  • Proprietary compressor; extraction code is freely available (unrar).

Structures read by the implementation

Offsets are in bytes from the start of the buffer named in each heading. Field names are taken from the implementation and are not an official specification. Fixed-width integers are shown as u/i (unsigned/signed) followed by bit width and byte order.

FileFields.ParseFile buffer h · RarCarver.cs

OffsetSizeTypeFieldNotes
p4u32 LEOdified
p4u32 LECrc
q4u32 LEOdified
q8i64 LEFile Time

Rar4Walker.FileHeaderCrcEnd buffer h · RarCarver.cs

OffsetSizeTypeFieldNotes
0x1A2u16 LEName Size
p2u16 LEExt

Rar4Walker.PlausibleFileHeader buffer h · RarCarver.cs

OffsetSizeTypeFieldNotes
0xF1u8–
0x191u8–
0x1A2u16 LEName Size

Rar4Walker.Process buffer h · RarCarver.cs

OffsetSizeTypeFieldNotes
0x32u16 LEFlags
0xB4u32 LEUnpacked
0x104u32 LECrc
0x144u32 LE–
0x181u8Ax Version
0x191u8Stored
0x191u8–
0x244u32 LE–
p2u16 LEVolume Number Value

Rar4Walker.ReadBlock buffer fixedPart · RarCarver.cs

OffsetSizeTypeFieldNotes
0x02u16 LEStored Crc
0x21u8Type
0x32u16 LEFlags
0x52u16 LEHeader Size

Rar4Walker.ReadBlock buffer header · RarCarver.cs

OffsetSizeTypeFieldNotes
0x74u32 LEData Size
0x204u32 LE–

KeyCache.ReadV5 buffer head · RarExtractor.cs

OffsetSizeTypeFieldNotes
0x04u32 LE–
p + 116bytesSalt
p + 178bytes–

V4Group.ReadV4 buffer first · RarExtractor.cs

OffsetSizeTypeFieldNotes
0x21u8–
0x52u16 LEEnc Size

V4Group.ReadV4 buffer head · RarExtractor.cs

OffsetSizeTypeFieldNotes
0x02u16 LE–
0x21u8Type
0x32u16 LEFlags
0x52u16 LESize
0x52u16 LEHead Size
0x74u32 LEAdd Size
0x74u32 LEPacked
0xB4u32 LEUnpacked
0x104u32 LECrc
0x144u32 LEDos Time
0x181u8Version
0x191u8Ethod
0x1A2u16 LEName Size
0x204u32 LE–
0x244u32 LE–

struct.ParseEncryptionRecord buffer h · RarExtractor.cs

OffsetSizeTypeFieldNotes
q + 116bytes–
q + 1716bytes–
q + 338bytes–

struct.ParseFile buffer h · RarExtractor.cs

OffsetSizeTypeFieldNotes
p4u32 LEOdified
p4u32 LECrc

Other fields read

Read inOffsetSizeTypeFieldNotes
RarVmFilters.Runpos4u32 LEAddr
RarArchiveModule.Probe0x07bytes–
Rar4Walker.EntryName0x32u16 LE–
Rar4Walker.FileName0x1A2u16 LEName Size
Rar4Walker.PlausibleSubHeader0x1A2u16 LEName Size
Rar5Walker.ReadBlock0x04u32 LEStored Crc

Constants

General DecodeTable

NameValueTypeNotes
LDecode[0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 64, 80, 96, 112…int[]
LBits[0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5]int[]
SDDecode[0, 4, 8, 16, 32, 64, 128, 192]int[]
SDBits[2, 2, 3, 4, 5, 6, 6, 6]int[]

General Unpack15

NameValueTypeNotes
DecL1[0x8000, 0xa000, 0xc000, 0xd000, 0xe000, 0xea00, 0xee00, 0xf000, 0xf200, 0xf200, 0xffff]int[]
PosL1[0, 0, 0, 2, 3, 5, 7, 11, 16, 20, 24, 32, 32]int[]
DecL2[0xa000, 0xc000, 0xd000, 0xe000, 0xea00, 0xee00, 0xf000, 0xf200, 0xf240, 0xffff]int[]
PosL2[0, 0, 0, 0, 5, 7, 9, 13, 18, 22, 26, 34, 36]int[]
DecHf0[0x8000, 0xc000, 0xe000, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xffff]int[]
PosHf0[0, 0, 0, 0, 0, 8, 16, 24, 33, 33, 33, 33, 33]int[]
DecHf1[0x2000, 0xc000, 0xe000, 0xf000, 0xf200, 0xf200, 0xf7e0, 0xffff]int[]
PosHf1[0, 0, 0, 0, 0, 0, 4, 44, 60, 76, 80, 80, 127]int[]
DecHf2[0x1000, 0x2400, 0x8000, 0xc000, 0xfa00, 0xffff, 0xffff, 0xffff]int[]
PosHf2[0, 0, 0, 0, 0, 0, 2, 7, 53, 117, 233, 0, 0]int[]
DecHf3[0x800, 0x2400, 0xee00, 0xfe80, 0xffff, 0xffff, 0xffff]int[]
PosHf3[0, 0, 0, 0, 0, 0, 0, 2, 16, 218, 251, 0, 0]int[]
DecHf4[0xff00, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff]int[]
PosHf4[0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0]int[]
ShortLen1[1, 3, 4, 4, 5, 6, 7, 8, 8, 4, 4, 5, 6, 6, 4, 0]int[]
ShortXor1[0, 0xa0, 0xd0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff, 0xc0, 0x80, 0x90, 0x98, 0x9c, 0xb0]int[]
ShortLen2[2, 3, 3, 3, 4, 4, 5, 6, 6, 4, 4, 5, 6, 6, 4, 0]int[]
ShortXor2[0, 0x40, 0x60, 0xa0, 0xd0, 0xe0, 0xf0, 0xf8, 0xfc, 0xc0, 0x80, 0x90, 0x98, 0x9c, 0xb0]int[]

General Unpack20

NameValueTypeNotes
DDecode[0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024, 1…int[]
DBits[0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, …int[]
NC298, DC = 48, RC = 28, BC = 19, MC = 257int

General Unpack29

NameValueTypeNotes
DDecode[0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024, 1…int[]
DBits[0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, …int[]
NC299, DC = 60, LDC = 17, RC = 28, BC = 20, Huff = NC + DC + LDC + RCint
VmGlobalAddr0x3C000uint
VmFixedGlobalSize0x40int

General RarRangeDecoder

NameValueTypeNotes
Top1u << 24, Bot = 1u << 15uint

General RarVmFilters

NameValueTypeNotes
FileSize0x1000000uint

General Rar5Unpack

NameValueTypeNotes
NC306intliterals + lengths
DC64intdistance slots
LDC16intlow-distance
RC44intrepeat lengths
BC20intpre-tree
HuffTableSizeNC + DC + LDC + RCint430

block state Rar5Unpack

NameValueTypeNotes
FilterDelta0, FilterE8 = 1, FilterE8E9 = 2, FilterArm = 3int
MaxFilterBlockSize0x400000int

—- Filters (RAR5: delta, x86 E8/E8E9, ARM) ———————————————— SolidStream

NameValueTypeNotes
fileSize0x1000000uint

General RarCarver

NameValueTypeNotes
SignatureV4[0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x00]byte[]
SignatureV5[0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x01, 0x00]byte[]
ResyncBack1024 * 1024long
ResyncAhead16L * 1024 * 1024long
ReadBufferSize1024 * 1024int

General Walker

NameValueTypeNotes
SectorErrorMarker.PatternLengthint

General Rar5Walker

NameValueTypeNotes
Main1, File = 2, Service = 3, Encryption = 4, EndArc = 5int

General RarExtractor

NameValueTypeNotes
SignatureV5[0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x01, 0x00]byte[]
SignatureV4[0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x00]byte[]
Main1, FileBlock = 2, Service = 3, Encryption = 4, EndArc = 5int

—————————————————————— RAR 1.5 – 4.x struct

NameValueTypeNotes
V4Main0x73, V4File = 0x74, V4Service = 0x7A, V4End = 0x7Bbyte

General RarArchiveModule

NameValueTypeNotes
MagicV5[0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x01, 0x00]byte[]
MagicV4[0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x00]byte[]

Implementation limits reader

ClassNameValueNotes
RarCarverMaxResyncs64
RarCarverMaxHeaderSize2 * 1024 * 1024
RarCarverMaxEntries1_000_000
RarCarverMaxNamesInDetails25
RarExtractorMaxEntries2_000_000
RarExtractorMaxHeaderSize2L * 1024 * 1024

RarVmFilter enum

NameValue
Unknown(next)
E8(next)
E8E9(next)
Itanium(next)
Delta(next)
Rgb(next)
Audio(next)
Upcase(next)
Structures and constants were extracted from: Carving/Plugins/Rar/Rar4Unpack.cs, Carving/Plugins/Rar/Rar5Unpack.cs, Carving/Plugins/Rar/RarCarver.cs, Carving/Plugins/Rar/RarExtractor.cs, Modules/FileSystems/RarArchiveModule.cs. Prose sections are a summary from public sources; verify details before relying on them.