Autopsy  3.1
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 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.events.type;
20 
21 import java.util.HashMap;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.function.BiFunction;
25 import java.util.logging.Level;
26 import org.apache.commons.lang3.StringUtils;
31 
35 public interface ArtifactEventType extends EventType {
36 
42 
44 
59  default AttributeEventDescription parseAttributesHelper(BlackboardArtifact artf, Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> attrMap) throws TskCoreException {
60  final BlackboardAttribute dateTimeAttr = attrMap.get(getDateTimeAttrubuteType());
61 
62  long time = dateTimeAttr.getValueLong();
63  String shortDescription = getShortExtractor().apply(artf, attrMap);
64  String medDescription = shortDescription + " : " + getMedExtractor().apply(artf, attrMap);
65  String fullDescription = medDescription + " : " + getFullExtractor().apply(artf, attrMap);
66  return new AttributeEventDescription(time, shortDescription, medDescription, fullDescription);
67  }
68 
72 
75  BiFunction<BlackboardArtifact, Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute>, String> getMedExtractor();
76 
79  BiFunction<BlackboardArtifact, Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute>, String> getShortExtractor();
80 
87 
88  final private long time;
89 
90  public long getTime() {
91  return time;
92  }
93 
94  public String getShortDescription() {
95  return shortDescription;
96  }
97 
98  public String getMedDescription() {
99  return medDescription;
100  }
101 
102  public String getFullDescription() {
103  return fullDescription;
104  }
105 
106  final private String shortDescription;
107 
108  final private String medDescription;
109 
110  final private String fullDescription;
111 
112  public AttributeEventDescription(long time, String shortDescription,
113  String medDescription,
114  String fullDescription) {
115  this.time = time;
116  this.shortDescription = shortDescription;
117  this.medDescription = medDescription;
118  this.fullDescription = fullDescription;
119  }
120 
139  ArtifactEventType type, BlackboardArtifact artf) throws TskCoreException {
140  //if we got passed an artifact that doesn't correspond to the type of the event,
141  //something went very wrong. throw an exception.
142  if (type.getArtifactType().getTypeID() != artf.getArtifactTypeID()) {
143  throw new IllegalArgumentException();
144  }
145 
146  /* build a map from attribute type to attribute, this makes
147  * implementing the parseAttributeHelper easier but could be
148  * ineffecient if we don't need most of the attributes. This would
149  * be unnessecary if there was an api on Blackboard artifacts to get
150  * specific attributes by type */
151  List<BlackboardAttribute> attributes = artf.getAttributes();
152  Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> attrMap = new HashMap<>();
153  for (BlackboardAttribute attr : attributes) {
155  getAttributeTypeName()), attr);
156  }
157 
158  if (attrMap.get(type.getDateTimeAttrubuteType()) == null) {
159  Logger.getLogger(AttributeEventDescription.class.getName()).log(Level.WARNING, "Artifact {0} has no date/time attribute, skipping it.", artf.getArtifactID()); // NON-NLS
160  return null;
161  }
162  //use the hook provided by this subtype implementation
163  return type.parseAttributesHelper(artf, attrMap);
164  }
165  }
166 
167  public static class AttributeExtractor implements BiFunction<BlackboardArtifact, Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute>, String> {
168 
169  @Override
170  public String apply(BlackboardArtifact artf, Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> attrMap) {
171  final BlackboardAttribute attr = attrMap.get(attribute);
172  return (attr != null) ? StringUtils.defaultString(attr.getDisplayString()) : " ";
173  }
174 
176 
178  this.attribute = attribute;
179  }
180  }
181 
182  public static class EmptyExtractor implements BiFunction<BlackboardArtifact, Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute>, String> {
183 
184  @Override
185  public String apply(BlackboardArtifact t, Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> u) {
186  return "";
187  }
188  }
189 }
String apply(BlackboardArtifact artf, Map< BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute > attrMap)
String apply(BlackboardArtifact t, Map< BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute > u)
BiFunction< BlackboardArtifact, Map< BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute >, String > getShortExtractor()
default AttributeEventDescription parseAttributesHelper(BlackboardArtifact artf, Map< BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute > attrMap)
BiFunction< BlackboardArtifact, Map< BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute >, String > getFullExtractor()
AttributeEventDescription(long time, String shortDescription, String medDescription, String fullDescription)
BlackboardAttribute.ATTRIBUTE_TYPE getDateTimeAttrubuteType()
BiFunction< BlackboardArtifact, Map< BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute >, String > getMedExtractor()
static AttributeEventDescription buildEventDescription(ArtifactEventType type, BlackboardArtifact artf)
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.