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 d.i.z / XA / gwarser / BtEO / Rafal / Dither / Nibiru and other contributors
- # 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
- #Patch to remove "Click to Activate" for embeds x64
- {
- # contributor: PX ;other possibile values include \xba[\xae\xb1\xb6\xb4]
- desc => 'Remove "Click to Activate" v12 [64bit]',
- assert => undef,
- test => qr/\x41\xb1\x01\xba\xae\x02\x00\x00\x45\x8d\x41\x17[\xe8\xe9]/s,
- match => qr/(?:\x45\x33\xc9)(\xba[\xb4]\x02\x00\x00\x45\x8d\x41\x17[\xe8\xe9])/s,
- replace => '"\x41\xb1\x01$1"'
- },
- #Patch to remove real hostname from MHTML's Content-ID field
- {
- # contributor: Dither
- desc => 'Remove real hostname from MHTML Content-ID v12 [64bit]',
- assert => undef,
- test => qr/\x85\xC0\xEB\x41\x48\x8D\x4D\xD0\xE8.{4}\x48\x8B\x55\xE0/s,
- match => qr/\x85\xC0\x75\x31\x48\x8D\x4D\xD0\xE8(.{4})\x48\x8B\x55\xE0/s,
- replace => '"\x85\xC0\xEB\x41\x48\x8D\x4D\xD0\xE8$1\x48\x8B\x55\xE0"'
- },
- #Disable UJS on HTTPS confirmation x64
- {
- # contributor: Dither
- desc => 'Silent HTTPS UserJS v12 [64bit]',
- assert => undef,
- test => qr/\x90\x90\x90\x90\x90\x48.{6}\x44\x89.{5}\x41\xFF\xC6\x44\x89.{5}\x41\xFF\xCE\x90\x90/s,
- match => qr/\xE8.{4}\x48(.{6})\x44\x39(.{5})\x0F\x85.{4}\x44\x39(.{5})\x74\x08/s,
- replace => '"\x90\x90\x90\x90\x90\x48$1\x44\x89$2\x41\xFF\xC6\x44\x89$3\x41\xFF\xCE\x90\x90"'
- },
- #Disable tab stacking x64
- {
- # contributor: Dither
- desc => 'Disable tab stacking v12 [64bit]',
- assert => undef,
- test => qr/\xEB\x5D\x48\x8B\xC8\xE8.{4}\x85/s,
- match => qr/\x74\x5D\x48\x8B\xC8\xE8(.{4})\x85/s,
- replace => '"\xEB\x5D\x48\x8B\xC8\xE8$1\x85"'
- },
- #Patch to remove "Click to Activate" for embeds
- {
- # contributors: BtEO [20120426], XA [20120426]
- desc => 'Remove "Click to Activate" v12 [32bit]',
- assert => undef,
- test => qr/\x6A\x01\x6A\x17[\xBF\x68].{4}\xE8.{4}[\x5F\x5E]\xC2\x04\x00.{5}\x6A\x01\x6A\x17[\xBF\x68].{4}\xE8.{4}[\x5F\x5E]\xC2\x04\x00/s,
- match => qr/\x6A\x00\x6A\x17([\xBF\x68].{4})\xE8(.{4})([\x5F\x5E])\xC2\x04\x00(.{5})\x6A\x00\x6A\x17([\xBF\x68].{4})\xE8(.{4})([\x5F\x5E])\xC2\x04\x00/s,
- replace => '"\x6A\x01\x6A\x17$1\xE8$2$3\xC2\x04\x00$4\x6A\x01\x6A\x17$5\xE8$6$7\xC2\x04\x00"'
- },
- #Disable addressbar gray URL highlighting
- #{
- # # contributors: Nibiru, BtEO
- # desc => 'Disable gray URL highlight v11, v12 [32bit]',
- # assert => undef,
- # test => qr/\xDB\x44\x24.[\x2B\x89][\x44\x54]\x24.\xD9\x05.{3}\x67(?:\x89\x44\x24.\xC7\x44\x24.\x01\x00{3}\xDC\xC9|\xB8\xFF\x00{3}\x2B\xC3\xDC\xC9\xC7\x44\x24.\x01\x00{3}|\xDC\xC9)\xDB\x44\x24.\xD8\xC9\xDE\xC2/s,
- # match => qr/(\xDB\x44\x24.[\x2B\x89][\x44\x54]\x24.)\xDD\x05(.{3}\x67(?:\x89\x44\x24.\xC7\x44\x24.\x01\x00{3}\xDC\xC9|\xB8\xFF\x00{3}\x2B\xC3\xDC\xC9\xC7\x44\x24.\x01\x00{3}|\xDC\xC9)\xDB\x44\x24.\xD8\xC9\xDE\xC2)/s,
- # replace => '"$1\xD9\x05$2"'
- #},
- #Disable UJS on HTTPS confirmation
- {
- # contributor: Dither
- desc => 'Silent HTTPS UserJS v11',
- assert => undef,
- test => qr/\x90\x90\x90\x90\x90\x90\x90\x89.{5}\x43\x90\x90\x90\x90\x90\x89.{5}/s,
- match => qr/\x56\x50\xE8.{4}\x39(.{5})\x0F\x85\x88\x00\x00\x00\x39(.{5})/s,
- replace => '"\x90\x90\x90\x90\x90\x90\x90\x89$1\x43\x90\x90\x90\x90\x90\x89$2"'
- },
- {
- # contributors: BtEO, XA, Dither
- desc => 'Silent HTTPS UserJS v12 [32bit]',
- assert => undef,
- test => qr/\x90{7}\x89.{5}\x43\x90\x89.{5}/s,
- match => qr/\x56\x50\xE8.{4}\x39(.{5})\x75.\x39(.{5})/s,
- replace => '"\x90\x90\x90\x90\x90\x90\x90\x89$1\x43\x90\x89$2"'
- },
- {
- # contributor: Dither
- desc => 'Silent HTTPS UserJS v12 HWA [32bit]',
- assert => undef,
- test => qr/\x90{12}\xA1.{4}\x89\x98.{4}\x43\x90\x89\x98.{4}\x4B\x90\x56/s,
- match => qr/\x56\xFF\xB7.{4}\xE8.{4}(\xA1.{4})\x39(\x98.{4})\x75.\x39(\x98.{4})\x74.\x56/s,
- replace => '"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90$1\x89$2\x43\x90\x89$3\x4B\x90\x56"'
- },
- #mp3 patch (for gstreamer mod)
- #{
- # # contributor: Dither
- # desc => 'Fix wave->mpeg (MP3) v11, 12',
- # 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"'
- #},
- #Disable tab stacking
- {
- # contributor: Dither
- desc => 'Disable tab stacking v12 HWA [32bit]',
- assert => undef,
- test => qr/\xFF\x75\x08\xE8.{4}\x89\xDF\x3B\xFB\x74.\x53\x57\xE8.{4}\x85\xC0\x74/s,
- match => qr/\xFF\x75\x08\xE8(.{4})\x8B\xF8\x3B\xFB\x74(.)\x53\x57\xE8(.{4})\x85\xC0\x74/s,
- replace => '"\xFF\x75\x08\xE8$1\x89\xDF\x3B\xFB\x74$2\x53\x57\xE8$3\x85\xC0\x74"'
- },
- #Change "Mask as IE" UserAgent to IE 11
- {
- # contributor: Dither
- desc => 'Refresh UserAgent for Mask as IE',
- assert => undef,
- test => qr/Trident\/7\.0/s,
- match => qr/Trident\/5\.0/s,
- replace => '"Trident/7.0"'
- },
- #Change "Mask as Firefox" UserAgent to Firefox 31
- {
- # contributor: Dither
- desc => 'Refresh UserAgent for Mask as Firefox',
- assert => undef,
- test => qr/Mozilla\/5\.0 \(%s%s; rv:31\.0\) Gecko\/20100101 Firefox\/31\.0\x00/s,
- match => qr/Mozilla\/5\.0 \(%s%s%s; rv:2\.0\) Gecko\/20100101 Firefox\/4.0\x00/s,
- replace => '"Mozilla/5.0 (%s%s; rv:31.0) Gecko/20100101 Firefox/31.0\x00"'
- },
- ]
- },
- );
- ###############################################################################
- my $BINARYTOPATCH = $ARGV[0];
- my $invokedByBatch = defined($ARGV[1])? int($ARGV[1]): 0; # 1 - invoked by batch, operate on original file
- if ( !$BINARYTOPATCH ) {
- print "\n - Missing file name argument. Assuming 'opera.dll'...";
- $BINARYTOPATCH = "opera.dll";
- }
- print "\n";
- open(FILE,'<'.$BINARYTOPATCH) or die " - Error opening file ". $BINARYTOPATCH ." for reading!\n";
- binmode FILE;
- my($buf, $data, $n);
- my $succ = 0;
- my $fail = 0;
- # read content of binary file to buf
- while ( ($n = read(FILE, $data, 102400) ) != 0 ) {
- $buf .= $data;
- }
- PATCH:
- foreach my $patchclass (@PATCH_INFO) {
- 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";
- $fail++;
- next PATCHSET;
- }
- if ($patchset->{test} and $buf =~ m/$patchset->{test}/) {
- print " - Already applied " . $patchclass->{desc} ."/". $patchset->{desc} ."... IGNORING\n";
- $fail++;
- next PATCHSET;
- }
- if ($buf =~ m/$patchset->{match}/ ) {
- print " + Applying ". $patchclass->{desc} ."/". $patchset->{desc} ."... ";
- $buf =~ s/$patchset->{match}/$patchset->{replace}/gee;
- print "SUCCESS!";
- print "\n";
- $succ++;
- next PATCHSET;
- }
- else {
- print "";
- }
- }
- }
- close(FILE);
- # return error when no match found
- if ($succ == 0 && $fail == 0) {
- print " * No known patterns found, probably file version mismatch.\n";
- exit 1;
- }
- if ($fail > 0 && $succ <= 0) {
- exit 1;
- }
- # create file with modified buf
- if ($invokedByBatch) {
- open(FILE, ">".$BINARYTOPATCH) or die " - Error opening file ". $BINARYTOPATCH ." for writing!\n";
- } else {
- rename($BINARYTOPATCH, $BINARYTOPATCH.".original") or die " - Error renaming file". $BINARYTOPATCH ." to ".$BINARYTOPATCH.".original for writing!\n";
- open(FILE, ">".$BINARYTOPATCH) or die " - Error opening file ". $BINARYTOPATCH ." for writing!\n";
- }
- binmode FILE;
- print FILE $buf;
- close(FILE);
- print " * Patched '". $BINARYTOPATCH."' successfully.".((!$invokedByBatch)?" Original saved as '".$BINARYTOPATCH.".original'":'')."\n";
- exit 0;
- ###############################################################################
- __END__
Advertisement