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;
37 class TextMessageAnalyzer {
39 private Connection connection = null;
40 private ResultSet resultSet = null;
41 private Statement statement = null;
42 private String dbPath =
"";
43 private long fileId = 0;
44 private java.io.File jFile = null;
45 List<AbstractFile> absFiles;
46 private String moduleName = iOSModuleFactory.getModuleName();
47 private static final Logger logger = Logger.getLogger(TextMessageAnalyzer.class.getName());
51 SleuthkitCase skCase = Case.getCurrentCase().getSleuthkitCase();
52 absFiles = skCase.findAllFilesWhere(
"name ='mmssms.db'");
53 if (absFiles.isEmpty()) {
56 for (AbstractFile AF : absFiles) {
58 jFile =
new java.io.File(Case.getCurrentCase().getTempDirectory(), AF.getName().replaceAll(
"[<>%|\"/:*\\\\]",
""));
59 ContentUtils.writeToFile(AF, jFile);
60 dbPath = jFile.toString();
62 findTextsInDB(dbPath, fileId);
63 }
catch (Exception e) {
64 logger.log(Level.SEVERE,
"Error parsing text messages", e);
67 }
catch (TskCoreException e) {
68 logger.log(Level.SEVERE,
"Error finding text messages", e);
72 private void findTextsInDB(String DatabasePath,
long fId) {
73 if (DatabasePath == null || DatabasePath.isEmpty()) {
77 Class.forName(
"org.sqlite.JDBC");
78 connection = DriverManager.getConnection(
"jdbc:sqlite:" + DatabasePath);
79 statement = connection.createStatement();
80 }
catch (ClassNotFoundException | SQLException e) {
81 logger.log(Level.SEVERE,
"Error opening database", e);
84 Case currentCase = Case.getCurrentCase();
85 SleuthkitCase skCase = currentCase.getSleuthkitCase();
87 AbstractFile f = skCase.getAbstractFileById(fId);
89 logger.log(Level.SEVERE,
"Error getting abstract file " + fId);
94 resultSet = statement.executeQuery(
95 "Select address,date,type,subject,body FROM sms;");
97 BlackboardArtifact bba;
103 while (resultSet.next()) {
104 address = resultSet.getString(
"address");
105 date = resultSet.getString(
"date");
106 type = resultSet.getString(
"type");
107 subject = resultSet.getString(
"subject");
108 body = resultSet.getString(
"body");
110 bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE);
114 if (type.equals(
"1")) {
115 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION.getTypeID(), moduleName,
"Incoming"));
116 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM.getTypeID(), moduleName, address));
119 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION.getTypeID(), moduleName,
"Outgoing"));
120 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO.getTypeID(), moduleName, address));
122 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME.getTypeID(), moduleName, date));
123 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION.getTypeID(), moduleName, type));
124 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SUBJECT.getTypeID(), moduleName, subject));
125 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TEXT.getTypeID(), moduleName, body));
126 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_MESSAGE_TYPE.getTypeID(), moduleName,
"SMS Message"));
129 }
catch (Exception e) {
130 logger.log(Level.SEVERE,
"Error parsing text messages to Blackboard", e);
136 }
catch (Exception e) {
137 logger.log(Level.SEVERE,
"Error closing database", e);
140 }
catch (Exception e) {
141 logger.log(Level.SEVERE,
"Error parsing text messages to Blackboard", e);