Autopsy  4.5.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-2014 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 javax.swing.Action;
27 import org.openide.nodes.Children;
28 import org.openide.nodes.Sheet;
29 import org.openide.util.NbBundle;
35 import org.sleuthkit.datamodel.Content;
36 import org.sleuthkit.datamodel.TskCoreException;
37 import org.sleuthkit.datamodel.VirtualDirectory;
38 import org.sleuthkit.datamodel.Volume;
40 
45 public class VolumeNode extends AbstractContentNode<Volume> {
46 
55  static String nameForVolume(Volume vol) {
56  return "vol" + Long.toString(vol.getAddr()); //NON-NLS
57  }
58 
63  public VolumeNode(Volume vol) {
64  super(vol);
65 
66  // set name, display name, and icon
67  String volName = nameForVolume(vol);
68 
69  long end = vol.getStart() + (vol.getLength() - 1);
70  String tempVolName = volName + " (" + vol.getDescription() + ": " + vol.getStart() + "-" + end + ")";
71  this.setDisplayName(tempVolName);
72 
73  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/vol-icon.png"); //NON-NLS
74  // Listen for ingest events so that we can detect new added files (e.g. carved)
76  // Listen for case events so that we can detect when case is closed
78  }
79 
80  private void removeListeners() {
83  }
84 
85  /*
86  * This property change listener refreshes the tree when a new file is
87  * carved out of the unallocated space of this volume.
88  */
89  private final PropertyChangeListener pcl = (PropertyChangeEvent evt) -> {
90  String eventType = evt.getPropertyName();
91 
92  // See if the new file is a child of ours
93  if (eventType.equals(IngestManager.IngestModuleEvent.CONTENT_CHANGED.toString())) {
94  if ((evt.getOldValue() instanceof ModuleContentEvent) == false) {
95  return;
96  }
97  ModuleContentEvent moduleContentEvent = (ModuleContentEvent) evt.getOldValue();
98  if ((moduleContentEvent.getSource() instanceof Content) == false) {
99  return;
100  }
101  Content newContent = (Content) moduleContentEvent.getSource();
102 
103  try {
104  Content parent = newContent.getParent();
105  if (parent != null) {
106  // Is this a new carved file?
107  if (parent.getName().equals(VirtualDirectory.NAME_CARVED)) {
108  // Was this new carved file produced from this volume?
109  if (parent.getParent().getId() == getContent().getId()) {
110  Children children = getChildren();
111  if (children != null) {
112  ((ContentChildren) children).refreshChildren();
113  children.getNodesCount();
114  }
115  }
116  }
117  }
118  } catch (TskCoreException ex) {
119  // Do nothing.
120  }
121  } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) {
122  if (evt.getNewValue() == null) {
123  // case was closed. Remove listeners so that we don't get called with a stale case handle
124  removeListeners();
125  }
126  }
127  };
128 
136  @Override
137  public Action[] getActions(boolean popup) {
138  List<Action> actionsList = new ArrayList<>();
139 
140  for (Action a : super.getActions(true)) {
141  actionsList.add(a);
142  }
143  actionsList.add(new FileSystemDetailsAction(content));
144  actionsList.add(new NewWindowViewAction(
145  NbBundle.getMessage(this.getClass(), "VolumeNode.getActions.viewInNewWin.text"), this));
146  actionsList.addAll(ExplorerNodeActionVisitor.getActions(content));
147 
148  return actionsList.toArray(new Action[0]);
149  }
150 
151  @Override
152  protected Sheet createSheet() {
153  Sheet s = super.createSheet();
154  Sheet.Set ss = s.get(Sheet.PROPERTIES);
155  if (ss == null) {
156  ss = Sheet.createPropertiesSet();
157  s.put(ss);
158  }
159 
160  ss.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.name.name"),
161  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.name.displayName"),
162  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.name.desc"),
163  this.getDisplayName()));
164  ss.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.id.name"),
165  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.id.displayName"),
166  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.id.desc"),
167  content.getAddr()));
168  ss.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.startSector.name"),
169  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.startSector.displayName"),
170  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.startSector.desc"),
171  content.getStart()));
172  ss.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.lenSectors.name"),
173  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.lenSectors.displayName"),
174  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.lenSectors.desc"),
175  content.getLength()));
176  ss.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.description.name"),
177  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.description.displayName"),
178  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.description.desc"),
179  content.getDescription()));
180  ss.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.flags.name"),
181  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.flags.displayName"),
182  NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.flags.desc"),
183  content.getFlagsAsString()));
184 
185  return s;
186  }
187 
188  @Override
189  public <T> T accept(ContentNodeVisitor<T> v) {
190  return v.visit(this);
191  }
192 
193  @Override
194  public boolean isLeafTypeNode() {
195  return false;
196  }
197 
198  @Override
199  public <T> T accept(DisplayableItemNodeVisitor<T> v) {
200  return v.visit(this);
201  }
202 
203  @Override
204  public String getItemType() {
205  return DisplayableItemNode.FILE_PARENT_NODE_KEY;
206  }
207 }
void removeIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized IngestManager getInstance()
final PropertyChangeListener pcl
Definition: VolumeNode.java:89
void addIngestModuleEventListener(final PropertyChangeListener listener)
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:419
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:464

Copyright © 2012-2016 Basis Technology. Generated on: Tue Feb 20 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.