Search code examples
kaitai-struct

Add custom process in ide.kaitai.io


I'm want to add a my custom process (writing on Java) for decoding bytes. But in ide.kaitai.io this don't working. In docs kaitai writed that is it possible (I don't sure, mb it is only for kaitai struct). Kaitai yaml:

  decoded_stitches:
    seq:
      - id: decode1
        type: u4
        repeat: expr
        repeat-expr: 4
      - id: data_count
        type: u4
      - id: decoded_data
        size: 4
        process: my_custom_processor()

If it is possible, please answer my question

I'm added file MyCustomProcessor.java in local storage ide.kaitai.io. Code MyCustomProcessor.java:

import io.kaitai.struct.CustomDecoder;

public class MyCustomProcessor implements CustomDecoder {
    @Override
    public byte[] decode(byte[] src) {
        // custom "bytes in -> bytes out" processing routine
        return src;
    }
}

Trying to rename file, debug in ide, but this class don't loaded


Solution

  • AFAIK it cannot convert Java code to JavaScript, you have to reimplement your custom processor in JavaScript.

    After you did that you can use the hack described on the WebIDE Features page:

    • Open the Developer Tools (usually F12 or Ctrl+Shift+I)
    • Insert your custom processor (written in JS) the following way:
    localStorage.setItem("userTypes", `
        class MyCustomProcessor {
            decode(src) {
                return src;
            }
        }
    
        this.MyCustomProcessor = MyCustomProcessor;`);