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

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