Guest User

supout.rif reader

a guest
Sep 13th, 2010
2,764
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.29 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use Compress::Zlib;
  3. use strict;
  4.  
  5. my $inf = shift;
  6. my $in;
  7. open(F, "<$inf") || die "Usage: unsup.pl /path/to/supout.inf";
  8. while (<F>) {
  9.     $_ =~ s/\s+$//; # strip terminating \r \n or other whitespace chars
  10.     if ($_ eq "--BEGIN ROUTEROS SUPOUT SECTION") {
  11.         $in = "";
  12.     } elsif ($_ eq "--END ROUTEROS SUPOUT SECTION") {
  13.         decode($in);
  14.     } else {
  15.         $in .= $_;
  16.     }
  17. }
  18.  
  19. # this is base64 but done in a different byte order
  20. sub decode {
  21.     my $in = shift;
  22.     # terminating "=" is so that index %64 == 0 for pad char
  23.     my $b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  24.     #my $np = length($in)-index($in,"="); # ignored at the moment
  25.     #$np = 0 if (-1 == index($in,"="));
  26.     my $out;
  27.     for (my $i = 0; $i < length($in); $i+=4) {
  28.         my $o = index($b64, substr($in,$i+3,1))%64 << 18 |
  29.             index($b64, substr($in,$i+2,1))%64 << 12 |
  30.             index($b64, substr($in,$i+1,1))%64 << 6 |
  31.             index($b64, substr($in,$i,1))%64;
  32.         $out .= chr($o%256);
  33.         $out .= chr(($o>>8) % 256);
  34.         $out .= chr(($o>>16) % 256);
  35.     }
  36.     # decoded data consists of "section_name\0zlib_compressed_data"
  37.     my $sec = substr($out, 0, index($out,"\0"));
  38.     print "==SECTION $sec\n";
  39.     my $cmp = substr($out, index($out,"\0")+1);
  40.     my $uncomp = uncompress($cmp);
  41.     print "$uncomp\n";
  42. }
Advertisement
Add Comment
Please, Sign In to add comment