-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] Parsing binaries of unknown size #545
Comments
You can. |
Thanks! I'll look into it. |
Not really, and it would be a while since that kind of functionality will be implemented in KS. For starters, there is no concept of "valid" or "invalid" parsing in KS right now, except for very rudimental validation checks done by Also, there's no way to "test each byte", i.e. launch for scan or search repeatedly. There is a separate proposal to implement something close to that in #538. That said, @KOLANICH is correct, and you can try to get away with limiting your input with some size relative to overall size of the file (i.e. something like footer:
pos: _io.size - 123
type: footer |
Okay, thanks for the insight! Really appreciate it. |
So, I've found out the sizes of the header and footer (32 words * 16-bit = 64 bytes, each) and I've tried using I tried using At the moment, there is no way to find out the number of data entries in the file (it's not defined in the binary), but can I still pass in the "middle" chunk of the data and have it read until Thanks for the advice! |
Reading "until end of substream limited to all but last 64 bytes" would be something like seq:
- id: all_but_footer
type: all_but_footer
size: _io.size - 64
- id: footer
type: footer
size: 64
types:
all_but_footer:
seq:
# ...
- id: elements
type: element
repeat: eos # this will be limited to substream, not main stream |
Oh! Thanks! I should have double-checked in the documentation. I'll give it a try. |
Seems that the answer was given, closing this discussion. Please feel free to reopen if anything still remains. |
Hi, I'm currently working with some custom physics data and I've been using https://www.carvesystems.com/news/parsing-binaries-with-kaitai-struct/ as a reference, but I don't know exactly where the footer is located.
Currently, we've just commented out the bits where we actually deal with the footer and just read the footer in as another event, but then we cut out the last event in the function to graph the data since it's really the footer.
Struct definition
Event Definition
Footer Definition
Is there a way I can test each byte to check if it's really an event (has all of the identifiers of an event) and then if it doesn't, and it's near the end of the file, read it as the footer?
Otherwise, can I tell it to stop reading events "this many bits" before the end of the file and read the rest as the footer?
Thanks!
Edit: added code
The text was updated successfully, but these errors were encountered: