Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ArtifactEventType.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014-16 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.timeline.datamodel.eventtype;
20 
21 import java.text.MessageFormat;
22 import java.util.Optional;
23 import java.util.function.Function;
24 import java.util.logging.Level;
25 import org.apache.commons.lang3.StringUtils;
27 import org.sleuthkit.datamodel.BlackboardArtifact;
28 import org.sleuthkit.datamodel.BlackboardAttribute;
29 import org.sleuthkit.datamodel.TskCoreException;
30 
34 public interface ArtifactEventType extends EventType {
35 
36  public static final Logger LOGGER = Logger.getLogger(ArtifactEventType.class.getName());
38 
42  public BlackboardArtifact.Type getArtifactType();
43 
44  public BlackboardAttribute.Type getDateTimeAttrubuteType();
45 
59  default AttributeEventDescription parseAttributesHelper(BlackboardArtifact artf) throws TskCoreException {
60  final BlackboardAttribute dateTimeAttr = artf.getAttribute(getDateTimeAttrubuteType());
61 
62  long time = dateTimeAttr.getValueLong();
63  String shortDescription = getShortExtractor().apply(artf);
64  String medDescription = shortDescription + " : " + getMedExtractor().apply(artf);
65  String fullDescription = medDescription + " : " + getFullExtractor().apply(artf);
66  return new AttributeEventDescription(time, shortDescription, medDescription, fullDescription);
67  }
68 
73  Function<BlackboardArtifact, String> getFullExtractor();
74 
79  Function<BlackboardArtifact, String> getMedExtractor();
80 
85  Function<BlackboardArtifact, String> getShortExtractor();
86 
93 
94  final private long time;
95 
96  public long getTime() {
97  return time;
98  }
99 
100  public String getShortDescription() {
101  return shortDescription;
102  }
103 
104  public String getMedDescription() {
105  return medDescription;
106  }
107 
108  public String getFullDescription() {
109  return fullDescription;
110  }
111 
112  final private String shortDescription;
113 
114  final private String medDescription;
115 
116  final private String fullDescription;
117 
118  public AttributeEventDescription(long time, String shortDescription,
119  String medDescription,
120  String fullDescription) {
121  this.time = time;
122  this.shortDescription = shortDescription;
123  this.medDescription = medDescription;
124  this.fullDescription = fullDescription;
125  }
126  }
127 
144  static public AttributeEventDescription buildEventDescription(ArtifactEventType type, BlackboardArtifact artf) throws TskCoreException {
145  //if we got passed an artifact that doesn't correspond to the type of the event,
146  //something went very wrong. throw an exception.
147  if (type.getArtifactType().getTypeID() != artf.getArtifactTypeID()) {
148  throw new IllegalArgumentException();
149  }
150  if (artf.getAttribute(type.getDateTimeAttrubuteType()) == null) {
151  LOGGER.log(Level.WARNING, "Artifact {0} has no date/time attribute, skipping it.", artf.getArtifactID()); // NON-NLS
152  return null;
153  }
154  //use the hook provided by this subtype implementation
155  return type.parseAttributesHelper(artf);
156  }
157 
158  static class AttributeExtractor implements Function<BlackboardArtifact, String> {
159 
160  public String apply(BlackboardArtifact artf) {
161  return Optional.ofNullable(getAttributeSafe(artf, attributeType))
162  .map(BlackboardAttribute::getDisplayString)
163  .map(StringUtils::defaultString)
164  .orElse("");
165  }
166 
167  private final BlackboardAttribute.Type attributeType;
168 
169  public AttributeExtractor(BlackboardAttribute.Type attribute) {
170  this.attributeType = attribute;
171  }
172 
173  }
174 
175  static class EmptyExtractor implements Function<BlackboardArtifact, String> {
176 
177  @Override
178  public String apply(BlackboardArtifact t) {
179  return "";
180  }
181  }
182 
183  static BlackboardAttribute getAttributeSafe(BlackboardArtifact artf, BlackboardAttribute.Type attrType) {
184  try {
185  return artf.getAttribute(attrType);
186  } catch (TskCoreException ex) {
187  LOGGER.log(Level.SEVERE, MessageFormat.format("Error getting extracting attribute from artifact {0}.", artf.getArtifactID()), ex); // NON-NLS
188  return null;
189  }
190  }
191 }
Function< BlackboardArtifact, String > getShortExtractor()
Function< BlackboardArtifact, String > getMedExtractor()
default AttributeEventDescription parseAttributesHelper(BlackboardArtifact artf)
Function< BlackboardArtifact, String > getFullExtractor()
AttributeEventDescription(long time, String shortDescription, String medDescription, String fullDescription)
synchronized static Logger getLogger(String name)
Definition: Logger.java:166
static BlackboardAttribute getAttributeSafe(BlackboardArtifact artf, BlackboardAttribute.Type attrType)
static AttributeEventDescription buildEventDescription(ArtifactEventType type, BlackboardArtifact artf)

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.