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;
40 class TextMessageAnalyzer {
42 private Connection connection = null;
43 private ResultSet resultSet = null;
44 private Statement statement = null;
45 private String dbPath =
"";
46 private long fileId = 0;
47 private java.io.File jFile = null;
48 List<AbstractFile> absFiles;
49 private String moduleName = iOSModuleFactory.getModuleName();
50 private static final Logger logger = Logger.getLogger(TextMessageAnalyzer.class.getName());
51 private Blackboard blackboard;
54 blackboard = Case.getCurrentCase().getServices().getBlackboard();
56 SleuthkitCase skCase = Case.getCurrentCase().getSleuthkitCase();
57 absFiles = skCase.findAllFilesWhere(
"name ='mmssms.db'");
58 if (absFiles.isEmpty()) {
61 for (AbstractFile AF : absFiles) {
63 jFile =
new java.io.File(Case.getCurrentCase().getTempDirectory(), AF.getName().replaceAll(
"[<>%|\"/:*\\\\]",
""));
64 ContentUtils.writeToFile(AF, jFile);
65 dbPath = jFile.toString();
67 findTextsInDB(dbPath, fileId);
68 }
catch (Exception e) {
69 logger.log(Level.SEVERE,
"Error parsing text messages", e);
72 }
catch (TskCoreException e) {
73 logger.log(Level.SEVERE,
"Error finding text messages", e);
77 private void findTextsInDB(String DatabasePath,
long fId) {
78 if (DatabasePath == null || DatabasePath.isEmpty()) {
82 Class.forName(
"org.sqlite.JDBC");
83 connection = DriverManager.getConnection(
"jdbc:sqlite:" + DatabasePath);
84 statement = connection.createStatement();
85 }
catch (ClassNotFoundException | SQLException e) {
86 logger.log(Level.SEVERE,
"Error opening database", e);
89 Case currentCase = Case.getCurrentCase();
90 SleuthkitCase skCase = currentCase.getSleuthkitCase();
92 AbstractFile f = skCase.getAbstractFileById(fId);
94 logger.log(Level.SEVERE,
"Error getting abstract file " + fId);
99 resultSet = statement.executeQuery(
100 "SELECT address,date,type,subject,body FROM sms;");
102 BlackboardArtifact bba;
108 while (resultSet.next()) {
109 address = resultSet.getString(
"address");
110 date = resultSet.getString(
"date");
111 type = resultSet.getString(
"type");
112 subject = resultSet.getString(
"subject");
113 body = resultSet.getString(
"body");
115 bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE);
118 if (type.equals(
"1")) {
119 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION, moduleName, NbBundle.getMessage(
this.getClass(),
"TextMessageAnalyzer.bbAttribute.incoming")));
120 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM, moduleName, address));
122 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION, moduleName, NbBundle.getMessage(
this.getClass(),
"TextMessageAnalyzer.bbAttribute.outgoing")));
123 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO, moduleName, address));
125 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME, moduleName, date));
126 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION, moduleName, type));
127 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SUBJECT, moduleName, subject));
128 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TEXT, moduleName, body));
129 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_MESSAGE_TYPE, moduleName, NbBundle.getMessage(
this.getClass(),
"TextMessageAnalyzer.bbAttribute.smsMessage")));
133 blackboard.indexArtifact(bba);
134 }
catch (Blackboard.BlackboardException ex) {
135 logger.log(Level.SEVERE, NbBundle.getMessage(Blackboard.class,
"Blackboard.unableToIndexArtifact.error.msg", bba.getDisplayName()), ex);
136 MessageNotifyUtil.Notify.error(
137 NbBundle.getMessage(Blackboard.class,
"Blackboard.unableToIndexArtifact.exception.msg"), bba.getDisplayName());
141 }
catch (Exception e) {
142 logger.log(Level.SEVERE,
"Error parsing text messages to Blackboard", e);
148 }
catch (Exception e) {
149 logger.log(Level.SEVERE,
"Error closing database", e);
152 }
catch (Exception e) {
153 logger.log(Level.SEVERE,
"Error parsing text messages to Blackboard", e);