Autopsy  4.19.0
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-2019 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.apache.commons.lang3.tuple.Pair;
31 import org.openide.nodes.Sheet;
32 import org.openide.util.NbBundle;
33 import org.openide.util.NbBundle.Messages;
46 import org.sleuthkit.datamodel.Content;
47 import org.sleuthkit.datamodel.Image;
48 import org.sleuthkit.datamodel.TskCoreException;
49 import org.sleuthkit.datamodel.VirtualDirectory;
51 import org.sleuthkit.datamodel.Tag;
52 
57 public class ImageNode extends AbstractContentNode<Image> {
58 
59  private static final Logger logger = Logger.getLogger(ImageNode.class.getName());
61 
70  static String nameForImage(Image i) {
71  return i.getName();
72  }
73 
77  public ImageNode(Image img) {
78  super(img);
79 
80  // set name, display name, and icon
81  String imgName = nameForImage(img);
82  this.setDisplayName(imgName);
83  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/hard-drive-icon.jpg"); //NON-NLS
84 
85  // Listen for ingest events so that we can detect new added files (e.g. carved)
87  // Listen for case events so that we can detect when case is closed
89  }
90 
91  private void removeListeners() {
94  }
95 
103  @Override
104  @Messages({"ImageNode.action.runIngestMods.text=Run Ingest Modules",
105  "ImageNode.getActions.openFileSearchByAttr.text=Open File Search by Attributes"})
106  public Action[] getActions(boolean context) {
107 
108  List<Action> actionsList = new ArrayList<>();
109  for (Action a : super.getActions(true)) {
110  actionsList.add(a);
111  }
112  actionsList.addAll(ExplorerNodeActionVisitor.getActions(content));
113  actionsList.add(new FileSearchAction(Bundle.ImageNode_getActions_openFileSearchByAttr_text()));
114  actionsList.add(new ViewSummaryInformationAction(content.getId()));
115  actionsList.add(new RunIngestModulesAction(Collections.<Content>singletonList(content)));
116  actionsList.add(new NewWindowViewAction(NbBundle.getMessage(this.getClass(), "ImageNode.getActions.viewInNewWin.text"), this));
117  actionsList.add(new DeleteDataSourceAction(content.getId()));
118  return actionsList.toArray(new Action[0]);
119  }
120 
121  @Override
122  @Messages({"ImageNode.createSheet.size.name=Size (Bytes)",
123  "ImageNode.createSheet.size.displayName=Size (Bytes)",
124  "ImageNode.createSheet.size.desc=Size of the data source in bytes.",
125  "ImageNode.createSheet.type.name=Type",
126  "ImageNode.createSheet.type.displayName=Type",
127  "ImageNode.createSheet.type.desc=Type of the image.",
128  "ImageNode.createSheet.type.text=Image",
129  "ImageNode.createSheet.sectorSize.name=Sector Size (Bytes)",
130  "ImageNode.createSheet.sectorSize.displayName=Sector Size (Bytes)",
131  "ImageNode.createSheet.sectorSize.desc=Sector size of the image in bytes.",
132  "ImageNode.createSheet.timezone.name=Timezone",
133  "ImageNode.createSheet.timezone.displayName=Timezone",
134  "ImageNode.createSheet.timezone.desc=Timezone of the image",
135  "ImageNode.createSheet.deviceId.name=Device ID",
136  "ImageNode.createSheet.deviceId.displayName=Device ID",
137  "ImageNode.createSheet.deviceId.desc=Device ID of the image"})
138  protected Sheet createSheet() {
139  Sheet sheet = super.createSheet();
140  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
141  if (sheetSet == null) {
142  sheetSet = Sheet.createPropertiesSet();
143  sheet.put(sheetSet);
144  }
145 
146  sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ImageNode.createSheet.name.name"),
147  NbBundle.getMessage(this.getClass(), "ImageNode.createSheet.name.displayName"),
148  NbBundle.getMessage(this.getClass(), "ImageNode.createSheet.name.desc"),
149  getDisplayName()));
150 
151  sheetSet.put(new NodeProperty<>(Bundle.ImageNode_createSheet_type_name(),
152  Bundle.ImageNode_createSheet_type_displayName(),
153  Bundle.ImageNode_createSheet_type_desc(),
154  Bundle.ImageNode_createSheet_type_text()));
155 
156  sheetSet.put(new NodeProperty<>(Bundle.ImageNode_createSheet_size_name(),
157  Bundle.ImageNode_createSheet_size_displayName(),
158  Bundle.ImageNode_createSheet_size_desc(),
159  this.content.getSize()));
160  sheetSet.put(new NodeProperty<>(Bundle.ImageNode_createSheet_sectorSize_name(),
161  Bundle.ImageNode_createSheet_sectorSize_displayName(),
162  Bundle.ImageNode_createSheet_sectorSize_desc(),
163  this.content.getSsize()));
164 
165  sheetSet.put(new NodeProperty<>(Bundle.ImageNode_createSheet_timezone_name(),
166  Bundle.ImageNode_createSheet_timezone_displayName(),
167  Bundle.ImageNode_createSheet_timezone_desc(),
168  this.content.getTimeZone()));
169 
170  sheetSet.put(new NodeProperty<>(Bundle.ImageNode_createSheet_deviceId_name(),
171  Bundle.ImageNode_createSheet_deviceId_displayName(),
172  Bundle.ImageNode_createSheet_deviceId_desc(),
173  content.getDeviceId()));
174 
175  return sheet;
176  }
177 
178  @Override
179  public <T> T accept(ContentNodeVisitor<T> visitor) {
180  return visitor.visit(this);
181  }
182 
183  @Override
184  public boolean isLeafTypeNode() {
185  return false;
186  }
187 
188  @Override
189  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
190  return visitor.visit(this);
191  }
192 
193  @Override
194  public String getItemType() {
195  return getClass().getName();
196  }
197 
198  /*
199  * This property change listener refreshes the tree when a new file is
200  * carved out of this image (i.e, the image is being treated as raw bytes
201  * and was ingested by the RawDSProcessor).
202  */
203  private final PropertyChangeListener pcl = (PropertyChangeEvent evt) -> {
204  String eventType = evt.getPropertyName();
205 
206  // See if the new file is a child of ours
207  if (eventType.equals(IngestManager.IngestModuleEvent.CONTENT_CHANGED.toString())) {
208  if ((evt.getOldValue() instanceof ModuleContentEvent) == false) {
209  return;
210  }
211  ModuleContentEvent moduleContentEvent = (ModuleContentEvent) evt.getOldValue();
212  if ((moduleContentEvent.getSource() instanceof Content) == false) {
213  return;
214  }
215  Content newContent = (Content) moduleContentEvent.getSource();
216 
217  try {
218  Content parent = newContent.getParent();
219  if (parent != null) {
220  // Is this a new carved file?
221  if (parent.getName().equals(VirtualDirectory.NAME_CARVED)) {
222  // Is this new carved file for this data source?
223  if (newContent.getDataSource().getId() == getContent().getDataSource().getId()) {
224  // Find the image (if any) associated with the new content and
225  // trigger a refresh if it matches the image wrapped by this node.
226  while ((parent = parent.getParent()) != null) {
227  if (parent.getId() == getContent().getId()) {
229  break;
230  }
231  }
232  }
233  }
234  }
235  } catch (TskCoreException ex) {
236  // Do nothing.
237  } catch (NoSuchEventBusException ex) {
238  logger.log(Level.WARNING, "Failed to post key refresh event.", ex); // NON-NLS
239  }
240  } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) {
241  if (evt.getNewValue() == null) {
242  // case was closed. Remove listeners so that we don't get called with a stale case handle
243  removeListeners();
244  }
245  }
246  };
247 
255  @Override
256  protected List<Tag> getAllTagsFromDatabase() {
257  return new ArrayList<>();
258  }
259 
269  @Override
271  return null;
272  }
273 
284  @Override
287  }
288 
301  @Override
302  protected Pair<Long, String> getCountPropertyAndDescription(CorrelationAttributeInstance.Type attributeType, String attributeValue, String defaultDescription) {
303  return Pair.of(-1L, NO_DESCR);
304  }
305 }
void removeIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized IngestManager getInstance()
CorrelationAttributeInstance getCorrelationAttributeInstance()
Definition: ImageNode.java:270
Action[] getActions(boolean context)
Definition: ImageNode.java:106
Pair< Long, String > getCountPropertyAndDescription(CorrelationAttributeInstance.Type attributeType, String attributeValue, String defaultDescription)
Definition: ImageNode.java:302
final PropertyChangeListener pcl
Definition: ImageNode.java:203
static void post(String nodeName, Object event)
DataResultViewerTable.HasCommentStatus getCommentProperty(List< Tag > tags, CorrelationAttributeInstance attribute)
Definition: ImageNode.java:285
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:60

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