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.iOS;
20 
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;
28 import org.openide.util.NbBundle;
34 import org.sleuthkit.datamodel.AbstractFile;
35 import org.sleuthkit.datamodel.BlackboardArtifact;
36 import org.sleuthkit.datamodel.BlackboardAttribute;
37 import org.sleuthkit.datamodel.SleuthkitCase;
38 import org.sleuthkit.datamodel.TskCoreException;
39 
40 class TextMessageAnalyzer {
41 
42  private Connection connection = null;
43  private ResultSet resultSet = null;
44  private Statement statement = null;
45  private String dbPath = "";
46  private long fileId = 0;
47  private java.io.File jFile = null;
48  List<AbstractFile> absFiles;
49  private String moduleName = iOSModuleFactory.getModuleName();
50  private static final Logger logger = Logger.getLogger(TextMessageAnalyzer.class.getName());
51  private Blackboard blackboard;
52 
53  void findTexts() {
54  blackboard = Case.getCurrentCase().getServices().getBlackboard();
55  try {
56  SleuthkitCase skCase = Case.getCurrentCase().getSleuthkitCase();
57  absFiles = skCase.findAllFilesWhere("name ='mmssms.db'"); //NON-NLS //get exact file name
58  if (absFiles.isEmpty()) {
59  return;
60  }
61  for (AbstractFile AF : absFiles) {
62  try {
63  jFile = new java.io.File(Case.getCurrentCase().getTempDirectory(), AF.getName().replaceAll("[<>%|\"/:*\\\\]", ""));
64  ContentUtils.writeToFile(AF, jFile);
65  dbPath = jFile.toString(); //path of file as string
66  fileId = AF.getId();
67  findTextsInDB(dbPath, fileId);
68  } catch (Exception e) {
69  logger.log(Level.SEVERE, "Error parsing text messages", e); //NON-NLS
70  }
71  }
72  } catch (TskCoreException e) {
73  logger.log(Level.SEVERE, "Error finding text messages", e); //NON-NLS
74  }
75  }
76 
77  private void findTextsInDB(String DatabasePath, long fId) {
78  if (DatabasePath == null || DatabasePath.isEmpty()) {
79  return;
80  }
81  try {
82  Class.forName("org.sqlite.JDBC"); //NON-NLS //load JDBC driver
83  connection = DriverManager.getConnection("jdbc:sqlite:" + DatabasePath); //NON-NLS
84  statement = connection.createStatement();
85  } catch (ClassNotFoundException | SQLException e) {
86  logger.log(Level.SEVERE, "Error opening database", e); //NON-NLS
87  }
88 
89  Case currentCase = Case.getCurrentCase();
90  SleuthkitCase skCase = currentCase.getSleuthkitCase();
91  try {
92  AbstractFile f = skCase.getAbstractFileById(fId);
93  if (f == null) {
94  logger.log(Level.SEVERE, "Error getting abstract file " + fId); //NON-NLS
95  return;
96  }
97 
98  try {
99  resultSet = statement.executeQuery(
100  "SELECT address,date,type,subject,body FROM sms;"); //NON-NLS
101 
102  BlackboardArtifact bba;
103  String address; // may be phone number, or other addresses
104  String date;//unix time
105  String type; // message received in inbox = 1, message sent = 2
106  String subject;//message subject
107  String body; //message body
108  while (resultSet.next()) {
109  address = resultSet.getString("address"); //NON-NLS
110  date = resultSet.getString("date"); //NON-NLS
111  type = resultSet.getString("type"); //NON-NLS
112  subject = resultSet.getString("subject"); //NON-NLS
113  body = resultSet.getString("body"); //NON-NLS
114 
115  bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE); //create Message artifact and then add attributes from result set.
116 
117  // @@@ NEed to put into more specific TO or FROM
118  if (type.equals("1")) {
119  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION, moduleName, NbBundle.getMessage(this.getClass(), "TextMessageAnalyzer.bbAttribute.incoming")));
120  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM, moduleName, address));
121  } else {
122  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION, moduleName, NbBundle.getMessage(this.getClass(), "TextMessageAnalyzer.bbAttribute.outgoing")));
123  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO, moduleName, address));
124  }
125  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME, moduleName, date));
126  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION, moduleName, type));
127  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SUBJECT, moduleName, subject));
128  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TEXT, moduleName, body));
129  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_MESSAGE_TYPE, moduleName, NbBundle.getMessage(this.getClass(), "TextMessageAnalyzer.bbAttribute.smsMessage")));
130 
131  try {
132  // index the artifact for keyword search
133  blackboard.indexArtifact(bba);
134  } catch (Blackboard.BlackboardException ex) {
135  logger.log(Level.SEVERE, NbBundle.getMessage(Blackboard.class, "Blackboard.unableToIndexArtifact.error.msg", bba.getDisplayName()), ex); //NON-NLS
136  MessageNotifyUtil.Notify.error(
137  NbBundle.getMessage(Blackboard.class, "Blackboard.unableToIndexArtifact.exception.msg"), bba.getDisplayName());
138  }
139  }
140 
141  } catch (Exception e) {
142  logger.log(Level.SEVERE, "Error parsing text messages to Blackboard", e); //NON-NLS
143  } finally {
144  try {
145  resultSet.close();
146  statement.close();
147  connection.close();
148  } catch (Exception e) {
149  logger.log(Level.SEVERE, "Error closing database", e); //NON-NLS
150  }
151  }
152  } catch (Exception e) {
153  logger.log(Level.SEVERE, "Error parsing text messages to Blackboard", e); //NON-NLS
154  }
155 
156  }
157 
158 }

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.