Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"Segment does not start with %r, but with %r" % (expected_tag, tag))
log.debug("Reading segment at %d", segment_position)
# Next four bytes are table of contents mask
toc_mask = types.Int32.read(file)
if log.isEnabledFor(logging.DEBUG):
for prop_name, prop_mask in toc_properties.items():
prop_is_set = (toc_mask & prop_mask) != 0
log.debug("Property %s is %s", prop_name, prop_is_set)
endianness = '>' if (toc_mask & toc_properties['kTocBigEndian']) else '<'
# Next four bytes are version number
version = types.Int32.read(file, endianness)
if version not in (4712, 4713):
log.warning("Unrecognised version number.")
# Now 8 bytes each for the offset values
next_segment_offset = types.Uint64.read(file, endianness)
raw_data_offset = types.Uint64.read(file, endianness)
# Calculate data and next segment position
lead_size = 7 * 4
data_position = segment_position + lead_size + raw_data_offset
if next_segment_offset == 0xFFFFFFFFFFFFFFFF:
# Segment size is unknown. This can happen if LabVIEW crashes.
# Try to read until the end of the file.
log.warning(
"Last segment of file has unknown size, "
"will attempt to read to the end of the file")
def _read_lead_in(self, file, segment_position, is_index_file=False):
expected_tag = b'TDSh' if is_index_file else b'TDSm'
tag = file.read(4)
if tag == b'':
raise EOFError
if tag != expected_tag:
raise ValueError(
"Segment does not start with %r, but with %r" % (expected_tag, tag))
log.debug("Reading segment at %d", segment_position)
# Next four bytes are table of contents mask
toc_mask = types.Int32.read(file)
if log.isEnabledFor(logging.DEBUG):
for prop_name, prop_mask in toc_properties.items():
prop_is_set = (toc_mask & prop_mask) != 0
log.debug("Property %s is %s", prop_name, prop_is_set)
endianness = '>' if (toc_mask & toc_properties['kTocBigEndian']) else '<'
# Next four bytes are version number
version = types.Int32.read(file, endianness)
if version not in (4712, 4713):
log.warning("Unrecognised version number.")
# Now 8 bytes each for the offset values
next_segment_offset = types.Uint64.read(file, endianness)
raw_data_offset = types.Uint64.read(file, endianness)