Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
TextMessageAnalyzer.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.modules.android;
20 
21 import java.io.File;
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;
29 
30 import org.openide.util.NbBundle;
37 import org.sleuthkit.datamodel.AbstractFile;
38 import org.sleuthkit.datamodel.BlackboardArtifact;
39 import org.sleuthkit.datamodel.BlackboardAttribute;
40 import org.sleuthkit.datamodel.Content;
41 import org.sleuthkit.datamodel.TskCoreException;
42 
46 class TextMessageAnalyzer {
47 
48  private static final String moduleName = AndroidModuleFactory.getModuleName();
49  private static final Logger logger = Logger.getLogger(TextMessageAnalyzer.class.getName());
50  private static Blackboard blackboard;
51 
52  public static void findTexts(Content dataSource, FileManager fileManager) {
53  blackboard = Case.getCurrentCase().getServices().getBlackboard();
54  try {
55 
56  List<AbstractFile> absFiles = fileManager.findFiles(dataSource, "mmssms.db"); //NON-NLS
57  for (AbstractFile abstractFile : absFiles) {
58  try {
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); //NON-NLS
64  }
65  }
66  } catch (TskCoreException e) {
67  logger.log(Level.SEVERE, "Error finding text messages", e); //NON-NLS
68  }
69  }
70 
71  private static void findTextsInDB(String DatabasePath, AbstractFile f) {
72  Connection connection = null;
73  ResultSet resultSet = null;
74  Statement statement = null;
75 
76  if (DatabasePath == null || DatabasePath.isEmpty()) {
77  return;
78  }
79  try {
80  Class.forName("org.sqlite.JDBC"); //NON-NLS //load JDBC driver
81  connection = DriverManager.getConnection("jdbc:sqlite:" + DatabasePath); //NON-NLS
82  statement = connection.createStatement();
83  } catch (ClassNotFoundException | SQLException e) {
84  logger.log(Level.SEVERE, "Error opening database", e); //NON-NLS
85  return;
86  }
87 
88  try {
89  resultSet = statement.executeQuery(
90  "SELECT address,date,read,type,subject,body FROM sms;"); //NON-NLS
91 
92  String address; // may be phone number, or other addresses
93 
94  String direction; // message received in inbox = 1, message sent = 2
95  String subject;//message subject
96  Integer read; // may be unread = 0, read = 1
97  String body; //message body
98  while (resultSet.next()) {
99  address = resultSet.getString("address"); //NON-NLS
100  Long date = Long.valueOf(resultSet.getString("date")) / 1000; //NON-NLS
101 
102  read = resultSet.getInt("read"); //NON-NLS
103  subject = resultSet.getString("subject"); //NON-NLS
104  body = resultSet.getString("body"); //NON-NLS
105 
106  BlackboardArtifact bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE); //create Message artifact and then add attributes from result set.
107  if (resultSet.getString("type").equals("1")) { //NON-NLS
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));
112  } else {
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));
117  }
118  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME, moduleName, date));
119 
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")));
126 
127  try {
128  // index the artifact for keyword search
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); //NON-NLS
132  MessageNotifyUtil.Notify.error(
133  NbBundle.getMessage(Blackboard.class, "Blackboard.unableToIndexArtifact.exception.msg"), bba.getDisplayName());
134  }
135  }
136  } catch (Exception e) {
137  logger.log(Level.SEVERE, "Error parsing text messages to Blackboard", e); //NON-NLS
138  } finally {
139  try {
140  if (resultSet != null) {
141  resultSet.close();
142  }
143  statement.close();
144  connection.close();
145  } catch (Exception e) {
146  logger.log(Level.SEVERE, "Error closing database", e); //NON-NLS
147  }
148  }
149  }
150 }

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.