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.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;
36 
37 class TextMessageAnalyzer {
38 
39  private Connection connection = null;
40  private ResultSet resultSet = null;
41  private Statement statement = null;
42  private String dbPath = "";
43  private long fileId = 0;
44  private java.io.File jFile = null;
45  List<AbstractFile> absFiles;
46  private String moduleName = iOSModuleFactory.getModuleName();
47  private static final Logger logger = Logger.getLogger(TextMessageAnalyzer.class.getName());
48 
49  void findTexts() {
50  try {
51  SleuthkitCase skCase = Case.getCurrentCase().getSleuthkitCase();
52  absFiles = skCase.findAllFilesWhere("name ='mmssms.db'"); //NON-NLS //get exact file name
53  if (absFiles.isEmpty()) {
54  return;
55  }
56  for (AbstractFile AF : absFiles) {
57  try {
58  jFile = new java.io.File(Case.getCurrentCase().getTempDirectory(), AF.getName().replaceAll("[<>%|\"/:*\\\\]", ""));
59  ContentUtils.writeToFile(AF, jFile);
60  dbPath = jFile.toString(); //path of file as string
61  fileId = AF.getId();
62  findTextsInDB(dbPath, fileId);
63  } catch (Exception e) {
64  logger.log(Level.SEVERE, "Error parsing text messages", e); //NON-NLS
65  }
66  }
67  } catch (TskCoreException e) {
68  logger.log(Level.SEVERE, "Error finding text messages", e); //NON-NLS
69  }
70  }
71 
72  private void findTextsInDB(String DatabasePath, long fId) {
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  }
83 
84  Case currentCase = Case.getCurrentCase();
85  SleuthkitCase skCase = currentCase.getSleuthkitCase();
86  try {
87  AbstractFile f = skCase.getAbstractFileById(fId);
88  if(f == null){
89  logger.log(Level.SEVERE, "Error getting abstract file " + fId); //NON-NLS
90  return;
91  }
92 
93  try {
94  resultSet = statement.executeQuery(
95  "Select address,date,type,subject,body FROM sms;"); //NON-NLS
96 
97  BlackboardArtifact bba;
98  String address; // may be phone number, or other addresses
99  String date;//unix time
100  String type; // message received in inbox = 1, message sent = 2
101  String subject;//message subject
102  String body; //message body
103  while (resultSet.next()) {
104  address = resultSet.getString("address"); //NON-NLS
105  date = resultSet.getString("date"); //NON-NLS
106  type = resultSet.getString("type"); //NON-NLS
107  subject = resultSet.getString("subject"); //NON-NLS
108  body = resultSet.getString("body"); //NON-NLS
109 
110  bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE); //create Message artifact and then add attributes from result set.
111 
112  // @@@ NEed to put into more specific TO or FROM
113 
114  if (type.equals("1")) {
115  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION.getTypeID(), moduleName, "Incoming"));
116  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM.getTypeID(), moduleName, address));
117  }
118  else {
119  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION.getTypeID(), moduleName, "Outgoing"));
120  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO.getTypeID(), moduleName, address));
121  }
122  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME.getTypeID(), moduleName, date));
123  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION.getTypeID(), moduleName, type));
124  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SUBJECT.getTypeID(), moduleName, subject));
125  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TEXT.getTypeID(), moduleName, body));
126  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_MESSAGE_TYPE.getTypeID(), moduleName, "SMS Message"));
127  }
128 
129  } catch (Exception e) {
130  logger.log(Level.SEVERE, "Error parsing text messages to Blackboard", e); //NON-NLS
131  } finally {
132  try {
133  resultSet.close();
134  statement.close();
135  connection.close();
136  } catch (Exception e) {
137  logger.log(Level.SEVERE, "Error closing database", e); //NON-NLS
138  }
139  }
140  } catch (Exception e) {
141  logger.log(Level.SEVERE, "Error parsing text messages to Blackboard", e); //NON-NLS
142  }
143 
144  }
145 
146 }

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.