Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Handoff and Instant Hotspot enabler for Macbook Air 2011
#!/usr/bin/env python
import mmap, subprocess, sys, os
# Ensure to run script as root - if not, rerun it
if os.geteuid() != 0:
os.execvp("sudo", ["sudo"] + sys.argv)
# Checking kext dev mode
mode = subprocess.check_output("nvram -p | grep kext-dev-mode | awk '{print $2}'", shell=True).strip()
if mode != 'kext-dev-mode=1':
print '[+] Enabling kext-dev-mode...',
subprocess.check_output('nvram boot-args="kext-dev-mode=1"', shell=True)
print 'done!'
print '[+] Rebooting...',
subprocess.check_output('reboot')
sys.exit(0)
# Backup kext
print '[+] Backing up kext...',
subprocess.check_output('cp -Rf /System/Library/Extensions/IO80211Family.kext ~/Desktop', shell=True)
subprocess.check_output('cp -Rf /System/Library/Extensions/IOBluetoothFamily.kext ~/Desktop', shell=True)
print 'done!'
# Get board id
print '[+] Reading board id...'
board_id = subprocess.check_output("ioreg -l | grep 'board-id' | awk -F\\\" '{print $4}'", shell=True).strip()
print '[+] Found board id', board_id
# Modify IO80211Family.kext
print '[+] Reading IO80211Family.kext'
kext_path = '/System/Library/Extensions/IO80211Family.kext/Contents/Plugins/AirPortBrcm4360.kext/Contents/MacOS/AirPortBrcm4360'
with open(kext_path, 'r+b') as f:
mm = mmap.mmap(f.fileno(), 0)
index = mm.find('Mac-')
print '[+] Found', mm[index:index+20]
print '[+] Replacing with', board_id
mm[index:index+20] = board_id
index = mm.rfind('Mac-')
print '[+] Found', mm[index:index+20]
print '[+] Replacing with', board_id
mm[index:index+20] = board_id
mm.close()
# Modify IOBluetoothFamily.kext
print '[+] Reading IOBluetoothFamily.kext'
kext_path = '/System/Library/Extensions/IOBluetoothFamily.kext/Contents/MacOS/IOBluetoothFamily'
with open(kext_path, 'r+b') as f:
mm = mmap.mmap(f.fileno(), 0)
index = mm.find('MacBookAir')
print '[+] Found', mm[index-1:index+69]
print '[+] Replacing with'
for offset in [10, 12, 26, 28, 39, 41, 52, 54, 65, 67]:
mm[index+offset] = '1'
print '[+] After replace', mm[index-1:index+69]
mm.close()
print '[+] Regenerating kext cache...',
subprocess.check_output('kextcache -system-prelinked-kernel', shell=True)
subprocess.check_output('kextcache -system-caches', shell=True)
print 'done!'
print '[+] Rebooting...'
subprocess.check_output('reboot')
sys.exit(0)
#!/usr/bin/env python
import subprocess, sys
# Ensure to run script as root - if not, rerun it
if os.geteuid() != 0:
os.execvp("sudo", ["sudo"] + sys.argv)
# Reverting kext dev mode
print '[+] Disabling kext-dev-mode...',
subprocess.check_output('nvram boot-args="kext-dev-mode=0"', shell=True)
print 'done!'
# Restore kext backup
print '[+] Restoring kext...',
subprocess.check_output('mv ~/Desktop/IO80211Family.kext /System/Library/Extensions', shell=True)
subprocess.check_output('mv ~/Desktop/IOBluetoothFamily.kext /System/Library/Extensions', shell=True)
print 'done!'
print '[+] Regenerating kext cache...',
subprocess.check_output('kextcache -system-prelinked-kernel', shell=True)
subprocess.check_output('kextcache -system-caches', shell=True)
print 'done!'
print '[+] Rebooting...'
subprocess.check_output('reboot')
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment