Dither

Opera 12 patches

May 16th, 2011
2,349
0
Never
5
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 10.13 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. # Perl script to apply common patches for Opera
  3. # Based on work of  d.i.z / XA / gwarser / BtEO / Rafal / Dither / Nibiru and other contributors
  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.             #Patch to remove "Click to Activate" for embeds x64
  20.             {
  21.                 # contributor: PX ;other possibile values include \xba[\xae\xb1\xb6\xb4]
  22.                 desc =>   'Remove "Click to Activate" v12 [64bit]',
  23.                 assert => undef,
  24.                 test =>   qr/\x41\xb1\x01\xba\xae\x02\x00\x00\x45\x8d\x41\x17[\xe8\xe9]/s,
  25.                 match =>  qr/(?:\x45\x33\xc9)(\xba[\xb4]\x02\x00\x00\x45\x8d\x41\x17[\xe8\xe9])/s,
  26.                 replace => '"\x41\xb1\x01$1"'
  27.             },
  28.             #Patch to remove real hostname from MHTML's Content-ID field
  29.             {
  30.                 # contributor: Dither
  31.                 desc =>   'Remove real hostname from MHTML Content-ID v12 [64bit]',
  32.                 assert => undef,
  33.                 test =>   qr/\x85\xC0\xEB\x41\x48\x8D\x4D\xD0\xE8.{4}\x48\x8B\x55\xE0/s,
  34.                 match =>  qr/\x85\xC0\x75\x31\x48\x8D\x4D\xD0\xE8(.{4})\x48\x8B\x55\xE0/s,
  35.                 replace => '"\x85\xC0\xEB\x41\x48\x8D\x4D\xD0\xE8$1\x48\x8B\x55\xE0"'
  36.             },
  37.             #Disable UJS on HTTPS confirmation x64
  38.             {
  39.                 # contributor: Dither
  40.                 desc =>   'Silent HTTPS UserJS v12 [64bit]',
  41.                 assert => undef,
  42.                 test =>   qr/\x90\x90\x90\x90\x90\x48.{6}\x44\x89.{5}\x41\xFF\xC6\x44\x89.{5}\x41\xFF\xCE\x90\x90/s,
  43.                 match =>  qr/\xE8.{4}\x48(.{6})\x44\x39(.{5})\x0F\x85.{4}\x44\x39(.{5})\x74\x08/s,
  44.                 replace => '"\x90\x90\x90\x90\x90\x48$1\x44\x89$2\x41\xFF\xC6\x44\x89$3\x41\xFF\xCE\x90\x90"'
  45.  
  46.             },
  47.             #Disable tab stacking x64
  48.             {
  49.                 # contributor: Dither
  50.                 desc =>   'Disable tab stacking v12 [64bit]',
  51.                 assert => undef,
  52.                 test =>   qr/\xEB\x5D\x48\x8B\xC8\xE8.{4}\x85/s,
  53.                 match =>  qr/\x74\x5D\x48\x8B\xC8\xE8(.{4})\x85/s,
  54.                 replace => '"\xEB\x5D\x48\x8B\xC8\xE8$1\x85"'
  55.             },
  56.             #Patch to remove "Click to Activate" for embeds
  57.             {
  58.                 # contributors: BtEO [20120426], XA [20120426]
  59.                 desc =>   'Remove "Click to Activate" v12 [32bit]',
  60.                 assert => undef,
  61.                 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,
  62.                 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,
  63.                 replace => '"\x6A\x01\x6A\x17$1\xE8$2$3\xC2\x04\x00$4\x6A\x01\x6A\x17$5\xE8$6$7\xC2\x04\x00"'
  64.             },
  65.             #Disable addressbar gray URL highlighting
  66.             #{
  67.             #    # contributors: Nibiru, BtEO
  68.             #    desc =>   'Disable gray URL highlight v11, v12 [32bit]',
  69.             #    assert => undef,
  70.             #    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,
  71.             #    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,
  72.             #    replace => '"$1\xD9\x05$2"'
  73.             #},
  74.             #Disable UJS on HTTPS confirmation
  75.             {
  76.                 # contributor: Dither
  77.                 desc =>   'Silent HTTPS UserJS v11',
  78.                 assert => undef,
  79.                 test =>   qr/\x90\x90\x90\x90\x90\x90\x90\x89.{5}\x43\x90\x90\x90\x90\x90\x89.{5}/s,
  80.                 match =>  qr/\x56\x50\xE8.{4}\x39(.{5})\x0F\x85\x88\x00\x00\x00\x39(.{5})/s,
  81.                 replace => '"\x90\x90\x90\x90\x90\x90\x90\x89$1\x43\x90\x90\x90\x90\x90\x89$2"'
  82.             },
  83.             {
  84.                 # contributors: BtEO, XA, Dither
  85.                 desc =>   'Silent HTTPS UserJS v12 [32bit]',
  86.                 assert => undef,
  87.                 test =>   qr/\x90{7}\x89.{5}\x43\x90\x89.{5}/s,
  88.                 match =>  qr/\x56\x50\xE8.{4}\x39(.{5})\x75.\x39(.{5})/s,
  89.                 replace => '"\x90\x90\x90\x90\x90\x90\x90\x89$1\x43\x90\x89$2"'
  90.             },
  91.             {
  92.                 # contributor: Dither
  93.                 desc =>   'Silent HTTPS UserJS v12 HWA [32bit]',
  94.                 assert => undef,
  95.                 test =>   qr/\x90{12}\xA1.{4}\x89\x98.{4}\x43\x90\x89\x98.{4}\x4B\x90\x56/s,
  96.                 match =>  qr/\x56\xFF\xB7.{4}\xE8.{4}(\xA1.{4})\x39(\x98.{4})\x75.\x39(\x98.{4})\x74.\x56/s,
  97.                 replace => '"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90$1\x89$2\x43\x90\x89$3\x4B\x90\x56"'
  98.  
  99.             },
  100.             #mp3 patch (for gstreamer mod)
  101.             #{
  102.             #    # contributor: Dither
  103.             #    desc =>   'Fix wave->mpeg (MP3) v11, 12',
  104.             #    assert => undef,
  105.             #    test =>   qr/\x6D\x70\x65\x67\x00\x00\x00\x00\x78\x2D\x77\x61\x76/s,
  106.             #    match =>  qr/\x77\x61\x76\x65\x00\x00\x00\x00\x78\x2D\x77\x61\x76/s,
  107.             #    replace => '"\x6D\x70\x65\x67\x00\x00\x00\x00\x78\x2D\x77\x61\x76"'
  108.             #},
  109.             #Disable tab stacking
  110.             {
  111.                 # contributor: Dither
  112.                 desc =>   'Disable tab stacking v12 HWA [32bit]',
  113.                 assert => undef,
  114.                 test =>   qr/\xFF\x75\x08\xE8.{4}\x89\xDF\x3B\xFB\x74.\x53\x57\xE8.{4}\x85\xC0\x74/s,
  115.                 match =>  qr/\xFF\x75\x08\xE8(.{4})\x8B\xF8\x3B\xFB\x74(.)\x53\x57\xE8(.{4})\x85\xC0\x74/s,
  116.                 replace => '"\xFF\x75\x08\xE8$1\x89\xDF\x3B\xFB\x74$2\x53\x57\xE8$3\x85\xC0\x74"'
  117.             },
  118.             #Change "Mask as IE" UserAgent to IE 11
  119.             {
  120.                 # contributor: Dither
  121.                 desc =>   'Refresh UserAgent for Mask as IE',
  122.                 assert => undef,
  123.                 test =>   qr/Trident\/7\.0/s,
  124.                 match =>  qr/Trident\/5\.0/s,
  125.                 replace => '"Trident/7.0"'
  126.             },
  127.             #Change "Mask as Firefox" UserAgent to Firefox 31
  128.             {
  129.                 # contributor: Dither
  130.                 desc =>   'Refresh UserAgent for Mask as Firefox',
  131.                 assert => undef,
  132.                 test =>   qr/Mozilla\/5\.0 \(%s%s; rv:31\.0\) Gecko\/20100101 Firefox\/31\.0\x00/s,
  133.                 match =>  qr/Mozilla\/5\.0 \(%s%s%s; rv:2\.0\) Gecko\/20100101 Firefox\/4.0\x00/s,
  134.                 replace => '"Mozilla/5.0 (%s%s; rv:31.0) Gecko/20100101 Firefox/31.0\x00"'
  135.             },
  136.         ]
  137.     },
  138. );
  139. ###############################################################################
  140.  
  141.  
  142. my $BINARYTOPATCH = $ARGV[0];
  143. my $invokedByBatch = defined($ARGV[1])? int($ARGV[1]): 0; # 1 - invoked by batch, operate on original file
  144.  
  145. if ( !$BINARYTOPATCH ) {
  146.     print "\n - Missing file name argument. Assuming 'opera.dll'...";
  147.     $BINARYTOPATCH = "opera.dll";
  148. }
  149.  
  150. print "\n";
  151. open(FILE,'<'.$BINARYTOPATCH) or die " - Error opening file ". $BINARYTOPATCH ." for reading!\n";
  152. binmode FILE;
  153.  
  154. my($buf, $data, $n);
  155. my $succ = 0;
  156. my $fail = 0;
  157.  
  158. # read content of binary file to buf
  159. while ( ($n = read(FILE, $data, 102400) ) != 0 ) {
  160.     $buf .= $data;
  161. }
  162.  
  163. PATCH:
  164. foreach my $patchclass (@PATCH_INFO) {
  165.     if ($patchclass->{assert} and !($buf =~ m/$patchclass->{assert}/) ) {
  166.         print "   o Invalid precondition ". $patchclass->{desc} ."... SKIPPING\n";
  167.         next PATCH;
  168.     }
  169.     if ($patchclass->{test} and $buf =~ m/$patchclass->{test}/ ) {
  170.         print "   - Already patched ". $patchclass->{desc} ."... IGNORING\n";
  171.         last PATCH;
  172.     }
  173.     PATCHSET:
  174.     foreach my $patchset (@{$patchclass->{patchset}}) {
  175.         if ($patchset->{assert} and !($buf =~ m/$patchset->{assert}/) ) {
  176.             print "   o Invalid precondition ". $patchclass->{desc} ."/". $patchset->{desc} ."... SKIPPING\n";
  177.             $fail++;
  178.             next PATCHSET;
  179.         }
  180.         if ($patchset->{test} and $buf =~ m/$patchset->{test}/) {
  181.             print "   - Already applied " . $patchclass->{desc} ."/". $patchset->{desc} ."... IGNORING\n";
  182.             $fail++;
  183.             next PATCHSET;
  184.         }
  185.         if ($buf =~ m/$patchset->{match}/ ) {
  186.                 print "   + Applying ". $patchclass->{desc} ."/". $patchset->{desc} ."... ";
  187.             $buf =~ s/$patchset->{match}/$patchset->{replace}/gee;
  188.             print "SUCCESS!";
  189.             print "\n";
  190.             $succ++;
  191.             next PATCHSET;
  192.         }
  193.         else {
  194.             print "";
  195.         }
  196.     }
  197. }
  198.  
  199. close(FILE);
  200.  
  201. # return error when no match found
  202. if ($succ == 0 && $fail == 0)  {
  203.     print " * No known patterns found, probably file version mismatch.\n";
  204.     exit 1;
  205. }
  206. if ($fail > 0 && $succ <= 0)  {
  207.     exit 1;
  208. }
  209.  
  210. # create file with modified buf
  211. if ($invokedByBatch) {
  212.     open(FILE, ">".$BINARYTOPATCH) or die " - Error opening file ". $BINARYTOPATCH ." for writing!\n";
  213. } else {
  214.     rename($BINARYTOPATCH, $BINARYTOPATCH.".original") or die " - Error renaming file". $BINARYTOPATCH ." to ".$BINARYTOPATCH.".original for writing!\n";
  215.     open(FILE, ">".$BINARYTOPATCH) or die " - Error opening file ". $BINARYTOPATCH ." for writing!\n";
  216. }
  217. binmode FILE;
  218. print FILE $buf;
  219. close(FILE);
  220. print " * Patched '". $BINARYTOPATCH."' successfully.".((!$invokedByBatch)?" Original saved as '".$BINARYTOPATCH.".original'":'')."\n";
  221.  
  222. exit 0;
  223.  
  224. ###############################################################################
  225.  
  226. __END__
Advertisement
Comments
  • User was banned
  • User was banned
  • karim08
    24 days
    Comment was deleted
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment