Autopsy  4.11.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
VolumeNode.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.datamodel;
20 
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
23 import java.util.ArrayList;
24 import java.util.EnumSet;
25 import java.util.List;
26 import java.util.logging.Level;
27 import javax.swing.Action;
28 import org.apache.commons.lang3.tuple.Pair;
29 import org.openide.nodes.Sheet;
30 import org.openide.util.NbBundle;
41 import org.sleuthkit.datamodel.Content;
42 import org.sleuthkit.datamodel.TskCoreException;
43 import org.sleuthkit.datamodel.VirtualDirectory;
44 import org.sleuthkit.datamodel.Volume;
46 import org.sleuthkit.datamodel.Tag;
47 
52 public class VolumeNode extends AbstractContentNode<Volume> {
53 
54  private static final Logger logger = Logger.getLogger(VolumeNode.class.getName());
55 
64  static String nameForVolume(Volume vol) {
65  return "vol" + Long.toString(vol.getAddr()); //NON-NLS
66  }
67 
72  public VolumeNode(Volume vol) {
73  super(vol);
74 
75  // set name, display name, and icon
76  String volName = nameForVolume(vol);
77 
78  long end = vol.getStart() + (vol.getLength() - 1);
79  String tempVolName = volName + " (" + vol.getDescription() + ": " + vol.getStart() + "-" + end + ")";
80  this.setDisplayName(tempVolName);
81 
82  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/vol-icon.png"); //NON-NLS
83  // Listen for ingest events so that we can detect new added files (e.g. carved)
85  // Listen for case events so that we can detect when case is closed
87  }
88 
89  private void removeListeners() {
92  }
93 
94  /*
95  * This property change listener refreshes the tree when a new file is
96  * carved out of the unallocated space of this volume.
97  */
98  private final PropertyChangeListener pcl = (PropertyChangeEvent evt) -> {
99  String eventType = evt.getPropertyName();
100 
101  // See if the new file is a child of ours
102  if (eventType.equals(IngestManager.IngestModuleEvent.CONTENT_CHANGED.toString())) {
103  if ((evt.getOldValue() instanceof ModuleContentEvent) == false) {
104  return;
105  }
106  ModuleContentEvent moduleContentEvent = (ModuleContentEvent) evt.getOldValue();
107  if ((moduleContentEvent.getSource() instanceof Content) == false) {
108  return;
109  }
110  Content newContent = (Content) moduleContentEvent.getSource();
111 
112  try {
113  Content parent = newContent.getParent();
114  if (parent != null) {
115  // Is this a new carved file?
116  if (parent.getName().equals(VirtualDirectory.NAME_CARVED)) {
117  // Is this new carved file for this data source?
118  if (newContent.getDataSource().getId() == getContent().getDataSource().getId()) {
119  // Find the volume (if any) associated with the new content and
120  // trigger a refresh if it matches the volume wrapped by this node.
121  while ((parent = parent.getParent()) != null) {
122  if (parent.getId() == getContent().getId()) {
124  break;
125  }
126  }
127  }
128  }
129  }
130  } catch (TskCoreException ex) {
131  // Do nothing.
132  } catch (NoSuchEventBusException ex) {
133  logger.log(Level.WARNING, eventType, ex);
134  }
135  } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) {
136  if (evt.getNewValue() == null) {
137  // case was closed. Remove listeners so that we don't get called with a stale case handle
138  removeListeners();
139  }
140  }
141  };
142 
150  @Override
151  public Action[] getActions(boolean popup) {
152  List<Action> actionsList = new ArrayList<>();
153 
154  for (Action a : super.getActions(true)) {
155  actionsList.add(a);
156  }
157  actionsList.add(new FileSystemDetailsAction(content));
158  actionsList.add(new NewWindowViewAction(
159  NbBundle.getMessage(this.getClass(), "VolumeNode.getActions.viewInNewWin.text"), this));
160  actionsList.addAll(ExplorerNodeActionVisitor.getActions(content));
161 
162  return actionsList.toArray(new Action[0]);
163  }
164 
165  @Override
166  protected Sheet createSheet() {
167  Sheet sheet = super.createSheet();
168  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
169  if (sheetSet == null) {
170  sheetSet = Sheet.createPropertiesSet();
171  sheet.put(sheetSet);
172  }
173 
174  sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.name.name"),
175  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.name.displayName"),
176  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.name.desc"),
177  this.getDisplayName()));
178  sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.id.name"),
179  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.id.displayName"),
180  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.id.desc"),
181  content.getAddr()));
182  sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.startSector.name"),
183  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.startSector.displayName"),
184  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.startSector.desc"),
185  content.getStart()));
186  sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.lenSectors.name"),
187  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.lenSectors.displayName"),
188  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.lenSectors.desc"),
189  content.getLength()));
190  sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.description.name"),
191  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.description.displayName"),
192  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.description.desc"),
193  content.getDescription()));
194  sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.flags.name"),
195  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.flags.displayName"),
196  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.flags.desc"),
197  content.getFlagsAsString()));
198 
199  return sheet;
200  }
201 
202  @Override
203  public <T> T accept(ContentNodeVisitor<T> visitor) {
204  return visitor.visit(this);
205  }
206 
207  @Override
208  public boolean isLeafTypeNode() {
209  return false;
210  }
211 
212  @Override
213  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
214  return visitor.visit(this);
215  }
216 
217  @Override
218  public String getItemType() {
219  return DisplayableItemNode.FILE_PARENT_NODE_KEY;
220  }
221 
229  @Override
230  protected List<Tag> getAllTagsFromDatabase() {
231  return new ArrayList<>();
232  }
233 
243  @Override
245  return null;
246  }
247 
257  @Override
258  protected Pair<DataResultViewerTable.Score, String> getScorePropertyAndDescription(List<Tag> tags) {
259  return Pair.of(DataResultViewerTable.Score.NO_SCORE, NO_DESCR);
260  }
261 
272  @Override
275  }
276 
289  @Override
290  protected Pair<Long, String> getCountPropertyAndDescription(CorrelationAttributeInstance.Type attributeType, String attributeValue, String defaultDescription) {
291  return Pair.of(-1L, NO_DESCR);
292  }
293 }
void removeIngestModuleEventListener(final PropertyChangeListener listener)
Pair< Long, String > getCountPropertyAndDescription(CorrelationAttributeInstance.Type attributeType, String attributeValue, String defaultDescription)
static synchronized IngestManager getInstance()
Pair< DataResultViewerTable.Score, String > getScorePropertyAndDescription(List< Tag > tags)
DataResultViewerTable.HasCommentStatus getCommentProperty(List< Tag > tags, CorrelationAttributeInstance attribute)
CorrelationAttributeInstance getCorrelationAttributeInstance()
final PropertyChangeListener pcl
Definition: VolumeNode.java:98
static void post(String nodeName, Object event)
void addIngestModuleEventListener(final PropertyChangeListener listener)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:441
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:486

Copyright © 2012-2018 Basis Technology. Generated on: Fri Jun 21 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.