Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
TextMessageAnalyzer.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.modules.android;
20 
21 import java.io.File;
22 import java.sql.Connection;
23 import java.sql.DriverManager;
24 import java.sql.ResultSet;
25 import java.sql.SQLException;
26 import java.sql.Statement;
27 import java.util.List;
28 import java.util.logging.Level;
29 import org.openide.util.NbBundle;
30 import org.openide.util.NbBundle.Messages;
38 import org.sleuthkit.datamodel.AbstractFile;
39 import org.sleuthkit.datamodel.BlackboardArtifact;
40 import org.sleuthkit.datamodel.BlackboardAttribute;
41 import org.sleuthkit.datamodel.Content;
42 import org.sleuthkit.datamodel.TskCoreException;
43 
47 class TextMessageAnalyzer {
48 
49  private static final String moduleName = AndroidModuleFactory.getModuleName();
50  private static final Logger logger = Logger.getLogger(TextMessageAnalyzer.class.getName());
51  private static Blackboard blackboard;
52 
53  public static void findTexts(Content dataSource, FileManager fileManager,
54  IngestJobContext context) {
55  blackboard = Case.getCurrentCase().getServices().getBlackboard();
56  try {
57 
58  List<AbstractFile> absFiles = fileManager.findFiles(dataSource, "mmssms.db"); //NON-NLS
59  for (AbstractFile abstractFile : absFiles) {
60  try {
61  File jFile = new File(Case.getCurrentCase().getTempDirectory(), abstractFile.getName());
62  ContentUtils.writeToFile(abstractFile, jFile, context::dataSourceIngestIsCancelled);
63  findTextsInDB(jFile.toString(), abstractFile);
64  } catch (Exception e) {
65  logger.log(Level.SEVERE, "Error parsing text messages", e); //NON-NLS
66  }
67  }
68  } catch (TskCoreException e) {
69  logger.log(Level.SEVERE, "Error finding text messages", e); //NON-NLS
70  }
71  }
72 
73  @Messages({"TextMessageAnalyzer.indexError.message=Failed to index text message artifact for keyword search."})
74  private static void findTextsInDB(String DatabasePath, AbstractFile f) {
75  Connection connection = null;
76  ResultSet resultSet = null;
77  Statement statement = null;
78 
79  if (DatabasePath == null || DatabasePath.isEmpty()) {
80  return;
81  }
82  try {
83  Class.forName("org.sqlite.JDBC"); //NON-NLS //load JDBC driver
84  connection = DriverManager.getConnection("jdbc:sqlite:" + DatabasePath); //NON-NLS
85  statement = connection.createStatement();
86  } catch (ClassNotFoundException | SQLException e) {
87  logger.log(Level.SEVERE, "Error opening database", e); //NON-NLS
88  return;
89  }
90 
91  try {
92  resultSet = statement.executeQuery(
93  "SELECT address,date,read,type,subject,body FROM sms;"); //NON-NLS
94 
95  String address; // may be phone number, or other addresses
96 
97  String direction; // message received in inbox = 1, message sent = 2
98  String subject;//message subject
99  Integer read; // may be unread = 0, read = 1
100  String body; //message body
101  while (resultSet.next()) {
102  address = resultSet.getString("address"); //NON-NLS
103  Long date = Long.valueOf(resultSet.getString("date")) / 1000; //NON-NLS
104 
105  read = resultSet.getInt("read"); //NON-NLS
106  subject = resultSet.getString("subject"); //NON-NLS
107  body = resultSet.getString("body"); //NON-NLS
108 
109  BlackboardArtifact bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE); //create Message artifact and then add attributes from result set.
110  if (resultSet.getString("type").equals("1")) { //NON-NLS
111  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION, moduleName,
112  NbBundle.getMessage(TextMessageAnalyzer.class,
113  "TextMessageAnalyzer.bbAttribute.incoming")));
114  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM, moduleName, address));
115  } else {
116  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION, moduleName,
117  NbBundle.getMessage(TextMessageAnalyzer.class,
118  "TextMessageAnalyzer.bbAttribute.outgoing")));
119  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO, moduleName, address));
120  }
121  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME, moduleName, date));
122 
123  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_READ_STATUS, moduleName, read));
124  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SUBJECT, moduleName, subject));
125  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TEXT, moduleName, body));
126  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_MESSAGE_TYPE, moduleName,
127  NbBundle.getMessage(TextMessageAnalyzer.class,
128  "TextMessageAnalyzer.bbAttribute.smsMessage")));
129 
130  try {
131  // index the artifact for keyword search
132  blackboard.indexArtifact(bba);
133  } catch (Blackboard.BlackboardException ex) {
134  logger.log(Level.SEVERE, "Unable to index blackboard artifact " + bba.getArtifactID(), ex); //NON-NLS
135  MessageNotifyUtil.Notify.error(
136  Bundle.TextMessageAnalyzer_indexError_message(), bba.getDisplayName());
137  }
138  }
139  } catch (Exception e) {
140  logger.log(Level.SEVERE, "Error parsing text messages to Blackboard", e); //NON-NLS
141  } finally {
142  try {
143  if (resultSet != null) {
144  resultSet.close();
145  }
146  statement.close();
147  connection.close();
148  } catch (Exception e) {
149  logger.log(Level.SEVERE, "Error closing database", e); //NON-NLS
150  }
151  }
152  }
153 }

Copyright © 2012-2016 Basis Technology. Generated on: Tue Oct 25 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.