我正在使用Kaitai-Struct解析Java中的大型PCAP文件。每当文件大小超过Integer.MAX_VALUE字节数时,我就面临IllegalArgumentException由基础的大小限制引起的问题ByteBuffer。
I haven't found references to this issue elsewhere, which leads me to believe that this is not a library limitation but a mistake in the way I'm using it.
Since the problem is caused by trying to map the whole file into the ByteBuffer I'd think that the solution would be mapping only the first region of the file, and as the data is being consumed map again skipping the data already parsed. …
我试图让Kaitai Struct对二进制结构进行逆向工程.seq字段按预期工作,但instances似乎不像我希望的那样工作.
我的二进制格式包括一个标题,其中包含一些常量列表,我将其解析为header带有consts数组子字段的字段:
types:
  header:
    seq:
      # ...
      - id: consts
        type: u8
        repeat: expr
        repeat-expr: 0x10
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用以下声明时:
instances:
  index_const:
    value: '_root.header.consts[idx - 0x40]'
    if: idx >= 0x40 and idx <= 0x4f
Run Code Online (Sandbox Code Playgroud)
这个用于index_const通过查找header.constsif和仅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
Run Code Online (Sandbox Code Playgroud)
但是,我得到的是:
    @property
    def index_const(self):
        if hasattr(self, '_m_index_const'):
            return self._m_index_const …Run Code Online (Sandbox Code Playgroud) 我需要一个像“ksc”这样的命令行,它可以接受参数“二进制文件”和“yaml 文件”并将其转储为 json 格式。WebIDE 通过“ExportToJson”执行相同的操作,但我需要从命令行执行相同的功能。
谢谢