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

Copyright © 2012-2016 Basis Technology. Generated on: Fri Sep 29 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.