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;
30 import org.openide.util.NbBundle;
46 class TextMessageAnalyzer {
48 private static final String moduleName = AndroidModuleFactory.getModuleName();
49 private static final Logger logger = Logger.getLogger(TextMessageAnalyzer.class.getName());
50 private static Blackboard blackboard;
52 public static void findTexts(Content dataSource, FileManager fileManager) {
53 blackboard = Case.getCurrentCase().getServices().getBlackboard();
56 List<AbstractFile> absFiles = fileManager.findFiles(dataSource,
"mmssms.db");
57 for (AbstractFile abstractFile : absFiles) {
59 File jFile =
new File(Case.getCurrentCase().getTempDirectory(), abstractFile.getName());
60 ContentUtils.writeToFile(abstractFile, jFile);
61 findTextsInDB(jFile.toString(), abstractFile);
62 }
catch (Exception e) {
63 logger.log(Level.SEVERE,
"Error parsing text messages", e);
66 }
catch (TskCoreException e) {
67 logger.log(Level.SEVERE,
"Error finding text messages", e);
71 private static void findTextsInDB(String DatabasePath, AbstractFile f) {
72 Connection connection = null;
73 ResultSet resultSet = null;
74 Statement statement = null;
76 if (DatabasePath == null || DatabasePath.isEmpty()) {
80 Class.forName(
"org.sqlite.JDBC");
81 connection = DriverManager.getConnection(
"jdbc:sqlite:" + DatabasePath);
82 statement = connection.createStatement();
83 }
catch (ClassNotFoundException | SQLException e) {
84 logger.log(Level.SEVERE,
"Error opening database", e);
89 resultSet = statement.executeQuery(
90 "SELECT address,date,read,type,subject,body FROM sms;");
98 while (resultSet.next()) {
99 address = resultSet.getString(
"address");
100 Long date = Long.valueOf(resultSet.getString(
"date")) / 1000;
102 read = resultSet.getInt(
"read");
103 subject = resultSet.getString(
"subject");
104 body = resultSet.getString(
"body");
106 BlackboardArtifact bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE);
107 if (resultSet.getString(
"type").equals(
"1")) {
108 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION, moduleName,
109 NbBundle.getMessage(TextMessageAnalyzer.class,
110 "TextMessageAnalyzer.bbAttribute.incoming")));
111 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM, moduleName, address));
113 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION, moduleName,
114 NbBundle.getMessage(TextMessageAnalyzer.class,
115 "TextMessageAnalyzer.bbAttribute.outgoing")));
116 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO, moduleName, address));
118 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME, moduleName, date));
120 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_READ_STATUS, moduleName, read));
121 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SUBJECT, moduleName, subject));
122 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TEXT, moduleName, body));
123 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_MESSAGE_TYPE, moduleName,
124 NbBundle.getMessage(TextMessageAnalyzer.class,
125 "TextMessageAnalyzer.bbAttribute.smsMessage")));
129 blackboard.indexArtifact(bba);
130 }
catch (Blackboard.BlackboardException ex) {
131 logger.log(Level.SEVERE, NbBundle.getMessage(Blackboard.class,
"Blackboard.unableToIndexArtifact.error.msg", bba.getDisplayName()), ex);
132 MessageNotifyUtil.Notify.error(
133 NbBundle.getMessage(Blackboard.class,
"Blackboard.unableToIndexArtifact.exception.msg"), bba.getDisplayName());
136 }
catch (Exception e) {
137 logger.log(Level.SEVERE,
"Error parsing text messages to Blackboard", e);
140 if (resultSet != null) {
145 }
catch (Exception e) {
146 logger.log(Level.SEVERE,
"Error closing database", e);