I know people here have answered very similar questions before, I can find some of the answers, but I'm looking for a comprehensive overview on how to deal with binary files.
My basic problem is that I am reverse engineering a binary file from a particular program. Sometimes I need to do odd things, like get a byte offset from a 3-byte chunk which has big-endian bytes, but little-endian bits within each byte, or use a multi-byte segment as a bit-mask to determine which fields are present.
I think I could write my own convoluted code, that would take an array of bytes, change it to dec using ord() then change that to binary using code I've found here, flipping the order when needed, then back to decimal, but it all seems rather clunky (for example, why have a decimal intermediate). Also, I feel like someone probably already wrote this somewhere and probably in a more elegant fashion than I could.
Can anyone point me in the right direction? Thanks.
Oh, and while I've seen struct, but I can't seem to figure out how to make it unpack how I would like it to. For example, as above sometimes I need to deal with 3 unsigned bytes, which doesn't work with H (short, 2 bytes) or L (long, 4 bytes).
My basic problem is that I am reverse engineering a binary file from a particular program. Sometimes I need to do odd things, like get a byte offset from a 3-byte chunk which has big-endian bytes, but little-endian bits within each byte, or use a multi-byte segment as a bit-mask to determine which fields are present.
I think I could write my own convoluted code, that would take an array of bytes, change it to dec using ord() then change that to binary using code I've found here, flipping the order when needed, then back to decimal, but it all seems rather clunky (for example, why have a decimal intermediate). Also, I feel like someone probably already wrote this somewhere and probably in a more elegant fashion than I could.
Can anyone point me in the right direction? Thanks.
Oh, and while I've seen struct, but I can't seem to figure out how to make it unpack how I would like it to. For example, as above sometimes I need to deal with 3 unsigned bytes, which doesn't work with H (short, 2 bytes) or L (long, 4 bytes).
Comment