Created
December 15, 2009 00:56
-
-
Save seancribbs/256616 to your computer and use it in GitHub Desktop.
Extracts files you're looking for out of Safari's web cache
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
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