Line | |
---|
1 | #! /usr/bin/perl -w |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | |
---|
6 | my $cachefile = shift @ARGV || die "usage: $0 cache.file [filename.to.save]"; |
---|
7 | if (! -r $cachefile) { |
---|
8 | die "$0: cannot read $cachefile"; |
---|
9 | } |
---|
10 | my $savefile = shift @ARGV; |
---|
11 | |
---|
12 | open CACHE, "<$cachefile"; |
---|
13 | |
---|
14 | |
---|
15 | my $hrcount = 2; |
---|
16 | my $filename; |
---|
17 | my $line; |
---|
18 | while ($hrcount > 0) { |
---|
19 | $line = <CACHE>; |
---|
20 | if ($line =~ /<hr>/) { $hrcount--; } |
---|
21 | if ($line =~ /https?:.+\/([^\/<]+)</) { |
---|
22 | $filename = $1; |
---|
23 | } |
---|
24 | if ($line =~ /Content-Disposition:.+filename=(")?([\w.]+)(")?/) { |
---|
25 | $filename = $2; |
---|
26 | } |
---|
27 | } |
---|
28 | print STDERR "$0: filename from cache: '$filename'\n"; |
---|
29 | if (! $savefile) { |
---|
30 | $savefile = $filename; |
---|
31 | } |
---|
32 | print STDERR "$0: save file to '$savefile'\n"; |
---|
33 | |
---|
34 | $hrcount = 1; |
---|
35 | while ($hrcount > 0) { |
---|
36 | $line = <CACHE>; |
---|
37 | if ($line =~ /<hr>/) { $hrcount--; } |
---|
38 | } |
---|
39 | |
---|
40 | $line = substr $line, 15; |
---|
41 | |
---|
42 | open SAVE, ">$savefile" || die "$0: cannot write $savefile"; |
---|
43 | binmode(SAVE); |
---|
44 | |
---|
45 | $hrcount = 1; |
---|
46 | while ($hrcount > 0) { |
---|
47 | print SAVE hex2bin($line); |
---|
48 | |
---|
49 | $line = <CACHE>; |
---|
50 | if ($line =~ /<hr>/) { $hrcount--; } |
---|
51 | } |
---|
52 | |
---|
53 | print STDERR "$0: done\n"; |
---|
54 | |
---|
55 | sub hex2bin { |
---|
56 | my $str = shift @_; |
---|
57 | |
---|
58 | $str = substr $str, 11, 64; |
---|
59 | |
---|
60 | return pack("H*", join("", split(" ", $str))); |
---|
61 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.