Skip to content
This repository was archived by the owner on Apr 15, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion iOSContacts.pm
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sub new
my ($class, $params) = @_;
my $self = {
_backup_directory => $params->{backup_directory},
_contacts_db_filename => '31bb7ba8914766d4ba40d6dfb6113c8b614be442',
_contacts_db_filename => '31/31bb7ba8914766d4ba40d6dfb6113c8b614be442',
_contacts_db => undef,
_contacts => undef
};
Expand Down
67 changes: 34 additions & 33 deletions iOSMessages.pm
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sub new
my ($class, $params) = @_;
my $self = {
_backup_directory => $params->{backup_directory},
_sms_db_filename => '3d0d7e5fb2ce288813306e4d4636395e047a3d28',
_sms_db_filename => '3d/3d0d7e5fb2ce288813306e4d4636395e047a3d28',
_sms_db => undef,
_messages => {},
_attachments => {}
Expand All @@ -20,7 +20,7 @@ sub new
print "direcotry " . $self->{_backup_directory} . "\n";
die 'Directory does not exist';
}

bless $self, $class;
$self->_generate_messages_hash();
return $self;
Expand All @@ -36,17 +36,17 @@ sub get_attachments{
return $self->{_attachments};
}

# Internal methods
# Internal methods
sub _db {
my ($self) = @_;

return $self->{_sms_db} if ($self->{_sms_db});

$self->{_sms_db} = DBI->connect(
"dbi:SQLite:dbname=".$self->{_backup_directory}.$self->{_sms_db_filename},
"",
"",
{ RaiseError => 1 },
$self->{_sms_db} = DBI->connect(
"dbi:SQLite:dbname=".$self->{_backup_directory}.$self->{_sms_db_filename},
"",
"",
{ RaiseError => 1 },
) or die $DBI::errstr;
return $self->{_sms_db};
}
Expand All @@ -55,27 +55,27 @@ sub _generate_messages_hash {
my ($self) = @_;

my $dbh = $self->_db;
my $query = qq|
SELECT
my $query = qq|
SELECT
m.rowid as RowID,
h.id AS UniqueID,
CASE is_from_me
WHEN 0 THEN "received"
WHEN 1 THEN "sent"
ELSE "Unknown"
END as Type,
CASE
WHEN date > 0 then TIME(date + 978307200, 'unixepoch', 'localtime')
h.id AS UniqueID,
CASE is_from_me
WHEN 0 THEN "received"
WHEN 1 THEN "sent"
ELSE "Unknown"
END as Type,
CASE
WHEN date > 0 then TIME(date / 1000000000 + 978307200, 'unixepoch', 'localtime')
ELSE NULL
END as Time,
CASE
WHEN date > 0 THEN strftime('%Y%m%d', date + 978307200, 'unixepoch', 'localtime')
CASE
WHEN date > 0 THEN strftime('%Y%m%d', date / 1000000000 + 978307200, 'unixepoch', 'localtime')
ELSE NULL
END as Date,
CASE
WHEN date > 0 THEN date + 978307200
END as Date,
CASE
WHEN date > 0 THEN date / 1000000000 + 978307200
ELSE NULL
END as Epoch,
END as Epoch,
text as Text,
maj.attachment_id AS AttachmentID
FROM message m
Expand All @@ -85,42 +85,43 @@ sub _generate_messages_hash {
ORDER BY UniqueID, Date, Time|;
my $sth = $dbh->prepare($query);
$sth->execute();

my $tempMessages = {};

while (my $text = $sth->fetchrow_hashref){
if (my $uniqueID = $text->{'UniqueID'}) {
my $uniqueID = $text->{'UniqueID'};
if ($date = $text->{'Date'}) {
push @{$tempMessages->{$uniqueID}->{$date}}, $text;
}

if ($text->{'AttachmentID'}) {
$self->_process_mms($text->{'AttachmentID'});
}

}
}
$self->{_messages} = $tempMessages;
}

sub _process_mms {
my ($self, $attachment_id) = @_;

my $dbh = $self->{_sms_db};
my $query = qq|SELECT * FROM attachment WHERE ROWID = ?|;
my $sth = $dbh->prepare($query);
$sth->execute($attachment_id);

my $attachment = $sth->fetchrow_hashref();
my $filepath = $attachment->{filename};
(my $filename = $filepath) =~ s{(.*)/(.*)}{$2}xms;
$filepath =~ s#^~/#MediaDomain-#;

my $sha1_filename = sha1_hex($filepath);
my $sha1_filename = substr($sha1_filename, 0, 2) . '/' . $sha1_filename;
$self->{_attachments}->{$attachment_id} = {
sha1_filename => $sha1_filename,
filename => $filename,
sha1_filename => $sha1_filename,
filename => $filename,
mime_type => $attachment->{mime_type}
};
}
Expand Down