Kaitai Struct:带条件的计算实例

选择0x4f

我正在尝试让Kaitai Struct对二进制结构进行逆向工程。seq字段可以按预期工作,但instances似乎不像我希望的那样工作。

我的二进制格式包括一个带有常量列表的标头,我将这些常量解析为header带有consts数组子字段的字段:

types:
  header:
    seq:
      # ...
      - id: consts
        type: u8
        repeat: expr
        repeat-expr: 0x10

但是,当我尝试使用以下声明时:

instances:
  index_const:
    value: '_root.header.consts[idx - 0x40]'
    if: idx >= 0x40 and idx <= 0x4f

index_const通过查找header.constsif和only if数组idx在[0x40..0x4f]范围内,可以计算出一个值

我使用Python作为目标语言,并假定它应该生成类似以下的代码:

    @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

但是,我得到的是:

    @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

是我自己,我是否缺少明显的东西,还是Kaitai Struct中的错误?

灰猫

是的,我想应该将其视为错误。至少,编译器应允许if在值实例中使用并正确处理它,或者不允许if并发出错误消息。

考虑到这一点,我认为没有理由为什么if允许使用常规的instances,而是用这种方式进行处理value instances

感谢您举报,我已经提交了一个问题


更新:该问题现已标记为已关闭。

if_instances现在测试。...解决了这一问题。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章