简体   繁体   中英

Kaitai Struct dump to json

I need a command line like "ksc" which can take parameters "binary file" and "yaml file" and dump it in json format. WebIDE is doing the same through "ExportToJson", but i need the same functionality from command line.

Thank You

Affiliate disclaimer: I'm a Kaitai Struct maintainer (see my GitHub profile ).

I need a command line like "ksc" which can take parameters "binary file" and "yaml file" and dump it in json format.

Use the utility ksdump included in the kaitai-struct-visualizer package. You can get it from RubyGems by running gem install kaitai-struct-visualizer (this will make the command ksdump available on your PATH ). You need to have Ruby installed, though. Also kaitai-struct-compiler is required to be installed (see https://kaitai.io/#download for instructions) and set up on your PATH .

The usage for your case is the following:

$ ksdump -f json sample.bin protocol.ksy

Alternatively, instead of installing Ruby, Kaitai Struct compiler and visualizer manually, you can pull the official Docker image https://hub.docker.com/r/kaitai/ksv , which comes with everything included. The usage looks like this (naturally, you need to get Docker in the first place):

$ docker run -v "$(pwd):/share" --entrypoint ksdump -it kaitai/ksv -f json sample.bin protocol.ksy

But consider that the Docker image kaitai/ksv takes up 1.06GB (I didn't expect that - I guess it's quite easy to get Docker images bloated), so you might not want to download it all through a slow network or a connection with data limit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM