Autopsy  4.5.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.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.ArrayList;
27 import java.util.Collection;
28 import java.util.List;
29 import java.util.logging.Level;
30 import org.openide.util.NbBundle.Messages;
37 import org.sleuthkit.datamodel.AbstractFile;
38 import org.sleuthkit.datamodel.BlackboardArtifact;
39 import org.sleuthkit.datamodel.BlackboardAttribute;
40 import org.sleuthkit.datamodel.SleuthkitCase;
41 import org.sleuthkit.datamodel.TskCoreException;
42 
43 class CallLogAnalyzer {
44 
45  private Connection connection = null;
46  private ResultSet resultSet = null;
47  private Statement statement = null;
48  private String dbPath = "";
49  private long fileId = 0;
50  private java.io.File jFile = null;
51  private String moduleName = iOSModuleFactory.getModuleName();
52  private static final Logger logger = Logger.getLogger(CallLogAnalyzer.class.getName());
53  private Blackboard blackboard;
54 
55  public void findCallLogs(IngestJobContext context) {
56  blackboard = Case.getCurrentCase().getServices().getBlackboard();
57  List<AbstractFile> absFiles;
58  try {
59  SleuthkitCase skCase = Case.getCurrentCase().getSleuthkitCase();
60  absFiles = skCase.findAllFilesWhere("name ='contacts2.db' OR name ='contacts.db'"); //NON-NLS //get exact file names
61  if (absFiles.isEmpty()) {
62  return;
63  }
64  for (AbstractFile AF : absFiles) {
65  try {
66  jFile = new java.io.File(Case.getCurrentCase().getTempDirectory(), AF.getName().replaceAll("[<>%|\"/:*\\\\]", ""));
67  ContentUtils.writeToFile(AF, jFile, context::dataSourceIngestIsCancelled);
68  dbPath = jFile.toString(); //path of file as string
69  fileId = AF.getId();
70  findCallLogsInDB(dbPath, fileId);
71  } catch (Exception e) {
72  logger.log(Level.SEVERE, "Error parsing Call logs", 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  @Messages({"CallLogAnalyzer.indexError.message=Failed to index call log artifact for keyword search."})
81  private void findCallLogsInDB(String DatabasePath, long fId) {
82  if (DatabasePath == null || DatabasePath.isEmpty()) {
83  return;
84  }
85  try {
86  Class.forName("org.sqlite.JDBC"); //NON-NLS //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  }
92 
93  Case currentCase = Case.getCurrentCase();
94  SleuthkitCase skCase = currentCase.getSleuthkitCase();
95  try {
96  AbstractFile f = skCase.getAbstractFileById(fId);
97  if (f == null) {
98  logger.log(Level.SEVERE, "Error getting abstract file " + fId); //NON-NLS
99  return;
100  }
101 
102  try {
103  resultSet = statement.executeQuery(
104  "SELECT number,date,duration,type, name FROM calls ORDER BY date DESC;"); //NON-NLS
105 
106  BlackboardArtifact bba;
107  String name; // name of person dialed or called. null if unregistered
108  String number; //string phone number
109  String duration; //duration of call in seconds
110  String date; // Unix time
111  String type; // 1 incoming, 2 outgoing, 3 missed
112 
113  while (resultSet.next()) {
114  name = resultSet.getString("name"); //NON-NLS
115  number = resultSet.getString("number"); //NON-NLS
116  duration = resultSet.getString("duration"); //NON-NLS
117  date = resultSet.getString("date"); //NON-NLS
118  type = resultSet.getString("type"); //NON-NLS
119 
120  bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_CALLLOG); //create a call log and then add attributes from result set.
121  Collection<BlackboardAttribute> attributes = new ArrayList<>();
122  if (type.equalsIgnoreCase("outgoing")) { //NON-NLS
123  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO, moduleName, number));
124  } else {
125  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM, moduleName, number));
126  }
127  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_START, moduleName, date)); // RC: Should be long!
128  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_END, moduleName, duration + date)); // RC: Should be long!
129  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION, moduleName, type));
130  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME, moduleName, name));
131 
132  bba.addAttributes(attributes);
133  try {
134  // index the artifact for keyword search
135  blackboard.indexArtifact(bba);
136  } catch (Blackboard.BlackboardException ex) {
137  logger.log(Level.SEVERE, "Unable to index blackboard artifact " + bba.getArtifactID(), ex); //NON-NLS
139  Bundle.CallLogAnalyzer_indexError_message(), bba.getDisplayName());
140  }
141  }
142  } catch (Exception e) {
143  logger.log(Level.SEVERE, "Error parsing Call logs to the Blackboard", e); //NON-NLS
144  } finally {
145  try {
146  resultSet.close();
147  statement.close();
148  connection.close();
149  } catch (Exception e) {
150  logger.log(Level.SEVERE, "Error closing the database", e); //NON-NLS
151  }
152  }
153  } catch (Exception e) {
154  logger.log(Level.SEVERE, "Error parsing Call logs to the Blackboard", e); //NON-NLS
155  }
156 
157  }
158 
159 }
static< T > long writeToFile(Content content, java.io.File outputFile, ProgressHandle progress, Future< T > worker, boolean source)
static void error(String title, String message)
synchronized void indexArtifact(BlackboardArtifact artifact)
Definition: Blackboard.java:59
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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