Autopsy  4.9.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
EventNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2018 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.explorernodes;
20 
21 import java.lang.reflect.InvocationTargetException;
22 import java.text.MessageFormat;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.List;
26 import java.util.logging.Level;
27 import javax.swing.Action;
28 import org.joda.time.DateTime;
29 import org.joda.time.DateTimeZone;
30 import org.openide.nodes.Children;
31 import org.openide.nodes.PropertySupport;
32 import org.openide.nodes.Sheet;
33 import org.openide.util.NbBundle;
34 import org.openide.util.lookup.Lookups;
47 import org.sleuthkit.datamodel.AbstractFile;
48 import org.sleuthkit.datamodel.BlackboardArtifact;
49 import org.sleuthkit.datamodel.BlackboardAttribute;
50 import org.sleuthkit.datamodel.SleuthkitCase;
51 import org.sleuthkit.datamodel.TskCoreException;
52 
56 public class EventNode extends DisplayableItemNode {
57 
58  private static final long serialVersionUID = 1L;
59 
60  private static final Logger LOGGER = Logger.getLogger(EventNode.class.getName());
61 
62  private final SingleEvent event;
63 
64  EventNode(SingleEvent event, AbstractFile file, BlackboardArtifact artifact) {
65  super(Children.LEAF, Lookups.fixed(event, file, artifact));
66  this.event = event;
67  this.setIconBaseWithExtension("org/sleuthkit/autopsy/timeline/images/" + event.getEventType().getIconBase()); // NON-NLS
68  }
69 
70  EventNode(SingleEvent event, AbstractFile file) {
71  super(Children.LEAF, Lookups.fixed(event, file));
72  this.event = event;
73  this.setIconBaseWithExtension("org/sleuthkit/autopsy/timeline/images/" + event.getEventType().getIconBase()); // NON-NLS
74  }
75 
76  @Override
77  @NbBundle.Messages({
78  "NodeProperty.displayName.icon=Icon",
79  "NodeProperty.displayName.description=Description",
80  "NodeProperty.displayName.baseType=Base Type",
81  "NodeProperty.displayName.subType=Sub Type",
82  "NodeProperty.displayName.known=Known",
83  "NodeProperty.displayName.dateTime=Date/Time"})
84  protected Sheet createSheet() {
85  Sheet sheet = super.createSheet();
86  Sheet.Set properties = sheet.get(Sheet.PROPERTIES);
87  if (properties == null) {
88  properties = Sheet.createPropertiesSet();
89  sheet.put(properties);
90  }
91 
92  properties.put(new NodeProperty<>("icon", Bundle.NodeProperty_displayName_icon(), "icon", true)); // NON-NLS //gets overridden with icon
93  properties.put(new TimeProperty("time", Bundle.NodeProperty_displayName_dateTime(), "time ", getDateTimeString()));// NON-NLS
94  properties.put(new NodeProperty<>("description", Bundle.NodeProperty_displayName_description(), "description", event.getFullDescription())); // NON-NLS
95  properties.put(new NodeProperty<>("eventBaseType", Bundle.NodeProperty_displayName_baseType(), "base type", event.getEventType().getSuperType().getDisplayName())); // NON-NLS
96  properties.put(new NodeProperty<>("eventSubType", Bundle.NodeProperty_displayName_subType(), "sub type", event.getEventType().getDisplayName())); // NON-NLS
97  properties.put(new NodeProperty<>("Known", Bundle.NodeProperty_displayName_known(), "known", event.getKnown().toString())); // NON-NLS
98 
99  return sheet;
100  }
101 
109  private String getDateTimeString() {
110  return new DateTime(event.getStartMillis(), DateTimeZone.UTC).toString(TimeLineController.getZonedFormatter());
111  }
112 
113  @Override
114  @NbBundle.Messages({
115  "EventNode.getAction.errorTitle=Error getting actions",
116  "EventNode.getAction.linkedFileMessage=There was a problem getting actions for the selected result. "
117  + " The 'View File in Timeline' action will not be available."})
118  public Action[] getActions(boolean context) {
119  Action[] superActions = super.getActions(context);
120  List<Action> actionsList = new ArrayList<>();
121  actionsList.addAll(Arrays.asList(superActions));
122 
123  final AbstractFile sourceFile = getLookup().lookup(AbstractFile.class);
124 
125  /*
126  * if this event is derived from an artifact, add actions to view the
127  * source file and a "linked" file, if present.
128  */
129  final BlackboardArtifact artifact = getLookup().lookup(BlackboardArtifact.class);
130  if (artifact != null) {
131  try {
132  AbstractFile linkedfile = findLinked(artifact);
133  if (linkedfile != null) {
134  actionsList.add(ViewFileInTimelineAction.createViewFileAction(linkedfile));
135  }
136  } catch (TskCoreException ex) {
137  LOGGER.log(Level.SEVERE, MessageFormat.format("Error getting linked file from blackboard artifact{0}.", artifact.getArtifactID()), ex); //NON-NLS
138  MessageNotifyUtil.Notify.error(Bundle.EventNode_getAction_errorTitle(), Bundle.EventNode_getAction_linkedFileMessage());
139  }
140 
141  //if this event has associated content, add the action to view the content in the timeline
142  if (null != sourceFile) {
143  actionsList.add(ViewFileInTimelineAction.createViewSourceFileAction(sourceFile));
144  }
145  }
146 
147  //get default actions for the source file
148  final List<Action> factoryActions = DataModelActionsFactory.getActions(sourceFile, artifact != null);
149 
150  actionsList.addAll(factoryActions);
151  return actionsList.toArray(new Action[actionsList.size()]);
152  }
153 
154  @Override
155  public boolean isLeafTypeNode() {
156  return true;
157  }
158 
159  @Override
160  public <T> T accept(DisplayableItemNodeVisitor<T> dinv) {
161  throw new UnsupportedOperationException("Not supported yet."); // NON-NLS
162  }
163 
164  @Override
165  public String getItemType() {
166  return getClass().getName();
167  }
168 
173  final private class TimeProperty extends PropertySupport.ReadWrite<String> {
174 
175  private String value;
176 
177  @Override
178  public boolean canWrite() {
179  return false;
180  }
181 
182  TimeProperty(String name, String displayName, String shortDescription, String value) {
183  super(name, String.class, displayName, shortDescription);
184  setValue("suppressCustomEditor", Boolean.TRUE); // remove the "..." (editing) button NON-NLS
185  this.value = value;
186  TimeLineController.getTimeZone().addListener(timeZone -> {
187  try {
189  } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
190  LOGGER.log(Level.SEVERE, "Unexpected error setting date/time property on EventNode explorer node", ex); //NON-NLS
191  }
192  });
193 
194  }
195 
196  @Override
197  public String getValue() throws IllegalAccessException, InvocationTargetException {
198  return value;
199  }
200 
201  @Override
202  public void setValue(String t) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
203  String oldValue = getValue();
204  value = t;
205  firePropertyChange("time", oldValue, t); // NON-NLS
206  }
207  }
208 
219  public static EventNode createEventNode(final Long eventID, FilteredEventsModel eventsModel) throws TskCoreException, NoCurrentCaseException {
220  /*
221  * Look up the event by id and creata an EventNode with the appropriate
222  * data in the lookup.
223  */
224  final SingleEvent eventById = eventsModel.getEventById(eventID);
225 
226  SleuthkitCase sleuthkitCase = Case.getCurrentCaseThrows().getSleuthkitCase();
227  AbstractFile file = sleuthkitCase.getAbstractFileById(eventById.getFileID());
228 
229  if (eventById.getArtifactID().isPresent()) {
230  BlackboardArtifact blackboardArtifact = sleuthkitCase.getBlackboardArtifact(eventById.getArtifactID().get());
231  return new EventNode(eventById, file, blackboardArtifact);
232  } else {
233  return new EventNode(eventById, file);
234  }
235  }
236 
249  static AbstractFile findLinked(BlackboardArtifact artifact) throws TskCoreException {
250 
251  BlackboardAttribute pathIDAttribute = artifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH_ID));
252 
253  if (pathIDAttribute != null) {
254  long contentID = pathIDAttribute.getValueLong();
255  if (contentID != -1) {
256  return artifact.getSleuthkitCase().getAbstractFileById(contentID);
257  }
258  }
259 
260  return null;
261  }
262 }
static EventNode createEventNode(final Long eventID, FilteredEventsModel eventsModel)
Definition: EventNode.java:219
static ReadOnlyObjectProperty< TimeZone > getTimeZone()
static List< Action > getActions(File file, boolean isArtifactSource)
static ViewFileInTimelineAction createViewSourceFileAction(AbstractFile file)
static void error(String title, String message)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static ViewFileInTimelineAction createViewFileAction(AbstractFile file)

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