Dither

HTML5 MP3 support in Opera 12

Jul 30th, 2013
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 3.56 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. # Perl script to apply common patches for Opera
  3. # Based on work of Dither
  4. # To run this file use the following command:
  5. #   perl -W -f -- "this.pl"
  6. #use warnings;
  7. #use strict;
  8.  
  9. ###############################################################################
  10. my @PATCH_INFO = (
  11.     {
  12.         desc =>   'Opera',
  13.         assert => undef,
  14.         test =>   undef,
  15.         match =>  qr/./s,
  16.         replace => undef,
  17.         patchset => [
  18.             #Comment out patches that you don't need because more changes -> more possible instability
  19.             #mp3 patch (for gstreamer mod)
  20.             {
  21.                 # contributor: Dither
  22.                 desc =>   'Fix wave->mpeg for HTML5 MP3',
  23.                 assert => undef,
  24.                 test =>   qr/\x6D\x70\x65\x67\x00\x00\x00\x00\x78\x2D\x77\x61\x76/s,
  25.                 match =>  qr/\x77\x61\x76\x65\x00\x00\x00\x00\x78\x2D\x77\x61\x76/s,
  26.                 replace => '"\x6D\x70\x65\x67\x00\x00\x00\x00\x78\x2D\x77\x61\x76"'
  27.             },
  28.         ]
  29.     },
  30. );
  31. ###############################################################################
  32.  
  33.  
  34. my $OPERABIN = $ARGV[0];
  35. my $invokedByBatch = defined($ARGV[1])? int($ARGV[1]): 0; # 1 - invoked by batch, operate on original file
  36.  
  37. if ( !$OPERABIN ) {
  38.     print " - Missing file name argument. Assuming 'opera.dll'...\n";
  39.     $OPERABIN = "opera.dll";
  40. }
  41.  
  42. print "\n";
  43. open(FILE,'<'.$OPERABIN) or die " - Error opening file ". $OPERABIN ." for reading!\n";
  44. binmode FILE;
  45.  
  46. my($buf, $data, $n);
  47. my $err = 1;
  48.  
  49. # read content of binary file to buf
  50. while ( ($n = read(FILE, $data, 102400) ) != 0 ) {
  51.     $buf .= $data;
  52. }
  53.  
  54. PATCH:
  55. foreach my $patchclass (@PATCH_INFO) {
  56.     #print ($patchclass->{desc}); print "Patching...\n";
  57.     if ($patchclass->{assert} and !($buf =~ m/$patchclass->{assert}/) ) {
  58.         print " o Invalid precondition ". $patchclass->{desc} ."... SKIPPING.\n";
  59.         next PATCH;
  60.     }
  61.     if ($patchclass->{test} and $buf =~ m/$patchclass->{test}/ ) {
  62.         print " - Already patched ". $patchclass->{desc} ."... IGNORING.\n";
  63.         last PATCH;
  64.     }
  65.     PATCHSET:
  66.     foreach my $patchset (@{$patchclass->{patchset}}) {
  67.         if ($patchset->{assert} and !($buf =~ m/$patchset->{assert}/) ) {
  68.             print " o Invalid precondition ". $patchclass->{desc} ."/". $patchset->{desc} ."... SKIPPING.\n";
  69.             next PATCHSET;
  70.         }
  71.         if ($patchset->{test} and $buf =~ m/$patchset->{test}/) {
  72.             print "   - Already applied " . $patchclass->{desc} ."/". $patchset->{desc} ."... IGNORING.\n";
  73.             next PATCHSET;
  74.         }
  75.         if ($buf =~ m/$patchset->{match}/ ) {
  76.             print "   + Applying ". $patchclass->{desc} ."/". $patchset->{desc} ."... ";
  77.             $buf =~ s/$patchset->{match}/$patchset->{replace}/gee;
  78.             print "SUCCESS!";
  79.             print "\n";
  80.             $err = 0;
  81.             next PATCHSET;
  82.         }
  83.         else {
  84.             print "";
  85.         }
  86.     }
  87. }
  88.  
  89. close(FILE);
  90.  
  91. # return error when no match found
  92. exit 1 if ($err);
  93.  
  94. # create file with modified buf
  95. if ($invokedByBatch) {
  96.     open(FILE, ">".$OPERABIN) or die " - Error opening file ". $OPERABIN ." for writing!\n";
  97. } else {
  98.     open(FILE, ">".$OPERABIN."_patched") or die " - Error opening file ". $OPERABIN ."_patched for writing!\n";
  99. }
  100. binmode FILE;
  101. print FILE $buf;
  102. close(FILE);
  103. print "\n * File '". $OPERABIN . (($invokedByBatch)?'_patched':'') ."' successfully written.\n";
  104.  
  105. exit 0;
  106.  
  107. ###############################################################################
  108.  
  109. __END__
Advertisement
Add Comment
Please, Sign In to add comment