Skip to main content

Module compress

Module compress 

Source
Expand description

SMB3 compression: the COMPRESSION_TRANSFORM_HEADER ([MS-SMB2] §2.2.42) and SMB2_COMPRESSION_CAPABILITIES negotiate context ([MS-SMB2] §2.2.3.1.3).

LZNT1 (compress + decompress) is delegated to the lznt1 crate; Pattern_V1 (a repeated-byte payload, §2.2.42.1) is expanded inline. Only the unchained transform form is produced; both forms are accepted on receive.

Modules§

algo
Compression algorithm ids ([MS-SMB2] §2.2.3.1.3).

Constants§

CAP_FLAG_CHAINED
SMB2_COMPRESSION_CAPABILITIES_FLAG_CHAINED ([MS-SMB2] §2.2.3.1.3): advertised in the negotiate context Flags field when chained compression is supported.
PROTOCOL_ID
COMPRESSION_TRANSFORM ProtocolId: 0xFC 'S' 'M' 'B'.
SUPPORTED
Algorithms this server can both send and receive.

Functions§

build_compression_caps
Encode the server SMB2_COMPRESSION_CAPABILITIES context data advertising algos, setting SMB2_COMPRESSION_CAPABILITIES_FLAG_CHAINED when chained.
compress_message
Wrap msg in an unchained LZNT1 COMPRESSION_TRANSFORM. Returns None when the algorithm is unsupported or compression does not shrink the message (the caller then sends it uncompressed).
compress_message_chained
Wrap msg in a chained COMPRESSION_TRANSFORM_HEADER ([MS-SMB2] \u00a72.2.42.2), emitting a Pattern_V1 payload for each long single-byte run and an algorithm (or uncompressed NONE) payload for the data between runs ([MS-SMB2] \u00a73.1.4.4). For a READ response the SMB2 header and READ structure are carried in a leading NONE payload so only the file data is compressed. Returns None when the result would not shrink the message.
decompress_message
Decompress a whole \xFCSMB COMPRESSION_TRANSFORM frame into the original SMB2 message. None on malformed input or an unsupported algorithm.
negotiate_algos
Intersect the client’s offered algorithms with the server’s, preserving the client’s order so the negotiate response echoes the requested CompressionIds when all are supported ([MS-SMB2] §3.3.5.4).
parse_compression_caps
Parse a client SMB2_COMPRESSION_CAPABILITIES context (§2.2.3.1.3) into its advertised algorithm list.
parse_compression_flags
Read the Flags field of a client SMB2_COMPRESSION_CAPABILITIES context (§2.2.3.1.3).