-
Notifications
You must be signed in to change notification settings - Fork 200
Description
I'm using the Kaitai Python runtime in https://github.com/Mahlet-Inc/hobbits to make a Kaitai runner and viewer plugin. It works in a few cases, but a user pointed out a pretty simple case in which it fails to calculate offsets correctly: Mahlet-Inc/hobbits#93
Here is the ksy:
meta:
file-extension: bla
id: servermod
endian: le
imports:
- /serialization/google_protobuf
seq:
- id: records
type: record
repeat: eos
types:
main_header:
seq:
- id: ip1
type: u1
- id: ip2
type: u1
- id: ip3
type: u1
- id: ip4
type: u1
- id: body_len
type: u4le
record:
seq:
- id: len_record
type: main_header
doc: Size of whole record, including all headers, footers and data
- id: ctype
type: u1
doc: ctype
- id: flow
type: u1
doc: flow
- id: cid
type: u4le
doc: cid
- id: did
type: u4le
doc: did
- id: seq1
type: u8le
doc: seq1
- id: command
type: u2le
doc: command
- id: protobuf
size: len_record.body_len - 24
type: google_protobuf
Here is where I hit a roadblock:
Sometimes the "_debug" metadata from the parse has an absolute offset, for example with the records[1].len_record
section:
{ '_debug': defaultdict(<class 'dict'>,
{ 'body_len': {'end': 46, 'start': 42},
'ip1': {'end': 39, 'start': 38},
'ip2': {'end': 40, 'start': 39},
'ip3': {'end': 41, 'start': 40},
'ip4': {'end': 42, 'start': 41}}),
'_io': <kaitaistruct.KaitaiStream object at 0x7fff98348070>,
'_parent': <servermod.Servermod.Record object at 0x7fff60bae8b0>,
'_root': <servermod.Servermod object at 0x7fff98368df0>,
'body_len': 34,
'ip1': 47,
'ip2': 254,
'ip3': 184,
'ip4': 155}
But for the records[1].protobuff
section, everything resets to relative offsetting:
{ '_debug': defaultdict(<class 'dict'>,
{ 'pairs': { 'arr': [ {'end': 2, 'start': 0},
{'end': 10, 'start': 2}],
'end': 10,
'start': 0}}),
'_io': <kaitaistruct.KaitaiStream object at 0x7fff60bae730>,
'_parent': None,
'_root': <google_protobuf.GoogleProtobuf object at 0x7fff60bae6d0>,
'pairs': [ <google_protobuf.GoogleProtobuf.Pair object at 0x7fff60bae670>,
<google_protobuf.GoogleProtobuf.Pair object at 0x7fff60bae580>]}
There might be a pattern to when it is relative (in which case I could get the absolute offset from the parent chunk), but I don't notice any such pattern.
I don't know much about kaitai, so it's likely that I'm missing something simple here, but I thought I'd ask for help since I can't find any documentation for parsing the python "_debug" section.