All Projects → kaitai-io → Kaitai_struct

kaitai-io / Kaitai_struct

Kaitai Struct: declarative language to generate binary data parsers in C++ / C# / Go / Java / JavaScript / Lua / Perl / PHP / Python / Ruby

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to Kaitai struct

Ntrghidra
Fully Featured Nintendo DS Loader for Ghidra
Stars: ✭ 56 (-97.95%)
Mutual labels:  file-format, reverse-engineering
Neteasemusiccrack
iOS网易云音乐 免VIP下载、去广告、去更新 无需越狱...
Stars: ✭ 221 (-91.92%)
Mutual labels:  reverse-engineering
Hexraystoolbox
Hexrays Toolbox - Find code patterns within the Hexrays AST
Stars: ✭ 202 (-92.62%)
Mutual labels:  reverse-engineering
Theos Jailed
A Theos module to develop jailed tweaks for iOS 8 and up
Stars: ✭ 214 (-92.18%)
Mutual labels:  reverse-engineering
Vac Bypass Loader
Loader for VAC Bypass written in C.
Stars: ✭ 204 (-92.54%)
Mutual labels:  reverse-engineering
Ctf All In One
CTF竞赛权威指南
Stars: ✭ 2,807 (+2.6%)
Mutual labels:  reverse-engineering
Hackthevote
Handouts, setup scripts, sources, and solutions for challenges from Hack The Vote CTFs
Stars: ✭ 198 (-92.76%)
Mutual labels:  reverse-engineering
Fleep Py
File format determination library for Python
Stars: ✭ 222 (-91.89%)
Mutual labels:  file-format
Sketchcrapp
SketchCrapp - Crack your Sketch.app in seconds :) Supports MacOS Big Sur.
Stars: ✭ 218 (-92.03%)
Mutual labels:  reverse-engineering
Game Hacking
Tutorials, tools, and more as related to reverse engineering video games.
Stars: ✭ 2,824 (+3.22%)
Mutual labels:  reverse-engineering
Goesp
Cross-platform streamproof ESP hack for Counter-Strike: Global Offensive, written in modern C++. Rendering and GUI powered by Dear ImGui.
Stars: ✭ 210 (-92.32%)
Mutual labels:  reverse-engineering
Gametracking
🛢 Dumping things, so you don't have to
Stars: ✭ 204 (-92.54%)
Mutual labels:  reverse-engineering
Unofficialcrusaderpatch
Unofficial balancing patch installer for Stronghold Crusader 1
Stars: ✭ 216 (-92.11%)
Mutual labels:  reverse-engineering
Luject
🍹A static injector of dynamic library for application (android, iphoneos, macOS, windows, linux)
Stars: ✭ 203 (-92.58%)
Mutual labels:  reverse-engineering
Jpsxdec
jPSXdec: cross-platform PlayStation 1 audio and video converter
Stars: ✭ 219 (-92%)
Mutual labels:  reverse-engineering
Lief
Authors
Stars: ✭ 2,730 (-0.22%)
Mutual labels:  reverse-engineering
Xapkdetector
APK/DEX detector for Windows, Linux and MacOS.
Stars: ✭ 208 (-92.4%)
Mutual labels:  reverse-engineering
Miasm
Reverse engineering framework in Python
Stars: ✭ 2,649 (-3.18%)
Mutual labels:  reverse-engineering
Gofsm
a featured FSM that can export state images
Stars: ✭ 222 (-91.89%)
Mutual labels:  graphviz
Klog
A plain-text file format and command line tool for time tracking
Stars: ✭ 222 (-91.89%)
Mutual labels:  file-format

Kaitai Struct

Join the chat at https://gitter.im/kaitai_struct/Lobby

What is Kaitai Struct?

Kaitai Struct is a declarative language used for describing various binary data structures laid out in files or in memory: i.e. binary file formats, network stream packet formats, etc.

The main idea is that a particular format is described in Kaitai Struct language only once and then can be compiled with a ksc into source files in one of the supported programming languages. These modules will include a generated code for a parser that can read described data structure from a file / stream and give access to it in a nice, easy-to-comprehend API.

What it's used for?

Have you ever found yourself writing repetitive, error-prone and hard-to-debug code that reads binary data structures from file / network stream and somehow represents them in memory for easier access?

Kaitai Struct tries to make this job easier — you only have to describe the binary format once and then everybody can use it from their programming languages — cross-language, cross-platform.

Kaitai Struct includes a growing collection of format descriptions, available in formats submodule repository.

Can you give me a quick example?

Sure. Consider this simple .ksy format description file that describes the header of a GIF file (a popular web image format):

meta:
  id: gif
  file-extension: gif
  endian: le
seq:
  - id: header
    type: header
  - id: logical_screen
    type: logical_screen
types:
  header:
    seq:
      - id: magic
        contents: 'GIF'
      - id: version
        size: 3
  logical_screen:
    seq:
      - id: image_width
        type: u2
      - id: image_height
        type: u2
      - id: flags
        type: u1
      - id: bg_color_index
        type: u1
      - id: pixel_aspect_ratio
        type: u1

It declares that GIF files usually have a .gif extension and use little-endian integer encoding. The file itself starts with two blocks: first comes header and then comes logical_screen:

  • "Header" consists of "magic" string of 3 bytes ("GIF") that identifies that it's a GIF file starting and then there are 3 more bytes that identify format version (87a or 89a).
  • "Logical screen descriptor" is a block of integers:
    • image_width and image_height are 2-byte unsigned ints
    • flags, bg_color_index and pixel_aspect_ratio take 1-byte unsigned int each

This .ksy file can be compiled it into Gif.cs / Gif.java / Gif.js / Gif.php / gif.py / gif.rb and then instantly one can load .gif file and access, for example, it's width and height.

In C#

Gif g = Gif.FromFile("path/to/some.gif");
Console.WriteLine("width = " + g.LogicalScreen.ImageWidth);
Console.WriteLine("height = " + g.LogicalScreen.ImageHeight);

In Java

Gif g = Gif.fromFile("path/to/some.gif");
System.out.println("width = " + g.logicalScreen().imageWidth());
System.out.println("height = " + g.logicalScreen().imageHeight());

In JavaScript

See JavaScript notes in the documentation for a more complete quick start guide.

var g = new Gif(new KaitaiStream(someArrayBuffer));
console.log("width = " + g.logicalScreen.imageWidth);
console.log("height = " + g.logicalScreen.imageHeight);

In Lua

local g = Gif:from_file("path/to/some.gif")
print("width = " .. g.logical_screen.image_width)
print("height = " .. g.logical_screen.image_height)

In Nim

let g = Gif.fromFile("path/to/some.gif")
echo "width = " & $g.logicalScreen.imageWidth
echo "height = " & $g.logicalScreen.imageHeight

In PHP

$g = Gif::fromFile('path/to/some.gif');
printf("width = %d\n", $g->logicalScreen()->imageWidth());
printf("height = %d\n", $g->logicalScreen()->imageHeight());

In Python

g = Gif.from_file("path/to/some.gif")
print "width = %d" % (g.logical_screen.image_width)
print "height = %d" % (g.logical_screen.image_height)

In Ruby

g = Gif.from_file("path/to/some.gif")
puts "width = #{g.logical_screen.image_width}"
puts "height = #{g.logical_screen.image_height}"

Of course, this example shows only a very limited subset of what Kaitai Struct can do. Please refer to the tutorials and documentation for more insights.

Supported languages

Official Kaitai Struct compiler now supports compiling .ksy into source modules for the following languages:

  • C#
  • Java
  • JavaScript
  • Lua
  • Nim
  • PHP
  • Python
  • Ruby

Downloading and installing

The easiest way to check out the whole Kaitai Struct project is to download the main project repository that already imports all other parts as sub-modules. Use:

git clone --recursive https://github.com/kaitai-io/kaitai_struct.git

Note the --recursive option.

Alternatively, one can check out individual sub-projects that consitute Kaitai Struct suite. They are:

Using KS in your project

Typically, using formats described in KS in your project, involves the following steps:

  • Describe the format — i.e. create a .ksy file
  • Compile .ksy file into target language source file and include that file in your project
  • Add KS runtime library for your particular language into your project (don't worry, it's small and it's there mostly to ensure readability of generated code)
  • Use generated class(es) to parse your binary file / stream and access its components

Check out the tutorial and documentation for more information.

Licensing

  • Compiler — GPLv3+
  • Runtime libraries — MIT or Apache v2 (=> you can include generated code even into proprietary applications) — see individual libraries for details
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].