Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- # Perl script to apply common patches for Opera
- # Based on work of Dither
- # To run this file use the following command:
- # perl -W -f -- "this.pl"
- #use warnings;
- #use strict;
- ###############################################################################
- my @PATCH_INFO = (
- {
- desc => 'Opera',
- assert => undef,
- test => undef,
- match => qr/./s,
- replace => undef,
- patchset => [
- #Comment out patches that you don't need because more changes -> more possible instability
- #mp3 patch (for gstreamer mod)
- {
- # contributor: Dither
- desc => 'Fix wave->mpeg for HTML5 MP3',
- assert => undef,
- test => qr/\x6D\x70\x65\x67\x00\x00\x00\x00\x78\x2D\x77\x61\x76/s,
- match => qr/\x77\x61\x76\x65\x00\x00\x00\x00\x78\x2D\x77\x61\x76/s,
- replace => '"\x6D\x70\x65\x67\x00\x00\x00\x00\x78\x2D\x77\x61\x76"'
- },
- ]
- },
- );
- ###############################################################################
- my $OPERABIN = $ARGV[0];
- my $invokedByBatch = defined($ARGV[1])? int($ARGV[1]): 0; # 1 - invoked by batch, operate on original file
- if ( !$OPERABIN ) {
- print " - Missing file name argument. Assuming 'opera.dll'...\n";
- $OPERABIN = "opera.dll";
- }
- print "\n";
- open(FILE,'<'.$OPERABIN) or die " - Error opening file ". $OPERABIN ." for reading!\n";
- binmode FILE;
- my($buf, $data, $n);
- my $err = 1;
- # read content of binary file to buf
- while ( ($n = read(FILE, $data, 102400) ) != 0 ) {
- $buf .= $data;
- }
- PATCH:
- foreach my $patchclass (@PATCH_INFO) {
- #print ($patchclass->{desc}); print "Patching...\n";
- if ($patchclass->{assert} and !($buf =~ m/$patchclass->{assert}/) ) {
- print " o Invalid precondition ". $patchclass->{desc} ."... SKIPPING.\n";
- next PATCH;
- }
- if ($patchclass->{test} and $buf =~ m/$patchclass->{test}/ ) {
- print " - Already patched ". $patchclass->{desc} ."... IGNORING.\n";
- last PATCH;
- }
- PATCHSET:
- foreach my $patchset (@{$patchclass->{patchset}}) {
- if ($patchset->{assert} and !($buf =~ m/$patchset->{assert}/) ) {
- print " o Invalid precondition ". $patchclass->{desc} ."/". $patchset->{desc} ."... SKIPPING.\n";
- next PATCHSET;
- }
- if ($patchset->{test} and $buf =~ m/$patchset->{test}/) {
- print " - Already applied " . $patchclass->{desc} ."/". $patchset->{desc} ."... IGNORING.\n";
- next PATCHSET;
- }
- if ($buf =~ m/$patchset->{match}/ ) {
- print " + Applying ". $patchclass->{desc} ."/". $patchset->{desc} ."... ";
- $buf =~ s/$patchset->{match}/$patchset->{replace}/gee;
- print "SUCCESS!";
- print "\n";
- $err = 0;
- next PATCHSET;
- }
- else {
- print "";
- }
- }
- }
- close(FILE);
- # return error when no match found
- exit 1 if ($err);
- # create file with modified buf
- if ($invokedByBatch) {
- open(FILE, ">".$OPERABIN) or die " - Error opening file ". $OPERABIN ." for writing!\n";
- } else {
- open(FILE, ">".$OPERABIN."_patched") or die " - Error opening file ". $OPERABIN ."_patched for writing!\n";
- }
- binmode FILE;
- print FILE $buf;
- close(FILE);
- print "\n * File '". $OPERABIN . (($invokedByBatch)?'_patched':'') ."' successfully written.\n";
- exit 0;
- ###############################################################################
- __END__
Advertisement
Add Comment
Please, Sign In to add comment