我正在尝试让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.consts
if和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] 删除。
我来说两句