19 package org.sleuthkit.autopsy.modules.iOS;
 
   21 import java.sql.Connection;
 
   22 import java.sql.DriverManager;
 
   23 import java.sql.ResultSet;
 
   24 import java.sql.SQLException;
 
   25 import java.sql.Statement;
 
   26 import java.util.List;
 
   27 import java.util.logging.Level;
 
   28 import org.openide.util.NbBundle;
 
   29 import org.openide.util.NbBundle.Messages;
 
   42 class TextMessageAnalyzer {
 
   44     private Connection connection = null;
 
   45     private ResultSet resultSet = null;
 
   46     private Statement statement = null;
 
   47     private String dbPath = 
"";
 
   48     private long fileId = 0;
 
   49     private java.io.File jFile = null;
 
   50     List<AbstractFile> absFiles;
 
   51     private String moduleName = iOSModuleFactory.getModuleName();
 
   52     private static final Logger logger = Logger.getLogger(TextMessageAnalyzer.class.getName());
 
   53     private Blackboard blackboard;
 
   55     void findTexts(IngestJobContext context) {
 
   56         blackboard = Case.getCurrentCase().getServices().getBlackboard();
 
   58             SleuthkitCase skCase = Case.getCurrentCase().getSleuthkitCase();
 
   59             absFiles = skCase.findAllFilesWhere(
"name ='mmssms.db'"); 
 
   60             if (absFiles.isEmpty()) {
 
   63             for (AbstractFile AF : absFiles) {
 
   65                     jFile = 
new java.io.File(Case.getCurrentCase().getTempDirectory(), AF.getName().replaceAll(
"[<>%|\"/:*\\\\]", 
""));
 
   66                     ContentUtils.writeToFile(AF, jFile, context::dataSourceIngestIsCancelled);
 
   67                     dbPath = jFile.toString(); 
 
   69                     findTextsInDB(dbPath, fileId);
 
   70                 } 
catch (Exception e) {
 
   71                     logger.log(Level.SEVERE, 
"Error parsing text messages", e); 
 
   74         } 
catch (TskCoreException e) {
 
   75             logger.log(Level.SEVERE, 
"Error finding text messages", e); 
 
   79     @Messages({
"TextMessageAnalyzer.indexError.message=Failed to index text message artifact for keyword search."})
 
   80     private void findTextsInDB(String DatabasePath, 
long fId) {
 
   81         if (DatabasePath == null || DatabasePath.isEmpty()) {
 
   85             Class.forName(
"org.sqlite.JDBC"); 
 
   86             connection = DriverManager.getConnection(
"jdbc:sqlite:" + DatabasePath); 
 
   87             statement = connection.createStatement();
 
   88         } 
catch (ClassNotFoundException | SQLException e) {
 
   89             logger.log(Level.SEVERE, 
"Error opening database", e); 
 
   92         Case currentCase = Case.getCurrentCase();
 
   93         SleuthkitCase skCase = currentCase.getSleuthkitCase();
 
   95             AbstractFile f = skCase.getAbstractFileById(fId);
 
   97                 logger.log(Level.SEVERE, 
"Error getting abstract file " + fId); 
 
  102                 resultSet = statement.executeQuery(
 
  103                         "SELECT address,date,type,subject,body FROM sms;"); 
 
  105                 BlackboardArtifact bba;
 
  111                 while (resultSet.next()) {
 
  112                     address = resultSet.getString(
"address"); 
 
  113                     date = resultSet.getString(
"date"); 
 
  114                     type = resultSet.getString(
"type"); 
 
  115                     subject = resultSet.getString(
"subject"); 
 
  116                     body = resultSet.getString(
"body"); 
 
  118                     bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE); 
 
  121                     if (type.equals(
"1")) {
 
  122                         bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION, moduleName, NbBundle.getMessage(
this.getClass(), 
"TextMessageAnalyzer.bbAttribute.incoming")));
 
  123                         bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM, moduleName, address));
 
  125                         bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION, moduleName, NbBundle.getMessage(
this.getClass(), 
"TextMessageAnalyzer.bbAttribute.outgoing")));
 
  126                         bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO, moduleName, address));
 
  128                     bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME, moduleName, date));
 
  129                     bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION, moduleName, type));
 
  130                     bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SUBJECT, moduleName, subject));
 
  131                     bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TEXT, moduleName, body));
 
  132                     bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_MESSAGE_TYPE, moduleName, NbBundle.getMessage(
this.getClass(), 
"TextMessageAnalyzer.bbAttribute.smsMessage")));
 
  136                         blackboard.indexArtifact(bba);
 
  137                     } 
catch (Blackboard.BlackboardException ex) {
 
  138                         logger.log(Level.SEVERE, 
"Unable to index blackboard artifact " + bba.getArtifactID(), ex); 
 
  139                         MessageNotifyUtil.Notify.error(
 
  140                                 Bundle.TextMessageAnalyzer_indexError_message(), bba.getDisplayName());
 
  144             } 
catch (Exception e) {
 
  145                 logger.log(Level.SEVERE, 
"Error parsing text messages to Blackboard", e); 
 
  151                 } 
catch (Exception e) {
 
  152                     logger.log(Level.SEVERE, 
"Error closing database", e); 
 
  155         } 
catch (Exception e) {
 
  156             logger.log(Level.SEVERE, 
"Error parsing text messages to Blackboard", e);