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

Copyright © 2012-2018 Basis Technology. Generated on: Tue Dec 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.