4 use Compress::Raw::Zlib ;
11 open FILE, "< $filename";
12 while ($line = <FILE>) {
19 my $ua = LWP::UserAgent->new;
22 my $ver = $ARGV[0];#'3.0144'; #'2.0400';
24 if ( ! defined $ver) {
25 die "usage: eyefi-firmware-fetch.pl <FIRMWARE VERSION> [optional MAC]";
28 my $m1 = 0x2d; #rand 0x30;
32 $mac = sprintf '00-18-56-%02x-%02x-%02x', $m1, $m2, $m3;
34 my $url = sprintf 'http://api.eye.fi/api/rest/eyeserver/v1/getCardFirmware?Card=%s&Version=%s', $mac, $ver;
36 my $res = $ua->get($url);
37 $xml = $res->content();
39 next if $xml =~ /Card not found./;
40 next if $xml =~ /File not found./;
43 my $filename .= "EYEFIFWU-$ver-$mac.bin";
44 printf STDERR "got %d bytes of xml\n", length($xml);
46 $xml =~ s/<\?xml.*<Firmware>//s;
47 printf STDERR "got %d bytes of xml\n", length($xml);
48 $xml =~ s/<\/Firmware>.*Response>//s;
49 printf STDERR "got %d bytes of xml\n", length($xml);
50 my $base64_encoded = $xml;
51 printf STDERR "got %d bytes of base64 encoded data\n", length($base64_encoded);
53 use Email::MIME::Encodings;
54 my $zlib_encoded = Email::MIME::Encodings::decode(base64 => $base64_encoded);
56 printf STDERR "got %d bytes of zlib encoded data\n", length($zlib_encoded);
62 ($i, $status) = new Compress::Raw::Zlib::Inflate() ;
63 $status = $i->inflate($zlib_encoded, $output);
64 $status = $i->inflateSync($zlib_encoded);
66 open FILE, "> $filename";
69 printf STDERR "done, wrote %d bytes to '$filename'\n", length($output);