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;
45 class TextMessageAnalyzer {
47 private static final String moduleName = AndroidModuleFactory.getModuleName();
48 private static final Logger logger = Logger.getLogger(TextMessageAnalyzer.class.getName());
50 public static void findTexts(Content dataSource, FileManager fileManager) {
53 List<AbstractFile> absFiles = fileManager.findFiles(dataSource,
"mmssms.db");
54 for (AbstractFile abstractFile : absFiles) {
56 File jFile =
new File(Case.getCurrentCase().getTempDirectory(), abstractFile.getName());
57 ContentUtils.writeToFile(abstractFile, jFile);
58 findTextsInDB(jFile.toString(), abstractFile);
59 }
catch (Exception e) {
60 logger.log(Level.SEVERE,
"Error parsing text messages", e);
63 }
catch (TskCoreException e) {
64 logger.log(Level.SEVERE,
"Error finding text messages", e);
68 private static void findTextsInDB(String DatabasePath, AbstractFile f) {
69 Connection connection = null;
70 ResultSet resultSet = null;
71 Statement statement = null;
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);
86 resultSet = statement.executeQuery(
87 "Select address,date,read,type,subject,body FROM sms;");
95 while (resultSet.next()) {
96 address = resultSet.getString(
"address");
97 Long date = Long.valueOf(resultSet.getString(
"date")) / 1000;
99 read = resultSet.getInt(
"read");
100 subject = resultSet.getString(
"subject");
101 body = resultSet.getString(
"body");
103 BlackboardArtifact bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE);
104 if (resultSet.getString(
"type").equals(
"1")) {
105 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION.getTypeID(), moduleName,
106 NbBundle.getMessage(TextMessageAnalyzer.class,
107 "TextMessageAnalyzer.bbAttribute.incoming")));
108 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM.getTypeID(), moduleName, address));
110 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION.getTypeID(), moduleName,
111 NbBundle.getMessage(TextMessageAnalyzer.class,
112 "TextMessageAnalyzer.bbAttribute.outgoing")));
113 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO.getTypeID(), moduleName, address));
115 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME.getTypeID(), moduleName, date));
117 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_READ_STATUS.getTypeID(), moduleName, read));
118 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SUBJECT.getTypeID(), moduleName, subject));
119 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TEXT.getTypeID(), moduleName, body));
120 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_MESSAGE_TYPE.getTypeID(), moduleName,
121 NbBundle.getMessage(TextMessageAnalyzer.class,
122 "TextMessageAnalyzer.bbAttribute.smsMessage")));
125 }
catch (Exception e) {
126 logger.log(Level.SEVERE,
"Error parsing text messages to Blackboard", e);
129 if (resultSet != null) {
134 }
catch (Exception e) {
135 logger.log(Level.SEVERE,
"Error closing database", e);