Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.10 KB | None | 0 0
  1. use strict;
  2. use Getopt::Long;
  3.  
  4.  
  5.  
  6. our ($input);
  7. my ($p, $b, $w, $l, $s, $total, $tmp_name);
  8. $input='bank.bnk';
  9.  
  10. GetOptions('input=s' => \$input);
  11.  
  12. # リスト処理
  13. unless(-e $input)
  14. {
  15.     print STDERR "\"$input\" not found.\n";
  16.     exit(-1);
  17. }
  18.  
  19. open(BNK, "<$input") || die "file open error: $!";
  20. binmode(BNK);
  21.  
  22. $total = 0;
  23. for my $i (0x00..0x3f)
  24. {
  25.     $p = $i<<2;
  26.     $s = 0;
  27.     seek(BNK, 12+$p, 0);    # dirテーブルへ移動
  28.     read(BNK, $b, 2);
  29.     $w = unpack("S", $b);
  30.     read(BNK, $b, 2);
  31.     $l = unpack("S", $b);
  32.     unless($w==0)
  33.     {
  34.         while(1)
  35.         {
  36.             seek(BNK, $w-0x7ff4+$s, 0);
  37.             read(BNK, $b, 1);
  38.             $s += 9;
  39.             if( (unpack("C", $b) & 1) == 1){last;}
  40.         }
  41.         $total += $s;
  42.         printf "%02x:: start:0x%04x - loop:0x%04x - size:0x%04x\n", $i, $w, $l, $s;
  43.         $tmp_name = sprintf("%2x.brr",$i);
  44.         open(BRR, ">$tmp_name"); binmode(BRR);
  45.         seek(BNK,$w-0x7ff4,0); read(BNK, $b, $s);
  46.         print BRR pack("S", $l-$w);
  47.         print BRR $b;
  48.         close(BRR);
  49.     }
  50.     else
  51.     {
  52.         printf "%02x:: NULL\n", $i;
  53.     }
  54. }
  55. printf "\n\nBank: 0x%04x / 0x7fee(%3f\%) space:0x%04x\n", $total, $total/0x7fee*100, 0x7fee-$total;
  56.  
  57. close(BNK);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement