Autopsy  4.8.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataResultFilterNode.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.directorytree;
20 
21 import java.awt.event.ActionEvent;
22 import java.beans.PropertyVetoException;
23 import java.text.MessageFormat;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.HashSet;
27 import java.util.List;
28 import java.util.logging.Level;
29 import java.util.prefs.PreferenceChangeEvent;
30 import java.util.prefs.PreferenceChangeListener;
31 import javax.swing.AbstractAction;
32 import javax.swing.Action;
33 import org.openide.explorer.ExplorerManager;
34 import org.openide.nodes.AbstractNode;
35 import org.openide.nodes.FilterNode;
36 import org.openide.nodes.Node;
37 import org.openide.nodes.Sheet;
38 import org.openide.util.NbBundle;
39 import org.openide.util.Utilities;
70 import org.sleuthkit.datamodel.AbstractFile;
71 import org.sleuthkit.datamodel.BlackboardArtifact;
72 import org.sleuthkit.datamodel.BlackboardAttribute;
73 import org.sleuthkit.datamodel.Content;
74 import org.sleuthkit.datamodel.DerivedFile;
75 import org.sleuthkit.datamodel.Directory;
76 import org.sleuthkit.datamodel.File;
77 import org.sleuthkit.datamodel.LayoutFile;
78 import org.sleuthkit.datamodel.LocalFile;
79 import org.sleuthkit.datamodel.LocalDirectory;
80 import org.sleuthkit.datamodel.SlackFile;
81 import org.sleuthkit.datamodel.TskData;
82 import org.sleuthkit.datamodel.TskException;
83 import org.sleuthkit.datamodel.VirtualDirectory;
84 import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
85 import org.sleuthkit.datamodel.Report;
86 import org.sleuthkit.datamodel.TskCoreException;
87 
93 public class DataResultFilterNode extends FilterNode {
94 
95  private static final Logger LOGGER = Logger.getLogger(DataResultFilterNode.class.getName());
96 
101 
102  static {
103  UserPreferences.addChangeListener(new PreferenceChangeListener() {
104  @Override
105  public void preferenceChange(PreferenceChangeEvent evt) {
106  switch (evt.getKey()) {
108  filterKnownFromDataSources = UserPreferences.hideKnownFilesInDataSourcesTree();
109  break;
111  filterKnownFromViews = UserPreferences.hideKnownFilesInViewsTree();
112  break;
114  filterSlackFromDataSources = UserPreferences.hideSlackFilesInDataSourcesTree();
115  break;
117  filterSlackFromViews = UserPreferences.hideSlackFilesInViewsTree();
118  break;
119  }
120  }
121  });
122  }
123 
126 
127  private final ExplorerManager sourceEm;
128 
138  public DataResultFilterNode(Node node, ExplorerManager em) {
139  super(node, new DataResultFilterChildren(node, em));
140  this.sourceEm = em;
141  }
142 
148  public void refresh() {
149  if (getOriginal() instanceof InstanceCountNode) {
150  InstanceCountNode innerNode = getLookup().lookup(InstanceCountNode.class);
151  innerNode.refresh();
152  }
153  }
154 
168  private DataResultFilterNode(Node node, ExplorerManager em, boolean filterKnown, boolean filterSlack) {
169  super(node, new DataResultFilterChildren(node, em, filterKnown, filterSlack));
170  this.sourceEm = em;
171  }
172 
181  @Override
182  public Action[] getActions(boolean popup) {
183 
184  List<Action> actions = new ArrayList<>();
185 
186  final DisplayableItemNode originalNode = (DisplayableItemNode) this.getOriginal();
187  List<Action> accept = originalNode.accept(getActionsDIV);
188  if (accept != null) {
189  actions.addAll(accept);
190  }
191 
192  //actions.add(new IndexContentFilesAction(nodeContent, "Index"));
193  return actions.toArray(new Action[actions.size()]);
194  }
195 
202  @Override
203  public Action getPreferredAction() {
204  final Node original = this.getOriginal();
205  // Once had a org.openide.nodes.ChildFactory$WaitFilterNode passed in
206  if ((original instanceof DisplayableItemNode) == false) {
207  return null;
208  }
209 
210  final DisplayableItemNode originalNode = (DisplayableItemNode) this.getOriginal();
211  return originalNode.accept(getPreferredActionsDIV);
212  }
213 
214  @Override
215  public Node.PropertySet[] getPropertySets() {
216  Node.PropertySet[] propertySets = super.getPropertySets();
217 
218  for (int i = 0; i < propertySets.length; i++) {
219  Node.PropertySet ps = propertySets[i];
220 
221  if (ps.getName().equals(Sheet.PROPERTIES)) {
222  Sheet.Set newPs = new Sheet.Set();
223  newPs.setName(ps.getName());
224  newPs.setDisplayName(ps.getDisplayName());
225  newPs.setShortDescription(ps.getShortDescription());
226 
227  newPs.put(ps.getProperties());
228  if (newPs.remove(AbstractFsContentNode.HIDE_PARENT) != null) {
229  newPs.remove(AbstractFilePropertyType.LOCATION.toString());
230  }
231  propertySets[i] = newPs;
232  }
233  }
234 
235  return propertySets;
236  }
237 
249  @Override
250  public String getDisplayName() {
251  final Node orig = getOriginal();
252  String name = orig.getDisplayName();
253  if ((orig instanceof BlackboardArtifactNode)) {
254  name = ((BlackboardArtifactNode) orig).getSourceName();
255  }
256  return name;
257  }
258 
265  public void setChildNodeSelectionInfo(NodeSelectionInfo selectedChildNodeInfo) {
266  if (getOriginal() instanceof DisplayableItemNode) {
267  ((DisplayableItemNode) getOriginal()).setChildNodeSelectionInfo(selectedChildNodeInfo);
268  }
269  }
270 
279  if (getOriginal() instanceof DisplayableItemNode) {
280  return ((DisplayableItemNode) getOriginal()).getChildNodeSelectionInfo();
281  } else {
282  return null;
283  }
284  }
285 
291  private static class DataResultFilterChildren extends FilterNode.Children {
292 
293  private final ExplorerManager sourceEm;
294 
295  private boolean filterKnown;
296  private boolean filterSlack;
297  private boolean filterArtifacts; // display message artifacts in the DataSource subtree
298 
302  private DataResultFilterChildren(Node arg, ExplorerManager sourceEm) {
303  super(arg);
304 
305  this.filterArtifacts = false;
306  switch (SelectionContext.getSelectionContext(arg)) {
307  case DATA_SOURCES:
308  filterSlack = filterSlackFromDataSources;
309  filterKnown = filterKnownFromDataSources;
310  filterArtifacts = true;
311  break;
312  case VIEWS:
313  filterSlack = filterSlackFromViews;
314  filterKnown = filterKnownFromViews;
315  break;
316  default:
317  filterSlack = false;
318  filterKnown = false;
319  break;
320  }
321  this.sourceEm = sourceEm;
322  }
323 
324  private DataResultFilterChildren(Node arg, ExplorerManager sourceEm, boolean filterKnown, boolean filterSlack) {
325  super(arg);
326  this.filterKnown = filterKnown;
327  this.filterSlack = filterSlack;
328  this.sourceEm = sourceEm;
329  }
330 
331  @Override
332  protected Node[] createNodes(Node key) {
333  AbstractFile file = key.getLookup().lookup(AbstractFile.class);
334  if (file != null) {
335  if (filterKnown && (file.getKnown() == TskData.FileKnown.KNOWN)) {
336  // Filter out child nodes that represent known files
337  return new Node[]{};
338  }
339  if (filterSlack && file.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)) {
340  // Filter out child nodes that represent slack files
341  return new Node[]{};
342  }
343  }
344 
345  // filter out all non-message artifacts, if displaying the results from the Data Source tree
346  BlackboardArtifact art = key.getLookup().lookup(BlackboardArtifact.class);
347  if (art != null
348  && filterArtifacts
349  && art.getArtifactTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID()
350  && art.getArtifactTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE.getTypeID()) {
351  return new Node[]{};
352  }
353 
354  return new Node[]{new DataResultFilterNode(key, sourceEm, filterKnown, filterSlack)};
355  }
356 
357  }
358 
359  @NbBundle.Messages("DataResultFilterNode.viewSourceArtifact.text=View Source Result")
364  private static class GetPopupActionsDisplayableItemNodeVisitor extends DisplayableItemNodeVisitor.Default<List<Action>> {
365 
366  @Override
367  public List<Action> visit(BlackboardArtifactNode ban) {
368  //set up actions for artifact node based on its Content object
369  //TODO all actions need to be consolidated in single place!
370  //they should be set in individual Node subclass and using a utility to get Actions per Content sub-type
371  // TODO UPDATE: There is now a DataModelActionsFactory utility;
372 
373  List<Action> actionsList = new ArrayList<>();
374 
375  //merge predefined specific node actions if bban subclasses have their own
376  for (Action a : ban.getActions(true)) {
377  actionsList.add(a);
378  }
379  BlackboardArtifact ba = ban.getLookup().lookup(BlackboardArtifact.class);
380  final int artifactTypeID = ba.getArtifactTypeID();
381 
382  if (artifactTypeID == BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT.getTypeID()
383  || artifactTypeID == BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()) {
384  if (ban.getLookup().lookup(AbstractFile.class) != null) {
385  // We only want the "View File in Directory" actions if we have a file...it is
386  // possible that we have a keyword hit on a Report.
387  actionsList.add(new ViewContextAction(
388  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewFileInDir.text"), ban));
389  }
390  } else if (artifactTypeID == BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT.getTypeID()) {
391  //action to go to the source artifact
392  actionsList.add(new ViewSourceArtifactAction(DataResultFilterNode_viewSourceArtifact_text(), ba));
393  // action to go to the source file of the artifact
394  actionsList.add(new ViewContextAction(
395  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewSrcFileInDir.text"), ban));
396  } else {
397  // if the artifact links to another file, add an action to go to
398  // that file
399  Content c = findLinked(ban);
400  if (c != null) {
401  actionsList.add(new ViewContextAction(
402  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewFileInDir.text"), c));
403  }
404  // action to go to the source file of the artifact
405  // action to go to the source file of the artifact
406  Content fileContent = ban.getLookup().lookup(AbstractFile.class);
407  if (fileContent == null) {
408  Content content = ban.getLookup().lookup(Content.class);
409  actionsList.add(new ViewContextAction("View Source Content in Directory", content));
410  } else {
411  actionsList.add(new ViewContextAction(
412  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewSrcFileInDir.text"), ban));
413  }
414  }
415  Content c = ban.getLookup().lookup(File.class);
416  Node n = null;
417  if (c != null) {
418  n = new FileNode((AbstractFile) c);
419  } else if ((c = ban.getLookup().lookup(Directory.class)) != null) {
420  n = new DirectoryNode((Directory) c);
421  } else if ((c = ban.getLookup().lookup(VirtualDirectory.class)) != null) {
422  n = new VirtualDirectoryNode((VirtualDirectory) c);
423  } else if ((c = ban.getLookup().lookup(LocalDirectory.class)) != null) {
424  n = new LocalDirectoryNode((LocalDirectory) c);
425  } else if ((c = ban.getLookup().lookup(LayoutFile.class)) != null) {
426  n = new LayoutFileNode((LayoutFile) c);
427  } else if ((c = ban.getLookup().lookup(LocalFile.class)) != null
428  || (c = ban.getLookup().lookup(DerivedFile.class)) != null) {
429  n = new LocalFileNode((AbstractFile) c);
430  if (FileTypeExtensions.getArchiveExtensions().contains("." + ((AbstractFile) c).getNameExtension().toLowerCase())) {
431  try {
432  if (c.getArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_DETECTED).size() > 0) {
433  actionsList.add(new ExtractArchiveWithPasswordAction((AbstractFile) c));
434  }
435  } catch (TskCoreException ex) {
436  LOGGER.log(Level.WARNING, "Unable to add unzip with password action to context menus", ex);
437  }
438  }
439  } else if ((c = ban.getLookup().lookup(SlackFile.class)) != null) {
440  n = new SlackFileNode((SlackFile) c);
441  } else if ((c = ban.getLookup().lookup(Report.class)) != null) {
442  actionsList.addAll(DataModelActionsFactory.getActions(c, false));
443  }
444  if (n != null) {
445  actionsList.add(null); // creates a menu separator
446  actionsList.add(new NewWindowViewAction(
447  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewInNewWin.text"), n));
448  actionsList.add(new ExternalViewerAction(
449  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.openInExtViewer.text"), n));
450  actionsList.add(null); // creates a menu separator
451  actionsList.add(ExtractAction.getInstance());
452  actionsList.add(null); // creates a menu separator
453  actionsList.add(AddContentTagAction.getInstance());
454  actionsList.add(AddBlackboardArtifactTagAction.getInstance());
455 
456  final Collection<AbstractFile> selectedFilesList
457  = new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
458  if (selectedFilesList.size() == 1) {
459  actionsList.add(DeleteFileContentTagAction.getInstance());
460  }
461  } else {
462  // There's no specific file associated with the artifact, but
463  // we can still tag the artifact itself
464  actionsList.add(null);
465  actionsList.add(AddBlackboardArtifactTagAction.getInstance());
466  }
467 
468  final Collection<BlackboardArtifact> selectedArtifactsList
469  = new HashSet<>(Utilities.actionsGlobalContext().lookupAll(BlackboardArtifact.class));
470  if (selectedArtifactsList.size() == 1) {
472  }
473 
474  if (n != null) {
475  actionsList.addAll(ContextMenuExtensionPoint.getActions());
476  }
477 
478  return actionsList;
479  }
480 
481  @Override
482  public List<Action> visit(Reports.ReportsListNode ditem) {
483  // The base class Action is "Collapse All", inappropriate.
484  return null;
485  }
486 
487  @Override
488  public List<Action> visit(FileTypesNode fileTypes) {
489  return defaultVisit(fileTypes);
490  }
491 
492  @Override
493  protected List<Action> defaultVisit(DisplayableItemNode ditem) {
494  //preserve the default node's actions
495  List<Action> actions = new ArrayList<>();
496 
497  for (Action action : ditem.getActions(true)) {
498  actions.add(action);
499  }
500 
501  return actions;
502  }
503 
504  private Content findLinked(BlackboardArtifactNode ba) {
505  BlackboardArtifact art = ba.getLookup().lookup(BlackboardArtifact.class);
506  Content c = null;
507  try {
508  for (BlackboardAttribute attr : art.getAttributes()) {
509  if (attr.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH_ID.getTypeID()) {
510  switch (attr.getAttributeType().getValueType()) {
511  case INTEGER:
512  int i = attr.getValueInt();
513  if (i != -1) {
514  c = art.getSleuthkitCase().getContentById(i);
515  }
516  break;
517  case LONG:
518  long l = attr.getValueLong();
519  if (l != -1) {
520  c = art.getSleuthkitCase().getContentById(l);
521  }
522  break;
523  }
524  }
525  }
526  } catch (TskException ex) {
527  Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Error getting linked file", ex); //NON-NLS
528  }
529  return c;
530  }
531 
532  }
533 
534  /*
535  * Action for double-click / preferred action on nodes.
536  */
537  private class GetPreferredActionsDisplayableItemNodeVisitor extends DisplayableItemNodeVisitor.Default<AbstractAction> {
538 
539  @Override
540  public AbstractAction visit(InstanceCountNode icn) {
541  return null;
542  }
543 
544  @Override
545  public AbstractAction visit(CommonAttributeValueNode md5n){
546  return null;
547  }
548 
549  @Override
550  public AbstractAction visit(CaseDBCommonAttributeInstanceNode fin){
551  return null;
552  }
553 
554  @Override
555  public AbstractAction visit(CentralRepoCommonAttributeInstanceNode iccan){
556  return null;
557  }
558 
559  @Override
560  public AbstractAction visit(BlackboardArtifactNode ban) {
561  BlackboardArtifact artifact = ban.getArtifact();
562  try {
563  if ((artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID())
564  || (artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_MESSAGE.getTypeID())) {
565  if (artifact.hasChildren()) {
566  return openChild(ban);
567  }
568  }
569  } catch (TskCoreException ex) {
570  LOGGER.log(Level.SEVERE, MessageFormat.format("Error getting children from blackboard artifact{0}.", artifact.getArtifactID()), ex); //NON-NLS
571  }
572  return new ViewContextAction(
573  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewInDir.text"), ban);
574  }
575 
576  @Override
577  public AbstractAction visit(DirectoryNode dn) {
578  if (dn.getDisplayName().equals(DirectoryNode.DOTDOTDIR)) {
579  return openParent(dn);
580  } else if (dn.getDisplayName().equals(DirectoryNode.DOTDIR) == false) {
581  return openChild(dn);
582  } else {
583  return null;
584  }
585  }
586 
587  @Override
588  public AbstractAction visit(FileNode fn) {
589  if (fn.hasContentChildren()) {
590  return openChild(fn);
591  } else {
592  return null;
593  }
594  }
595 
596  @Override
597  public AbstractAction visit(LocalFileNode dfn) {
598  if (dfn.hasContentChildren()) {
599  return openChild(dfn);
600  } else {
601  return null;
602  }
603  }
604 
605  @Override
606  public AbstractAction visit(Reports.ReportNode reportNode) {
607  return reportNode.getPreferredAction();
608  }
609 
610  @Override
611  protected AbstractAction defaultVisit(DisplayableItemNode c) {
612  return openChild(c);
613  }
614 
615  @Override
616  public AbstractAction visit(FileTypesNode fileTypes) {
617  return openChild(fileTypes);
618  }
619 
628  private AbstractAction openChild(final AbstractNode dataModelNode) {
629  // get the current selection from the directory tree explorer manager,
630  // which is a DirectoryTreeFilterNode. One of that node's children
631  // is a DirectoryTreeFilterNode that wraps the dataModelNode. We need
632  // to set that wrapped node as the selection and root context of the
633  // directory tree explorer manager (sourceEm)
634  final Node currentSelectionInDirectoryTree = sourceEm.getSelectedNodes()[0];
635 
636  return new AbstractAction() {
637  @Override
638  public void actionPerformed(ActionEvent e) {
639  if (currentSelectionInDirectoryTree != null) {
640  // Find the filter version of the passed in dataModelNode.
641  final org.openide.nodes.Children children = currentSelectionInDirectoryTree.getChildren();
642  // This call could break if the DirectoryTree is re-implemented with lazy ChildFactory objects.
643  Node newSelection = children.findChild(dataModelNode.getName());
644 
645  /*
646  * We got null here when we were viewing a ZIP file in
647  * the Views -> Archives area and double clicking on it
648  * got to this code. It tried to find the child in the
649  * tree and didn't find it. An exception was then thrown
650  * from setting the selected node to be null.
651  */
652  if (newSelection != null) {
653  try {
654  sourceEm.setExploredContextAndSelection(newSelection, new Node[]{newSelection});
655  } catch (PropertyVetoException ex) {
656  Logger logger = Logger.getLogger(DataResultFilterNode.class.getName());
657  logger.log(Level.WARNING, "Error: can't open the selected directory.", ex); //NON-NLS
658  }
659  }
660  }
661  }
662  };
663  }
664 
673  private AbstractAction openParent(AbstractNode node) {
674  // @@@ Why do we ignore node?
675  Node[] selectedFilterNodes = sourceEm.getSelectedNodes();
676  Node selectedFilterNode = selectedFilterNodes[0];
677  final Node parentNode = selectedFilterNode.getParentNode();
678 
679  return new AbstractAction() {
680  @Override
681  public void actionPerformed(ActionEvent e) {
682  try {
683  sourceEm.setSelectedNodes(new Node[]{parentNode});
684  } catch (PropertyVetoException ex) {
685  Logger logger = Logger.getLogger(DataResultFilterNode.class.getName());
686  logger.log(Level.WARNING, "Error: can't open the parent directory.", ex); //NON-NLS
687  }
688  }
689  };
690  }
691  }
692 }
abstract< T > T accept(DisplayableItemNodeVisitor< T > visitor)
static List< Action > getActions(File file, boolean isArtifactSource)
static final DisplayableItemNodeVisitor< List< Action > > getActionsDIV
static synchronized AddBlackboardArtifactTagAction getInstance()
static synchronized DeleteFileBlackboardArtifactTagAction getInstance()
DataResultFilterChildren(Node arg, ExplorerManager sourceEm, boolean filterKnown, boolean filterSlack)
static synchronized ExtractAction getInstance()
void setChildNodeSelectionInfo(NodeSelectionInfo selectedChildNodeInfo)
static synchronized DeleteFileContentTagAction getInstance()
final DisplayableItemNodeVisitor< AbstractAction > getPreferredActionsDIV
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static void addChangeListener(PreferenceChangeListener listener)
static synchronized AddContentTagAction getInstance()
DataResultFilterNode(Node node, ExplorerManager em, boolean filterKnown, boolean filterSlack)

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