Skip to main content

Squashfs image parser

Project description

PySquashfsImage is a lightweight library for reading squashfs image files in Python. It provides a way to read squashfs images header and to retrieve encapsulated binaries. It is compatible with Python 2.6, 2.7 and Python 3.1+.

Installation

pip install PySquashfsImage

If you are using Python <= 3.2 and need LZMA decompression, install backports.lzma.

For LZ4 decompression, install lz4 (Python 3.7+).

For Zstandard decompression install zstandard (Python 3.7+).

Use as a library

List all elements in the image:

from PySquashfsImage import SquashFsImage

image = SquashFsImage('/path/to/my/image.img')
for item in image.root.find_all():
    print(item.name)
image.close()

Print all files and folder with human readable path:

from PySquashfsImage import SquashFsImage

image = SquashFsImage('/path/to/my/image.img')
for path in image.root.find_all_paths():
    print(path)
image.close()

Print only files:

from PySquashfsImage import SquashFsImage

image = SquashFsImage('/path/to/my/image.img')
for item in image.root.find_all():
    if not item.is_dir:
        print(item.path)
image.close()

Save the content of a file:

from PySquashfsImage import SquashFsImage

image = SquashFsImage('/path/to/my/image.img')
for item in image.root.find_all():
    if item.name == 'myfilename':
        with open('/tmp/' + item.name, 'wb') as f:
            print('Saving original ' + item.path + ' in /tmp/' + item.name)
            f.write(item.read_bytes())
image.close()

Use as a command

$ pysquashfsimage -h
usage: pysquashfsimage [-h] [-V] file paths [paths ...]

positional arguments:
  file           squashfs filesystem
  paths          directories or files to print information about

options:
  -h, --help     show this help message and exit
  -V, --version  show program's version number and exit

For each path, if it is a directory it will print the mode and name of each contained file, with sizes and symlinks.

If a path is a file, print its content.

Example command:

$ pysquashfsimage myimage.img /bin /etc/passwd

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PySquashfsImage-0.8.0.linux-x86_64.tar.gz (24.9 kB view hashes)

Uploaded Source

Built Distributions

PySquashfsImage-0.8.0-py3.10.egg (25.0 kB view hashes)

Uploaded Source

PySquashfsImage-0.8.0-py3-none-any.whl (32.9 kB view hashes)

Uploaded Python 3

PySquashfsImage-0.8.0-py2.py3-none-any.whl (33.2 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page