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.ArrayList;
27 import java.util.Collection;
28 import java.util.List;
29 import java.util.logging.Level;
30 import org.openide.util.NbBundle;
31 import org.openide.util.NbBundle.Messages;
44 class TextMessageAnalyzer {
46 private Connection connection = null;
47 private ResultSet resultSet = null;
48 private Statement statement = null;
49 private String dbPath =
"";
50 private long fileId = 0;
51 private java.io.File jFile = null;
52 List<AbstractFile> absFiles;
53 private String moduleName = iOSModuleFactory.getModuleName();
54 private static final Logger logger = Logger.getLogger(TextMessageAnalyzer.class.getName());
55 private Blackboard blackboard;
57 void findTexts(IngestJobContext context) {
58 blackboard = Case.getCurrentCase().getServices().getBlackboard();
60 SleuthkitCase skCase = Case.getCurrentCase().getSleuthkitCase();
61 absFiles = skCase.findAllFilesWhere(
"name ='mmssms.db'");
62 if (absFiles.isEmpty()) {
65 for (AbstractFile AF : absFiles) {
67 jFile =
new java.io.File(Case.getCurrentCase().getTempDirectory(), AF.getName().replaceAll(
"[<>%|\"/:*\\\\]",
""));
68 ContentUtils.writeToFile(AF, jFile, context::dataSourceIngestIsCancelled);
69 dbPath = jFile.toString();
71 findTextsInDB(dbPath, fileId);
72 }
catch (Exception e) {
73 logger.log(Level.SEVERE,
"Error parsing text messages", e);
76 }
catch (TskCoreException e) {
77 logger.log(Level.SEVERE,
"Error finding text messages", e);
81 @Messages({
"TextMessageAnalyzer.indexError.message=Failed to index text message artifact for keyword search."})
82 private void findTextsInDB(String DatabasePath,
long fId) {
83 if (DatabasePath == null || DatabasePath.isEmpty()) {
87 Class.forName(
"org.sqlite.JDBC");
88 connection = DriverManager.getConnection(
"jdbc:sqlite:" + DatabasePath);
89 statement = connection.createStatement();
90 }
catch (ClassNotFoundException | SQLException e) {
91 logger.log(Level.SEVERE,
"Error opening database", e);
94 Case currentCase = Case.getCurrentCase();
95 SleuthkitCase skCase = currentCase.getSleuthkitCase();
97 AbstractFile f = skCase.getAbstractFileById(fId);
99 logger.log(Level.SEVERE,
"Error getting abstract file " + fId);
104 resultSet = statement.executeQuery(
105 "SELECT address,date,type,subject,body FROM sms;");
107 BlackboardArtifact bba;
113 while (resultSet.next()) {
114 address = resultSet.getString(
"address");
115 date = resultSet.getString(
"date");
116 type = resultSet.getString(
"type");
117 subject = resultSet.getString(
"subject");
118 body = resultSet.getString(
"body");
120 bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE);
121 Collection<BlackboardAttribute> attributes =
new ArrayList<>();
123 if (type.equals(
"1")) {
124 attributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION, moduleName, NbBundle.getMessage(
this.getClass(),
"TextMessageAnalyzer.bbAttribute.incoming")));
125 attributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM, moduleName, address));
127 attributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION, moduleName, NbBundle.getMessage(
this.getClass(),
"TextMessageAnalyzer.bbAttribute.outgoing")));
128 attributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO, moduleName, address));
130 attributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME, moduleName, date));
131 attributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION, moduleName, type));
132 attributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SUBJECT, moduleName, subject));
133 attributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TEXT, moduleName, body));
134 attributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_MESSAGE_TYPE, moduleName, NbBundle.getMessage(
this.getClass(),
"TextMessageAnalyzer.bbAttribute.smsMessage")));
136 bba.addAttributes(attributes);
139 blackboard.indexArtifact(bba);
140 }
catch (Blackboard.BlackboardException ex) {
141 logger.log(Level.SEVERE,
"Unable to index blackboard artifact " + bba.getArtifactID(), ex);
142 MessageNotifyUtil.Notify.error(
143 Bundle.TextMessageAnalyzer_indexError_message(), bba.getDisplayName());
147 }
catch (Exception e) {
148 logger.log(Level.SEVERE,
"Error parsing text messages to Blackboard", e);
154 }
catch (Exception e) {
155 logger.log(Level.SEVERE,
"Error closing database", e);
158 }
catch (Exception e) {
159 logger.log(Level.SEVERE,
"Error parsing text messages to Blackboard", e);