Autopsy  4.6.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 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.md5.name=MD5 Hash",
129  "ImageNode.createSheet.md5.displayName=MD5 Hash",
130  "ImageNode.createSheet.md5.desc=MD5 Hash of the image",
131  "ImageNode.createSheet.timezone.name=Timezone",
132  "ImageNode.createSheet.timezone.displayName=Timezone",
133  "ImageNode.createSheet.timezone.desc=Timezone of the image",
134  "ImageNode.createSheet.deviceId.name=Device ID",
135  "ImageNode.createSheet.deviceId.displayName=Device ID",
136  "ImageNode.createSheet.deviceId.desc=Device ID of the image"})
137  protected Sheet createSheet() {
138  Sheet sheet = super.createSheet();
139  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
140  if (sheetSet == null) {
141  sheetSet = Sheet.createPropertiesSet();
142  sheet.put(sheetSet);
143  }
144 
145  sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ImageNode.createSheet.name.name"),
146  NbBundle.getMessage(this.getClass(), "ImageNode.createSheet.name.displayName"),
147  NbBundle.getMessage(this.getClass(), "ImageNode.createSheet.name.desc"),
148  getDisplayName()));
149 
150  sheetSet.put(new NodeProperty<>(Bundle.ImageNode_createSheet_type_name(),
151  Bundle.ImageNode_createSheet_type_displayName(),
152  Bundle.ImageNode_createSheet_type_desc(),
153  Bundle.ImageNode_createSheet_type_text()));
154 
155  sheetSet.put(new NodeProperty<>(Bundle.ImageNode_createSheet_size_name(),
156  Bundle.ImageNode_createSheet_size_displayName(),
157  Bundle.ImageNode_createSheet_size_desc(),
158  this.content.getSize()));
159  sheetSet.put(new NodeProperty<>(Bundle.ImageNode_createSheet_sectorSize_name(),
160  Bundle.ImageNode_createSheet_sectorSize_displayName(),
161  Bundle.ImageNode_createSheet_sectorSize_desc(),
162  this.content.getSsize()));
163 
164  sheetSet.put(new NodeProperty<>(Bundle.ImageNode_createSheet_md5_name(),
165  Bundle.ImageNode_createSheet_md5_displayName(),
166  Bundle.ImageNode_createSheet_md5_desc(),
167  this.content.getMd5()));
168 
169  sheetSet.put(new NodeProperty<>(Bundle.ImageNode_createSheet_timezone_name(),
170  Bundle.ImageNode_createSheet_timezone_displayName(),
171  Bundle.ImageNode_createSheet_timezone_desc(),
172  this.content.getTimeZone()));
173 
174  try (CaseDbQuery query = Case.getOpenCase().getSleuthkitCase().executeQuery("SELECT device_id FROM data_source_info WHERE obj_id = " + this.content.getId());) {
175  ResultSet deviceIdSet = query.getResultSet();
176  if (deviceIdSet.next()) {
177  sheetSet.put(new NodeProperty<>(Bundle.ImageNode_createSheet_deviceId_name(),
178  Bundle.ImageNode_createSheet_deviceId_displayName(),
179  Bundle.ImageNode_createSheet_deviceId_desc(),
180  deviceIdSet.getString("device_id")));
181  }
182  } catch (SQLException | TskCoreException | NoCurrentCaseException ex) {
183  logger.log(Level.SEVERE, "Failed to get device id for the following image: " + this.content.getId(), ex);
184  }
185 
186  return sheet;
187  }
188 
189  @Override
190  public <T> T accept(ContentNodeVisitor<T> visitor) {
191  return visitor.visit(this);
192  }
193 
194  @Override
195  public boolean isLeafTypeNode() {
196  return false;
197  }
198 
199  @Override
200  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
201  return visitor.visit(this);
202  }
203 
204  @Override
205  public String getItemType() {
206  return getClass().getName();
207  }
208 
209  /*
210  * This property change listener refreshes the tree when a new file is
211  * carved out of this image (i.e, the image is being treated as raw bytes
212  * and was ingested by the RawDSProcessor).
213  */
214  private final PropertyChangeListener pcl = (PropertyChangeEvent evt) -> {
215  String eventType = evt.getPropertyName();
216 
217  // See if the new file is a child of ours
218  if (eventType.equals(IngestManager.IngestModuleEvent.CONTENT_CHANGED.toString())) {
219  if ((evt.getOldValue() instanceof ModuleContentEvent) == false) {
220  return;
221  }
222  ModuleContentEvent moduleContentEvent = (ModuleContentEvent) evt.getOldValue();
223  if ((moduleContentEvent.getSource() instanceof Content) == false) {
224  return;
225  }
226  Content newContent = (Content) moduleContentEvent.getSource();
227 
228  try {
229  Content parent = newContent.getParent();
230  if (parent != null) {
231  // Is this a new carved file?
232  if (parent.getName().equals(VirtualDirectory.NAME_CARVED)) {
233  // Was this new carved file produced from this image?
234  if (parent.getParent().getId() == getContent().getId()) {
235  Children children = getChildren();
236  if (children != null) {
237  ((ContentChildren) children).refreshChildren();
238  children.getNodesCount();
239  }
240  }
241  }
242  }
243  } catch (TskCoreException ex) {
244  // Do nothing.
245  }
246  } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) {
247  if (evt.getNewValue() == null) {
248  // case was closed. Remove listeners so that we don't get called with a stale case handle
249  removeListeners();
250  }
251  }
252  };
253 
254 }
void removeIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized IngestManager getInstance()
Action[] getActions(boolean context)
Definition: ImageNode.java:102
final PropertyChangeListener pcl
Definition: ImageNode.java:214
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:420
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:465

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