I am trying to get Kaitai Struct to reverse engineer the binary structure. The seq fields work as intended, but the instances don't seem to work the way I want them to.
My binary format includes a header with a list of constants, which I parse as header with a subfield of the consts array:
types: header: seq:
However, when I try to use the following declaration:
instances: index_const: value: '_root.header.consts[idx - 0x40]' if: idx >= 0x40 and idx <= 0x4f
This method is designed to calculate the value of index_const by searching the header.consts array if and only if idx is in the range from [0x40..0x4f].
I use Python as my target language, and I assume that it should generate code, for example:
@property def index_const(self): if hasattr(self, '_m_index_const'): return self._m_index_const if self.idx >= 64 and self.idx <= 79: self._m_index_const = self._root.header.consts[(self.idx - 64)]; return self._m_index_const
However, I get:
@property def index_const(self): if hasattr(self, '_m_index_const'): return self._m_index_const self._m_index_const = self._root.header.consts[(self.idx - 64)]; return self._m_index_const
Is it just me, will I miss something obvious or is it a mistake in Kaitai Struct?
source share