Autopsy  4.11.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-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.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.apache.commons.lang3.tuple.Pair;
32 import org.openide.nodes.Sheet;
33 import org.openide.util.NbBundle;
34 import org.openide.util.NbBundle.Messages;
47 import org.sleuthkit.datamodel.Content;
48 import org.sleuthkit.datamodel.Image;
49 import org.sleuthkit.datamodel.SleuthkitCase.CaseDbQuery;
50 import org.sleuthkit.datamodel.TskCoreException;
51 import org.sleuthkit.datamodel.VirtualDirectory;
53 import org.sleuthkit.datamodel.Tag;
54 
59 public class ImageNode extends AbstractContentNode<Image> {
60 
61  private static final Logger logger = Logger.getLogger(ImageNode.class.getName());
62 
71  static String nameForImage(Image i) {
72  return i.getName();
73  }
74 
78  public ImageNode(Image img) {
79  super(img);
80 
81  // set name, display name, and icon
82  String imgName = nameForImage(img);
83  this.setDisplayName(imgName);
84  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/hard-drive-icon.jpg"); //NON-NLS
85 
86  // Listen for ingest events so that we can detect new added files (e.g. carved)
88  // Listen for case events so that we can detect when case is closed
90  }
91 
92  private void removeListeners() {
95  }
96 
104  @Override
105  @Messages({"ImageNode.action.runIngestMods.text=Run Ingest Modules",
106  "ImageNode.getActions.openFileSearchByAttr.text=Open File Search by Attributes",})
107  public Action[] getActions(boolean context) {
108 
109  List<Action> actionsList = new ArrayList<>();
110  for (Action a : super.getActions(true)) {
111  actionsList.add(a);
112  }
113  actionsList.addAll(ExplorerNodeActionVisitor.getActions(content));
114  actionsList.add(new FileSearchAction(
115  Bundle.ImageNode_getActions_openFileSearchByAttr_text()));
116  actionsList.add(new ViewSummaryInformationAction(content.getId()));
117  actionsList.add(new RunIngestModulesAction(Collections.<Content>singletonList(content)));
118  actionsList.add(new NewWindowViewAction(
119  NbBundle.getMessage(this.getClass(), "ImageNode.getActions.viewInNewWin.text"), this));
120  return actionsList.toArray(new Action[0]);
121  }
122 
123  @Override
124  @Messages({"ImageNode.createSheet.size.name=Size (Bytes)",
125  "ImageNode.createSheet.size.displayName=Size (Bytes)",
126  "ImageNode.createSheet.size.desc=Size of the data source in bytes.",
127  "ImageNode.createSheet.type.name=Type",
128  "ImageNode.createSheet.type.displayName=Type",
129  "ImageNode.createSheet.type.desc=Type of the image.",
130  "ImageNode.createSheet.type.text=Image",
131  "ImageNode.createSheet.sectorSize.name=Sector Size (Bytes)",
132  "ImageNode.createSheet.sectorSize.displayName=Sector Size (Bytes)",
133  "ImageNode.createSheet.sectorSize.desc=Sector size of the image in bytes.",
134  "ImageNode.createSheet.timezone.name=Timezone",
135  "ImageNode.createSheet.timezone.displayName=Timezone",
136  "ImageNode.createSheet.timezone.desc=Timezone of the image",
137  "ImageNode.createSheet.deviceId.name=Device ID",
138  "ImageNode.createSheet.deviceId.displayName=Device ID",
139  "ImageNode.createSheet.deviceId.desc=Device ID of the image"})
140  protected Sheet createSheet() {
141  Sheet sheet = super.createSheet();
142  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
143  if (sheetSet == null) {
144  sheetSet = Sheet.createPropertiesSet();
145  sheet.put(sheetSet);
146  }
147 
148  sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ImageNode.createSheet.name.name"),
149  NbBundle.getMessage(this.getClass(), "ImageNode.createSheet.name.displayName"),
150  NbBundle.getMessage(this.getClass(), "ImageNode.createSheet.name.desc"),
151  getDisplayName()));
152 
153  sheetSet.put(new NodeProperty<>(Bundle.ImageNode_createSheet_type_name(),
154  Bundle.ImageNode_createSheet_type_displayName(),
155  Bundle.ImageNode_createSheet_type_desc(),
156  Bundle.ImageNode_createSheet_type_text()));
157 
158  sheetSet.put(new NodeProperty<>(Bundle.ImageNode_createSheet_size_name(),
159  Bundle.ImageNode_createSheet_size_displayName(),
160  Bundle.ImageNode_createSheet_size_desc(),
161  this.content.getSize()));
162  sheetSet.put(new NodeProperty<>(Bundle.ImageNode_createSheet_sectorSize_name(),
163  Bundle.ImageNode_createSheet_sectorSize_displayName(),
164  Bundle.ImageNode_createSheet_sectorSize_desc(),
165  this.content.getSsize()));
166 
167  sheetSet.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.getCurrentCaseThrows().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  sheetSet.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 | NoCurrentCaseException ex) {
181  logger.log(Level.SEVERE, "Failed to get device id for the following image: " + this.content.getId(), ex);
182  }
183 
184  return sheet;
185  }
186 
187  @Override
188  public <T> T accept(ContentNodeVisitor<T> visitor) {
189  return visitor.visit(this);
190  }
191 
192  @Override
193  public boolean isLeafTypeNode() {
194  return false;
195  }
196 
197  @Override
198  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
199  return visitor.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  // Is this new carved file for this data source?
232  if (newContent.getDataSource().getId() == getContent().getDataSource().getId()) {
233  // Find the image (if any) associated with the new content and
234  // trigger a refresh if it matches the image wrapped by this node.
235  while ((parent = parent.getParent()) != null) {
236  if (parent.getId() == getContent().getId()) {
238  break;
239  }
240  }
241  }
242  }
243  }
244  } catch (TskCoreException ex) {
245  // Do nothing.
246  } catch (NoSuchEventBusException ex) {
247  logger.log(Level.WARNING, "Failed to post key refresh event.", ex); // NON-NLS
248  }
249  } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) {
250  if (evt.getNewValue() == null) {
251  // case was closed. Remove listeners so that we don't get called with a stale case handle
252  removeListeners();
253  }
254  }
255  };
256 
264  @Override
265  protected List<Tag> getAllTagsFromDatabase() {
266  return new ArrayList<>();
267  }
268 
278  @Override
280  return null;
281  }
282 
292  @Override
293  protected Pair<DataResultViewerTable.Score, String> getScorePropertyAndDescription(List<Tag> tags) {
294  return Pair.of(DataResultViewerTable.Score.NO_SCORE, NO_DESCR);
295  }
296 
307  @Override
310  }
311 
324  @Override
325  protected Pair<Long, String> getCountPropertyAndDescription(CorrelationAttributeInstance.Type attributeType, String attributeValue, String defaultDescription) {
326  return Pair.of(-1L, NO_DESCR);
327  }
328 }
void removeIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized IngestManager getInstance()
CorrelationAttributeInstance getCorrelationAttributeInstance()
Definition: ImageNode.java:279
Action[] getActions(boolean context)
Definition: ImageNode.java:107
Pair< Long, String > getCountPropertyAndDescription(CorrelationAttributeInstance.Type attributeType, String attributeValue, String defaultDescription)
Definition: ImageNode.java:325
Pair< DataResultViewerTable.Score, String > getScorePropertyAndDescription(List< Tag > tags)
Definition: ImageNode.java:293
final PropertyChangeListener pcl
Definition: ImageNode.java:212
static void post(String nodeName, Object event)
DataResultViewerTable.HasCommentStatus getCommentProperty(List< Tag > tags, CorrelationAttributeInstance attribute)
Definition: ImageNode.java:308
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:441
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:486

Copyright © 2012-2018 Basis Technology. Generated on: Fri Jun 21 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.