Skip to content

Instantly share code, notes, and snippets.

@ihoka
Forked from seancribbs/extract_safari_cache.rb
Created December 15, 2009 17:13
Show Gist options
  • Save ihoka/257099 to your computer and use it in GitHub Desktop.
Save ihoka/257099 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'active_record'
# Open Safari's sqlite3 cache database
arb = ActiveRecord::Base
arb.establish_connection(
:adapter => "sqlite3",
:database => File.join(ENV['HOME'], 'Library', 'Caches', 'com.apple.Safari', 'Cache.db'))
# How to match files (LIKE string)
match = ARGV.shift
# Where to save the results (must exist)
dir = ARGV.shift
# Find matching responses
responses = arb.connection.select_all(%Q[select entry_ID, request_key from cfurl_cache_response where request_key like "%#{match}%"])
Dir.chdir(dir) do
# Write out the blob of each cached response
responses.each do |hash|
filename = File.basename(hash['request_key'])
blob = arb.connection.select_value("select receiver_data from cfurl_cache_blob_data where entry_ID=#{hash['entry_ID']}")
puts "Writing #{filename}..."
File.open(filename, "wb"){|f| f.write blob }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment