Kaitai Struct + Kaitai FS

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
wobwob
Posts: 2
Joined: Fri Jun 16, 2017 6:52 am
Location: Germany

Kaitai Struct + Kaitai FS

Post by wobwob »

Hi,

I've been a long-time reader of OSDev forums and wiki, which helped me a lot in the past. Today I've stumbled upon an interesting project that seems to be unknown for OSDev dwellers, and, IMHO, it is really revolutionary and a real game changer.

The project I'm talking about is a new open source domain-specific language Kaitai Struct and its sister project, Kaitai FS. Kaitai Struct allows one to specify multitude of complex data structures using declarative language, which can be then examined in an browser-based IDE:

Image

or console IDE:

Image

In this respect, it is like a free clone of 010 Editor or Hexinator, which is already cool. But there's a much, much cooler feature around the corner: it can be compiled into a parser library in many programming languages (C/C++, C#, Java, JavaScript, Python, Ruby, Perl, PHP, Go, etc).

The idea of specifying filesystems as data structures is just brilliant. Instead of re-writing yet another (probably buggy) implementation of FAT, ISO9660, NTFS, or whatever filesystem you plan to support in your OS, you can just take ready-made vfat.ksy, iso9660.ksy, etc, and you get a working implementation library in language of your choice right away! Kaitai FS is a project that does exactly that: it provides a thin wrapper that converts .ksy filesystem implementations (and also containers, archive files, etc) into FUSE-based implementations in Python for Linux and OS X.

There's even a guy who reverse engineering newest Apple's APFS filesystem using Kaitai: https://github.com/cugu/apfs.ksy — and, I guess, it means that APFS can be supported as well ;)

What do you think of it? Anyone planning to use filesystems declared in .ksy syntax for your projects? I do :)

I wonder if we should add ksy links to all the formats specified informally in Wiki? Kaitai project already seems to have ELF, MZ, PE, Mach-O executables described in .ksy, and quite a few filesystems. That would be likely helpful for generations to come :)
Boris
Member
Member
Posts: 145
Joined: Sat Nov 07, 2015 3:12 pm

Re: Kaitai Struct + Kaitai FS

Post by Boris »

The language seems good. I need to check if this little one can replace lexx/yacc. From what i see, you can create context and branch according to magic items so it may work.
Nice finding !
User avatar
wobwob
Posts: 2
Joined: Fri Jun 16, 2017 6:52 am
Location: Germany

Re: Kaitai Struct + Kaitai FS

Post by wobwob »

Boris wrote:I need to check if this little one can replace lexx/yacc.
Not really — it is for parsing binary, which is usually designed to be machine-readable, i.e. non-ambiguous. Generally, it's a bad idea to parse, for example, FAT filesystem with lexx/yacc (that would be way too verbose and you'll end up writing gazillions of states and lexems instead of focusing on the format), but it is a good idea to parse it with KS.
Post Reply