Hedroed / png-parser

Analyse PNG file format for CTF, python API and CLI
MIT License
96 stars 11 forks source link
chunk cli compression ctf ctf-tools exif idat image image-processing palette parser parser-framework parser-library png png-chunks png-parser python pythonapi steg steganography

png-parser

Best tool to analyse PNG files, it shows you PNG chunks : header, palette, and text.

demo

demo text

pip install --user git+https://github.com/Hedroed/png-parser

Usage

> $ png-parser --help

 ▄▄▄· ▐ ▄  ▄▄ •  ▄▄▄· ▄▄▄· ▄▄▄  .▄▄ · ▄▄▄ .▄▄▄
▐█ ▄█•█▌▐█▐█ ▀ ▪▐█ ▄█▐█ ▀█ ▀▄ █·▐█ ▀. ▀▄.▀·▀▄ █·
 ██▀·▐█▐▐▌▄█ ▀█▄ ██▀·▄█▀▀█ ▐▀▀▄ ▄▀▀▀█▄▐▀▀▪▄▐▀▀▄
▐█▪·•██▐█▌▐█▄▪▐█▐█▪·•▐█ ▪▐▌▐█•█▌▐█▄▪▐█▐█▄▄▌▐█•█▌
.▀   ▀▀ █▪·▀▀▀▀ .▀    ▀  ▀ .▀  ▀ ▀▀▀▀  ▀▀▀ .▀  ▀
v2.0.0

usage: png-parser [-h] [-a | -c CHUNK_ID | -t TYPE | --text] [-d] [--length] [--crc] [--hex] [--show] [--output OUTPUT] [-v] file

Prints PNG text sections

positional arguments:
  file                  A PNG image

optional arguments:
  -h, --help            Show this help message and exit
  -a, --all             Print all chunk infos
  -c CHUNK_ID, --chunk CHUNK_ID
                        Select chunk with this id
  -t TYPE, --type TYPE  Select chunk by type
  --text                Display all text chunk
  -d, --data            Print chunk data
  --length              Print chunk length
  --crc                 Print chunk crc and check if it is right
  --hex                 Print bytes position in Hexadecimal
  -s, --show            Show image
  --output OUTPUT       Save image (fix input file errors if any)
  -v, --verbose         Increase verbosity

API

Class PngParser

PngParser(file)

file: str or file type

PngParser.get_image_data()

PngParser.set_image_data()

PngParser.get_chunk_by_index(idx)

PngParser.get_chunk_by_type(type)

Class Chunk

Chunk(type, data=None, crc=None)

Chunk.update_crc()

Chunk.length

Class ImageData

ImageData(header, data, palette=None)

ImageData.scanlines

ImageData.get_pixel(x, y)

ImageData.set_pixel(x, y, pixel) ImageData.set_pixel(x, y, data)

Class Scanline

Scanline(filter, data, previous=None)

Scanline.filter

Scanline.data

Class Pixel

Pixel(type, channels) Pixel.getitem

Dev

Install for development

python setup.py develop

Run example

python example/read_png_filters.py

DOC

PNG Chunks

Length Chunk type Chunk data CRC
4 bytes 4 bytes Length bytes 4 bytes

Critical Chunks:

Ancillary Chunks:

(c) https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header