Autopsy 4.22.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-2021 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 */
19package org.sleuthkit.autopsy.datamodel;
20
21import java.beans.PropertyChangeEvent;
22import java.beans.PropertyChangeListener;
23import java.util.ArrayList;
24import java.util.Arrays;
25import java.util.EnumSet;
26import java.util.List;
27import java.util.Set;
28import java.util.logging.Level;
29import javax.swing.Action;
30import org.openide.nodes.Sheet;
31import org.openide.util.NbBundle;
32import org.sleuthkit.autopsy.casemodule.Case;
33import org.sleuthkit.autopsy.coreutils.Logger;
34import org.sleuthkit.autopsy.datamodel.BaseChildFactory.NoSuchEventBusException;
35import org.sleuthkit.autopsy.directorytree.ExplorerNodeActionVisitor;
36import org.sleuthkit.autopsy.directorytree.NewWindowViewAction;
37import org.sleuthkit.autopsy.ingest.IngestManager;
38import org.sleuthkit.autopsy.ingest.ModuleContentEvent;
39import org.sleuthkit.datamodel.Content;
40import org.sleuthkit.datamodel.Pool;
41import org.sleuthkit.datamodel.TskCoreException;
42import org.sleuthkit.datamodel.VirtualDirectory;
43import org.sleuthkit.datamodel.Volume;
44import org.sleuthkit.autopsy.directorytree.FileSystemDetailsAction;
45import org.sleuthkit.datamodel.Tag;
46
51public class VolumeNode extends AbstractContentNode<Volume> {
52
53 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 long end = vol.getStart() + (vol.getLength() - 1);
78 String tempVolName = volName + " (" + vol.getDescription() + ": " + vol.getStart() + "-" + end + ")";
79
80 // If this is a pool volume use a custom display name
81 try {
82 if (vol.getParent() != null
83 && vol.getParent().getParent() instanceof Pool) {
84 // Pool volumes are not contiguous so printing a range of blocks is inaccurate
85 tempVolName = volName + " (" + vol.getDescription() + ": " + vol.getStart() + ")";
86 }
87 } catch (TskCoreException ex) {
88 logger.log(Level.WARNING, "Error looking up parent(s) of volume with obj ID = " + vol.getId(), ex);
89 }
90 this.setDisplayName(tempVolName);
91
92 this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/vol-icon.png"); //NON-NLS
93 // Listen for ingest events so that we can detect new added files (e.g. carved)
95 // Listen for case events so that we can detect when case is closed
97 }
98
103
104 /*
105 * This property change listener refreshes the tree when a new file is
106 * carved out of the unallocated space of this volume.
107 */
108 private final PropertyChangeListener pcl = (PropertyChangeEvent evt) -> {
109 String eventType = evt.getPropertyName();
110
111 // See if the new file is a child of ours
112 if (eventType.equals(IngestManager.IngestModuleEvent.CONTENT_CHANGED.toString())) {
113 if ((evt.getOldValue() instanceof ModuleContentEvent) == false) {
114 return;
115 }
116 ModuleContentEvent moduleContentEvent = (ModuleContentEvent) evt.getOldValue();
117 if ((moduleContentEvent.getSource() instanceof Content) == false) {
118 return;
119 }
120 Content newContent = (Content) moduleContentEvent.getSource();
121
122 try {
123 Content parent = newContent.getParent();
124 if (parent != null) {
125 // Is this a new carved file?
126 if (parent.getName().equals(VirtualDirectory.NAME_CARVED)) {
127 // Is this new carved file for this data source?
128 if (newContent.getDataSource().getId() == getContent().getDataSource().getId()) {
129 // Find the volume (if any) associated with the new content and
130 // trigger a refresh if it matches the volume wrapped by this node.
131 while ((parent = parent.getParent()) != null) {
132 if (parent.getId() == getContent().getId()) {
134 break;
135 }
136 }
137 }
138 }
139 }
140 } catch (TskCoreException ex) {
141 // Do nothing.
142 } catch (NoSuchEventBusException ex) {
143 logger.log(Level.WARNING, eventType, ex);
144 }
145 } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) {
146 if (evt.getNewValue() == null) {
147 // case was closed. Remove listeners so that we don't get called with a stale case handle
149 }
150 }
151 };
152
160 @Override
161 public Action[] getActions(boolean popup) {
162 List<Action> actionsList = new ArrayList<>();
163 actionsList.add(new FileSystemDetailsAction(content));
164 actionsList.add(new NewWindowViewAction(
165 NbBundle.getMessage(this.getClass(), "VolumeNode.getActions.viewInNewWin.text"), this));
166 actionsList.addAll(ExplorerNodeActionVisitor.getActions(content));
167 actionsList.add(null);
168 actionsList.addAll(Arrays.asList(super.getActions(true)));
169
170 return actionsList.toArray(new Action[actionsList.size()]);
171 }
172
173 @Override
174 protected Sheet createSheet() {
175 Sheet sheet = super.createSheet();
176 Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
177 if (sheetSet == null) {
178 sheetSet = Sheet.createPropertiesSet();
179 sheet.put(sheetSet);
180 }
181
182 sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.name.name"),
183 NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.name.displayName"),
184 NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.name.desc"),
185 this.getDisplayName()));
186 sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.id.name"),
187 NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.id.displayName"),
188 NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.id.desc"),
189 content.getAddr()));
190 sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.startSector.name"),
191 NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.startSector.displayName"),
192 NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.startSector.desc"),
193 content.getStart()));
194 sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.lenSectors.name"),
195 NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.lenSectors.displayName"),
196 NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.lenSectors.desc"),
197 content.getLength()));
198 sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.description.name"),
199 NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.description.displayName"),
200 NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.description.desc"),
201 content.getDescription()));
202 sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.flags.name"),
203 NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.flags.displayName"),
204 NbBundle.getMessage(this.getClass(), "VolumeNode.createSheet.flags.desc"),
205 content.getFlagsAsString()));
206
207 return sheet;
208 }
209
210 @Override
211 public <T> T accept(ContentNodeVisitor<T> visitor) {
212 return visitor.visit(this);
213 }
214
215 @Override
216 public boolean isLeafTypeNode() {
217 return false;
218 }
219
220 @Override
221 public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
222 return visitor.visit(this);
223 }
224
225 @Override
226 public String getItemType() {
227 return DisplayableItemNode.FILE_PARENT_NODE_KEY;
228 }
229
237 @Override
238 protected List<Tag> getAllTagsFromDatabase() {
239 return new ArrayList<>();
240 }
241
242}
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition Case.java:757
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition Case.java:712
synchronized static Logger getLogger(String name)
Definition Logger.java:124
static void post(String nodeName, Object event)
static final Set< IngestManager.IngestModuleEvent > INGEST_MODULE_EVENTS_OF_INTEREST
static synchronized IngestManager getInstance()
void removeIngestModuleEventListener(final PropertyChangeListener listener)
void addIngestModuleEventListener(final PropertyChangeListener listener)

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.