in reply to Re^2: File extraction 2nd try
in thread File extraction 2nd try
Parsing a .PNG file really isn't hard, especially if you don't really care about the content. Here's something to get you started:
use strict; use warnings; my $file = '...'; open my $pngIn, '<:raw', $file or die "Can't open '$file': $!\n"; read $pngIn, my $header, 8; my ($prefix, $png, $crlf, $ctrlZ, $lf) = unpack "aa3a2aa", $header; die "Bad header prefix\n" if ord $prefix != 0x89; die "Bad header type\n" if $png ne 'PNG'; die "Bad header crlf\n" if $crlf ne "\r\n"; die "Bad header Ctrl-Z\n" if ord $ctrlZ != 0x1a; die "Bad header newline\n" if $lf ne "\n"; while (!eof $pngIn) { read $pngIn, my $chunkHeader, 8 or last; my ($length, $type) = unpack "Na4", $chunkHeader; read $pngIn, my $body, $length + 4 or die "Truncated chunk\n"; my ($payload, $crc) = unpack "a$length N", $body; last if $type eq 'IEND'; }
Tested on Windows. Probably OK on a big endien machine but those are harder to come by now that Apple have gone Intel. It doesn't do anything with the chunk data other than skipping through the chunk headers. It also doesn't try to be smart about excessively large chunks.
|
|---|