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

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.