-
Notifications
You must be signed in to change notification settings - Fork 204
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: can kaitai for archive/android_sparse.ksy be used to iterate over files? #699
Comments
It is possible to create Android sparse image files for files that are not ext2/3/4 file systems (I've done that). I would recommend taking a two step approach. |
This doesn't look like it's broken. It just tells you that the validation of the magic number at types:
file_header_prefix:
seq:
- id: magic
contents: [0x3a, 0xff, 0x26, 0xed] Documentation of the So the first 4 bytes of the input binary file were expected to be If you want to try some valid
Just to clarify, the Android sparse image format AFAIK doesn't directly support storing multiple files. Check out https://2net.co.uk/tutorial/android-sparse-image-format:
This suggests that only individual "files" are packed as Android sparse images. But it appears to be common that the Android sparse image format is used to "compress" a file system image (like ext4), which of course can contain many files.
You can use Kaitai Struct to unpack an Android sparse image if you want. I guess the standard solution to do it would be to use the After you unpack the filesystem image from the Android sparse image, I wouldn't recommend using Kaitai Struct to access the files in that filesystem. It will be easier and more robust to just mount it if you're on Linux, or I think 7-Zip (which is primarily for Windows, and also has a command-line interface) can unpack some file system images. There are probably other ways, these are just ones I can think of. |
Thanks @armijnhemel , do you mean convert to non-sparse and iterate non-sparse? Thanks @generalmimon for the detailed answer!
Why? |
If you want to go down this path, feel free to try it. If you're determined, it could work out well in the end. I just wanted to make sure you know about the simpler and more established solutions first. I don't know much about how complex the filesystems are on the inside, but it will be certainly harder than unpacking the Android sparse image with KS (because that should be very easy; in contrast, I assume filesystems must inherently have at least some degree of complexity). And it will largely depend on what kind of file system it is. If it's ext2 as you mentioned, you might be somewhat in luck because we seem to have a .ksy spec for it (https://formats.kaitai.io/ext2/), but I've personally never tested it, so I don't know how good or complete it is. If it was some other file system, you might have to write a .ksy spec for it yourself, if no one has already done so. Which is perhaps not that hard (of course, it really depends on the complexity of the format), but it definitely takes some time, so hopefully it's not your case. There is some open issue about ext2 at the moment - #662. Maybe you'll run into it, maybe not. @armijnhemel also notes the following in #662 (comment):
Which suggests that our ext2 specification is far from complete, so you may need to extend it if you really want to use it (please inform us about the problems you're run into or send pull requests so we can improve it in the future). But maybe it will work fine for you as is, who knows. To find out, I would just advise using https://ide.kaitai.io/devel/ extensively first on various ext2 images that your application might encounter to evaluate if it's even viable to go this route (and also to check if you can actually find the files there).
Wait, if you want to "repack" everything, does it mean that you also need serialization in addition to parsing? If so, you might be in luck again because serialization has been implemented for Python (and Java) not long ago (see https://doc.kaitai.io/serialization.html), but hasn't been released yet, so you would have to build the compiler from source as explained there. |
Hello, I am working with android sparse images and want to iterate over byte blocks for each files in the image.
Currently I am transforming them to ext2 and then use debugfs to get byte blocks in the file.
Can I do this with kaitai? I could open my files using android_sparse.ksy but I don't see how to go from
class Chunk(KaitaiStruct):
to actual files. Is it possible?Thanks!
Offtopic: https://ide.kaitai.io/ for acrhive/android_sparse.ksy looks broken:
The text was updated successfully, but these errors were encountered: