-
-
Save avibryant/122105 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class File | |
def seek_to(str) | |
until eof? | |
start = pos | |
buf = read(10000) | |
if(offset = buf.index(str)) | |
seek(start + offset + str.size) | |
return true | |
else | |
seek(start + 5000) | |
end | |
end | |
return nil | |
end | |
end | |
Safari = "/Applications/Safari.app/Contents/MacOS/Safari" | |
Find = "google.com/%@" | |
Replace = "bing.com/%@?q=%@\0" | |
unless File.exists? Safari | |
$stderr.puts "Couldn't find Safari at #{Safari}" | |
exit 1 | |
end | |
File.open(Safari, 'r+') do |f| | |
$stderr.puts "Scanning #{Safari}..." | |
if f.seek_to(Find) && f.seek_to(Find) | |
$stderr.puts "Backing up #{Safari} to #{Safari}.old" | |
`cp #{Safari} #{Safari}.old` | |
$stderr.puts "Patching #{Safari}" | |
f.seek(f.pos - Find.size) | |
f.write(Replace) | |
else | |
$stderr.puts "Couldn't figure out where to apply the patch" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment