Autopsy  4.4
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-2017 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.List;
28 import java.util.logging.Level;
29 import javax.swing.Action;
30 import org.openide.nodes.Children;
31 import org.openide.nodes.Sheet;
32 import org.openide.util.NbBundle;
33 import org.openide.util.NbBundle.Messages;
42 import org.sleuthkit.datamodel.Content;
43 import org.sleuthkit.datamodel.Image;
44 import org.sleuthkit.datamodel.SleuthkitCase.CaseDbQuery;
45 import org.sleuthkit.datamodel.TskCoreException;
46 import org.sleuthkit.datamodel.VirtualDirectory;
47 
52 public class ImageNode extends AbstractContentNode<Image> {
53 
54  private static final Logger logger = Logger.getLogger(ImageNode.class.getName());
55 
64  static String nameForImage(Image i) {
65  return i.getName();
66  }
67 
71  public ImageNode(Image img) {
72  super(img);
73 
74  // set name, display name, and icon
75  String imgName = nameForImage(img);
76  this.setDisplayName(imgName);
77  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/hard-drive-icon.jpg"); //NON-NLS
78 
79  // Listen for ingest events so that we can detect new added files (e.g. carved)
81  // Listen for case events so that we can detect when case is closed
83  }
84 
85  private void removeListeners() {
88  }
89 
97  @Override
98  @Messages({"ImageNode.action.runIngestMods.text=Run Ingest Modules",
99  "ImageNode.getActions.openFileSearchByAttr.text=Open File Search by Attributes",})
100  public Action[] getActions(boolean context) {
101 
102  List<Action> actionsList = new ArrayList<>();
103  for (Action a : super.getActions(true)) {
104  actionsList.add(a);
105  }
106  actionsList.addAll(ExplorerNodeActionVisitor.getActions(content));
107  actionsList.add(new FileSearchAction(
108  Bundle.ImageNode_getActions_openFileSearchByAttr_text()));
109  actionsList.add(new RunIngestModulesAction(Collections.<Content>singletonList(content)));
110  actionsList.add(new NewWindowViewAction(
111  NbBundle.getMessage(this.getClass(), "ImageNode.getActions.viewInNewWin.text"), this));
112  return actionsList.toArray(new Action[0]);
113  }
114 
115  @Override
116  @Messages({"ImageNode.createSheet.size.name=Size (Bytes)",
117  "ImageNode.createSheet.size.displayName=Size (Bytes)",
118  "ImageNode.createSheet.size.desc=Size of the data source in bytes.",
119  "ImageNode.createSheet.type.name=Type",
120  "ImageNode.createSheet.type.displayName=Type",
121  "ImageNode.createSheet.type.desc=Type of the image.",
122  "ImageNode.createSheet.type.text=Image",
123  "ImageNode.createSheet.sectorSize.name=Sector Size (Bytes)",
124  "ImageNode.createSheet.sectorSize.displayName=Sector Size (Bytes)",
125  "ImageNode.createSheet.sectorSize.desc=Sector size of the image in bytes.",
126  "ImageNode.createSheet.md5.name=MD5 Hash",
127  "ImageNode.createSheet.md5.displayName=MD5 Hash",
128  "ImageNode.createSheet.md5.desc=MD5 Hash of the image",
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 s = super.createSheet();
137  Sheet.Set ss = s.get(Sheet.PROPERTIES);
138  if (ss == null) {
139  ss = Sheet.createPropertiesSet();
140  s.put(ss);
141  }
142 
143  ss.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  ss.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  ss.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  ss.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  ss.put(new NodeProperty<>(Bundle.ImageNode_createSheet_md5_name(),
163  Bundle.ImageNode_createSheet_md5_displayName(),
164  Bundle.ImageNode_createSheet_md5_desc(),
165  this.content.getMd5()));
166 
167  ss.put(new NodeProperty<>(Bundle.ImageNode_createSheet_timezone_name(),
168  Bundle.ImageNode_createSheet_timezone_displayName(),
169  Bundle.ImageNode_createSheet_timezone_desc(),
170  this.content.getTimeZone()));
171 
172  try (CaseDbQuery query = Case.getCurrentCase().getSleuthkitCase().executeQuery("SELECT device_id FROM data_source_info WHERE obj_id = " + this.content.getId());) {
173  ResultSet deviceIdSet = query.getResultSet();
174  if (deviceIdSet.next()) {
175  ss.put(new NodeProperty<>(Bundle.ImageNode_createSheet_deviceId_name(),
176  Bundle.ImageNode_createSheet_deviceId_displayName(),
177  Bundle.ImageNode_createSheet_deviceId_desc(),
178  deviceIdSet.getString("device_id")));
179  }
180  } catch (SQLException | TskCoreException ex) {
181  logger.log(Level.SEVERE, "Failed to get device id for the following image: " + this.content.getId(), ex);
182  }
183 
184  return s;
185  }
186 
187  @Override
188  public <T> T accept(ContentNodeVisitor<T> v) {
189  return v.visit(this);
190  }
191 
192  @Override
193  public boolean isLeafTypeNode() {
194  return false;
195  }
196 
197  @Override
198  public <T> T accept(DisplayableItemNodeVisitor<T> v) {
199  return v.visit(this);
200  }
201 
202  @Override
203  public String getItemType() {
204  return getClass().getName();
205  }
206 
207  /*
208  * This property change listener refreshes the tree when a new file is
209  * carved out of this image (i.e, the image is being treated as raw bytes
210  * and was ingested by the RawDSProcessor).
211  */
212  private final PropertyChangeListener pcl = (PropertyChangeEvent evt) -> {
213  String eventType = evt.getPropertyName();
214 
215  // See if the new file is a child of ours
216  if (eventType.equals(IngestManager.IngestModuleEvent.CONTENT_CHANGED.toString())) {
217  if ((evt.getOldValue() instanceof ModuleContentEvent) == false) {
218  return;
219  }
220  ModuleContentEvent moduleContentEvent = (ModuleContentEvent) evt.getOldValue();
221  if ((moduleContentEvent.getSource() instanceof Content) == false) {
222  return;
223  }
224  Content newContent = (Content) moduleContentEvent.getSource();
225 
226  try {
227  Content parent = newContent.getParent();
228  if (parent != null) {
229  // Is this a new carved file?
230  if (parent.getName().equals(VirtualDirectory.NAME_CARVED)) {
231  // Was this new carved file produced from this image?
232  if (parent.getParent().getId() == getContent().getId()) {
233  Children children = getChildren();
234  if (children != null) {
235  ((ContentChildren) children).refreshChildren();
236  children.getNodesCount();
237  }
238  }
239  }
240  }
241  } catch (TskCoreException ex) {
242  // Do nothing.
243  }
244  } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) {
245  if (evt.getNewValue() == null) {
246  // case was closed. Remove listeners so that we don't get called with a stale case handle
247  removeListeners();
248  }
249  }
250  };
251 
252 }
void removeIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized IngestManager getInstance()
static void removePropertyChangeListener(PropertyChangeListener listener)
Definition: Case.java:369
Action[] getActions(boolean context)
Definition: ImageNode.java:100
final PropertyChangeListener pcl
Definition: ImageNode.java:212
static void addPropertyChangeListener(PropertyChangeListener listener)
Definition: Case.java:357
void addIngestModuleEventListener(final PropertyChangeListener listener)
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

Copyright © 2012-2016 Basis Technology. Generated on: Tue Jun 13 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.