You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be easy to create something that parses and let's the user visualize the binary format presented like ide.kaitai.io
The harder part would be to make it useful and editable. Binary protocols often have length and checksums all over the place, which aren't obviously editable even with kaitai.
But even if this wasn't possible to edit easily, it might be something nice to present to users for binary formats like protobuffs as well as for some media elements.
This is more useful probably for responses than for requests, unless we add a mime envelope parser, as file uploads are often encoded like that. That said, it does happen that some websites generate binary protobuff on the client.
https://doc.kaitai.io/lang_javascript.html might be better, although looking at the API, it seems like the offsets arent exposed in the API, only the parsed objects.. this means it might be hard to associate the offset at which a specific field is located.
so, it might be possible to just iterate over all defined properties of an object, get their byteOffset (and byteLength) if they are Array views, and get _byteOffset otherwise.
so, a possibly easier solution to this would be to provide a fake implementation of KaitaiStream that stores the information of offsets for all the values it returns.
So, I would like to recover the parsing offsets information (eg, where each value came from, so I can do something similar to the ide.kaitai.io hex editor, and know where each offset corresponds to), this isn't exposed on the KaiaiStream API, but seems possible to recover by providing a fake implementation of KaitaiStream that stores the information of offsets for all the values it returns in a Map.
KaitaiStream.prototype.readS1=function(){this.ensureBytesLeft(1);varv=this._dataView.getInt8(this.pos);this.pos+=1;returnthis._addToMap(v);// <<-- this is new};
with
KaitaiStream.prototype._map=newMap;// (this has to be set in the constructor)KaitaiStream.prototype._last=0;KaitaiStream.prototype._addToMap=(v)=>{constobj=newv.constructor(v);this._map.set(obj,{index: this._map.size,start: this._last,end: this.pos});this._last=this.pos;returnobj;};
then when reading the values, I can just search them on the map.
KS has a somewhat hidden 'debug' mode which does exactly what you need: adds a _debug field into objects and stores the start, end and so-called ioOffset of the fields.
If you generate the parser code with the WebIDE, then use the JS code (debug) tab here:
Activity
sirdarckcat commentedon Jan 2, 2021
https://github.com/kaitai-io/kaitai_struct_typescript_runtime
sirdarckcat commentedon Jan 2, 2021
https://doc.kaitai.io/lang_javascript.html might be better, although looking at the API, it seems like the offsets arent exposed in the API, only the parsed objects.. this means it might be hard to associate the offset at which a specific field is located.
https://github.com/kaitai-io/kaitai_struct_webide/tree/master/src/worker
sirdarckcat commentedon Jan 2, 2021
hmm object offsets seem to be exposed via
_byteOffsetin a somewhat hacky way https://github.com/kaitai-io/kaitai_struct_javascript_runtime/blob/master/KaitaiStream.jsbut even then
And the primitives byte offsets are exposed via Uint8Array native byteOffset property.
sirdarckcat commentedon Jan 2, 2021
so, it might be possible to just iterate over all defined properties of an object, get their
byteOffset(andbyteLength) if they are Array views, and get_byteOffsetotherwise.sirdarckcat commentedon Jan 2, 2021
from the example in http://doc.kaitai.io/lang_javascript.html:
seems to work at least for things that are arrays, but it does not seem to work for things that are returned as primitives
it's unclear how the webide gets this information
sirdarckcat commentedon Jan 2, 2021
this is exposed by the compiler it seems
sirdarckcat commentedon Jan 2, 2021
so, a possibly easier solution to this would be to provide a fake implementation of KaitaiStream that stores the information of offsets for all the values it returns.
sirdarckcat commentedon Jan 2, 2021
So, I would like to recover the parsing offsets information (eg, where each value came from, so I can do something similar to the ide.kaitai.io hex editor, and know where each offset corresponds to), this isn't exposed on the KaiaiStream API, but seems possible to recover by providing a fake implementation of KaitaiStream that stores the information of offsets for all the values it returns in a Map.
Example:
would be:
with
then when reading the values, I can just search them on the map.
sirdarckcat commentedon Jan 2, 2021
@koczkatamas (hopefully this works ^.^) would #63 (comment) work?
koczkatamas commentedon Jan 2, 2021
KS has a somewhat hidden 'debug' mode which does exactly what you need: adds a
_debugfield into objects and stores thestart,endand so-calledioOffsetof the fields.If you generate the parser code with the WebIDE, then use the

JS code (debug)tab here:Otherwise if you use the KS JS compiler, then you can set the
debugproperty of thecompilemethod totrueto generate debug code instead of a non-debug one: https://github.com/kaitai-io/kaitai_struct_compiler/tree/master/js#basic-usage-of-compile-methodI hope this is what you need :)
sirdarckcat commentedon Jan 2, 2021
woohoo! thanks =D