Skip to content

Instantly share code, notes, and snippets.

@temojin
Created April 13, 2011 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save temojin/917179 to your computer and use it in GitHub Desktop.
Save temojin/917179 to your computer and use it in GitHub Desktop.
script extracts hidden iphone backup files
#!/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