Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CallLogAnalyzer.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.io.IOException;
23 import java.sql.Connection;
24 import java.sql.DriverManager;
25 import java.sql.ResultSet;
26 import java.sql.SQLException;
27 import java.sql.Statement;
28 import java.util.Arrays;
29 import java.util.List;
30 import java.util.logging.Level;
31 import org.openide.util.NbBundle;
38 import org.sleuthkit.datamodel.AbstractFile;
39 import org.sleuthkit.datamodel.BlackboardArtifact;
40 import org.sleuthkit.datamodel.BlackboardAttribute;
41 import org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE;
42 import org.sleuthkit.datamodel.Content;
43 import org.sleuthkit.datamodel.TskCoreException;
44 
49 class CallLogAnalyzer {
50 
51  private static final String moduleName = AndroidModuleFactory.getModuleName();
52  private static final Logger logger = Logger.getLogger(CallLogAnalyzer.class.getName());
53  private static Blackboard blackboard;
54 
58  private static final Iterable<String> tableNames = Arrays.asList("calls", "logs"); //NON-NLS
59 
60  public static void findCallLogs(Content dataSource, FileManager fileManager) {
61  blackboard = Case.getCurrentCase().getServices().getBlackboard();
62  try {
63  List<AbstractFile> absFiles = fileManager.findFiles(dataSource, "logs.db"); //NON-NLS
64  absFiles.addAll(fileManager.findFiles(dataSource, "contacts.db")); //NON-NLS
65  absFiles.addAll(fileManager.findFiles(dataSource, "contacts2.db")); //NON-NLS
66  for (AbstractFile abstractFile : absFiles) {
67  try {
68  File file = new File(Case.getCurrentCase().getTempDirectory(), abstractFile.getName());
69  ContentUtils.writeToFile(abstractFile, file);
70  findCallLogsInDB(file.toString(), abstractFile);
71  } catch (IOException e) {
72  logger.log(Level.SEVERE, "Error writing temporary call log db to disk", e); //NON-NLS
73  }
74  }
75  } catch (TskCoreException e) {
76  logger.log(Level.SEVERE, "Error finding call logs", e); //NON-NLS
77  }
78  }
79 
80  private static void findCallLogsInDB(String DatabasePath, AbstractFile f) {
81 
82  if (DatabasePath == null || DatabasePath.isEmpty()) {
83  return;
84  }
85  try (Connection connection = DriverManager.getConnection("jdbc:sqlite:" + DatabasePath); //NON-NLS
86  Statement statement = connection.createStatement();) {
87 
88  for (String tableName : tableNames) {
89  try (ResultSet resultSet = statement.executeQuery(
90  "SELECT number,date,duration,type, name FROM " + tableName + " ORDER BY date DESC;");) { //NON-NLS
91  logger.log(Level.INFO, "Reading call log from table {0} in db {1}", new Object[]{tableName, DatabasePath}); //NON-NLS
92  while (resultSet.next()) {
93  Long date = resultSet.getLong("date") / 1000;
94  final CallDirection direction = CallDirection.fromType(resultSet.getInt("type")); //NON-NLS
95  String directionString = direction != null ? direction.getDisplayName() : "";
96  final String number = resultSet.getString("number"); //NON-NLS
97  final long duration = resultSet.getLong("duration"); //NON-NLS //duration of call is in seconds
98  final String name = resultSet.getString("name"); //NON-NLS // name of person dialed or called. null if unregistered
99 
100  try {
101  BlackboardArtifact bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_CALLLOG); //create a call log and then add attributes from result set.
102  if (direction == CallDirection.OUTGOING) {
103  bba.addAttribute(new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO, moduleName, number));
104  } else {
105  bba.addAttribute(new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM, moduleName, number));
106  }
107  bba.addAttribute(new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_DATETIME_START, moduleName, date));
108  bba.addAttribute(new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_DATETIME_END, moduleName, duration + date));
109  bba.addAttribute(new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_DIRECTION, moduleName, directionString));
110  bba.addAttribute(new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_NAME, moduleName, name));
111 
112  try {
113  // index the artifact for keyword search
114  blackboard.indexArtifact(bba);
115  } catch (Blackboard.BlackboardException ex) {
116  logger.log(Level.SEVERE, NbBundle.getMessage(Blackboard.class, "Blackboard.unableToIndexArtifact.error.msg", bba.getDisplayName()), ex); //NON-NLS
117  MessageNotifyUtil.Notify.error(
118  NbBundle.getMessage(Blackboard.class, "Blackboard.unableToIndexArtifact.exception.msg"), bba.getDisplayName());
119  }
120  } catch (TskCoreException ex) {
121  logger.log(Level.SEVERE, "Error posting call log record to the Blackboard", ex); //NON-NLS
122  }
123  }
124  } catch (SQLException e) {
125  logger.log(Level.WARNING, "Could not read table {0} in db {1}", new Object[]{tableName, DatabasePath}); //NON-NLS
126  }
127  }
128  } catch (SQLException e) {
129  logger.log(Level.SEVERE, "Could not parse call log; error connecting to db " + DatabasePath, e); //NON-NLS
130  }
131  }
132 
133  private static enum CallDirection {
134 
135  INCOMING(1, "Incoming"), OUTGOING(2, "Outgoing"), MISSED(3, "Missed"); //NON-NLS
136 
137  private final int type;
138 
139  private final String displayName;
140 
141  public String getDisplayName() {
142  return displayName;
143  }
144 
145  private CallDirection(int type, String displayName) {
146  this.type = type;
147  this.displayName = displayName;
148  }
149 
150  static CallDirection fromType(int t) {
151  switch (t) {
152  case 1:
153  return INCOMING;
154  case 2:
155  return OUTGOING;
156  case 3:
157  return MISSED;
158  default:
159  return null;
160  }
161  }
162  }
163 }

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.