Autopsy  4.19.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.Set;
27 import java.util.logging.Level;
28 import javax.swing.Action;
29 import org.apache.commons.lang3.tuple.Pair;
30 import org.openide.nodes.Sheet;
31 import org.openide.util.NbBundle;
42 import org.sleuthkit.datamodel.Content;
43 import org.sleuthkit.datamodel.Pool;
44 import org.sleuthkit.datamodel.TskCoreException;
45 import org.sleuthkit.datamodel.VirtualDirectory;
46 import org.sleuthkit.datamodel.Volume;
48 import org.sleuthkit.datamodel.Tag;
49 
54 public class VolumeNode extends AbstractContentNode<Volume> {
55 
56  private static final Logger logger = Logger.getLogger(VolumeNode.class.getName());
58 
67  static String nameForVolume(Volume vol) {
68  return "vol" + Long.toString(vol.getAddr()); //NON-NLS
69  }
70 
75  public VolumeNode(Volume vol) {
76  super(vol);
77 
78  // set name, display name, and icon
79  String volName = nameForVolume(vol);
80  long end = vol.getStart() + (vol.getLength() - 1);
81  String tempVolName = volName + " (" + vol.getDescription() + ": " + vol.getStart() + "-" + end + ")";
82 
83  // If this is a pool volume use a custom display name
84  try {
85  if (vol.getParent() != null &&
86  vol.getParent().getParent() instanceof Pool) {
87  // Pool volumes are not contiguous so printing a range of blocks is inaccurate
88  tempVolName = volName + " (" + vol.getDescription() + ": " + vol.getStart() + ")";
89  }
90  } catch (TskCoreException ex) {
91  logger.log(Level.WARNING, "Error looking up parent(s) of volume with obj ID = "+ vol.getId(), ex);
92  }
93  this.setDisplayName(tempVolName);
94 
95  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/vol-icon.png"); //NON-NLS
96  // Listen for ingest events so that we can detect new added files (e.g. carved)
98  // Listen for case events so that we can detect when case is closed
100  }
101 
102  private void removeListeners() {
105  }
106 
107  /*
108  * This property change listener refreshes the tree when a new file is
109  * carved out of the unallocated space of this volume.
110  */
111  private final PropertyChangeListener pcl = (PropertyChangeEvent evt) -> {
112  String eventType = evt.getPropertyName();
113 
114  // See if the new file is a child of ours
115  if (eventType.equals(IngestManager.IngestModuleEvent.CONTENT_CHANGED.toString())) {
116  if ((evt.getOldValue() instanceof ModuleContentEvent) == false) {
117  return;
118  }
119  ModuleContentEvent moduleContentEvent = (ModuleContentEvent) evt.getOldValue();
120  if ((moduleContentEvent.getSource() instanceof Content) == false) {
121  return;
122  }
123  Content newContent = (Content) moduleContentEvent.getSource();
124 
125  try {
126  Content parent = newContent.getParent();
127  if (parent != null) {
128  // Is this a new carved file?
129  if (parent.getName().equals(VirtualDirectory.NAME_CARVED)) {
130  // Is this new carved file for this data source?
131  if (newContent.getDataSource().getId() == getContent().getDataSource().getId()) {
132  // Find the volume (if any) associated with the new content and
133  // trigger a refresh if it matches the volume wrapped by this node.
134  while ((parent = parent.getParent()) != null) {
135  if (parent.getId() == getContent().getId()) {
137  break;
138  }
139  }
140  }
141  }
142  }
143  } catch (TskCoreException ex) {
144  // Do nothing.
145  } catch (NoSuchEventBusException ex) {
146  logger.log(Level.WARNING, eventType, ex);
147  }
148  } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) {
149  if (evt.getNewValue() == null) {
150  // case was closed. Remove listeners so that we don't get called with a stale case handle
151  removeListeners();
152  }
153  }
154  };
155 
163  @Override
164  public Action[] getActions(boolean popup) {
165  List<Action> actionsList = new ArrayList<>();
166 
167  for (Action a : super.getActions(true)) {
168  actionsList.add(a);
169  }
170  actionsList.add(new FileSystemDetailsAction(content));
171  actionsList.add(new NewWindowViewAction(
172  NbBundle.getMessage(this.getClass(), "VolumeNode.getActions.viewInNewWin.text"), this));
173  actionsList.addAll(ExplorerNodeActionVisitor.getActions(content));
174 
175  return actionsList.toArray(new Action[actionsList.size()]);
176  }
177 
178  @Override
179  protected Sheet createSheet() {
180  Sheet sheet = super.createSheet();
181  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
182  if (sheetSet == null) {
183  sheetSet = Sheet.createPropertiesSet();
184  sheet.put(sheetSet);
185  }
186 
187  sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.name.name"),
188  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.name.displayName"),
189  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.name.desc"),
190  this.getDisplayName()));
191  sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.id.name"),
192  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.id.displayName"),
193  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.id.desc"),
194  content.getAddr()));
195  sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.startSector.name"),
196  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.startSector.displayName"),
197  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.startSector.desc"),
198  content.getStart()));
199  sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.lenSectors.name"),
200  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.lenSectors.displayName"),
201  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.lenSectors.desc"),
202  content.getLength()));
203  sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.description.name"),
204  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.description.displayName"),
205  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.description.desc"),
206  content.getDescription()));
207  sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.flags.name"),
208  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.flags.displayName"),
209  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.flags.desc"),
210  content.getFlagsAsString()));
211 
212  return sheet;
213  }
214 
215  @Override
216  public <T> T accept(ContentNodeVisitor<T> visitor) {
217  return visitor.visit(this);
218  }
219 
220  @Override
221  public boolean isLeafTypeNode() {
222  return false;
223  }
224 
225  @Override
226  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
227  return visitor.visit(this);
228  }
229 
230  @Override
231  public String getItemType() {
232  return DisplayableItemNode.FILE_PARENT_NODE_KEY;
233  }
234 
242  @Override
243  protected List<Tag> getAllTagsFromDatabase() {
244  return new ArrayList<>();
245  }
246 
256  @Override
258  return null;
259  }
260 
271  @Override
274  }
275 
288  @Override
289  protected Pair<Long, String> getCountPropertyAndDescription(CorrelationAttributeInstance.Type attributeType, String attributeValue, String defaultDescription) {
290  return Pair.of(-1L, NO_DESCR);
291  }
292 }
void removeIngestModuleEventListener(final PropertyChangeListener listener)
Pair< Long, String > getCountPropertyAndDescription(CorrelationAttributeInstance.Type attributeType, String attributeValue, String defaultDescription)
static synchronized IngestManager getInstance()
static final Set< IngestManager.IngestModuleEvent > INGEST_MODULE_EVENTS_OF_INTEREST
Definition: VolumeNode.java:57
DataResultViewerTable.HasCommentStatus getCommentProperty(List< Tag > tags, CorrelationAttributeInstance attribute)
CorrelationAttributeInstance getCorrelationAttributeInstance()
final PropertyChangeListener pcl
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:711
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:756

Copyright © 2012-2021 Basis Technology. Generated on: Fri Aug 6 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.