3

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.

David A
  • 763
  • 1
  • 9
  • 22
  • If you are on linux, you can use the loopback device to mount the partition in the image file. Google will tell you how. – tdelaney Aug 14 '13 at 15:56
  • @tdelaney yes , with linux no problem, my phyton script must be windows compatible, – David A Aug 14 '13 at 15:59

2 Answers2

1

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.

davidg
  • 695
  • 6
  • 8
0

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).

eadmaster
  • 1,347
  • 13
  • 23