Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
GoogleMapLocationAnalyzer.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.openide.util.NbBundle;
30 import org.openide.util.NbBundle.Messages;
38 import org.sleuthkit.datamodel.AbstractFile;
39 import org.sleuthkit.datamodel.BlackboardArtifact;
40 import org.sleuthkit.datamodel.BlackboardAttribute;
41 import org.sleuthkit.datamodel.Content;
42 import org.sleuthkit.datamodel.TskCoreException;
43 
47 class GoogleMapLocationAnalyzer {
48 
49  private static final String moduleName = AndroidModuleFactory.getModuleName();
50  private static final Logger logger = Logger.getLogger(GoogleMapLocationAnalyzer.class.getName());
51  private static Blackboard blackboard;
52 
53  public static void findGeoLocations(Content dataSource, FileManager fileManager,
54  IngestJobContext context) {
55  List<AbstractFile> absFiles;
56  blackboard = Case.getCurrentCase().getServices().getBlackboard();
57  try {
58  absFiles = fileManager.findFiles(dataSource, "da_destination_history"); //NON-NLS
59  if (absFiles.isEmpty()) {
60  return;
61  }
62  for (AbstractFile abstractFile : absFiles) {
63  try {
64  File jFile = new java.io.File(Case.getCurrentCase().getTempDirectory(), abstractFile.getName());
65  ContentUtils.writeToFile(abstractFile, jFile, context::dataSourceIngestIsCancelled);
66  findGeoLocationsInDB(jFile.toString(), abstractFile);
67  } catch (Exception e) {
68  logger.log(Level.SEVERE, "Error parsing Google map locations", e); //NON-NLS
69  }
70  }
71  } catch (TskCoreException e) {
72  logger.log(Level.SEVERE, "Error finding Google map locations", e); //NON-NLS
73  }
74  }
75 
76  @Messages({"GoogleMapLocationAnalyzer.indexError.message=Failed to index GPS route artifact for keyword search."})
77  private static void findGeoLocationsInDB(String DatabasePath, AbstractFile f) {
78  Connection connection = null;
79  ResultSet resultSet = null;
80  Statement statement = null;
81 
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  return;
92  }
93 
94  try {
95  resultSet = statement.executeQuery(
96  "SELECT time,dest_lat,dest_lng,dest_title,dest_address,source_lat,source_lng FROM destination_history;"); //NON-NLS
97 
98  while (resultSet.next()) {
99  Long time = Long.valueOf(resultSet.getString("time")) / 1000; //NON-NLS
100  String dest_title = resultSet.getString("dest_title"); //NON-NLS
101  String dest_address = resultSet.getString("dest_address"); //NON-NLS
102 
103  double dest_lat = convertGeo(resultSet.getString("dest_lat")); //NON-NLS
104  double dest_lng = convertGeo(resultSet.getString("dest_lng")); //NON-NLS
105  double source_lat = convertGeo(resultSet.getString("source_lat")); //NON-NLS
106  double source_lng = convertGeo(resultSet.getString("source_lng")); //NON-NLS
107 
108 // bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_TRACKPOINT);//src
109 // bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_CATEGORY.getTypeID(), moduleName, "Source"));
110 // bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE.getTypeID(), moduleName, source_lat));
111 // bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE.getTypeID(), moduleName, source_lng));
112 // bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME.getTypeID(), moduleName, time));
113 // bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DESCRIPTION.getTypeID(), moduleName, "Google Maps History"));
114 //
115 // bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_TRACKPOINT);//dest
116 // bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_CATEGORY.getTypeID(), moduleName, "Destination"));
117 // bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME.getTypeID(), moduleName, time));
118 // bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE.getTypeID(), moduleName, dest_lat));
119 // bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE.getTypeID(), moduleName, dest_lng));
120 // bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME.getTypeID(), moduleName, dest_title));
121 // bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_LOCATION.getTypeID(), moduleName, dest_address));
122 // bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME.getTypeID(), moduleName, "Google Maps History"));
123  BlackboardArtifact bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_ROUTE);
124  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_CATEGORY, moduleName,
125  NbBundle.getMessage(GoogleMapLocationAnalyzer.class,
126  "GoogleMapLocationAnalyzer.bbAttribute.destination")));
127  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME, moduleName, time));
128  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE_END, moduleName, dest_lat));
129  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE_END, moduleName, dest_lng));
130  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE_START, moduleName, source_lat));
131  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE_START, moduleName, source_lng));
132  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME, moduleName, dest_title));
133  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_LOCATION, moduleName, dest_address));
134  bba.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME, moduleName,
135  NbBundle.getMessage(GoogleMapLocationAnalyzer.class,
136  "GoogleMapLocationAnalyzer.bbAttribute.googleMapsHistory")));
137 
138  try {
139  // index the artifact for keyword search
140  blackboard.indexArtifact(bba);
141  } catch (Blackboard.BlackboardException ex) {
142  logger.log(Level.SEVERE, "Unable to index blackboard artifact " + bba.getArtifactID(), ex); //NON-NLS
143  MessageNotifyUtil.Notify.error(
144  Bundle.GoogleMapLocationAnalyzer_indexError_message(), bba.getDisplayName());
145  }
146  }
147  } catch (Exception e) {
148  logger.log(Level.SEVERE, "Error parsing Google map locations to the Blackboard", e); //NON-NLS
149  } finally {
150  try {
151  if (resultSet != null) {
152  resultSet.close();
153  }
154  statement.close();
155  connection.close();
156  } catch (Exception e) {
157  logger.log(Level.SEVERE, "Error closing the database", e); //NON-NLS
158  }
159  }
160  }
161 
162  //add periods 6 decimal places before the end.
163  private static double convertGeo(String s) {
164  if (s.length() > 6) {
165  return Double.valueOf(s.substring(0, s.length() - 6) + "." + s.substring(s.length() - 6, s.length()));
166  } else {
167  return Double.valueOf(s);
168  }
169  }
170 }

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