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

Copyright © 2012-2016 Basis Technology. Generated on: Mon Jan 2 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.