Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
TangoMessageAnalyzer.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.apache.commons.codec.binary.Base64;
30 import org.openide.util.NbBundle;
41 
45 class TangoMessageAnalyzer {
46 
47  private static final String moduleName = AndroidModuleFactory.getModuleName();
48  private static final Logger logger = Logger.getLogger(TangoMessageAnalyzer.class.getName());
49 
50  public static void findTangoMessages(Content dataSource, FileManager fileManager) {
51  List<AbstractFile> absFiles;
52  try {
53  absFiles = fileManager.findFiles(dataSource, "tc.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  findTangoMessagesInDB(jFile.toString(), abstractFile);
59  } catch (Exception e) {
60  logger.log(Level.SEVERE, "Error parsing Tango messages", e); //NON-NLS
61  }
62  }
63  } catch (TskCoreException e) {
64  logger.log(Level.SEVERE, "Error finding Tango messages", e); //NON-NLS
65  }
66  }
67 
68  private static void findTangoMessagesInDB(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 conv_id, create_time,direction,payload FROM messages ORDER BY create_time DESC;"); //NON-NLS
88 
89  String conv_id; // seems to wrap around the message found in payload after decoding from base-64
90  String direction; // 1 incoming, 2 outgoing
91  String payload; // seems to be a base64 message wrapped by the conv_id
92 
93  while (resultSet.next()) {
94  conv_id = resultSet.getString("conv_id"); //NON-NLS
95  Long create_time = Long.valueOf(resultSet.getString("create_time")) / 1000; //NON-NLS
96  if (resultSet.getString("direction").equals("1")) { //NON-NLS
97  direction = "Incoming"; //NON-NLS
98  } else {
99  direction = "Outgoing"; //NON-NLS
100  }
101  payload = resultSet.getString("payload"); //NON-NLS
102 
103  BlackboardArtifact bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE); //create a call log and then add attributes from result set.
104  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME.getTypeID(), moduleName, create_time));
105  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION.getTypeID(), moduleName, direction));
106  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TEXT.getTypeID(), moduleName, decodeMessage(conv_id, payload)));
107  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_MESSAGE_TYPE.getTypeID(), moduleName,
108  NbBundle.getMessage(TangoMessageAnalyzer.class,
109  "TangoMessageAnalyzer.bbAttribute.tangoMessage")));
110  }
111 
112  } catch (Exception e) {
113  logger.log(Level.SEVERE, "Error parsing Tango messages to the Blackboard", e); //NON-NLS
114  } finally {
115  try {
116  if (resultSet != null) {
117  resultSet.close();
118  }
119  statement.close();
120  connection.close();
121  } catch (Exception e) {
122  logger.log(Level.SEVERE, "Error closing database", e); //NON-NLS
123  }
124  }
125  }
126 
127  //take the message string which is wrapped by a certain string, and return the text enclosed.
128  private static String decodeMessage(String wrapper, String message) {
129  String result = "";
130  byte[] decoded = Base64.decodeBase64(message);
131  try {
132  String Z = new String(decoded, "UTF-8");
133  result = Z.split(wrapper)[1];
134  } catch (Exception e) {
135  logger.log(Level.SEVERE, "Error decoding a Tango message", e); //NON-NLS
136  }
137  return result;
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.