Autopsy  4.14.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 2012-2020 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 
196  public void setChildNodeSelectionInfo(NodeSelectionInfo selectedChildNodeInfo) {
197  if (getOriginal() instanceof DisplayableItemNode) {
198  ((DisplayableItemNode) getOriginal()).setChildNodeSelectionInfo(selectedChildNodeInfo);
199  }
200  }
201 
210  if (getOriginal() instanceof DisplayableItemNode) {
211  return ((DisplayableItemNode) getOriginal()).getChildNodeSelectionInfo();
212  } else {
213  return null;
214  }
215  }
216 
222  private static class DataResultFilterChildren extends FilterNode.Children {
223 
224  private final ExplorerManager sourceEm;
225  private final boolean filterArtifacts; // display message artifacts in the DataSource subtree
226 
230  private DataResultFilterChildren(Node arg, ExplorerManager sourceEm) {
231  super(arg);
232 
233  filterArtifacts = SelectionContext.getSelectionContext(arg).equals(SelectionContext.DATA_SOURCES);
234 
235  this.sourceEm = sourceEm;
236  }
237 
238  @Override
239  protected Node[] createNodes(Node key) {
240  // if displaying the results from the Data Source tree
241  // filter out artifacts
242 
243  // In older versions of Autopsy, attachments were children of email/message artifacts
244  // and hence email/messages with attachments are shown in the tree data source tree,
245  BlackboardArtifact art = key.getLookup().lookup(BlackboardArtifact.class);
246  if (art != null && filterArtifacts
247  && ((FilterNodeUtils.showMessagesInDatasourceTree() == false)
248  || (FilterNodeUtils.showMessagesInDatasourceTree()
249  && art.getArtifactTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID()
250  && art.getArtifactTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE.getTypeID()))) {
251  return new Node[]{};
252  }
253 
254  return new Node[]{new DataResultFilterNode(key, sourceEm)};
255  }
256  }
257 
258  @NbBundle.Messages("DataResultFilterNode.viewSourceArtifact.text=View Source Result")
263  private static class GetPopupActionsDisplayableItemNodeVisitor extends DisplayableItemNodeVisitor.Default<List<Action>> {
264 
265  @Override
266  public List<Action> visit(BlackboardArtifactNode ban) {
267  //set up actions for artifact node based on its Content object
268  //TODO all actions need to be consolidated in single place!
269  //they should be set in individual Node subclass and using a utility to get Actions per Content sub-type
270  // TODO UPDATE: There is now a DataModelActionsFactory utility;
271 
272  List<Action> actionsList = new ArrayList<>();
273 
274  //merge predefined specific node actions if bban subclasses have their own
275  for (Action a : ban.getActions(true)) {
276  actionsList.add(a);
277  }
278 
279  //Add seperator between the decorated actions and the actions from the node itself.
280  actionsList.add(null);
281  BlackboardArtifact ba = ban.getLookup().lookup(BlackboardArtifact.class);
282  final int artifactTypeID = ba.getArtifactTypeID();
283 
284  if (artifactTypeID == BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT.getTypeID()
285  || artifactTypeID == BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()) {
286  if (ban.getLookup().lookup(AbstractFile.class) != null) {
287  // We only want the "View File in Directory" actions if we have a file...it is
288  // possible that we have a keyword hit on a Report.
289  actionsList.add(new ViewContextAction(
290  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewFileInDir.text"), ban));
291  }
292  } else if (artifactTypeID == BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT.getTypeID()) {
293  //action to go to the source artifact
294  actionsList.add(new ViewSourceArtifactAction(DataResultFilterNode_viewSourceArtifact_text(), ba));
295  // action to go to the source file of the artifact
296  actionsList.add(new ViewContextAction(
297  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewSrcFileInDir.text"), ban));
298  } else {
299  // if the artifact links to another file, add an action to go to
300  // that file
301  Content c = findLinked(ban);
302  if (c != null) {
303  actionsList.add(new ViewContextAction(
304  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewFileInDir.text"), c));
305  }
306  // action to go to the source file of the artifact
307  // action to go to the source file of the artifact
308  Content fileContent = ban.getLookup().lookup(AbstractFile.class);
309  if (fileContent == null) {
310  Content content = ban.getLookup().lookup(Content.class);
311  actionsList.add(new ViewContextAction("View Source Content in Directory", content));
312  } else {
313  actionsList.add(new ViewContextAction(
314  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewSrcFileInDir.text"), ban));
315  }
316  }
317  Content c = ban.getLookup().lookup(File.class);
318  Node n = null;
319  if (c != null) {
320  n = new FileNode((AbstractFile) c);
321  } else if ((c = ban.getLookup().lookup(Directory.class)) != null) {
322  n = new DirectoryNode((Directory) c);
323  } else if ((c = ban.getLookup().lookup(VirtualDirectory.class)) != null) {
324  n = new VirtualDirectoryNode((VirtualDirectory) c);
325  } else if ((c = ban.getLookup().lookup(LocalDirectory.class)) != null) {
326  n = new LocalDirectoryNode((LocalDirectory) c);
327  } else if ((c = ban.getLookup().lookup(LayoutFile.class)) != null) {
328  n = new LayoutFileNode((LayoutFile) c);
329  } else if ((c = ban.getLookup().lookup(LocalFile.class)) != null
330  || (c = ban.getLookup().lookup(DerivedFile.class)) != null) {
331  n = new LocalFileNode((AbstractFile) c);
332  if (FileTypeExtensions.getArchiveExtensions().contains("." + ((AbstractFile) c).getNameExtension().toLowerCase())) {
333  try {
334  if (c.getArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_DETECTED).size() > 0) {
335  actionsList.add(new ExtractArchiveWithPasswordAction((AbstractFile) c));
336  }
337  } catch (TskCoreException ex) {
338  LOGGER.log(Level.WARNING, "Unable to add unzip with password action to context menus", ex);
339  }
340  }
341  } else if ((c = ban.getLookup().lookup(SlackFile.class)) != null) {
342  n = new SlackFileNode((SlackFile) c);
343  } else if ((c = ban.getLookup().lookup(Report.class)) != null) {
344  actionsList.addAll(DataModelActionsFactory.getActions(c, false));
345  }
346  if (n != null) {
347  final Collection<AbstractFile> selectedFilesList
348  = new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
349  actionsList.add(null); // creates a menu separator
350  actionsList.add(new NewWindowViewAction(
351  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewInNewWin.text"), n));
352  if (selectedFilesList.size() == 1) {
353  actionsList.add(new ExternalViewerAction(
354  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.openInExtViewer.text"), n));
355  } else {
356  actionsList.add(ExternalViewerShortcutAction.getInstance());
357  }
358  actionsList.add(null); // creates a menu separator
359  actionsList.add(ExtractAction.getInstance());
360  actionsList.add(ExportCSVAction.getInstance());
361  actionsList.add(null); // creates a menu separator
362  actionsList.add(AddContentTagAction.getInstance());
363  actionsList.add(AddBlackboardArtifactTagAction.getInstance());
364 
365  if (selectedFilesList.size() == 1) {
366  actionsList.add(DeleteFileContentTagAction.getInstance());
367  }
368  } else {
369  // There's no specific file associated with the artifact, but
370  // we can still tag the artifact itself
371  actionsList.add(null);
372  actionsList.add(AddBlackboardArtifactTagAction.getInstance());
373  }
374 
375  final Collection<BlackboardArtifact> selectedArtifactsList
376  = new HashSet<>(Utilities.actionsGlobalContext().lookupAll(BlackboardArtifact.class));
377  if (selectedArtifactsList.size() == 1) {
379  }
380 
381  if (n != null) {
382  actionsList.addAll(ContextMenuExtensionPoint.getActions());
383  }
384 
385  return actionsList;
386  }
387 
388  @Override
389  public List<Action> visit(Reports.ReportsListNode ditem) {
390  // The base class Action is "Collapse All", inappropriate.
391  return null;
392  }
393 
394  @Override
395  public List<Action> visit(FileTypesNode fileTypes) {
396  return defaultVisit(fileTypes);
397  }
398 
399  @Override
400  protected List<Action> defaultVisit(DisplayableItemNode ditem) {
401  //preserve the default node's actions
402  List<Action> actions = new ArrayList<>();
403 
404  for (Action action : ditem.getActions(true)) {
405  actions.add(action);
406  }
407 
408  return actions;
409  }
410 
411  private Content findLinked(BlackboardArtifactNode ba) {
412  BlackboardArtifact art = ba.getLookup().lookup(BlackboardArtifact.class);
413  Content c = null;
414  try {
415  for (BlackboardAttribute attr : art.getAttributes()) {
416  if (attr.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH_ID.getTypeID()) {
417  switch (attr.getAttributeType().getValueType()) {
418  case INTEGER:
419  int i = attr.getValueInt();
420  if (i != -1) {
421  c = art.getSleuthkitCase().getContentById(i);
422  }
423  break;
424  case LONG:
425  long l = attr.getValueLong();
426  if (l != -1) {
427  c = art.getSleuthkitCase().getContentById(l);
428  }
429  break;
430  }
431  }
432  }
433  } catch (TskException ex) {
434  Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Error getting linked file", ex); //NON-NLS
435  }
436  return c;
437  }
438 
439  }
440 
441  /*
442  * Action for double-click / preferred action on nodes.
443  */
444  private class GetPreferredActionsDisplayableItemNodeVisitor extends DisplayableItemNodeVisitor.Default<AbstractAction> {
445 
446  @Override
447  public AbstractAction visit(InstanceCountNode icn) {
448  return null;
449  }
450 
451  @Override
452  public AbstractAction visit(InstanceCaseNode icn) {
453  return null;
454  }
455 
456  @Override
457  public AbstractAction visit(InstanceDataSourceNode icn) {
458  return null;
459  }
460 
461  @Override
462  public AbstractAction visit(CommonAttributeValueNode md5n) {
463  return null;
464  }
465 
466  @Override
467  public AbstractAction visit(CaseDBCommonAttributeInstanceNode fin) {
468  return null;
469  }
470 
471  @Override
472  public AbstractAction visit(CentralRepoCommonAttributeInstanceNode iccan) {
473  return null;
474  }
475 
476  @Override
477  public AbstractAction visit(BlackboardArtifactNode ban) {
478 
479  Action preferredAction = ban.getPreferredAction();
480  if(preferredAction instanceof AbstractAction) {
481  return (AbstractAction) preferredAction;
482  }
483 
484  BlackboardArtifact artifact = ban.getArtifact();
485  try {
486  if ((artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID())
487  || (artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_MESSAGE.getTypeID())) {
488  if (artifact.hasChildren()) {
489  return openChild(ban);
490  }
491  }
492  } catch (TskCoreException ex) {
493  LOGGER.log(Level.SEVERE, MessageFormat.format("Error getting children from blackboard artifact{0}.", artifact.getArtifactID()), ex); //NON-NLS
494  }
495  return new ViewContextAction(
496  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewInDir.text"), ban);
497  }
498 
499  @Override
500  public AbstractAction visit(DirectoryNode dn) {
501  if (dn.getDisplayName().equals(DirectoryNode.DOTDOTDIR)) {
502  return openParent(dn);
503  } else if (dn.getDisplayName().equals(DirectoryNode.DOTDIR) == false) {
504  return openChild(dn);
505  } else {
506  return null;
507  }
508  }
509 
510  @Override
511  public AbstractAction visit(FileNode fn) {
512  if (fn.hasContentChildren()) {
513  return openChild(fn);
514  } else {
515  return null;
516  }
517  }
518 
519  @Override
520  public AbstractAction visit(LocalFileNode dfn) {
521  if (dfn.hasContentChildren()) {
522  return openChild(dfn);
523  } else {
524  return null;
525  }
526  }
527 
528  @Override
529  public AbstractAction visit(Reports.ReportNode reportNode) {
530  return reportNode.getPreferredAction();
531  }
532 
533  @Override
534  protected AbstractAction defaultVisit(DisplayableItemNode c) {
535  return openChild(c);
536  }
537 
538  @Override
539  public AbstractAction visit(FileTypesNode fileTypes) {
540  return openChild(fileTypes);
541  }
542 
551  private AbstractAction openChild(final AbstractNode dataModelNode) {
552  // get the current selection from the directory tree explorer manager,
553  // which is a DirectoryTreeFilterNode. One of that node's children
554  // is a DirectoryTreeFilterNode that wraps the dataModelNode. We need
555  // to set that wrapped node as the selection and root context of the
556  // directory tree explorer manager (sourceEm)
557  if(sourceEm == null || sourceEm.getSelectedNodes().length == 0) {
558  return null;
559  }
560  final Node currentSelectionInDirectoryTree = sourceEm.getSelectedNodes()[0];
561 
562  return new AbstractAction() {
563  @Override
564  public void actionPerformed(ActionEvent e) {
565  if (currentSelectionInDirectoryTree != null) {
566  // Find the filter version of the passed in dataModelNode.
567  final org.openide.nodes.Children children = currentSelectionInDirectoryTree.getChildren();
568  // This call could break if the DirectoryTree is re-implemented with lazy ChildFactory objects.
569  Node newSelection = children.findChild(dataModelNode.getName());
570 
571  /*
572  * We got null here when we were viewing a ZIP file in
573  * the Views -> Archives area and double clicking on it
574  * got to this code. It tried to find the child in the
575  * tree and didn't find it. An exception was then thrown
576  * from setting the selected node to be null.
577  */
578  if (newSelection != null) {
579  try {
580  sourceEm.setExploredContextAndSelection(newSelection, new Node[]{newSelection});
581  } catch (PropertyVetoException ex) {
582  Logger logger = Logger.getLogger(DataResultFilterNode.class.getName());
583  logger.log(Level.WARNING, "Error: can't open the selected directory.", ex); //NON-NLS
584  }
585  }
586  }
587  }
588  };
589  }
590 
599  private AbstractAction openParent(AbstractNode node) {
600  if(sourceEm == null) {
601  return null;
602  }
603  // @@@ Why do we ignore node?
604  Node[] selectedFilterNodes = sourceEm.getSelectedNodes();
605  Node selectedFilterNode = selectedFilterNodes[0];
606  final Node parentNode = selectedFilterNode.getParentNode();
607 
608  return new AbstractAction() {
609  @Override
610  public void actionPerformed(ActionEvent e) {
611  try {
612  sourceEm.setSelectedNodes(new Node[]{parentNode});
613  } catch (PropertyVetoException ex) {
614  Logger logger = Logger.getLogger(DataResultFilterNode.class.getName());
615  logger.log(Level.WARNING, "Error: can't open the parent directory.", ex); //NON-NLS
616  }
617  }
618  };
619  }
620  }
621 }
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-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.