Autopsy  4.18.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
EXIFProcessor.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2020 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.pictureanalyzer.impls;
20 
21 import com.drew.imaging.ImageMetadataReader;
22 import com.drew.imaging.ImageProcessingException;
23 import com.drew.lang.GeoLocation;
24 import com.drew.lang.Rational;
25 import com.drew.metadata.Metadata;
26 import com.drew.metadata.exif.ExifIFD0Directory;
27 import com.drew.metadata.exif.ExifSubIFDDirectory;
28 import com.drew.metadata.exif.GpsDirectory;
29 import java.io.BufferedInputStream;
30 import java.io.IOException;
31 import java.util.ArrayList;
32 import java.util.Arrays;
33 import java.util.Collection;
34 import java.util.Date;
35 import java.util.Set;
36 import java.util.HashSet;
37 import java.util.TimeZone;
38 import java.util.logging.Level;
39 import org.apache.commons.lang3.StringUtils;
40 import org.openide.util.NbBundle;
41 import org.openide.util.lookup.ServiceProvider;
45 import org.sleuthkit.datamodel.AbstractFile;
49 import org.sleuthkit.datamodel.Blackboard;
50 import org.sleuthkit.datamodel.BlackboardArtifact;
51 import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_METADATA_EXIF;
52 import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_USER_CONTENT_SUSPECTED;
53 import org.sleuthkit.datamodel.BlackboardAttribute;
54 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE;
55 import org.sleuthkit.datamodel.Content;
56 import org.sleuthkit.datamodel.Image;
57 import org.sleuthkit.datamodel.ReadContentInputStream;
58 import org.sleuthkit.datamodel.TskCoreException;
60 import org.sleuthkit.datamodel.Score;
61 
68 @ServiceProvider(service = PictureProcessor.class)
69 public class EXIFProcessor implements PictureProcessor {
70 
71  private static final Logger logger = Logger.getLogger(EXIFProcessor.class.getName());
72 
73  @Override
74  @NbBundle.Messages({
75  "ExifProcessor.indexError.message=Failed to post EXIF Metadata artifact(s).",
76  "ExifProcessor.userContent.description=EXIF metadata data exists for this file."
77  })
78  public void process(IngestJobContext context, AbstractFile file) {
79  final String MODULE_NAME = PictureAnalyzerIngestModuleFactory.getModuleName();
80 
81  try (BufferedInputStream bin = new BufferedInputStream(new ReadContentInputStream(file));) {
82 
83  final Collection<BlackboardAttribute> attributes = new ArrayList<>();
84  final Metadata metadata = ImageMetadataReader.readMetadata(bin);
85 
86  // Date
87  final ExifSubIFDDirectory exifDir = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
88  if (exifDir != null) {
89 
90  // set the timeZone for the current datasource.
91  TimeZone timeZone = null;
92  try {
93  Content dataSource = file.getDataSource();
94  if ((dataSource != null) && (dataSource instanceof Image)) {
95  Image image = (Image) dataSource;
96  timeZone = TimeZone.getTimeZone(image.getTimeZone());
97  }
98  } catch (TskCoreException ex) {
99  logger.log(Level.INFO, "Error getting time zones", ex); //NON-NLS
100  }
101 
102  final Date date = exifDir.getDate(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL, timeZone);
103  if (date != null) {
104  attributes.add(new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_DATETIME_CREATED, MODULE_NAME, date.getTime() / 1000));
105  }
106  }
107 
108  if (context.fileIngestIsCancelled()) {
109  return;
110  }
111 
112  // GPS Stuff
113  final GpsDirectory gpsDir = metadata.getFirstDirectoryOfType(GpsDirectory.class);
114  if (gpsDir != null) {
115  final GeoLocation loc = gpsDir.getGeoLocation();
116  if (loc != null) {
117  attributes.add(new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_GEO_LATITUDE, MODULE_NAME, loc.getLatitude()));
118  attributes.add(new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE, MODULE_NAME, loc.getLongitude()));
119  }
120 
121  final Rational altitude = gpsDir.getRational(GpsDirectory.TAG_ALTITUDE);
122  if (altitude != null) {
123  attributes.add(new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_GEO_ALTITUDE, MODULE_NAME, altitude.doubleValue()));
124  }
125  }
126 
127  if (context.fileIngestIsCancelled()) {
128  return;
129  }
130 
131  // Device info
132  final ExifIFD0Directory devDir = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
133  if (devDir != null) {
134  final String model = devDir.getString(ExifIFD0Directory.TAG_MODEL);
135  if (StringUtils.isNotBlank(model)) {
136  attributes.add(new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_DEVICE_MODEL, MODULE_NAME, model));
137  }
138 
139  final String make = devDir.getString(ExifIFD0Directory.TAG_MAKE);
140  if (StringUtils.isNotBlank(make)) {
141  attributes.add(new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_DEVICE_MAKE, MODULE_NAME, make));
142  }
143  }
144 
145  if (context.fileIngestIsCancelled()) {
146  return;
147  }
148 
149  final Blackboard blackboard = Case.getCurrentCaseThrows().getSleuthkitCase().getBlackboard();
150 
151  if (!attributes.isEmpty() && !blackboard.artifactExists(file, TSK_METADATA_EXIF, attributes)) {
152 
153  final BlackboardArtifact exifArtifact = file.newDataArtifact(new BlackboardArtifact.Type(TSK_METADATA_EXIF), attributes);
154 
155  final BlackboardArtifact userSuspectedArtifact = file.newAnalysisResult(
156  BlackboardArtifact.Type.TSK_USER_CONTENT_SUSPECTED, Score.SCORE_UNKNOWN, null, null, null,
157  Arrays.asList(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COMMENT, MODULE_NAME, Bundle.ExifProcessor_userContent_description())))
158  .getAnalysisResult();
159 
160  try {
161  // index the artifact for keyword search
162  blackboard.postArtifact(exifArtifact, MODULE_NAME);
163  blackboard.postArtifact(userSuspectedArtifact, MODULE_NAME);
164  } catch (Blackboard.BlackboardException ex) {
165  logger.log(Level.SEVERE, "Unable to index blackboard artifact " + exifArtifact.getArtifactID(), ex); //NON-NLS
167  Bundle.ExifProcessor_indexError_message(), exifArtifact.getDisplayName());
168  }
169  }
170  } catch (TskCoreException ex) {
171  logger.log(Level.WARNING, "Failed to create blackboard artifact for " //NON-NLS
172  + "exif metadata ({0}).", ex.getLocalizedMessage()); //NON-NLS
173  } catch (IOException | ImageProcessingException unused) {
174  // In this case the stack trace is not needed in the log.
175  logger.log(Level.WARNING, String.format("Error parsing " //NON-NLS
176  + "image file '%s/%s' (id=%d).", file.getParentPath(), file.getName(), file.getId())); //NON-NLS
177  } catch (NoCurrentCaseException ex) {
178  logger.log(Level.INFO, "Exception while getting open case.", ex); //NON-NLS
179  }
180  }
181 
182  @Override
183  public Set<String> mimeTypes() {
184  return new HashSet<String>() {
185  {
186  add("audio/x-wav");
187  add("image/jpeg");
188  add("image/tiff");
189  }
190  };
191  }
192 }
void process(IngestJobContext context, AbstractFile file)
static void error(String title, String message)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2021 Basis Technology. Generated on: Thu Jul 8 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.