.dat file format of Faster Than Light (FTL): Python parsing library

Application

Faster Than Light (FTL)

File extension

dat

This page hosts a formal specification of .dat file format of Faster Than Light (FTL) using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.

Usage

Parse a local file and get structure in memory:

data = FtlDat.from_file("path/to/local/file.dat")

Or parse structure from a bytes:

from kaitaistruct import KaitaiStream, BytesIO

raw = b"\x00\x01\x02..."
data = FtlDat(KaitaiStream(BytesIO(raw)))

After that, one can get various attributes from the structure by invoking getter methods like:

data.numFiles # => Number of files in the archive

Python source code to parse .dat file format of Faster Than Light (FTL)

ftl_dat.py

# This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

from pkg_resources import parse_version
from kaitaistruct import __version__ as ks_version, KaitaiStruct, KaitaiStream, BytesIO


if parse_version(ks_version) < parse_version('0.7'):
    raise Exception("Incompatible Kaitai Struct Python API: 0.7 or later is required, but you have %s" % (ks_version))

class FtlDat(KaitaiStruct):
    def __init__(self, _io, _parent=None, _root=None):
        self._io = _io
        self._parent = _parent
        self._root = _root if _root else self
        self._read()

    def _read(self):
        self.num_files = self._io.read_u4le()
        self.files = [None] * (self.num_files)
        for i in range(self.num_files):
            self.files[i] = self._root.File(self._io, self, self._root)


    class File(KaitaiStruct):
        def __init__(self, _io, _parent=None, _root=None):
            self._io = _io
            self._parent = _parent
            self._root = _root if _root else self
            self._read()

        def _read(self):
            self.meta_ofs = self._io.read_u4le()

        @property
        def meta(self):
            if hasattr(self, '_m_meta'):
                return self._m_meta if hasattr(self, '_m_meta') else None

            if self.meta_ofs != 0:
                _pos = self._io.pos()
                self._io.seek(self.meta_ofs)
                self._m_meta = self._root.Meta(self._io, self, self._root)
                self._io.seek(_pos)

            return self._m_meta if hasattr(self, '_m_meta') else None


    class Meta(KaitaiStruct):
        def __init__(self, _io, _parent=None, _root=None):
            self._io = _io
            self._parent = _parent
            self._root = _root if _root else self
            self._read()

        def _read(self):
            self.file_size = self._io.read_u4le()
            self.filename_size = self._io.read_u4le()
            self.filename = (self._io.read_bytes(self.filename_size)).decode(u"UTF-8")
            self.body = self._io.read_bytes(self.file_size)