Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
ExtractedContent.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-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.datamodel;
20 
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.Comparator;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.logging.Level;
29 import org.openide.nodes.ChildFactory;
30 import org.openide.nodes.Children;
31 import org.openide.nodes.Node;
32 import org.openide.nodes.Sheet;
33 import org.openide.util.NbBundle;
34 import org.openide.util.lookup.Lookups;
64 
69 public class ExtractedContent implements AutopsyVisitableItem {
70 
71  private SleuthkitCase skCase; // set to null after case has been closed
72  public static final String NAME = NbBundle.getMessage(RootNode.class, "ExtractedContentNode.name.text");
73 
75  this.skCase = skCase;
76  }
77 
78  @Override
79  public <T> T accept(AutopsyItemVisitor<T> v) {
80  return v.visit(this);
81  }
82 
84  return skCase;
85  }
86 
87  public class RootNode extends DisplayableItemNode {
88 
89  public RootNode(SleuthkitCase skCase) {
90  super(Children.create(new TypeFactory(), true), Lookups.singleton(NAME));
91  super.setName(NAME);
92  super.setDisplayName(NAME);
93  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/extracted_content.png"); //NON-NLS
94  }
95 
96  @Override
97  public boolean isLeafTypeNode() {
98  return false;
99  }
100 
101  @Override
102  public <T> T accept(DisplayableItemNodeVisitor<T> v) {
103  return v.visit(this);
104  }
105 
106  @Override
107  protected Sheet createSheet() {
108  Sheet s = super.createSheet();
109  Sheet.Set ss = s.get(Sheet.PROPERTIES);
110  if (ss == null) {
111  ss = Sheet.createPropertiesSet();
112  s.put(ss);
113  }
114 
115  ss.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ExtractedContentNode.createSheet.name.name"),
116  NbBundle.getMessage(this.getClass(), "ExtractedContentNode.createSheet.name.displayName"),
117  NbBundle.getMessage(this.getClass(), "ExtractedContentNode.createSheet.name.desc"),
118  NAME));
119  return s;
120  }
121  }
122 
128  private class TypeFactory extends ChildFactory.Detachable<BlackboardArtifact.ARTIFACT_TYPE> {
129  private final ArrayList<BlackboardArtifact.ARTIFACT_TYPE> doNotShow;
130  // maps the artifact type to its child node
131  private final HashMap<BlackboardArtifact.ARTIFACT_TYPE, TypeNode> typeNodeList = new HashMap<>();
132 
133  public TypeFactory() {
134  super();
135 
136  // these are shown in other parts of the UI tree
137  doNotShow = new ArrayList<>();
144  }
145 
146  private final PropertyChangeListener pcl = new PropertyChangeListener() {
147  @Override
148  public void propertyChange(PropertyChangeEvent evt) {
149  String eventType = evt.getPropertyName();
150 
151  if (eventType.equals(IngestManager.IngestModuleEvent.DATA_ADDED.toString())) {
152  final ModuleDataEvent event = (ModuleDataEvent) evt.getOldValue();
153  if (doNotShow.contains(event.getArtifactType()) == false) {
154  refresh(true);
155  }
156  } else if (eventType.equals(IngestManager.IngestJobEvent.COMPLETED.toString())
157  || eventType.equals(IngestManager.IngestJobEvent.CANCELLED.toString())) {
158  refresh(true);
159  }
160  else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) {
161  // case was closed. Remove listeners so that we don't get called with a stale case handle
162  if (evt.getNewValue() == null) {
163  removeNotify();
164  skCase = null;
165  }
166  }
167  }
168  };
169 
170  @Override
171  protected void addNotify() {
175  }
176 
177  @Override
178  protected void removeNotify() {
182  typeNodeList.clear();
183  }
184 
185  @Override
186  protected boolean createKeys(List<BlackboardArtifact.ARTIFACT_TYPE> list) {
187  if (skCase == null) {
188  return false;
189  }
190 
191  try {
193  inUse.removeAll(doNotShow);
194  Collections.sort(inUse,
195  new Comparator<BlackboardArtifact.ARTIFACT_TYPE>() {
196  @Override
198  return a.getDisplayName().compareTo(b.getDisplayName());
199  }
200  });
201  list.addAll(inUse);
202 
203  // the create node method will get called only for new types
204  // refresh the counts if we already created them from a previous update
205  for (BlackboardArtifact.ARTIFACT_TYPE art : inUse) {
206  TypeNode node = typeNodeList.get(art);
207  if (node != null) {
208  node.updateDisplayName();
209  }
210  }
211  } catch (TskCoreException ex) {
212  Logger.getLogger(TypeFactory.class.getName()).log(Level.SEVERE, "Error getting list of artifacts in use: " + ex.getLocalizedMessage()); //NON-NLS
213  return false;
214  }
215  return true;
216  }
217 
218  @Override
220  TypeNode node = new TypeNode(key);
221  typeNodeList.put(key, node);
222  return node;
223  }
224  }
225 
232  public class TypeNode extends DisplayableItemNode {
233 
235  private long childCount = 0;
236 
238  super(Children.create(new ArtifactFactory(type), true), Lookups.singleton(type.getDisplayName()));
239  super.setName(type.getLabel());
240  this.type = type;
241  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/" + getIcon(type)); //NON-NLS
242  updateDisplayName();
243  }
244 
245  final void updateDisplayName() {
246  if (skCase == null) {
247  return;
248  }
249 
250  // NOTE: This completely destroys our lazy-loading ideal
251  // a performance increase might be had by adding a
252  // "getBlackboardArtifactCount()" method to skCase
253  try {
254  this.childCount = skCase.getBlackboardArtifactsTypeCount(type.getTypeID());
255  } catch (TskException ex) {
256  Logger.getLogger(TypeNode.class.getName())
257  .log(Level.WARNING, "Error getting child count", ex); //NON-NLS
258  }
259  super.setDisplayName(type.getDisplayName() + " (" + childCount + ")");
260  }
261 
262  @Override
263  protected Sheet createSheet() {
264  Sheet s = super.createSheet();
265  Sheet.Set ss = s.get(Sheet.PROPERTIES);
266  if (ss == null) {
267  ss = Sheet.createPropertiesSet();
268  s.put(ss);
269  }
270 
271  ss.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ArtifactTypeNode.createSheet.artType.name"),
272  NbBundle.getMessage(this.getClass(), "ArtifactTypeNode.createSheet.artType.displayName"),
273  NbBundle.getMessage(this.getClass(), "ArtifactTypeNode.createSheet.artType.desc"),
274  type.getDisplayName()));
275 
276  ss.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ArtifactTypeNode.createSheet.childCnt.name"),
277  NbBundle.getMessage(this.getClass(), "ArtifactTypeNode.createSheet.childCnt.displayName"),
278  NbBundle.getMessage(this.getClass(), "ArtifactTypeNode.createSheet.childCnt.desc"),
279  childCount));
280 
281  return s;
282  }
283 
284  @Override
285  public <T> T accept(DisplayableItemNodeVisitor<T> v) {
286  return v.visit(this);
287  }
288 
289  // @@@ TODO: Merge with BlackboartArtifactNode.getIcon()
291  switch (type) {
292  case TSK_WEB_BOOKMARK:
293  return "bookmarks.png"; //NON-NLS
294  case TSK_WEB_COOKIE:
295  return "cookies.png"; //NON-NLS
296  case TSK_WEB_HISTORY:
297  return "history.png"; //NON-NLS
298  case TSK_WEB_DOWNLOAD:
299  return "downloads.png"; //NON-NLS
300  case TSK_INSTALLED_PROG:
301  return "programs.png"; //NON-NLS
302  case TSK_RECENT_OBJECT:
303  return "recent_docs.png"; //NON-NLS
304  case TSK_DEVICE_ATTACHED:
305  return "usb_devices.png"; //NON-NLS
306  case TSK_WEB_SEARCH_QUERY:
307  return "searchquery.png"; //NON-NLS
308  case TSK_METADATA_EXIF:
309  return "camera-icon-16.png"; //NON-NLS
310  case TSK_EMAIL_MSG:
311  return "mail-icon-16.png"; //NON-NLS
312  case TSK_CONTACT:
313  return "contact.png"; //NON-NLS
314  case TSK_MESSAGE:
315  return "message.png"; //NON-NLS
316  case TSK_CALLLOG:
317  return "calllog.png"; //NON-NLS
318  case TSK_CALENDAR_ENTRY:
319  return "calendar.png"; //NON-NLS
320  case TSK_SPEED_DIAL_ENTRY:
321  return "speeddialentry.png"; //NON-NLS
322  case TSK_BLUETOOTH_PAIRING:
323  return "bluetooth.png"; //NON-NLS
324  case TSK_GPS_BOOKMARK:
325  return "gpsfav.png"; //NON-NLS
326  case TSK_GPS_LAST_KNOWN_LOCATION:
327  return "gps-lastlocation.png"; //NON-NLS
328  case TSK_GPS_SEARCH:
329  return "gps-search.png"; //NON-NLS
330  case TSK_SERVICE_ACCOUNT:
331  return "account-icon-16.png"; //NON-NLS
332  case TSK_ENCRYPTION_DETECTED:
333  return "encrypted-file.png"; //NON-NLS
334  case TSK_EXT_MISMATCH_DETECTED:
335  return "mismatch-16.png"; //NON-NLS
336  case TSK_OS_INFO:
337  return "computer.png"; //NON-NLS
338 
339  }
340  return "artifact-icon.png"; //NON-NLS
341  }
342 
343  @Override
344  public boolean isLeafTypeNode() {
345  return true;
346  }
347  }
348 
352  private class ArtifactFactory extends ChildFactory.Detachable<BlackboardArtifact> {
353 
355 
357  super();
358  this.type = type;
359  }
360 
361  private final PropertyChangeListener pcl = new PropertyChangeListener() {
362  @Override
363  public void propertyChange(PropertyChangeEvent evt) {
364  String eventType = evt.getPropertyName();
365 
366  if (eventType.equals(IngestManager.IngestModuleEvent.DATA_ADDED.toString())) {
367  final ModuleDataEvent event = (ModuleDataEvent) evt.getOldValue();
368  if (event.getArtifactType() == type) {
369  refresh(true);
370  }
371  } else if (eventType.equals(IngestManager.IngestJobEvent.COMPLETED.toString())
372  || eventType.equals(IngestManager.IngestJobEvent.CANCELLED.toString())) {
373  refresh(true);
374  }
375  }
376  };
377 
378  @Override
379  protected void addNotify() {
382  }
383 
384  @Override
385  protected void removeNotify() {
388  }
389 
390  @Override
391  protected boolean createKeys(List<BlackboardArtifact> list) {
392  if (skCase == null) {
393  return false;
394  }
395 
396  try {
397  List<BlackboardArtifact> arts = skCase.getBlackboardArtifacts(type.getTypeID());
398  list.addAll(arts);
399  } catch (TskException ex) {
400  Logger.getLogger(ArtifactFactory.class.getName()).log(Level.SEVERE, "Couldn't get blackboard artifacts from database", ex); //NON-NLS
401  }
402  return true;
403  }
404 
405  @Override
406  protected Node createNodeForKey(BlackboardArtifact key) {
407  return new BlackboardArtifactNode(key);
408  }
409  }
410 }
void removeIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized IngestManager getInstance()
ArrayList< BlackboardArtifact > getBlackboardArtifacts(int artifactTypeID)
void removeIngestJobEventListener(final PropertyChangeListener listener)
ArrayList< BlackboardArtifact.ARTIFACT_TYPE > getBlackboardArtifactTypesInUse()
void addIngestJobEventListener(final PropertyChangeListener listener)
String getIcon(BlackboardArtifact.ARTIFACT_TYPE type)
final ArrayList< BlackboardArtifact.ARTIFACT_TYPE > doNotShow
static synchronized void removePropertyChangeListener(PropertyChangeListener listener)
Definition: Case.java:837
boolean createKeys(List< BlackboardArtifact.ARTIFACT_TYPE > list)
long getBlackboardArtifactsTypeCount(int artifactTypeID)
final HashMap< BlackboardArtifact.ARTIFACT_TYPE, TypeNode > typeNodeList
void addIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized void addPropertyChangeListener(PropertyChangeListener listener)
Definition: Case.java:833
static Logger getLogger(String name)
Definition: Logger.java:131
Node createNodeForKey(BlackboardArtifact.ARTIFACT_TYPE key)

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.