Originally posted on 2024-04-25
I’ve now tried 010 Editor, ImHex, and fq.
010 Editor and ImHex’s development workflows didn’t work for me.
fq was better, and actually really great for certain things, but I wanted something I could generate code with. So here I am.
Installation
On MacOS:
brew install kaitai-struct-compiler
sudo gem install kaitai-struct-visualizerThe Ruby gem installation time is punishing and silent but it seems to work even on MacOS’s old version of Ruby which is ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin23] as of this writing.
Now you’ll have two three tools installed:
kaitai-struct-compiler- to compile.ksyfiles to your language of choiceksv- to visualize a file using the format defined in a.ksyfileksdump- to dump an entire file using the format defined in a.ksyfile
Testing
Try a sample file first before using the tools. Make small changes and test incrementally. As with all other binary file definition systems I’ve tried the errors can be a bit confusing. Let’s try the GIF format example from the Kaitai site:
Assuming your .gif file is called pronounced-like-the-peanut-butter.gif these three commands should work:
ksv -i gif.ksy pronounced-like-the-peanut-butter.gifksdump -f json pronounced-like-the-peanut-butter.gif gif.ksykaitai-struct-compiler -t go gif.ksy