Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
ImageNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2012-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  */
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.Collections;
25 import java.util.EnumSet;
26 import java.util.List;
27 import java.util.Set;
28 import java.util.logging.Level;
29 import javax.swing.Action;
30 import org.openide.nodes.Sheet;
31 import org.openide.util.NbBundle;
32 import org.openide.util.NbBundle.Messages;
43 import org.sleuthkit.datamodel.Content;
44 import org.sleuthkit.datamodel.Image;
45 import org.sleuthkit.datamodel.TskCoreException;
46 import org.sleuthkit.datamodel.VirtualDirectory;
48 import org.sleuthkit.datamodel.Tag;
49 
54 public class ImageNode extends AbstractContentNode<Image> {
55 
56  private static final Logger logger = Logger.getLogger(ImageNode.class.getName());
58 
67  static String nameForImage(Image i) {
68  return i.getName();
69  }
70 
74  public ImageNode(Image img) {
75  super(img);
76 
77  // set name, display name, and icon
78  String imgName = nameForImage(img);
79  this.setDisplayName(imgName);
80  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/hard-drive-icon.jpg"); //NON-NLS
81 
82  // Listen for ingest events so that we can detect new added files (e.g. carved)
84  // Listen for case events so that we can detect when case is closed
86  }
87 
88  private void removeListeners() {
91  }
92 
100  @Override
101  @Messages({"ImageNode.action.runIngestMods.text=Run Ingest Modules",
102  "ImageNode.getActions.openFileSearchByAttr.text=Open File Search by Attributes"})
103  public Action[] getActions(boolean context) {
104 
105  List<Action> actionsList = new ArrayList<>();
106  for (Action a : super.getActions(true)) {
107  actionsList.add(a);
108  }
109  actionsList.addAll(ExplorerNodeActionVisitor.getActions(content));
110  actionsList.add(new FileSearchAction(Bundle.ImageNode_getActions_openFileSearchByAttr_text(), content.getId()));
111  actionsList.add(new ViewSummaryInformationAction(content.getId()));
112  actionsList.add(new RunIngestModulesAction(Collections.<Content>singletonList(content)));
113  actionsList.add(new NewWindowViewAction(NbBundle.getMessage(this.getClass(), "ImageNode.getActions.viewInNewWin.text"), this));
114  actionsList.add(new DeleteDataSourceAction(content.getId()));
115  return actionsList.toArray(new Action[0]);
116  }
117 
118  @Override
119  @Messages({"ImageNode.createSheet.size.name=Size (Bytes)",
120  "ImageNode.createSheet.size.displayName=Size (Bytes)",
121  "ImageNode.createSheet.size.desc=Size of the data source in bytes.",
122  "ImageNode.createSheet.type.name=Type",
123  "ImageNode.createSheet.type.displayName=Type",
124  "ImageNode.createSheet.type.desc=Type of the image.",
125  "ImageNode.createSheet.type.text=Image",
126  "ImageNode.createSheet.sectorSize.name=Sector Size (Bytes)",
127  "ImageNode.createSheet.sectorSize.displayName=Sector Size (Bytes)",
128  "ImageNode.createSheet.sectorSize.desc=Sector size of the image in bytes.",
129  "ImageNode.createSheet.timezone.name=Timezone",
130  "ImageNode.createSheet.timezone.displayName=Timezone",
131  "ImageNode.createSheet.timezone.desc=Timezone of the image",
132  "ImageNode.createSheet.deviceId.name=Device ID",
133  "ImageNode.createSheet.deviceId.displayName=Device ID",
134  "ImageNode.createSheet.deviceId.desc=Device ID of the image"})
135  protected Sheet createSheet() {
136  Sheet sheet = super.createSheet();
137  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
138  if (sheetSet == null) {
139  sheetSet = Sheet.createPropertiesSet();
140  sheet.put(sheetSet);
141  }
142 
143  sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ImageNode.createSheet.name.name"),
144  NbBundle.getMessage(this.getClass(), "ImageNode.createSheet.name.displayName"),
145  NbBundle.getMessage(this.getClass(), "ImageNode.createSheet.name.desc"),
146  getDisplayName()));
147 
148  sheetSet.put(new NodeProperty<>(Bundle.ImageNode_createSheet_type_name(),
149  Bundle.ImageNode_createSheet_type_displayName(),
150  Bundle.ImageNode_createSheet_type_desc(),
151  Bundle.ImageNode_createSheet_type_text()));
152 
153  sheetSet.put(new NodeProperty<>(Bundle.ImageNode_createSheet_size_name(),
154  Bundle.ImageNode_createSheet_size_displayName(),
155  Bundle.ImageNode_createSheet_size_desc(),
156  this.content.getSize()));
157  sheetSet.put(new NodeProperty<>(Bundle.ImageNode_createSheet_sectorSize_name(),
158  Bundle.ImageNode_createSheet_sectorSize_displayName(),
159  Bundle.ImageNode_createSheet_sectorSize_desc(),
160  this.content.getSsize()));
161 
162  sheetSet.put(new NodeProperty<>(Bundle.ImageNode_createSheet_timezone_name(),
163  Bundle.ImageNode_createSheet_timezone_displayName(),
164  Bundle.ImageNode_createSheet_timezone_desc(),
165  this.content.getTimeZone()));
166 
167  sheetSet.put(new NodeProperty<>(Bundle.ImageNode_createSheet_deviceId_name(),
168  Bundle.ImageNode_createSheet_deviceId_displayName(),
169  Bundle.ImageNode_createSheet_deviceId_desc(),
170  content.getDeviceId()));
171 
172  return sheet;
173  }
174 
175  @Override
176  public <T> T accept(ContentNodeVisitor<T> visitor) {
177  return visitor.visit(this);
178  }
179 
180  @Override
181  public boolean isLeafTypeNode() {
182  return false;
183  }
184 
185  @Override
186  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
187  return visitor.visit(this);
188  }
189 
190  @Override
191  public String getItemType() {
192  return getClass().getName();
193  }
194 
195  /*
196  * This property change listener refreshes the tree when a new file is
197  * carved out of this image (i.e, the image is being treated as raw bytes
198  * and was ingested by the RawDSProcessor).
199  */
200  private final PropertyChangeListener pcl = (PropertyChangeEvent evt) -> {
201  String eventType = evt.getPropertyName();
202 
203  // See if the new file is a child of ours
204  if (eventType.equals(IngestManager.IngestModuleEvent.CONTENT_CHANGED.toString())) {
205  if ((evt.getOldValue() instanceof ModuleContentEvent) == false) {
206  return;
207  }
208  ModuleContentEvent moduleContentEvent = (ModuleContentEvent) evt.getOldValue();
209  if ((moduleContentEvent.getSource() instanceof Content) == false) {
210  return;
211  }
212  Content newContent = (Content) moduleContentEvent.getSource();
213 
214  try {
215  Content parent = newContent.getParent();
216  if (parent != null) {
217  // Is this a new carved file?
218  if (parent.getName().equals(VirtualDirectory.NAME_CARVED)) {
219  // Is this new carved file for this data source?
220  if (newContent.getDataSource().getId() == getContent().getDataSource().getId()) {
221  // Find the image (if any) associated with the new content and
222  // trigger a refresh if it matches the image wrapped by this node.
223  while ((parent = parent.getParent()) != null) {
224  if (parent.getId() == getContent().getId()) {
226  break;
227  }
228  }
229  }
230  }
231  }
232  } catch (TskCoreException ex) {
233  // Do nothing.
234  } catch (NoSuchEventBusException ex) {
235  logger.log(Level.WARNING, "Failed to post key refresh event.", ex); // NON-NLS
236  }
237  } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) {
238  if (evt.getNewValue() == null) {
239  // case was closed. Remove listeners so that we don't get called with a stale case handle
240  removeListeners();
241  }
242  }
243  };
244 
252  @Override
253  protected List<Tag> getAllTagsFromDatabase() {
254  return new ArrayList<>();
255  }
256 }
void removeIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized IngestManager getInstance()
Action[] getActions(boolean context)
Definition: ImageNode.java:103
final PropertyChangeListener pcl
Definition: ImageNode.java:200
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
static final Set< IngestManager.IngestModuleEvent > INGEST_MODULE_EVENTS_OF_INTEREST
Definition: ImageNode.java:57

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