pysap.SAPCAR module¶
-
class
pysap.SAPCAR.
SAPCARArchive
(fil, mode='rb+', version='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
-
fd
= None¶
-
filename
= None¶
-
files
¶ The list of file objects inside this archive file.
Returns: list of file objects Return type: L{dict} of L{SAPCARArchiveFile}
-
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
-
read
()[source]¶ Reads the SAP CAR archive file and populates the files list.
Raises: Exception – if the file is invalid or unsupported
-
version
¶ The version of the archive file.
Returns: version Return type: string
-
-
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
-
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
-
filename
¶ The name of the file.
Returns: name of the file Return type: string
-
classmethod
from_archive_file
(archive_file, version='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='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: - Exception – If the file to open is a directory
- DecompressError – If there’s a decompression error
- SAPCARInvalidFileException – If the file is invalid
- SAPCARInvalidChecksumException – If the checksum is invalid
-
perm_mode
¶ The permissions mode of the file.
Returns: permissions in numeric format Return type: int
-
permissions
¶ The permissions of the file.
Returns: permissions in human-readable format Return type: string
-
size
¶ The size of the file.
Returns: size of the file Return type: int
-
timestamp
¶ The timestamp of the file.
Returns: timestamp in human-readable format Return type: string
-
timestamp_raw
¶ The timestamp of the file.
Returns: timestamp in numeric format Return type: int
-
type
¶ The type of the file.
Returns: type of the file Return type: string
-
version
¶ The version of the file.
Returns: version of the file Return type: string
-
static
-
class
pysap.SAPCAR.
SAPCARArchiveFilev200Format
(_pkt='', post_transform=None, _internal=0, _underlayer=None, **fields)[source]¶ Bases:
pysap.utils.fields.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: - DecompressError – If there’s a decompression error
- SAPCARInvalidFileException – If the file is invalid
-
fields_desc
= [<Field (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).type>, <Field (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).perm_mode>, <Field (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).file_length_low>, <Field (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).file_length_high>, <Field (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).timestamp>, <Field (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).code_page>, <Field (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).user_info_length>, <Field (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).filename_length>, <Field (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).filename>, <Field (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).user_info>, <scapy.fields.ConditionalField object>]¶
-
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
= '2.00'¶
-
-
class
pysap.SAPCAR.
SAPCARArchiveFilev201Format
(_pkt='', post_transform=None, _internal=0, _underlayer=None, **fields)[source]¶ Bases:
pysap.SAPCAR.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
= [<Field (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).type>, <Field (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).perm_mode>, <Field (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).file_length_low>, <Field (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).file_length_high>, <Field (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).timestamp>, <Field (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).code_page>, <Field (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).user_info_length>, <Field (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).filename_length>, <Field (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).filename>, <Field (SAPCARArchiveFilev200Format,SAPCARArchiveFilev201Format).user_info>, <scapy.fields.ConditionalField object>]¶
-
is_filename_null_terminated
= True¶
-
version
= '2.01'¶
-
-
class
pysap.SAPCAR.
SAPCARArchiveFormat
(_pkt='', post_transform=None, _internal=0, _underlayer=None, **fields)[source]¶ Bases:
scapy.packet.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
= [<Field (SAPCARArchiveFormat).magic_string>, <Field (SAPCARArchiveFormat).version>, <scapy.fields.ConditionalField object>, <scapy.fields.ConditionalField object>]¶
-
-
class
pysap.SAPCAR.
SAPCARCompressedBlobFormat
(_pkt='', post_transform=None, _internal=0, _underlayer=None, **fields)[source]¶ Bases:
pysap.utils.fields.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
= [<Field (SAPCARCompressedBlobFormat).compressed_length>, <Field (SAPCARCompressedBlobFormat).uncompress_length>, <Field (SAPCARCompressedBlobFormat).algorithm>, <Field (SAPCARCompressedBlobFormat).magic_bytes>, <Field (SAPCARCompressedBlobFormat).special>, <scapy.fields.ConditionalField object>, <scapy.fields.ConditionalField object>]¶
-
-
class
pysap.SAPCAR.
SAPCARCompressedBlockFormat
(_pkt='', post_transform=None, _internal=0, _underlayer=None, **fields)[source]¶ Bases:
pysap.utils.fields.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
= [<Field (SAPCARCompressedBlockFormat).type>, <scapy.fields.ConditionalField object>, <scapy.fields.ConditionalField object>]¶
-
-
exception
pysap.SAPCAR.
SAPCARInvalidChecksumException
[source]¶ Bases:
exceptions.Exception
Exception to denote a syntactically valid SAP CAR file with an invalid checksum
-
exception
pysap.SAPCAR.
SAPCARInvalidFileException
[source]¶ Bases:
exceptions.Exception
Exception to denote an invalid SAP CAR file
-
pysap.SAPCAR.
SAPCAR_BLOCK_TYPE_COMPRESSED
= 'DA'¶ SAP CAR compressed block
-
pysap.SAPCAR.
SAPCAR_BLOCK_TYPE_COMPRESSED_LAST
= 'ED'¶ SAP CAR compressed end of data block
-
pysap.SAPCAR.
SAPCAR_BLOCK_TYPE_UNCOMPRESSED
= 'UD'¶ SAP CAR uncompressed block
-
pysap.SAPCAR.
SAPCAR_BLOCK_TYPE_UNCOMPRESSED_LAST
= 'UE'¶ SAP CAR uncompressed end of data block
-
pysap.SAPCAR.
SAPCAR_HEADER_MAGIC_STRING_BACKUP
= 'CAR\x00'¶ SAP CAR archive header magic string backup file
-
pysap.SAPCAR.
SAPCAR_HEADER_MAGIC_STRING_STANDARD
= 'CAR '¶ SAP CAR archive header magic string standard
-
pysap.SAPCAR.
SAPCAR_TYPE_AS400
= 'SV'¶ SAP CAR AS400 save file string
-
pysap.SAPCAR.
SAPCAR_TYPE_DIR
= 'DR'¶ SAP CAR directory string
-
pysap.SAPCAR.
SAPCAR_TYPE_FILE
= 'RG'¶ SAP CAR regular file string
-
pysap.SAPCAR.
SAPCAR_TYPE_LINK
= 'LK'¶ SAP CAR Unix soft link string
-
pysap.SAPCAR.
SAPCAR_TYPE_SHORTCUT
= 'SC'¶ SAP CAR Windows short cut string
-
pysap.SAPCAR.
SAPCAR_TYPE_SIGNATURE
= 'SM'¶ SAP CAR SIGNATURE.SMF file string
-
pysap.SAPCAR.
SAPCAR_VERSION_200
= '2.00'¶ SAP CAR file format version 2.00 string
-
pysap.SAPCAR.
SAPCAR_VERSION_201
= '2.01'¶ SAP CAR file format version 2.01 string
-
pysap.SAPCAR.
sapcar_archive_file_versions
= {'2.00': <class 'pysap.SAPCAR.SAPCARArchiveFilev200Format'>, '2.01': <class 'pysap.SAPCAR.SAPCARArchiveFilev201Format'>}¶ SAP CAR file format versions