Autopsy  4.13.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-2019 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 javax.swing.AbstractAction;
30 import javax.swing.Action;
31 import org.openide.explorer.ExplorerManager;
32 import org.openide.nodes.AbstractNode;
33 import org.openide.nodes.FilterNode;
34 import org.openide.nodes.Node;
35 import org.openide.nodes.Sheet;
36 import org.openide.util.NbBundle;
37 import org.openide.util.Utilities;
68 import org.sleuthkit.datamodel.AbstractFile;
69 import org.sleuthkit.datamodel.BlackboardArtifact;
70 import org.sleuthkit.datamodel.BlackboardAttribute;
71 import org.sleuthkit.datamodel.Content;
72 import org.sleuthkit.datamodel.DerivedFile;
73 import org.sleuthkit.datamodel.Directory;
74 import org.sleuthkit.datamodel.File;
75 import org.sleuthkit.datamodel.LayoutFile;
76 import org.sleuthkit.datamodel.LocalFile;
77 import org.sleuthkit.datamodel.LocalDirectory;
78 import org.sleuthkit.datamodel.SlackFile;
79 import org.sleuthkit.datamodel.TskException;
80 import org.sleuthkit.datamodel.VirtualDirectory;
81 import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
82 import org.sleuthkit.datamodel.Report;
83 import org.sleuthkit.datamodel.TskCoreException;
84 
90 public class DataResultFilterNode extends FilterNode {
91 
92  private static final Logger LOGGER = Logger.getLogger(DataResultFilterNode.class.getName());
93 
96 
97  // Assumptions are made in GetPreferredActionsDisplayableItemNodeVisitor that
98  // sourceEm is the directory tree explorer manager.
99  private final ExplorerManager sourceEm;
100 
108  public DataResultFilterNode(Node node) {
109  this(node, null);
110  }
111 
121  public DataResultFilterNode(Node node, ExplorerManager em) {
122  super(node, new DataResultFilterChildren(node, em));
123  this.sourceEm = em;
124  }
125 
134  @Override
135  public Action[] getActions(boolean popup) {
136 
137  List<Action> actions = new ArrayList<>();
138  if (this.getOriginal() instanceof DisplayableItemNode) {
139  final DisplayableItemNode originalNode = (DisplayableItemNode) this.getOriginal();
140  List<Action> accept = originalNode.accept(getActionsDIV);
141  if (accept != null) {
142  actions.addAll(accept);
143  }
144  }
145 
146  //actions.add(new IndexContentFilesAction(nodeContent, "Index"));
147  return actions.toArray(new Action[actions.size()]);
148  }
149 
156  @Override
157  public Action getPreferredAction() {
158  final Node original = this.getOriginal();
159  // Once had a org.openide.nodes.ChildFactory$WaitFilterNode passed in
160  if ((original instanceof DisplayableItemNode) == false) {
161  return null;
162  }
163 
164  final DisplayableItemNode originalNode = (DisplayableItemNode) this.getOriginal();
165  return originalNode.accept(getPreferredActionsDIV);
166  }
167 
168  @Override
169  public Node.PropertySet[] getPropertySets() {
170  Node.PropertySet[] propertySets = super.getPropertySets();
171 
172  for (int i = 0; i < propertySets.length; i++) {
173  Node.PropertySet ps = propertySets[i];
174 
175  if (ps.getName().equals(Sheet.PROPERTIES)) {
176  Sheet.Set newPs = new Sheet.Set();
177  newPs.setName(ps.getName());
178  newPs.setDisplayName(ps.getDisplayName());
179  newPs.setShortDescription(ps.getShortDescription());
180 
181  newPs.put(ps.getProperties());
182  newPs.remove(AbstractFsContentNode.HIDE_PARENT);
183  propertySets[i] = newPs;
184  }
185  }
186 
187  return propertySets;
188  }
189 
201  @Override
202  public String getDisplayName() {
203  final Node orig = getOriginal();
204  String name = orig.getDisplayName();
205  if ((orig instanceof BlackboardArtifactNode)) {
206  name = ((BlackboardArtifactNode) orig).getSourceName();
207  }
208  return name;
209  }
210 
217  public void setChildNodeSelectionInfo(NodeSelectionInfo selectedChildNodeInfo) {
218  if (getOriginal() instanceof DisplayableItemNode) {
219  ((DisplayableItemNode) getOriginal()).setChildNodeSelectionInfo(selectedChildNodeInfo);
220  }
221  }
222 
231  if (getOriginal() instanceof DisplayableItemNode) {
232  return ((DisplayableItemNode) getOriginal()).getChildNodeSelectionInfo();
233  } else {
234  return null;
235  }
236  }
237 
243  private static class DataResultFilterChildren extends FilterNode.Children {
244 
245  private final ExplorerManager sourceEm;
246  private final boolean filterArtifacts; // display message artifacts in the DataSource subtree
247 
251  private DataResultFilterChildren(Node arg, ExplorerManager sourceEm) {
252  super(arg);
253 
254  filterArtifacts = SelectionContext.getSelectionContext(arg).equals(SelectionContext.DATA_SOURCES);
255 
256  this.sourceEm = sourceEm;
257  }
258 
259  @Override
260  protected Node[] createNodes(Node key) {
261  // if displaying the results from the Data Source tree
262  // filter out artifacts
263 
264  // In older versions of Autopsy, attachments were children of email/message artifacts
265  // and hence email/messages with attachments are shown in the tree data source tree,
266  BlackboardArtifact art = key.getLookup().lookup(BlackboardArtifact.class);
267  if (art != null && filterArtifacts
268  && ((FilterNodeUtils.showMessagesInDatasourceTree() == false)
269  || (FilterNodeUtils.showMessagesInDatasourceTree()
270  && art.getArtifactTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID()
271  && art.getArtifactTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE.getTypeID()))) {
272  return new Node[]{};
273  }
274 
275  return new Node[]{new DataResultFilterNode(key, sourceEm)};
276  }
277  }
278 
279  @NbBundle.Messages("DataResultFilterNode.viewSourceArtifact.text=View Source Result")
284  private static class GetPopupActionsDisplayableItemNodeVisitor extends DisplayableItemNodeVisitor.Default<List<Action>> {
285 
286  @Override
287  public List<Action> visit(BlackboardArtifactNode ban) {
288  //set up actions for artifact node based on its Content object
289  //TODO all actions need to be consolidated in single place!
290  //they should be set in individual Node subclass and using a utility to get Actions per Content sub-type
291  // TODO UPDATE: There is now a DataModelActionsFactory utility;
292 
293  List<Action> actionsList = new ArrayList<>();
294 
295  //merge predefined specific node actions if bban subclasses have their own
296  for (Action a : ban.getActions(true)) {
297  actionsList.add(a);
298  }
299 
300  //Add seperator between the decorated actions and the actions from the node itself.
301  actionsList.add(null);
302  BlackboardArtifact ba = ban.getLookup().lookup(BlackboardArtifact.class);
303  final int artifactTypeID = ba.getArtifactTypeID();
304 
305  if (artifactTypeID == BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT.getTypeID()
306  || artifactTypeID == BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()) {
307  if (ban.getLookup().lookup(AbstractFile.class) != null) {
308  // We only want the "View File in Directory" actions if we have a file...it is
309  // possible that we have a keyword hit on a Report.
310  actionsList.add(new ViewContextAction(
311  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewFileInDir.text"), ban));
312  }
313  } else if (artifactTypeID == BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT.getTypeID()) {
314  //action to go to the source artifact
315  actionsList.add(new ViewSourceArtifactAction(DataResultFilterNode_viewSourceArtifact_text(), ba));
316  // action to go to the source file of the artifact
317  actionsList.add(new ViewContextAction(
318  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewSrcFileInDir.text"), ban));
319  } else {
320  // if the artifact links to another file, add an action to go to
321  // that file
322  Content c = findLinked(ban);
323  if (c != null) {
324  actionsList.add(new ViewContextAction(
325  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewFileInDir.text"), c));
326  }
327  // action to go to the source file of the artifact
328  // action to go to the source file of the artifact
329  Content fileContent = ban.getLookup().lookup(AbstractFile.class);
330  if (fileContent == null) {
331  Content content = ban.getLookup().lookup(Content.class);
332  actionsList.add(new ViewContextAction("View Source Content in Directory", content));
333  } else {
334  actionsList.add(new ViewContextAction(
335  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewSrcFileInDir.text"), ban));
336  }
337  }
338  Content c = ban.getLookup().lookup(File.class);
339  Node n = null;
340  if (c != null) {
341  n = new FileNode((AbstractFile) c);
342  } else if ((c = ban.getLookup().lookup(Directory.class)) != null) {
343  n = new DirectoryNode((Directory) c);
344  } else if ((c = ban.getLookup().lookup(VirtualDirectory.class)) != null) {
345  n = new VirtualDirectoryNode((VirtualDirectory) c);
346  } else if ((c = ban.getLookup().lookup(LocalDirectory.class)) != null) {
347  n = new LocalDirectoryNode((LocalDirectory) c);
348  } else if ((c = ban.getLookup().lookup(LayoutFile.class)) != null) {
349  n = new LayoutFileNode((LayoutFile) c);
350  } else if ((c = ban.getLookup().lookup(LocalFile.class)) != null
351  || (c = ban.getLookup().lookup(DerivedFile.class)) != null) {
352  n = new LocalFileNode((AbstractFile) c);
353  if (FileTypeExtensions.getArchiveExtensions().contains("." + ((AbstractFile) c).getNameExtension().toLowerCase())) {
354  try {
355  if (c.getArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_DETECTED).size() > 0) {
356  actionsList.add(new ExtractArchiveWithPasswordAction((AbstractFile) c));
357  }
358  } catch (TskCoreException ex) {
359  LOGGER.log(Level.WARNING, "Unable to add unzip with password action to context menus", ex);
360  }
361  }
362  } else if ((c = ban.getLookup().lookup(SlackFile.class)) != null) {
363  n = new SlackFileNode((SlackFile) c);
364  } else if ((c = ban.getLookup().lookup(Report.class)) != null) {
365  actionsList.addAll(DataModelActionsFactory.getActions(c, false));
366  }
367  if (n != null) {
368  final Collection<AbstractFile> selectedFilesList
369  = new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
370  actionsList.add(null); // creates a menu separator
371  actionsList.add(new NewWindowViewAction(
372  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewInNewWin.text"), n));
373  if (selectedFilesList.size() == 1) {
374  actionsList.add(new ExternalViewerAction(
375  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.openInExtViewer.text"), n));
376  } else {
377  actionsList.add(ExternalViewerShortcutAction.getInstance());
378  }
379  actionsList.add(null); // creates a menu separator
380  actionsList.add(ExtractAction.getInstance());
381  actionsList.add(ExportCSVAction.getInstance());
382  actionsList.add(null); // creates a menu separator
383  actionsList.add(AddContentTagAction.getInstance());
384  actionsList.add(AddBlackboardArtifactTagAction.getInstance());
385 
386  if (selectedFilesList.size() == 1) {
387  actionsList.add(DeleteFileContentTagAction.getInstance());
388  }
389  } else {
390  // There's no specific file associated with the artifact, but
391  // we can still tag the artifact itself
392  actionsList.add(null);
393  actionsList.add(AddBlackboardArtifactTagAction.getInstance());
394  }
395 
396  final Collection<BlackboardArtifact> selectedArtifactsList
397  = new HashSet<>(Utilities.actionsGlobalContext().lookupAll(BlackboardArtifact.class));
398  if (selectedArtifactsList.size() == 1) {
400  }
401 
402  if (n != null) {
403  actionsList.addAll(ContextMenuExtensionPoint.getActions());
404  }
405 
406  return actionsList;
407  }
408 
409  @Override
410  public List<Action> visit(Reports.ReportsListNode ditem) {
411  // The base class Action is "Collapse All", inappropriate.
412  return null;
413  }
414 
415  @Override
416  public List<Action> visit(FileTypesNode fileTypes) {
417  return defaultVisit(fileTypes);
418  }
419 
420  @Override
421  protected List<Action> defaultVisit(DisplayableItemNode ditem) {
422  //preserve the default node's actions
423  List<Action> actions = new ArrayList<>();
424 
425  for (Action action : ditem.getActions(true)) {
426  actions.add(action);
427  }
428 
429  return actions;
430  }
431 
432  private Content findLinked(BlackboardArtifactNode ba) {
433  BlackboardArtifact art = ba.getLookup().lookup(BlackboardArtifact.class);
434  Content c = null;
435  try {
436  for (BlackboardAttribute attr : art.getAttributes()) {
437  if (attr.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH_ID.getTypeID()) {
438  switch (attr.getAttributeType().getValueType()) {
439  case INTEGER:
440  int i = attr.getValueInt();
441  if (i != -1) {
442  c = art.getSleuthkitCase().getContentById(i);
443  }
444  break;
445  case LONG:
446  long l = attr.getValueLong();
447  if (l != -1) {
448  c = art.getSleuthkitCase().getContentById(l);
449  }
450  break;
451  }
452  }
453  }
454  } catch (TskException ex) {
455  Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Error getting linked file", ex); //NON-NLS
456  }
457  return c;
458  }
459 
460  }
461 
462  /*
463  * Action for double-click / preferred action on nodes.
464  */
465  private class GetPreferredActionsDisplayableItemNodeVisitor extends DisplayableItemNodeVisitor.Default<AbstractAction> {
466 
467  @Override
468  public AbstractAction visit(InstanceCountNode icn) {
469  return null;
470  }
471 
472  @Override
473  public AbstractAction visit(InstanceCaseNode icn) {
474  return null;
475  }
476 
477  @Override
478  public AbstractAction visit(InstanceDataSourceNode icn) {
479  return null;
480  }
481 
482  @Override
483  public AbstractAction visit(CommonAttributeValueNode md5n) {
484  return null;
485  }
486 
487  @Override
488  public AbstractAction visit(CaseDBCommonAttributeInstanceNode fin) {
489  return null;
490  }
491 
492  @Override
493  public AbstractAction visit(CentralRepoCommonAttributeInstanceNode iccan) {
494  return null;
495  }
496 
497  @Override
498  public AbstractAction visit(BlackboardArtifactNode ban) {
499 
500  Action preferredAction = ban.getPreferredAction();
501  if(preferredAction instanceof AbstractAction) {
502  return (AbstractAction) preferredAction;
503  }
504 
505  BlackboardArtifact artifact = ban.getArtifact();
506  try {
507  if ((artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID())
508  || (artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_MESSAGE.getTypeID())) {
509  if (artifact.hasChildren()) {
510  return openChild(ban);
511  }
512  }
513  } catch (TskCoreException ex) {
514  LOGGER.log(Level.SEVERE, MessageFormat.format("Error getting children from blackboard artifact{0}.", artifact.getArtifactID()), ex); //NON-NLS
515  }
516  return new ViewContextAction(
517  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewInDir.text"), ban);
518  }
519 
520  @Override
521  public AbstractAction visit(DirectoryNode dn) {
522  if (dn.getDisplayName().equals(DirectoryNode.DOTDOTDIR)) {
523  return openParent(dn);
524  } else if (dn.getDisplayName().equals(DirectoryNode.DOTDIR) == false) {
525  return openChild(dn);
526  } else {
527  return null;
528  }
529  }
530 
531  @Override
532  public AbstractAction visit(FileNode fn) {
533  if (fn.hasContentChildren()) {
534  return openChild(fn);
535  } else {
536  return null;
537  }
538  }
539 
540  @Override
541  public AbstractAction visit(LocalFileNode dfn) {
542  if (dfn.hasContentChildren()) {
543  return openChild(dfn);
544  } else {
545  return null;
546  }
547  }
548 
549  @Override
550  public AbstractAction visit(Reports.ReportNode reportNode) {
551  return reportNode.getPreferredAction();
552  }
553 
554  @Override
555  protected AbstractAction defaultVisit(DisplayableItemNode c) {
556  return openChild(c);
557  }
558 
559  @Override
560  public AbstractAction visit(FileTypesNode fileTypes) {
561  return openChild(fileTypes);
562  }
563 
572  private AbstractAction openChild(final AbstractNode dataModelNode) {
573  // get the current selection from the directory tree explorer manager,
574  // which is a DirectoryTreeFilterNode. One of that node's children
575  // is a DirectoryTreeFilterNode that wraps the dataModelNode. We need
576  // to set that wrapped node as the selection and root context of the
577  // directory tree explorer manager (sourceEm)
578  if(sourceEm == null || sourceEm.getSelectedNodes().length == 0) {
579  return null;
580  }
581  final Node currentSelectionInDirectoryTree = sourceEm.getSelectedNodes()[0];
582 
583  return new AbstractAction() {
584  @Override
585  public void actionPerformed(ActionEvent e) {
586  if (currentSelectionInDirectoryTree != null) {
587  // Find the filter version of the passed in dataModelNode.
588  final org.openide.nodes.Children children = currentSelectionInDirectoryTree.getChildren();
589  // This call could break if the DirectoryTree is re-implemented with lazy ChildFactory objects.
590  Node newSelection = children.findChild(dataModelNode.getName());
591 
592  /*
593  * We got null here when we were viewing a ZIP file in
594  * the Views -> Archives area and double clicking on it
595  * got to this code. It tried to find the child in the
596  * tree and didn't find it. An exception was then thrown
597  * from setting the selected node to be null.
598  */
599  if (newSelection != null) {
600  try {
601  sourceEm.setExploredContextAndSelection(newSelection, new Node[]{newSelection});
602  } catch (PropertyVetoException ex) {
603  Logger logger = Logger.getLogger(DataResultFilterNode.class.getName());
604  logger.log(Level.WARNING, "Error: can't open the selected directory.", ex); //NON-NLS
605  }
606  }
607  }
608  }
609  };
610  }
611 
620  private AbstractAction openParent(AbstractNode node) {
621  if(sourceEm == null) {
622  return null;
623  }
624  // @@@ Why do we ignore node?
625  Node[] selectedFilterNodes = sourceEm.getSelectedNodes();
626  Node selectedFilterNode = selectedFilterNodes[0];
627  final Node parentNode = selectedFilterNode.getParentNode();
628 
629  return new AbstractAction() {
630  @Override
631  public void actionPerformed(ActionEvent e) {
632  try {
633  sourceEm.setSelectedNodes(new Node[]{parentNode});
634  } catch (PropertyVetoException ex) {
635  Logger logger = Logger.getLogger(DataResultFilterNode.class.getName());
636  logger.log(Level.WARNING, "Error: can't open the parent directory.", ex); //NON-NLS
637  }
638  }
639  };
640  }
641  }
642 }
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()
static synchronized ExportCSVAction getInstance()
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 synchronized AddContentTagAction getInstance()

Copyright © 2012-2019 Basis Technology. Generated on: Tue Jan 7 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.