pysap.SAPCAR module

class pysap.SAPCAR.SAPCARArchive(fil, mode='rb+', version=b'2.01')[source]

Bases: object

Proxy class that can be used to read SAP CAR archive files.

add_file(filename, archive_filename=None)[source]

Adds a new file to the SAP CAR archive file.

Parameters:
  • filename (string) – name of the file to add

  • archive_filename (string) – name of the file to use in the archive

close()[source]

Close the file descriptor object associated to the archive file.

create()[source]

Creates the structure for holding a new SAP CAR archive file.

fd = None
filename = None
property files

The list of file objects inside this archive file.

Returns:

list of file objects

Return type:

L{dict} of L{SAPCARArchiveFile}

property files_names

The list of file names inside this archive file.

Returns:

list of file names

Return type:

L{list} of L{string}

open(filename)[source]

Returns a file-like object that can be used to access a file inside the SAP CAR archive.

Parameters:

filename (string) – name of the file to open

Returns:

a file-like object that can be used to access the decompressed file.

Return type:

file

raw()[source]

Returns the raw data of the archive file.

Returns:

raw data

Return type:

string

read()[source]

Reads the SAP CAR archive file and populates the files list.

Raises:

Exception – if the file is invalid or unsupported

property version

The version of the archive file.

Returns:

version

Return type:

string

write()[source]

Writes the SAP CAR archive file to the file descriptor.

write_as(filename=None)[source]

Writes the SAP CAR archive file to another file.

Parameters:

filename (string) – name of the file to write to

class pysap.SAPCAR.SAPCARArchiveFile(file_format=None)[source]

Bases: object

Proxy class that can be used to access a file inside a SAP CAR archive and obtain its properties.

static calculate_checksum(data)[source]

Calculates the CRC32 checksum of a given data string.

Parameters:

data (str) – data to calculate the checksum over

Returns:

the CRC32 checksum

Return type:

int

check_checksum()[source]

Checks if the checksum of the file is valid.

Returns:

if the checksum matches

Return type:

bool

property checksum

The checksum of the file.

Returns:

checksum

Return type:

int

Raises:

SAPCARInvalidFileException – if the file is invalid and contains more than one end of data block

property filename

The name of the file.

Returns:

name of the file

Return type:

string

classmethod from_archive_file(archive_file, version=b'2.01')[source]

Populates the file format object from another archive file object.

Parameters:
  • archive_file (L{SAPCARArchiveFile}) – archive file object to build the file format object from

  • version (string) – version of the file to construct

Raises:

ValueError – if the version requested is invalid

classmethod from_file(filename, version=b'2.01', archive_filename=None)[source]

Populates the file format object from an actual file on the local file system.

Parameters:
  • filename (string) – filename to build the file format object from

  • version (string) – version of the file to construct

  • archive_filename (string) – filename to use inside the archive file

Raises:

ValueError – if the version requested is invalid

is_directory()[source]

Determines if the file is a directory.

Returns:

if the file is a directory

Return type:

bool

is_file()[source]

Determines if the file is a regular file.

Returns:

if the file is a regular file

Return type:

bool

open(enforce_checksum=False)[source]

Opens the compressed file and returns a file-like object that can be used to access its uncompressed content.

Parameters:

enforce_checksum (bool) – If the checksum validation should be enforce

Returns:

file-like object with the uncompressed file content

Return type:

file

Raises:
property perm_mode

The permissions mode of the file.

Returns:

permissions in numeric format

Return type:

int

property permissions

The permissions of the file.

Returns:

permissions in human-readable format

Return type:

string

property size

The size of the file.

Returns:

size of the file

Return type:

int

property timestamp

The timestamp of the file.

Returns:

timestamp in human-readable format

Return type:

string

property timestamp_raw

The timestamp of the file.

Returns:

timestamp in numeric format

Return type:

int

property type

The type of the file.

Returns:

type of the file

Return type:

string

property version

The version of the file.

Returns:

version of the file

Return type:

string

class pysap.SAPCAR.SAPCARArchiveFilev200Format(_pkt, /, *, type=b'RG', perm_mode=0, file_length_low=0, file_length_high=0, timestamp=0, code_page=0, user_info_length=0, filename_length=0, filename=None, user_info=None, blocks=[])[source]

Bases: PacketNoPadded

SAP CAR file information format

This is ued to parse files inside a SAP CAR archive.

aliastypes = [<class 'pysap.SAPCAR.SAPCARArchiveFilev200Format'>, <class 'pysap.utils.fields.PacketNoPadded'>, <class 'scapy.packet.Packet'>]
extract(fd)[source]

Extracts the archive file and writes the extracted file to the provided file object. Returns the checksum obtained from the archive. If blocks are uncompressed, the file is directly extracted. If the blocks are compressed, each block is added to a buffer, skipping the length field, and decompression is performed after the block marked as end of data. Expected length and compression header is obtained from the first block and checksum from the end of data block.

Parameters:

fd (file) – file-like object to write the extracted file to

Returns:

checksum

Return type:

int

Raises:
fields_desc: List[AnyField] = [<StrFixedLenField (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).type>, <LEIntField (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).perm_mode>, <LELongField (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).file_length_low>, <LEIntField (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).file_length_high>, <LELongField (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).timestamp>, <LEIntField (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).code_page>, <FieldLenField (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).user_info_length>, <FieldLenField (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).filename_length>, <StrNullFixedLenField (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).filename>, <StrFixedLenField (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).user_info>, <scapy.fields.ConditionalField object>]
property file_length

Getter for the file length fields. It converts the two length fields (low and high) as provided in the archive file into a long long integer.

is_filename_null_terminated = False
version = b'2.00'
class pysap.SAPCAR.SAPCARArchiveFilev201Format(_pkt, /, *, type=b'RG', perm_mode=0, file_length_low=0, file_length_high=0, timestamp=0, code_page=0, user_info_length=0, filename_length=0, filename=None, user_info=None, blocks=[])[source]

Bases: SAPCARArchiveFilev200Format

SAP CAR file information format

This is used to parse files inside a SAP CAR archive.

aliastypes = [<class 'pysap.SAPCAR.SAPCARArchiveFilev201Format'>, <class 'pysap.SAPCAR.SAPCARArchiveFilev200Format'>, <class 'pysap.utils.fields.PacketNoPadded'>, <class 'scapy.packet.Packet'>]
fields_desc: List[AnyField] = [<StrFixedLenField (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).type>, <LEIntField (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).perm_mode>, <LELongField (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).file_length_low>, <LEIntField (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).file_length_high>, <LELongField (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).timestamp>, <LEIntField (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).code_page>, <FieldLenField (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).user_info_length>, <FieldLenField (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).filename_length>, <StrNullFixedLenField (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).filename>, <StrFixedLenField (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).user_info>, <scapy.fields.ConditionalField object>]
is_filename_null_terminated = True
version = b'2.01'
class pysap.SAPCAR.SAPCARArchiveFormat(_pkt, /, *, magic_string=b'CAR ', version=b'2.01', files0=[], files1=[])[source]

Bases: Packet

SAP CAR file format

This is used to parse SAP CAR archive files.

aliastypes = [<class 'pysap.SAPCAR.SAPCARArchiveFormat'>, <class 'scapy.packet.Packet'>]
fields_desc: List[AnyField] = [<StrFixedLenField (SAPCARArchiveFormat).magic_string>, <StrFixedLenField (SAPCARArchiveFormat).version>, <scapy.fields.ConditionalField object>, <scapy.fields.ConditionalField object>]
class pysap.SAPCAR.SAPCARCompressedBlobFormat(_pkt, /, *, compressed_length=8, uncompress_length=0, algorithm=18, magic_bytes=b'\x1f\x9d', special=2, blob=None)[source]

Bases: PacketNoPadded

SAP CAR compressed blob

This is used for decompressing blobs inside the compressed block.

aliastypes = [<class 'pysap.SAPCAR.SAPCARCompressedBlobFormat'>, <class 'pysap.utils.fields.PacketNoPadded'>, <class 'scapy.packet.Packet'>]
fields_desc: List[AnyField] = [<LEIntField (SAPCARCompressedBlobFormat).compressed_length>, <LEIntField (SAPCARCompressedBlobFormat).uncompress_length>, <ByteEnumField (SAPCARCompressedBlobFormat).algorithm>, <StrFixedLenField (SAPCARCompressedBlobFormat).magic_bytes>, <ByteField (SAPCARCompressedBlobFormat).special>, <scapy.fields.MultipleTypeField object>]
class pysap.SAPCAR.SAPCARCompressedBlockFormat(_pkt, /, *, type=b'ED', compressed=<SAPCARCompressedBlobFormat  |>, checksum=0)[source]

Bases: PacketNoPadded

SAP CAR compressed block

This is used for decompressing blocks inside the file info format.

aliastypes = [<class 'pysap.SAPCAR.SAPCARCompressedBlockFormat'>, <class 'pysap.utils.fields.PacketNoPadded'>, <class 'scapy.packet.Packet'>]
fields_desc: List[AnyField] = [<StrFixedLenField (SAPCARCompressedBlockFormat).type>, <scapy.fields.ConditionalField object>, <scapy.fields.ConditionalField object>]
exception pysap.SAPCAR.SAPCARInvalidChecksumException[source]

Bases: Exception

Exception to denote a syntactically valid SAP CAR file with an invalid checksum

exception pysap.SAPCAR.SAPCARInvalidFileException[source]

Bases: Exception

Exception to denote an invalid SAP CAR file

pysap.SAPCAR.SAPCAR_BLOCK_TYPE_COMPRESSED = b'DA'

SAP CAR compressed block

pysap.SAPCAR.SAPCAR_BLOCK_TYPE_COMPRESSED_LAST = b'ED'

SAP CAR compressed end of data block

pysap.SAPCAR.SAPCAR_BLOCK_TYPE_UNCOMPRESSED = b'UD'

SAP CAR uncompressed block

pysap.SAPCAR.SAPCAR_BLOCK_TYPE_UNCOMPRESSED_LAST = b'UE'

SAP CAR uncompressed end of data block

pysap.SAPCAR.SAPCAR_HEADER_MAGIC_STRING_BACKUP = b'CAR\x00'

SAP CAR archive header magic string backup file

pysap.SAPCAR.SAPCAR_HEADER_MAGIC_STRING_STANDARD = b'CAR '

SAP CAR archive header magic string standard

pysap.SAPCAR.SAPCAR_TYPE_AS400 = b'SV'

SAP CAR AS400 save file string

pysap.SAPCAR.SAPCAR_TYPE_DIR = b'DR'

SAP CAR directory string

pysap.SAPCAR.SAPCAR_TYPE_FILE = b'RG'

SAP CAR regular file string

SAP CAR Unix soft link string

pysap.SAPCAR.SAPCAR_TYPE_SHORTCUT = b'SC'

SAP CAR Windows short cut string

pysap.SAPCAR.SAPCAR_TYPE_SIGNATURE = b'SM'

SAP CAR SIGNATURE.SMF file string

pysap.SAPCAR.SAPCAR_VERSION_200 = b'2.00'

SAP CAR file format version 2.00 string

pysap.SAPCAR.SAPCAR_VERSION_201 = b'2.01'

SAP CAR file format version 2.01 string

pysap.SAPCAR.filemode(mode)[source]

Convert a file’s mode to a string of the form ‘-rwxrwxrwx’.

pysap.SAPCAR.sapcar_archive_file_versions = {b'2.00': <class 'pysap.SAPCAR.SAPCARArchiveFilev200Format'>, b'2.01': <class 'pysap.SAPCAR.SAPCARArchiveFilev201Format'>}

SAP CAR file format versions

pysap.SAPCAR.sapcar_is_last_block(packet)[source]

Helper function that evaluates if a block packet is the end of data one or not.

Parameters:

packet (Packet) – packet to check

Returns:

if the block packet is the end of data one

Return type:

bool