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
Offset-based reading #52
Comments
Managed to solve it:
The |
The |
BinData operates in a single pass as single pass formats are easier to comprehend. Easy comprehension is a primary design goal. The offset example above is not necessarily single pass, as the offsets may point to earlier in the stream. Solving this example requires multi pass processing, introduced in BinData 2.3.0. Here is how to do this with BinData: class Blob < BinData::Record; end;
class SuperBlob < BinData::Record
auto_call_delayed_io
endian :big
uint32 :len
array :blob_offsets, :initial_length => :len do
uint32 :type
uint32 :offs
end
array :blobs, :initial_length => :len do
delayed_io :type => :blob,
:read_abs_offset => lambda { offset_adjustment + blob_offsets[index].offs }
end
end |
Suppose I have a table of offsets to some child objects, given that the offsets in the table are relative to the parent:
I couldn't find how can I make such structure into an array of
Blob
records. I have also tried:Which didn't work properly, probably because the offset is adjusted related to the start of the IO, not the start of
SuperBlob
object. Is it possible to rebase the offset calculation to a given field in theSuperBlob
object. I'm trying to port the following code from Python (notice it has a feature calledAnchor
: https://github.com/comex/cs/blob/master/macho_cs.py)The text was updated successfully, but these errors were encountered: