-
-
Save jahway603/b2f4d6ed004aa7f7080b86c850827d27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
@ARGV or die "Usage: $0 PNGFILE...\nOutputs the file names of the PNG files with trailing data."; | |
FILE: while (@ARGV) { | |
my $fn = shift; | |
eval { | |
no warnings 'exiting'; | |
open my $fh, "<", $fn; | |
read $fh, my $magic, 8; | |
$magic eq "\x89PNG\x0d\x0a\x1a\x0a" or next FILE; | |
while (1) { | |
read $fh, my $size_packed, 4; | |
my $size = unpack "N", $size_packed; | |
read $fh, my $ctype, 4; | |
#print "[$ctype=$size]", tell($fh), "\n"; | |
seek $fh, $size + 4, 1; # skip data + checksum | |
last if $ctype eq "IEND"; | |
next FILE if eof $fh; | |
} | |
next FILE if eof $fh; | |
my $extra = (-s $fn) - tell $fh; | |
next FILE if $extra <= 4; | |
print $fn, "\n"; | |
}; | |
warn "$fn: $@\n" if $@; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment