测品娱乐
您的当前位置:首页rar文档结构分析

rar文档结构分析

来源:测品娱乐


RAR version 3.40 - Technical information

技术信息

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

THE ARCHIVE FORMAT DESCRIBED BELOW IS ONLY VALID FOR VERSIONS SINCE 1.50

下面文档管理器格式的描述仅仅是对1.5以后的版本是有用的

==========================================================================

RAR archive file format

RAR文档管理器格式

==========================================================================

Archive file consists of variable length blocks. The order of these

blocks may vary, but the first block must be a marker block followed by

an archive header block.

归档文件是由可变长度的块组成,但是跟随在归档头块的第一个块一定要是一个标志块

Each block begins with the following fields:

每一个块是由一下部分组成

HEAD_CRC 2 bytes CRC of total block or block part

CRC的总块或者局部块

HEAD_TYPE 1 byte Block type

块类型

HEAD_FLAGS 2 bytes Block flags

块标志

HEAD_SIZE 2 bytes Block size

块大小

ADD_SIZE 4 bytes Optional field - added block size

可选的区域,添加的块大小

Field ADD_SIZE present only if (HEAD_FLAGS & 0x8000) != 0

区域ADD_SIZE只有在head_flags&0x8000不等于0的时候才会被提出

Total block size is HEAD_SIZE if (HEAD_FLAGS & 0x8000) == 0

and HEAD_SIZE+ADD_SIZE if the field ADD_SIZE is present - when

(HEAD_FLAGS & 0x8000) != 0.

总块大小就是Head_size,如果add_size被提出的话那么就是head_size+add_size,这些都是在head_flags==0的情况下

In each block the followings bits in HEAD_FLAGS have the same meaning:

每一个块都有几个位来标志head_flags,他有这样的意思

0x4000 - if set, older RAR versions will ignore the block

and remove it when the archive is updated.

if clear, the block is copied to the new archive

file when the archive is updated;

如果设定,老版本的rar会在更新的忽略这个块,并且移除它。如果清除,

当更新的时候,块会被复制到新的归档文件中

0x8000 - if set, ADD_SIZE field is present and the full block

size is HEAD_SIZE+ADD_SIZE.

如果设定,add_size区域会被提出,并且总块大小被设定为head_size+add_size

Declared block types:

声明块类型

HEAD_TYPE=0x72 marker block

标志块

HEAD_TYPE=0x73 archive header

归档头部

HEAD_TYPE=0x74 file header

文件头部

HEAD_TYPE=0x75 old style comment header

老风格的头内容

HEAD_TYPE=0x76 old style authenticity information

老风格的授权信息

HEAD_TYPE=0x77 old style subblock

老风格的子块

HEAD_TYPE=0x78 old style recovery record

老风格的恢复记录

HEAD_TYPE=0x79 old style authenticity information

老风格的授权信息

HEAD_TYPE=0x7a subblock

子块

Comment block is actually used only within other blocks and doesn't

exist separately.

块内容不能的存在,要依靠其他块使用

Archive processing is made in the following manner:

归档过程遵守以下的风格

1. Read and check marker block

读和检查标志块

2. Read archive header

读归档头部

3. Read or skip HEAD_SIZE-sizeof(MAIN_HEAD) bytes

读或者是忽略head_size大小

4. If end of archive encountered then terminate archive processing,

else read 7 bytes into fields HEAD_CRC, HEAD_TYPE, HEAD_FLAGS,

HEAD_SIZE.

如果归档遭遇结束,那么终止归档过程,不然的话,读7个字节在区域head_crc,head_type,head_flags,head_size

5. Check HEAD_TYPE.

检查head_TYpe

if HEAD_TYPE==0x74

read file header ( first 7 bytes already read )

读文件头

read or skip HEAD_SIZE-sizeof(FILE_HEAD) bytes

读或者忽略head_size

if (HEAD_FLAGS & 0x100)

read or skip HIGH_PACK_SIZE*0x1000000x52 0x61 0x72 0x21 0x1a 0x07 0x00000+PACK_SIZE bytes

读或者忽略high_pack_size

else

read or skip PACK_SIZE bytes

读或者是忽略pack_size

else

read corresponding HEAD_TYPE block:

读相应的head_type块

read HEAD_SIZE-7 bytes

if (HEAD_FLAGS & 0x8000)

read ADD_SIZE bytes

6. go to 4.

转到第4步

==========================================================================

Block Formats

块格式

==========================================================================

Marker block ( MARK_HEAD )

标志块

HEAD_CRC Always 0x6152

2 bytes

HEAD_TYPE Header type: 0x72

1 byte

HEAD_FLAGS Always 0x1a21

2 bytes

HEAD_SIZE Block size = 0x0007

2 bytes

The marker block is actually considered as a fixed byte

sequence: 0x52 0x61 0x72 0x21 0x1a 0x07 0x00

标志块事实上被认为是一个修复字节,次序:0x52 0x61 0x72 0x21 0x1a 0x07 0x00

Archive header ( MAIN_HEAD )

归档头部

HEAD_CRC CRC of fields HEAD_TYPE to RESERVED2

2 bytes

HEAD_TYPE Header type: 0x73

1 byte

HEAD_FLAGS Bit flags:

2 bytes

0x0001 - Volume attribute (archive volume)

卷属性

0x0002 - Archive comment present

目前的归档内容

RAR 3.x uses the separate comment block

and does not set this flag.

RAR3.0使用的内容块,这个标志没有设定

0x0004 - Archive lock attribute

归档锁属性

0x0008 - Solid attribute (solid archive)

”固态“属性

0x0010 - New volume naming scheme ('volname.partN.rar')

新卷的命名方案

0x0020 - Authenticity information present

RAR 3.x does not set this flag.

目前的授权信息,rar3.X没有这个标志

0x0040 - Recovery record present

当前的恢复记录

0x0080 - Block headers are encrypted

块头是被加密的

0x0100 - First volume (set only by RAR 3.0 and later)

第一个卷,只有RAR3.0以后的版本才被确立

other bits in HEAD_FLAGS are reserved for

internal use

其他的位为国内用户保留

HEAD_SIZE Archive header total size including archive comments

2 bytes 归档头大小,包括归档内容。

RESERVED1 Reserved

2 bytes

RESERVED2 Reserved

4 bytes

File header (File in archive)

文件头

HEAD_CRC CRC of fields from HEAD_TYPE to FILEATTR

2 bytes and file name

HEAD_TYPE Header type: 0x74

1 byte

HEAD_FLAGS Bit flags:

2 bytes

0x01 - file continued from previous volume

文件从前一个卷继续

0x02 - file continued in next volume

文件从后一个卷继续

0x04 - file encrypted with password

文件使用密码加密

0x08 - file comment present

目前的文件内容

RAR 3.x uses the separate comment block

and does not set this flag.

0x10 - information from previous files is used (solid flag)

(for RAR 2.0 and later)

之前的文件信息被使用(RAR2.0以后版本可用)

bits 7 6 5 (for RAR 2.0 and later)

0 0 0 - dictionary size KB

0 0 1 - dictionary size 128 KB

0 1 0 - dictionary size 256 KB

0 1 1 - dictionary size 512 KB

1 0 0 - dictionary size 1024 KB

1 0 1 - dictionary size 2048 KB

1 1 0 - dictionary size 4096 KB

1 1 1 - file is directory

0x100 - HIGH_PACK_SIZE and HIGH_UNP_SIZE fields

are present. These fields are used to archive

only very large files (larger than 2Gb),

for smaller files these fields are absent.

high_pack_size和high_unp_size区域被提出,这些区域仅仅在归档大于2GB的文件时候才管用,对于小文件,他们是缺席的

0x200 - FILE_NAME contains both usual and encoded

Unicode name separated by zero. In this case

NAME_SIZE field is equal to the length

of usual name plus encoded Unicode name plus 1.

file_name的包括普通的和可编码的双字节编码,在这种情况下,name_size区域等价于普通名字+可编码的双字节编码+1的长度。

0x400 - the header contains additional 8 bytes

after the file name, which are required to

increase encryption security (so called 'salt').

头部在文件名之外包括额外的8个字节,这些字节是用来加密的

0x800 - Version flag. It is an old file version,

a version number is appended to file name as ';n'.

版本表示,版本数被附加到文件名中,用;n的形式

0x1000 - Extended time field present.

延伸的时间区域被提出

0x8000 - this bit always is set, so the complete

block size is HEAD_SIZE + PACK_SIZE

(and plus HIGH_PACK_SIZE, if bit 0x100 is set)

这个位通常被设定,因此,完全的块大小是head_size+pack_size(如果bit 0x100被设定的话,那么还要加上high_pack_size)

HEAD_SIZE File header full size including file name and comments

2 bytes 文件头大小包括文件名和内容

PACK_SIZE Compressed file size

4 bytes 压缩文件大小

UNP_SIZE Uncompressed file size

4 bytes 灭有压缩之前的大小

HOST_OS Operating system used for archiving

使用归档的操作系统

1 byte 0 - MS DOS

1 - OS/2

2 - Win32

3 - Unix

4 - Mac OS

5 - BeOS

FILE_CRC File CRC

4 bytes

FTIME Date and time in standard MS DOS format

4 bytes 标准ms dos格式的时间和日期

UNP_VER RAR version needed to extract file

释放文件所需要的RAR版本

1 byte

Version number is encoded as

10 * Major version + minor version.

版本号是可编码的作为,主版本号+小版本号

METHOD Packing method

打包方式

1 byte

0x30 - storing

存储

0x31 - fastest compression

最快压缩

0x32 - fast compression

快压缩

0x33 - normal compression

普通压缩

0x34 - good compression

好压缩

0x35 - best compression

最好压缩

NAME_SIZE File name size

2 bytes 文件名大小

ATTR File attributes

4 bytes 文件属性

HIGH_PACK_SIZE High 4 bytes of bit value of compressed file size.

压缩文件大小的进制高4位表示

4 bytes Optional value, presents only if bit 0x100 in HEAD_FLAGS

is set.

可选的数值,只有是head_flags的bit是0x100时才被选定

HIGH_UNP_SIZE High 4 bytes of bit value of uncompressed file size.

未压缩文件的进制高4位表示

4 bytes Optional value, presents only if bit 0x100 in HEAD_FLAGS

is set.

FILE_NAME File name - string of NAME_SIZE bytes size

文件名

SALT present if (HEAD_FLAGS & 0x400) != 0

8 bytes

EXT_TIME present if (HEAD_FLAGS & 0x1000) != 0

variable size

可变大小

other new fields may appear here.

其他新的区域可能在这里出现

==========================================================================

Application notes

==========================================================================

1. To process an SFX archive you need to skip the SFX module searching

for the marker block in the archive. There is no marker block sequence (0x52

0x61 0x72 0x21 0x1a 0x07 0x00) in the SFX module itself.

进行一个SFX归档的时候,你需要忽略SFX模块对于标志块的检查。在SFX模块中灭有对于标志块的块序列

2. The CRC is calculated using the standard polynomial 0xEDB88320. In

case the size of the CRC is less than 4 bytes, only the low order bytes

are used.

CRC适当的使用标准的多项式oxedb88320.在这种情况下 CRC少于4字节。只有低4字节才被使用..

因篇幅问题不能全部显示,请点此查看更多更全内容