Advertisement
Guest User

Untitled

a guest
Nov 1st, 2011
1,358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.93 KB | None | 0 0
  1. #!perl
  2. use POSIX;
  3. use strict;
  4. use IO::Uncompress::Inflate qw(inflate);
  5. sub grect {
  6.     my($fh) = @_;
  7.     read $fh, $_, 1;
  8.     $_ = unpack "C", $_;
  9.     $_ = ($_ >> 3) * 4 + 5;
  10.     $_ = ceil($_ / 8) - 1; # skipping rect
  11.     seek $fh, $_, 1;
  12.     $_;
  13. }
  14. sub gui16 {
  15.     my($fh) = @_;
  16.     read $fh, $_, 2;
  17.     unpack "v", $_;
  18. }
  19. sub gui32 {
  20.     my($fh) = @_;
  21.     read $fh, $_, 4;
  22.     unpack "V", $_;
  23. }
  24. sub gtag {
  25.     my ($fh) = @_;
  26.     if (eof($fh)) {
  27.         return 0;
  28.     }
  29.     my ($s, $t);
  30.     $t = gui16($fh);
  31.     ($s, $t) = ($t & 0x3f, $t >> 6);
  32.     if ($s == 0x3f) {
  33.         $s = gui32($fh);
  34.     }
  35.     my $c;
  36.     read $fh, $c, $s;
  37.     [$t, $c];
  38. }
  39. my ($fh, $fhz, $s);
  40. open $fh, $ARGV[0];
  41. binmode $fh;
  42. read $fh, $s, 3;
  43. die "nope" if $s ne "CWS";
  44. read $fh, $s, 5;
  45. $fhz = new IO::Uncompress::Inflate $fh;
  46. grect($fhz);
  47. gui16($fhz);
  48. gui16($fhz);
  49. my ($i, $a) = (0);
  50. while ($a = gtag($fhz)) {
  51.     open O, ">${i}_$a->[0].o";
  52.     binmode O;
  53.     print O $a->[1];
  54.     $a = undef;
  55.     close O;
  56.     $i++;
  57. }
  58.  
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement