Autopsy  4.18.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.DataArtifact;
83 import org.sleuthkit.datamodel.Report;
84 import org.sleuthkit.datamodel.TskCoreException;
85 
91 public class DataResultFilterNode extends FilterNode {
92 
93  private static final Logger LOGGER = Logger.getLogger(DataResultFilterNode.class.getName());
94 
97 
98  // Assumptions are made in GetPreferredActionsDisplayableItemNodeVisitor that
99  // sourceEm is the directory tree explorer manager.
100  private final ExplorerManager sourceEm;
101 
109  public DataResultFilterNode(Node node) {
110  this(node, null);
111  }
112 
122  public DataResultFilterNode(Node node, ExplorerManager em) {
123  super(node, new DataResultFilterChildren(node, em));
124  this.sourceEm = em;
125  }
126 
135  @Override
136  public Action[] getActions(boolean popup) {
137 
138  List<Action> actions = new ArrayList<>();
139  if (this.getOriginal() instanceof DisplayableItemNode) {
140  final DisplayableItemNode originalNode = (DisplayableItemNode) this.getOriginal();
141  List<Action> accept = originalNode.accept(getActionsDIV);
142  if (accept != null) {
143  actions.addAll(accept);
144  }
145  }
146 
147  //actions.add(new IndexContentFilesAction(nodeContent, "Index"));
148  return actions.toArray(new Action[actions.size()]);
149  }
150 
157  @Override
158  public Action getPreferredAction() {
159  final Node original = this.getOriginal();
160  // Once had a org.openide.nodes.ChildFactory$WaitFilterNode passed in
161  if ((original instanceof DisplayableItemNode) == false) {
162  return null;
163  }
164 
165  final DisplayableItemNode originalNode = (DisplayableItemNode) this.getOriginal();
166  return originalNode.accept(getPreferredActionsDIV);
167  }
168 
169  @Override
170  public Node.PropertySet[] getPropertySets() {
171  Node.PropertySet[] propertySets = super.getPropertySets();
172 
173  for (int i = 0; i < propertySets.length; i++) {
174  Node.PropertySet ps = propertySets[i];
175 
176  if (ps.getName().equals(Sheet.PROPERTIES)) {
177  Sheet.Set newPs = new Sheet.Set();
178  newPs.setName(ps.getName());
179  newPs.setDisplayName(ps.getDisplayName());
180  newPs.setShortDescription(ps.getShortDescription());
181 
182  newPs.put(ps.getProperties());
183  newPs.remove(AbstractFsContentNode.HIDE_PARENT);
184  propertySets[i] = newPs;
185  }
186  }
187 
188  return propertySets;
189  }
190 
197  public void setChildNodeSelectionInfo(NodeSelectionInfo selectedChildNodeInfo) {
198  if (getOriginal() instanceof DisplayableItemNode) {
199  ((DisplayableItemNode) getOriginal()).setChildNodeSelectionInfo(selectedChildNodeInfo);
200  }
201  }
202 
211  if (getOriginal() instanceof DisplayableItemNode) {
212  return ((DisplayableItemNode) getOriginal()).getChildNodeSelectionInfo();
213  } else {
214  return null;
215  }
216  }
217 
223  private static class DataResultFilterChildren extends FilterNode.Children {
224 
225  private final ExplorerManager sourceEm;
226  private final boolean filterArtifacts; // display message artifacts in the DataSource subtree
227 
231  private DataResultFilterChildren(Node arg, ExplorerManager sourceEm) {
232  super(arg);
233 
234  filterArtifacts = SelectionContext.getSelectionContext(arg).equals(SelectionContext.DATA_SOURCES);
235 
236  this.sourceEm = sourceEm;
237  }
238 
239  @Override
240  protected Node[] createNodes(Node key) {
241  // if displaying the results from the Data Source tree
242  // filter out artifacts
243 
244  // In older versions of Autopsy, attachments were children of email/message artifacts
245  // and hence email/messages with attachments are shown in the tree data source tree,
246  BlackboardArtifact art = key.getLookup().lookup(BlackboardArtifact.class);
247  if (art != null && filterArtifacts
248  && ((FilterNodeUtils.showMessagesInDatasourceTree() == false)
249  || (FilterNodeUtils.showMessagesInDatasourceTree()
250  && art.getArtifactTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID()
251  && art.getArtifactTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE.getTypeID()))) {
252  return new Node[]{};
253  }
254 
255  return new Node[]{new DataResultFilterNode(key, sourceEm)};
256  }
257  }
258 
259  @NbBundle.Messages("DataResultFilterNode.viewSourceArtifact.text=View Source Result")
264  private static class GetPopupActionsDisplayableItemNodeVisitor extends DisplayableItemNodeVisitor.Default<List<Action>> {
265 
266  @Override
267  public List<Action> visit(BlackboardArtifactNode ban) {
268  //set up actions for artifact node based on its Content object
269  //TODO all actions need to be consolidated in single place!
270  //they should be set in individual Node subclass and using a utility to get Actions per Content sub-type
271  // TODO UPDATE: There is now a DataModelActionsFactory utility;
272 
273  List<Action> actionsList = new ArrayList<>();
274 
275  //merge predefined specific node actions if bban subclasses have their own
276  for (Action a : ban.getActions(true)) {
277  actionsList.add(a);
278  }
279 
280  //Add seperator between the decorated actions and the actions from the node itself.
281  actionsList.add(null);
282  BlackboardArtifact ba = ban.getLookup().lookup(BlackboardArtifact.class);
283  final int artifactTypeID = ba.getArtifactTypeID();
284 
285  if (artifactTypeID == BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT.getTypeID()
286  || artifactTypeID == BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()) {
287  if (ban.getLookup().lookup(AbstractFile.class) != null) {
288  // We only want the "View File in Directory" actions if we have a file...it is
289  // possible that we have a keyword hit on a Report.
290  actionsList.add(new ViewContextAction(
291  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewFileInDir.text"), ban));
292  }
293  } else if (artifactTypeID == BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT.getTypeID()) {
294  //action to go to the source artifact
295  actionsList.add(new ViewSourceArtifactAction(DataResultFilterNode_viewSourceArtifact_text(), ba));
296  // action to go to the source file of the artifact
297  actionsList.add(new ViewContextAction(
298  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewSrcFileInDir.text"), ban));
299  } else {
300  // if the artifact links to another file, add an action to go to
301  // that file
302  Content c = findLinked(ban);
303  if (c != null) {
304  actionsList.add(new ViewContextAction(
305  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewFileInDir.text"), c));
306  }
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 
363  // don't show AddContentTagAction for data artifacts.
364  if (!(ban.getArtifact() instanceof DataArtifact)) {
365  actionsList.add(AddContentTagAction.getInstance());
366  }
367 
368  actionsList.add(AddBlackboardArtifactTagAction.getInstance());
369 
370  // don't show DeleteFileContentTagAction for data artifacts.
371  if ((!(ban.getArtifact() instanceof DataArtifact)) && (selectedFilesList.size() == 1)) {
372  actionsList.add(DeleteFileContentTagAction.getInstance());
373  }
374  } else {
375  // There's no specific file associated with the artifact, but
376  // we can still tag the artifact itself
377  actionsList.add(null);
378  actionsList.add(AddBlackboardArtifactTagAction.getInstance());
379  }
380 
381  final Collection<BlackboardArtifact> selectedArtifactsList
382  = new HashSet<>(Utilities.actionsGlobalContext().lookupAll(BlackboardArtifact.class));
383  if (selectedArtifactsList.size() == 1) {
385  }
386 
387  if (n != null) {
388  actionsList.addAll(ContextMenuExtensionPoint.getActions());
389  }
390 
391  return actionsList;
392  }
393 
394  @Override
395  public List<Action> visit(Reports.ReportsListNode ditem) {
396  // The base class Action is "Collapse All", inappropriate.
397  return null;
398  }
399 
400  @Override
401  public List<Action> visit(FileTypesNode fileTypes) {
402  return defaultVisit(fileTypes);
403  }
404 
405  @Override
406  protected List<Action> defaultVisit(DisplayableItemNode ditem) {
407  //preserve the default node's actions
408  List<Action> actions = new ArrayList<>();
409 
410  for (Action action : ditem.getActions(true)) {
411  actions.add(action);
412  }
413 
414  return actions;
415  }
416 
417  private Content findLinked(BlackboardArtifactNode ba) {
418  BlackboardArtifact art = ba.getLookup().lookup(BlackboardArtifact.class);
419  Content c = null;
420  try {
421  for (BlackboardAttribute attr : art.getAttributes()) {
422  if (attr.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH_ID.getTypeID()) {
423  switch (attr.getAttributeType().getValueType()) {
424  case INTEGER:
425  int i = attr.getValueInt();
426  if (i != -1) {
427  c = art.getSleuthkitCase().getContentById(i);
428  }
429  break;
430  case LONG:
431  long l = attr.getValueLong();
432  if (l != -1) {
433  c = art.getSleuthkitCase().getContentById(l);
434  }
435  break;
436  }
437  }
438  }
439  } catch (TskException ex) {
440  Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Error getting linked file", ex); //NON-NLS
441  }
442  return c;
443  }
444 
445  }
446 
447  /*
448  * Action for double-click / preferred action on nodes.
449  */
450  private class GetPreferredActionsDisplayableItemNodeVisitor extends DisplayableItemNodeVisitor.Default<AbstractAction> {
451 
452  @Override
453  public AbstractAction visit(InstanceCountNode icn) {
454  return null;
455  }
456 
457  @Override
458  public AbstractAction visit(InstanceCaseNode icn) {
459  return null;
460  }
461 
462  @Override
463  public AbstractAction visit(InstanceDataSourceNode icn) {
464  return null;
465  }
466 
467  @Override
468  public AbstractAction visit(CommonAttributeValueNode md5n) {
469  return null;
470  }
471 
472  @Override
473  public AbstractAction visit(CaseDBCommonAttributeInstanceNode fin) {
474  return null;
475  }
476 
477  @Override
478  public AbstractAction visit(CentralRepoCommonAttributeInstanceNode iccan) {
479  return null;
480  }
481 
482  @Override
483  public AbstractAction visit(BlackboardArtifactNode ban) {
484 
485  Action preferredAction = ban.getPreferredAction();
486  if(preferredAction instanceof AbstractAction) {
487  return (AbstractAction) preferredAction;
488  }
489 
490  BlackboardArtifact artifact = ban.getArtifact();
491  try {
492  if ((artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID())
493  || (artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_MESSAGE.getTypeID())) {
494  if (artifact.hasChildren()) {
495  return openChild(ban);
496  }
497  }
498  } catch (TskCoreException ex) {
499  LOGGER.log(Level.SEVERE, MessageFormat.format("Error getting children from blackboard artifact{0}.", artifact.getArtifactID()), ex); //NON-NLS
500  }
501  return new ViewContextAction(
502  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewInDir.text"), ban);
503  }
504 
505  @Override
506  public AbstractAction visit(DirectoryNode dn) {
507  if (dn.getDisplayName().equals(DirectoryNode.DOTDOTDIR)) {
508  return openParent(dn);
509  } else if (dn.getDisplayName().equals(DirectoryNode.DOTDIR) == false) {
510  return openChild(dn);
511  } else {
512  return null;
513  }
514  }
515 
516  @Override
517  public AbstractAction visit(FileNode fn) {
518  if (fn.hasContentChildren()) {
519  return openChild(fn);
520  } else {
521  return null;
522  }
523  }
524 
525  @Override
526  public AbstractAction visit(LocalFileNode dfn) {
527  if (dfn.hasContentChildren()) {
528  return openChild(dfn);
529  } else {
530  return null;
531  }
532  }
533 
534  @Override
535  public AbstractAction visit(Reports.ReportNode reportNode) {
536  return reportNode.getPreferredAction();
537  }
538 
539  @Override
540  protected AbstractAction defaultVisit(DisplayableItemNode c) {
541  return openChild(c);
542  }
543 
544  @Override
545  public AbstractAction visit(FileTypesNode fileTypes) {
546  return openChild(fileTypes);
547  }
548 
557  private AbstractAction openChild(final AbstractNode dataModelNode) {
558  // get the current selection from the directory tree explorer manager,
559  // which is a DirectoryTreeFilterNode. One of that node's children
560  // is a DirectoryTreeFilterNode that wraps the dataModelNode. We need
561  // to set that wrapped node as the selection and root context of the
562  // directory tree explorer manager (sourceEm)
563  if(sourceEm == null || sourceEm.getSelectedNodes().length == 0) {
564  return null;
565  }
566  final Node currentSelectionInDirectoryTree = sourceEm.getSelectedNodes()[0];
567 
568  return new AbstractAction() {
569  @Override
570  public void actionPerformed(ActionEvent e) {
571  if (currentSelectionInDirectoryTree != null) {
572  // Find the filter version of the passed in dataModelNode.
573  final org.openide.nodes.Children children = currentSelectionInDirectoryTree.getChildren();
574  // This call could break if the DirectoryTree is re-implemented with lazy ChildFactory objects.
575  Node newSelection = children.findChild(dataModelNode.getName());
576 
577  /*
578  * We got null here when we were viewing a ZIP file in
579  * the Views -> Archives area and double clicking on it
580  * got to this code. It tried to find the child in the
581  * tree and didn't find it. An exception was then thrown
582  * from setting the selected node to be null.
583  */
584  if (newSelection != null) {
585  try {
586  sourceEm.setExploredContextAndSelection(newSelection, new Node[]{newSelection});
587  } catch (PropertyVetoException ex) {
588  Logger logger = Logger.getLogger(DataResultFilterNode.class.getName());
589  logger.log(Level.WARNING, "Error: can't open the selected directory.", ex); //NON-NLS
590  }
591  }
592  }
593  }
594  };
595  }
596 
605  private AbstractAction openParent(AbstractNode node) {
606  if(sourceEm == null) {
607  return null;
608  }
609  // @@@ Why do we ignore node?
610  Node[] selectedFilterNodes = sourceEm.getSelectedNodes();
611  Node selectedFilterNode = selectedFilterNodes[0];
612  final Node parentNode = selectedFilterNode.getParentNode();
613 
614  return new AbstractAction() {
615  @Override
616  public void actionPerformed(ActionEvent e) {
617  try {
618  sourceEm.setSelectedNodes(new Node[]{parentNode});
619  } catch (PropertyVetoException ex) {
620  Logger logger = Logger.getLogger(DataResultFilterNode.class.getName());
621  logger.log(Level.WARNING, "Error: can't open the parent directory.", ex); //NON-NLS
622  }
623  }
624  };
625  }
626  }
627 }
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-2021 Basis Technology. Generated on: Thu Jul 8 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.