hedroed / png-parser Goto Github PK
View Code? Open in Web Editor NEWAnalyse PNG file format for CTF, python API and CLI
License: MIT License
Analyse PNG file format for CTF, python API and CLI
License: MIT License
PS C:\Windows\System32> png-parser
Traceback (most recent call last):
File "C:\Users\Anton\AppData\Roaming\Python\Python310\Scripts\png-parser-script.py", line 33, in <module>
sys.exit(load_entry_point('png-parser==2.0.0', 'console_scripts', 'png-parser')())
File "C:\Users\Anton\AppData\Roaming\Python\Python310\Scripts\png-parser-script.py", line 25, in importlib_load_entry_point
return next(matches).load()
File "C:\Program Files\Python310\lib\importlib\metadata\__init__.py", line 162, in load
module = import_module(match.group('module'))
File "C:\Program Files\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "C:\Users\Anton\AppData\Roaming\Python\Python310\site-packages\pngparser\__init__.py", line 1, in <module>
from .png import PngParser, PNG_MAGIC_NUMBER
File "C:\Users\Anton\AppData\Roaming\Python\Python310\site-packages\pngparser\png.py", line 9, in <module>
from .chunks import create_chunk, ChunkRaw
File "C:\Users\Anton\AppData\Roaming\Python\Python310\site-packages\pngparser\chunks\__init__.py", line 6, in <module>
from .ihdr import ChunkIHDR
File "C:\Users\Anton\AppData\Roaming\Python\Python310\site-packages\pngparser\chunks\ihdr.py", line 3, in <module>
from ..utils import pixel_type_to_length
File "C:\Users\Anton\AppData\Roaming\Python\Python310\site-packages\pngparser\utils.py", line 30, in <module>
class BitArray(collections.Iterator):
AttributeError: module 'collections' has no attribute 'Iterator'
Can i use this parser for parsing binary data and find PNG inside it?
I tried png-parser
with pal2
/pal4
/rgb48
images:
pngparser -v -s test.png
... and they all fail. There are mainly 3 problems.
For all images, scanline_width
is incorrect, so each scanline read is either too short or too long.
png-parser/pngparser/imagedata.py
Lines 232 to 234 in 4d75f17
Guess it should be like:
# line_width_bit = pixel_count_per_line * components_per_pixel * bit_per_component
line_width_bit = self.header.width * self.header.pixel_len * self.header.bit_depth
# line_width = round_up(line_width_bit / 8) + the_filter_byte
line_width = (line_width_bit + 7) // 8 + 1
i.e. include bit_per_component
(actually self.header.bit_depth
) in calculation.
(I suggest renaming pixel_len
to component_count
, but it's also a little weird: paletted images can have more than 1 component, so maybe a better name?)
For pal2
/pal4
images, it failed to convert index to pixel.
png-parser/pngparser/imagedata.py
Lines 332 to 333 in 4d75f17
The correct way is:
if self.palette:
bit_depth = self.header.bit_depth # bit count per sample
pixels = [self.palette[i] for i in BitArray(row, bit_depth)]
For rgb48
images, it failed to scale pixel value to 0~255 range when displaying.
png-parser/pngparser/imagedata.py
Lines 337 to 341 in 4d75f17
With rgb48
, bit_depth
is 16, i.e. val in range(0, 65536)
.
So val
should be divided by 256, or be shifted 8 bits to the right:
if bit_depth > 8:
# shrink value between 0 and 255
val = val >> (bit_depth - 8)
I can craft a PR for these issues, but I'm not sure about the wording problem. Anyone has an idea?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.