Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
WWFMessageAnalyzer.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 import org.openide.util.NbBundle;
30 import org.openide.util.NbBundle.Messages;
38 import org.sleuthkit.datamodel.AbstractFile;
39 import org.sleuthkit.datamodel.BlackboardArtifact;
40 import org.sleuthkit.datamodel.BlackboardAttribute;
41 import org.sleuthkit.datamodel.Content;
42 import org.sleuthkit.datamodel.TskCoreException;
43 
48 class WWFMessageAnalyzer {
49 
50  private static final String moduleName = AndroidModuleFactory.getModuleName();
51  private static final Logger logger = Logger.getLogger(WWFMessageAnalyzer.class.getName());
52  private static Blackboard blackboard;
53 
54  public static void findWWFMessages(Content dataSource, FileManager fileManager,
55  IngestJobContext context) {
56  List<AbstractFile> absFiles;
57  blackboard = Case.getCurrentCase().getServices().getBlackboard();
58  try {
59  absFiles = fileManager.findFiles(dataSource, "WordsFramework"); //NON-NLS
60 
61  for (AbstractFile abstractFile : absFiles) {
62  try {
63  File jFile = new File(Case.getCurrentCase().getTempDirectory(), abstractFile.getName());
64  ContentUtils.writeToFile(abstractFile, jFile, context::dataSourceIngestIsCancelled);
65 
66  findWWFMessagesInDB(jFile.toString(), abstractFile);
67  } catch (Exception e) {
68  logger.log(Level.SEVERE, "Error parsing WWF messages", e); //NON-NLS
69  }
70  }
71  } catch (TskCoreException e) {
72  logger.log(Level.SEVERE, "Error finding WWF messages", e); //NON-NLS
73  }
74  }
75 
76  @Messages({"WWFMessageAnalyzer.indexError.message=Failed to index WWF message artifact for keyword search."})
77  private static void findWWFMessagesInDB(String DatabasePath, AbstractFile f) {
78  Connection connection = null;
79  ResultSet resultSet = null;
80  Statement statement = null;
81 
82  if (DatabasePath == null || DatabasePath.isEmpty()) {
83  return;
84  }
85  try {
86  Class.forName("org.sqlite.JDBC"); //load JDBC driver
87  connection = DriverManager.getConnection("jdbc:sqlite:" + DatabasePath); //NON-NLS
88  statement = connection.createStatement();
89  } catch (ClassNotFoundException | SQLException e) {
90  logger.log(Level.SEVERE, "Error opening database", e); //NON-NLS
91  return;
92  }
93 
94  try {
95  resultSet = statement.executeQuery(
96  "SELECT message,strftime('%s' ,created_at) as datetime,user_id,game_id FROM chat_messages ORDER BY game_id DESC, created_at DESC;"); //NON-NLS
97 
98  String message; // WWF Message
99  String user_id; // the ID of the user who sent the message.
100  String game_id; // ID of the game which the the message was sent.
101 
102  while (resultSet.next()) {
103  message = resultSet.getString("message"); //NON-NLS
104  Long created_at = resultSet.getLong("datetime"); //NON-NLS
105  user_id = resultSet.getString("user_id"); //NON-NLS
106  game_id = resultSet.getString("game_id"); //NON-NLS
107 
108  BlackboardArtifact bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE); //create a call log and then add attributes from result set.
109  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME, moduleName, created_at));
110  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME, moduleName, user_id));
111  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_MSG_ID, moduleName, game_id));
112  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TEXT, moduleName, message));
113  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_MESSAGE_TYPE, moduleName,
114  NbBundle.getMessage(WWFMessageAnalyzer.class,
115  "WWFMessageAnalyzer.bbAttribute.wordsWithFriendsMsg")));
116 
117  try {
118  // index the artifact for keyword search
119  blackboard.indexArtifact(bba);
120  } catch (Blackboard.BlackboardException ex) {
121  logger.log(Level.SEVERE, "Unable to index blackboard artifact " + bba.getArtifactID(), ex); //NON-NLS
122  MessageNotifyUtil.Notify.error(
123  Bundle.WWFMessageAnalyzer_indexError_message(), bba.getDisplayName());
124  }
125  }
126  } catch (Exception e) {
127  logger.log(Level.SEVERE, "Error parsing WWF messages to the Blackboard", e); //NON-NLS
128  } finally {
129  try {
130  if (resultSet != null) {
131  resultSet.close();
132  }
133  statement.close();
134  connection.close();
135  } catch (Exception e) {
136  logger.log(Level.SEVERE, "Error closing database", e); //NON-NLS
137  }
138  }
139  }
140 }

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