Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/usr/bin/perl
  2. # paul@unsup.sbrk.co.uk
  3. use Compress::Zlib;
  4. use strict;
  5.  
  6. my $inf = shift;
  7. my $in;
  8. open(F, "<$inf") || die "Usage: unsup.pl /path/to/supout.inf";
  9. while (<F>) {
  10.     $_ =~ s/\s+$//; # strip terminating \r \n or other whitespace chars
  11.     if ($_ eq "--BEGIN ROUTEROS SUPOUT SECTION") {
  12.         $in = "";
  13.     } elsif ($_ eq "--END ROUTEROS SUPOUT SECTION") {
  14.         decode($in);
  15.     } else {
  16.         $in .= $_;
  17.     }
  18. }
  19.  
  20. # this is base64 but done in a different byte order
  21. sub decode {
  22.     my $in = shift;
  23.     # terminating "=" is so that index %64 == 0 for pad char
  24.     my $b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  25.     #my $np = length($in)-index($in,"="); # ignored at the moment
  26.     #$np = 0 if (-1 == index($in,"="));
  27.     my $out;
  28.     for (my $i = 0; $i < length($in); $i+=4) {
  29.         my $o = index($b64, substr($in,$i+3,1))%64 << 18 |
  30.             index($b64, substr($in,$i+2,1))%64 << 12 |
  31.             index($b64, substr($in,$i+1,1))%64 << 6 |
  32.             index($b64, substr($in,$i,1))%64;
  33.         $out .= chr($o%256);
  34.         $out .= chr(($o>>8) % 256);
  35.         $out .= chr(($o>>16) % 256);
  36.     }
  37.     # decoded data consists of "section_name\0zlib_compressed_data"
  38.     my $sec = substr($out, 0, index($out,"\0"));
  39.     print "==SECTION $sec\n";
  40.     my $cmp = substr($out, index($out,"\0")+1);
  41.     my $uncomp = uncompress($cmp);
  42.     print "$uncomp\n";
  43. }