#!/usr/bin/perl #################################################### # Patches the Airport Extreme driver for use in MOL # Copyright 2005, Joseph Jezak # Based on work by Mattias Nissler and Johannes Berg # This file is public domain #################################################### use strict; my $patch = 0; ### Deal with the user's options if ($ARGV[0] eq "--patch") { $patch = 1; } elsif ($ARGV[0] eq "--revert") { $patch = 0; } else { print "This program patches the AppleAirport2 driver to use PIO mode, which\n"; print "enables usage of the Airport Extreme from within MOL.\n\n"; print "Usage:\taepatch [--patch or --revert] [path]\n"; print " --revert\tReverts the patch and restores the driver\n"; print " --patch\tPatches the driver for PIO support\n\n"; print "The optional path for the location of the kext defaults to:\n"; print "/System/Library/Extensions/AppleAirport2.kext/Contents/MacOS/AppleAirPort2\n\n"; print "*** PLEASE BACK UP THE DRIVER FIRST! YOU HAVE BEEN WARNED! ***\n"; exit(); } ### Set up the driver path my $driver; if($ARGV[1] eq "") { $driver = "/System/Library/Extensions/AppleAirport2.kext/Contents/MacOS/AppleAirPort2"; } else { $driver = $ARGV[1]; } ### Open the File open AE2, "+<".$driver or die "Can't open ".$driver."!\n"; ### Get file size my @ae2stat = stat AE2; ### Find the number of times we check for PIO (so we can see if it's compatible) $|=1; print "Checking for compatible driver ..."; $|=0; my $int = 0; my @positions; while(read (AE2, $int, 4)) { if ($int eq pack("CCCC", 56, 1, 0, 80)) { push @positions, (tell AE2) - 4; } } ### If PIO isn't supported if($#positions + 1 != 3) { print "failed.\n"; print " *** Sorry your driver does not support PIO mode. Please try another version.\n"; } ### Patch the driver else { print "ok.\n"; seek AE2, $positions[1] + 16, 0; read AE2, $int, 4; ### Patch it if($patch){ print " *** Patching the driver... "; if($int eq pack("CCCC",57,0,0,0)) { seek AE2, -4, 1; print AE2 pack("CCCC",57,0,0,1); print "done.\n"; } else { print "failed.\n"; print " *** Sorry, either this driver version is not supported or it's already patched!\n"; } } ### Reverse the patch else { print " *** Reversing the patch... "; if($int eq pack("CCCC", 57,0,0,1)) { seek AE2, -4, 1; print AE2 pack("CCCC",57,0,0,0); print "done.\n"; } else { print "failed.\n"; print " *** Sorry, either this driver version is not supported or it isn't patched yet!\n"; } } } ### Close the driver close AE2;