Kaitai: Describe the structure of data, not how you read or write it
kaitai.io
kaitai.io
> Reading and writing binary formats is hard... Kaitai Struct tries to make this job easier...
Kaitai cannot write data back out. [1] This is a major limitation for me. It would be nice to use it as a mutation engine for fuzzing, but without being able to write it back out, it is mostly just beneficial for analysis.
I really wish though that there were more traction here, as I really believe that we should be quite prepared do deal with bits and not protobufs by default. nothing wrong with protobufs for quite a number of uses. I just don't know why people are so afraid of and/or biased against bit strings.
Are we not talking about writing binary files that conform to the spec?
Like, in the case of a GIF: simply writing valid garbage data should produce a file that presents as a valid GIF with noise for the image. Similarly: reading the file through the parser and writing it out unmodified should create an identical file (assuming no stenography).
Right?
There are already similarly declarative tools which can accomplish this. Haskell has binary parsing libraries which work similarly and give you both reading and writing capabilities.
It's a declarative bit-level symmetrical reader writer generator library.
ASN.1 does more or less what I was hoping Kaitai can do. Where's the breakthrough?
I just want to be able to describe network protocols in some "language" and generate code that can serialize/deserialize it.
Any chances you have some reference to what you saw?
I understand what you're saying though. Memories of using this were... unpleasant. I think the 'best' alternative for me would be RecordFlux. Ada-like syntax, generation of AoRTE-provable SPARK code, and recently the expressivity of the tool has increased. And the whole thing is in python, easily extensible to build things from the type description: generators, fuzzers, advanced specific parsers (need only one field and want the control fields' positions and sizes), wireshark plugins, Postgres extensions...
I really like what they're doing there. Might be the one of the low-effort (for the user!) lead-bullets for safer software.
And this paper https://dl.acm.org/doi/10.1145/1863523.1863525 "Invertible syntax descriptions: unifying parsing and pretty printing"
And this Haskell library https://hackage.haskell.org/package/roundtrip among others
https://construct.readthedocs.io/en/latest/intro.html#exampl...
I’ve long searched for something better than Construct, but so far I have yet to find even an equal.
[1] https://github.com/wpietri/simpleais [2] https://gpsd.gitlab.io/gpsd/AIVDM.html
100% fix formats with no self reference or for example checksums that sits in front of the checksumd data (no streaming possible)...
>Kaitai: Describe the structure of data, not how you read or write it
I started working on an alternative that supported writing but didn't follow through since I didn't think many people were interested in Kaitai to begin with.
Recently I learned about some pretty cool work using it with respect to high-energy physics:
edit: i forgot to add - there is an issue for serialization on kaitai github repo for some time [1], with some interesting discussion around the implementation challenges
The logic itself is simple, as you read data byte-by-byte you need to check check if the previous byte was 0xFF and the frame or tag is marked as unsychronized. Yet it's not that simple to describe this declaratively. I wonder if Kaitai can actually do this. From what I see Kaitai does have at least part of ID3 described, but it doesn't seem to actually do unsynchronization, as far as I can tell from the code.
Seems like there's an obvious bootstrapping task there that would then make the custom .ksy format irrelevant.
https://github.com/bjorn-ali-goransson/wz-pie-converter
(Its for 3d models for the FOSS game Warzone 2100)
supports unions and 4 popular type safe languages. The idea is that you'd write decorators in those languages to implement functionality similar to ksy or write a template to generate ksy and reuse Kaitai tool chain.
gRPC is an RPC framework that uses Protobufs.
Things like Protobuf can serialize/deserialize any data but it’s very opiniated about how to do this. You won’t convince it to work with existing file formats.
I was playing with it a while back along with wasm and got it to decode all the individual opcodes (along with the rest of the file) but it turned out to be really, really slow in the generated python version. C++ probably has much better performance but I haven't actually tested the difference.
Essentially you start with the serialization format instead of starting with the deserialized data (or like how the title of this submission says, "describe the structure of data"). As such, you can somewhat describe protobufs [0] using Kaitai structs, but the converse is not necessarily true.
There's actually a section under their FAQ [1] with a more in-depth response to this.
I don't really know what to tell you other than that YAML is not well-suited to this domain, and designing a domain-specific language which meets the particular needs of the system, and only just, would be better. You could base it off of C structs or Rust types or s-expressions or whatever else, the exact syntax isn't important so long as it allows you to concisely and precisely specify the semantics of the tool.