Autopsy  3.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.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.List;
27 import java.util.logging.Level;
36 
37 class CallLogAnalyzer {
38 
39  private Connection connection = null;
40  private ResultSet resultSet = null;
41  private Statement statement = null;
42  private String dbPath = "";
43  private long fileId = 0;
44  private java.io.File jFile = null;
45  private String moduleName = iOSModuleFactory.getModuleName();
46  private static final Logger logger = Logger.getLogger(CallLogAnalyzer.class.getName());
47 
48  public void findCallLogs() {
49  List<AbstractFile> absFiles;
50  try {
52  absFiles = skCase.findAllFilesWhere("name ='contacts2.db' OR name ='contacts.db'"); //NON-NLS //get exact file names
53  if (absFiles.isEmpty()) {
54  return;
55  }
56  for (AbstractFile AF : absFiles) {
57  try {
58  jFile = new java.io.File(Case.getCurrentCase().getTempDirectory(), AF.getName().replaceAll("[<>%|\"/:*\\\\]", ""));
59  ContentUtils.writeToFile(AF, jFile);
60  dbPath = jFile.toString(); //path of file as string
61  fileId = AF.getId();
62  findCallLogsInDB(dbPath, fileId);
63  } catch (Exception e) {
64  logger.log(Level.SEVERE, "Error parsing Call logs", e); //NON-NLS
65  }
66  }
67  } catch (TskCoreException e) {
68  logger.log(Level.SEVERE, "Error finding Call logs", e); //NON-NLS
69  }
70  }
71 
72  private void findCallLogsInDB(String DatabasePath, long fId) {
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  }
83 
84  Case currentCase = Case.getCurrentCase();
85  SleuthkitCase skCase = currentCase.getSleuthkitCase();
86  try {
87  AbstractFile f = skCase.getAbstractFileById(fId);
88  if(f == null){
89  logger.log(Level.SEVERE, "Error getting abstract file " + fId); //NON-NLS
90  return;
91  }
92 
93  try {
94  resultSet = statement.executeQuery(
95  "SELECT number,date,duration,type, name FROM calls ORDER BY date DESC;"); //NON-NLS
96 
98  String name; // name of person dialed or called. null if unregistered
99  String number; //string phone number
100  String duration; //duration of call in seconds
101  String date; // Unix time
102  String type; // 1 incoming, 2 outgoing, 3 missed
103 
104  while (resultSet.next()) {
105  name = resultSet.getString("name"); //NON-NLS
106  number = resultSet.getString("number"); //NON-NLS
107  duration = resultSet.getString("duration"); //NON-NLS
108  date = resultSet.getString("date"); //NON-NLS
109  type = resultSet.getString("type"); //NON-NLS
110 
111  bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_CALLLOG); //create a call log and then add attributes from result set.
112  if(type.equalsIgnoreCase("outgoing")) { //NON-NLS
114  }
115  else {
117  }
119  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_END.getTypeID(), moduleName, duration + date));
120  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION.getTypeID(), moduleName, type));
121  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME.getTypeID(), moduleName, name));
122 
123  }
124  } catch (Exception e) {
125  logger.log(Level.SEVERE, "Error parsing Call logs to the Blackboard", e); //NON-NLS
126  } finally {
127  try {
128  resultSet.close();
129  statement.close();
130  connection.close();
131  } catch (Exception e) {
132  logger.log(Level.SEVERE, "Error closing the database", e); //NON-NLS
133  }
134  }
135  } catch (Exception e) {
136  logger.log(Level.SEVERE, "Error parsing Call logs to the Blackboard", e); //NON-NLS
137  }
138 
139  }
140 
141 }
static< T, V > long writeToFile(Content content, java.io.File outputFile, ProgressHandle progress, SwingWorker< T, V > worker, boolean source)
AbstractFile getAbstractFileById(long id)
void addAttribute(BlackboardAttribute attr)
BlackboardArtifact newArtifact(int artifactTypeID)
List< AbstractFile > findAllFilesWhere(String sqlWhereClause)
static Logger getLogger(String name)
Definition: Logger.java:131

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.