Reputation: 821
I have a fat32 partition image file dump, for example created with dd. how i can parse this file with python and extract the desired file inside this partition.
Upvotes: 4
Views: 3952
Reputation: 1447
Just found out this nice lib7zip bindings that can read RAW FAT images (and much more).
Example usage:
# pip install git+https://github.com/topia/pylib7zip
from lib7zip import Archive, formats
archive = Archive("fd.ima", forcetype="FAT")
# iterate over archive contents
for f in archive:
if f.is_dir:
continue
print("; %12s %s %s" % ( f.size, f.mtime.strftime("%H:%M.%S %Y-%m-%d"), f.path))
f_crc = f.crc
if not f_crc:
# extract in memory and compute crc32
f_crc = -1
try:
f_contents = f.contents
except:
# possible extraction error
continue
if len(f_contents) > 0:
f_crc = crc32(f_contents)
# end if
print("%s %08X " % ( f.path, f_crc ) )
An alternative is pyfatfs (untested by me).
Upvotes: 0
Reputation: 695
As far as reading a FAT32 filesystem image in Python goes, the Wikipedia page has all the detail you need to write a read-only implementation.
Construct may be of some use. Looks like they have an example for FAT16 (https://github.com/construct/construct/blob/master/construct/formats/filesystem/fat16.py) which you could try extending.
Upvotes: 1