19 package org.sleuthkit.autopsy.modules.android;
 
   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;
 
   47 class TextMessageAnalyzer {
 
   49     private static final String moduleName = AndroidModuleFactory.getModuleName();
 
   50     private static final Logger logger = Logger.getLogger(TextMessageAnalyzer.class.getName());
 
   51     private static Blackboard blackboard;
 
   53     public static void findTexts(Content dataSource, FileManager fileManager,
 
   54             IngestJobContext context) {
 
   55         blackboard = Case.getCurrentCase().getServices().getBlackboard();
 
   58             List<AbstractFile> absFiles = fileManager.findFiles(dataSource, 
"mmssms.db"); 
 
   59             for (AbstractFile abstractFile : absFiles) {
 
   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); 
 
   68         } 
catch (TskCoreException e) {
 
   69             logger.log(Level.SEVERE, 
"Error finding text messages", e); 
 
   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;
 
   79         if (DatabasePath == null || DatabasePath.isEmpty()) {
 
   83             Class.forName(
"org.sqlite.JDBC"); 
 
   84             connection = DriverManager.getConnection(
"jdbc:sqlite:" + DatabasePath); 
 
   85             statement = connection.createStatement();
 
   86         } 
catch (ClassNotFoundException | SQLException e) {
 
   87             logger.log(Level.SEVERE, 
"Error opening database", e); 
 
   92             resultSet = statement.executeQuery(
 
   93                     "SELECT address,date,read,type,subject,body FROM sms;"); 
 
  101             while (resultSet.next()) {
 
  102                 address = resultSet.getString(
"address"); 
 
  103                 Long date = Long.valueOf(resultSet.getString(
"date")) / 1000; 
 
  105                 read = resultSet.getInt(
"read"); 
 
  106                 subject = resultSet.getString(
"subject"); 
 
  107                 body = resultSet.getString(
"body"); 
 
  109                 BlackboardArtifact bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE); 
 
  110                 if (resultSet.getString(
"type").equals(
"1")) { 
 
  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));
 
  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));
 
  121                 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME, moduleName, date));
 
  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")));
 
  132                     blackboard.indexArtifact(bba);
 
  133                 } 
catch (Blackboard.BlackboardException ex) {
 
  134                     logger.log(Level.SEVERE, 
"Unable to index blackboard artifact " + bba.getArtifactID(), ex); 
 
  135                     MessageNotifyUtil.Notify.error(
 
  136                             Bundle.TextMessageAnalyzer_indexError_message(), bba.getDisplayName());
 
  139         } 
catch (Exception e) {
 
  140             logger.log(Level.SEVERE, 
"Error parsing text messages to Blackboard", e); 
 
  143                 if (resultSet != null) {
 
  148             } 
catch (Exception e) {
 
  149                 logger.log(Level.SEVERE, 
"Error closing database", e);