Created
April 13, 2011 08:15
-
-
Save temojin/917179 to your computer and use it in GitHub Desktop.
script extracts hidden iphone backup files
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
#!/usr/bin/perl -w | |
#origin: http://pastie.textmate.org/89891 | |
use strict; | |
# This file clumsily extracts the DB's hidden in the iPhone backup files | |
# Usage: perl -w bkupextract.pl /Users/flip/Library/Application\ Support/MobileSync/Backup/*/* | |
my %seen; | |
foreach my $filename (@ARGV) { | |
# Slurp File Contents | |
open(FILE, "<$filename") or die "Can't open $filename: $!"; | |
my $data = do {local $/; binmode FILE; }; | |
close(FILE); | |
# skip non-SQLite Files | |
($data =~ m|SQLite|) or next; | |
# identify the file and use it to name the output | |
my $type = ($data =~ m!([^/]*?)\.(sqlitedb|db)!) ? $1 : 'unknown'; | |
$seen{$type}++; | |
my $outfilename = sprintf "%s_%02d.db", $type, $seen{$type}; | |
# Helpful progress report | |
printf STDERR "%-60s to %-25s\n", $filename, $type, $outfilename; | |
# dump the part between "SQLite format 3" and end | |
# FIXME -- is there cruft at end? I don't know the SQLite format. Maybe you do? | |
open(OUTFILE, ">$outfilename") or die "Can't open $outfilename: $!"; | |
binmode OUTFILE; | |
my $sqlitedb = $data; | |
$sqlitedb =~ s/^(.*?SQLite format 3)/SQLite format 3/; | |
print OUTFILE $sqlitedb; | |
close(OUTFILE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment