I came across a file with an obscure database format and would like to recover some information from it. After using python
to open and read the file as bytes, and use re.search
with pattern of b"\x89\x50\x4e\x47"
(PNG file header), I found an offset in the file that matches this. Upon further examination, it's likely that this is the starting position of an actual PNG file (the first 16 bytes in hex are 89504e470d0a1a0a0000000d49484452
). However, with no information regarding the size of this PNG file, how should I determine it programmatically (using the information from the header)? It would be appreciated if some existing PNG debugging tool can be used.
I already tried output the rest of this database file starting from this offset and save it as a PNG, but it doesn't work as my image viewer report the file is corrupted.
CodePudding user response:
PNG images have footers that you can utilize to determine when to stop.
You can seek up until IEND
, then move right 4 bytes to capture the CRC data, and extract all the bytes up to that point.
After which, you should be able to get the full PNG file.