Autopsy  3.1
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;
41 
45 class TextMessageAnalyzer {
46 
47  private static final String moduleName = AndroidModuleFactory.getModuleName();
48  private static final Logger logger = Logger.getLogger(TextMessageAnalyzer.class.getName());
49 
50  public static void findTexts(Content dataSource, FileManager fileManager) {
51  try {
52 
53  List<AbstractFile> absFiles = fileManager.findFiles(dataSource, "mmssms.db"); //NON-NLS
54  for (AbstractFile abstractFile : absFiles) {
55  try {
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); //NON-NLS
61  }
62  }
63  } catch (TskCoreException e) {
64  logger.log(Level.SEVERE, "Error finding text messages", e); //NON-NLS
65  }
66  }
67 
68  private static void findTextsInDB(String DatabasePath, AbstractFile f) {
69  Connection connection = null;
70  ResultSet resultSet = null;
71  Statement statement = null;
72 
73  if (DatabasePath == null || DatabasePath.isEmpty()) {
74  return;
75  }
76  try {
77  Class.forName("org.sqlite.JDBC"); //NON-NLS //load JDBC driver
78  connection = DriverManager.getConnection("jdbc:sqlite:" + DatabasePath); //NON-NLS
79  statement = connection.createStatement();
80  } catch (ClassNotFoundException | SQLException e) {
81  logger.log(Level.SEVERE, "Error opening database", e); //NON-NLS
82  return;
83  }
84 
85  try {
86  resultSet = statement.executeQuery(
87  "Select address,date,read,type,subject,body FROM sms;"); //NON-NLS
88 
89  String address; // may be phone number, or other addresses
90 
91  String direction; // message received in inbox = 1, message sent = 2
92  String subject;//message subject
93  Integer read; // may be unread = 0, read = 1
94  String body; //message body
95  while (resultSet.next()) {
96  address = resultSet.getString("address"); //NON-NLS
97  Long date = Long.valueOf(resultSet.getString("date")) / 1000; //NON-NLS
98 
99  read = resultSet.getInt("read"); //NON-NLS
100  subject = resultSet.getString("subject"); //NON-NLS
101  body = resultSet.getString("body"); //NON-NLS
102 
103  BlackboardArtifact bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE); //create Message artifact and then add attributes from result set.
104  if (resultSet.getString("type").equals("1")) { //NON-NLS
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));
109  } else {
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));
114  }
115  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME.getTypeID(), moduleName, date));
116 
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")));
123  }
124 
125  } catch (Exception e) {
126  logger.log(Level.SEVERE, "Error parsing text messages to Blackboard", e); //NON-NLS
127  } finally {
128  try {
129  if (resultSet != null) {
130  resultSet.close();
131  }
132  statement.close();
133  connection.close();
134  } catch (Exception e) {
135  logger.log(Level.SEVERE, "Error closing database", e); //NON-NLS
136  }
137  }
138  }
139 }

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.