Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AbstractAbstractFileNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2014 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 org.openide.nodes.Children;
24 import java.util.Map;
25 import java.util.logging.Level;
26 import org.apache.commons.lang3.StringUtils;
27 import org.openide.util.NbBundle;
32 import org.sleuthkit.datamodel.AbstractFile;
33 import org.sleuthkit.datamodel.Content;
34 import org.sleuthkit.datamodel.TskCoreException;
35 
41 public abstract class AbstractAbstractFileNode<T extends AbstractFile> extends AbstractContentNode<T> {
42 
43  private static final Logger LOGGER = Logger.getLogger(AbstractAbstractFileNode.class.getName());
44 
49  AbstractAbstractFileNode(T abstractFile) {
50  super(abstractFile);
51  String name = abstractFile.getName();
52  int dotIndex = name.lastIndexOf(".");
53  if (dotIndex > 0) {
54  String ext = name.substring(dotIndex).toLowerCase();
55 
56  // If this is an archive file we will listen for ingest events
57  // that will notify us when new content has been identified.
58  for (String s : FileTypeExtensions.getArchiveExtensions()) {
59  if (ext.equals(s)) {
61  }
62  }
63  }
64  // Listen for case events so that we can detect when case is closed
66  }
67 
68  private void removeListeners() {
71  }
72 
73  private final PropertyChangeListener pcl = (PropertyChangeEvent evt) -> {
74  String eventType = evt.getPropertyName();
75 
76  // Is this a content changed event?
77  if (eventType.equals(IngestManager.IngestModuleEvent.CONTENT_CHANGED.toString())) {
78  if ((evt.getOldValue() instanceof ModuleContentEvent) == false) {
79  return;
80  }
81  ModuleContentEvent moduleContentEvent = (ModuleContentEvent) evt.getOldValue();
82  if ((moduleContentEvent.getSource() instanceof Content) == false) {
83  return;
84  }
85  Content newContent = (Content) moduleContentEvent.getSource();
86 
87  // Does the event indicate that content has been added to *this* file?
88  if (getContent().getId() == newContent.getId()) {
89  // If so, refresh our children.
90  try {
91  Children parentsChildren = getParentNode().getChildren();
92  if (parentsChildren != null) {
93  ((ContentChildren) parentsChildren).refreshChildren();
94  parentsChildren.getNodesCount();
95  }
96  } catch (NullPointerException ex) {
97  // Skip
98  }
99 
100  }
101  } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) {
102  if (evt.getNewValue() == null) {
103  // case was closed. Remove listeners so that we don't get called with a stale case handle
104  removeListeners();
105  }
106  }
107  };
108 
109  // Note: this order matters for the search result, changed it if the order of property headers on the "KeywordSearchNode"changed
110  public static enum AbstractFilePropertyType {
111 
112  NAME {
113  @Override
114  public String toString() {
115  return NbBundle.getMessage(this.getClass(), "AbstractAbstractFileNode.nameColLbl");
116  }
117  },
118  LOCATION {
119  @Override
120  public String toString() {
121  return NbBundle.getMessage(this.getClass(), "AbstractAbstractFileNode.locationColLbl");
122  }
123  },
124  MOD_TIME {
125  @Override
126  public String toString() {
127  return NbBundle.getMessage(this.getClass(), "AbstractAbstractFileNode.modifiedTimeColLbl");
128  }
129  },
130  CHANGED_TIME {
131  @Override
132  public String toString() {
133  return NbBundle.getMessage(this.getClass(), "AbstractAbstractFileNode.changeTimeColLbl");
134  }
135  },
136  ACCESS_TIME {
137  @Override
138  public String toString() {
139  return NbBundle.getMessage(this.getClass(), "AbstractAbstractFileNode.accessTimeColLbl");
140  }
141  },
142  CREATED_TIME {
143  @Override
144  public String toString() {
145  return NbBundle.getMessage(this.getClass(), "AbstractAbstractFileNode.createdTimeColLbl");
146  }
147  },
148  SIZE {
149  @Override
150  public String toString() {
151  return NbBundle.getMessage(this.getClass(), "AbstractAbstractFileNode.sizeColLbl");
152  }
153  },
154  FLAGS_DIR {
155  @Override
156  public String toString() {
157  return NbBundle.getMessage(this.getClass(), "AbstractAbstractFileNode.flagsDirColLbl");
158  }
159  },
160  FLAGS_META {
161  @Override
162  public String toString() {
163  return NbBundle.getMessage(this.getClass(), "AbstractAbstractFileNode.flagsMetaColLbl");
164  }
165  },
166  MODE {
167  @Override
168  public String toString() {
169  return NbBundle.getMessage(this.getClass(), "AbstractAbstractFileNode.modeColLbl");
170  }
171  },
172  USER_ID {
173  @Override
174  public String toString() {
175  return NbBundle.getMessage(this.getClass(), "AbstractAbstractFileNode.useridColLbl");
176  }
177  },
178  GROUP_ID {
179  @Override
180  public String toString() {
181  return NbBundle.getMessage(this.getClass(), "AbstractAbstractFileNode.groupidColLbl");
182  }
183  },
184  META_ADDR {
185  @Override
186  public String toString() {
187  return NbBundle.getMessage(this.getClass(), "AbstractAbstractFileNode.metaAddrColLbl");
188  }
189  },
190  ATTR_ADDR {
191  @Override
192  public String toString() {
193  return NbBundle.getMessage(this.getClass(), "AbstractAbstractFileNode.attrAddrColLbl");
194  }
195  },
196  TYPE_DIR {
197  @Override
198  public String toString() {
199  return NbBundle.getMessage(this.getClass(), "AbstractAbstractFileNode.typeDirColLbl");
200  }
201  },
202  TYPE_META {
203  @Override
204  public String toString() {
205  return NbBundle.getMessage(this.getClass(), "AbstractAbstractFileNode.typeMetaColLbl");
206  }
207  },
208  KNOWN {
209  @Override
210  public String toString() {
211  return NbBundle.getMessage(this.getClass(), "AbstractAbstractFileNode.knownColLbl");
212  }
213  },
214  HASHSETS {
215  @Override
216  public String toString() {
217  return NbBundle.getMessage(this.getClass(), "AbstractAbstractFileNode.inHashsetsColLbl");
218  }
219  },
220  MD5HASH {
221  @Override
222  public String toString() {
223  return NbBundle.getMessage(this.getClass(), "AbstractAbstractFileNode.md5HashColLbl");
224  }
225  },
226  ObjectID {
227  @Override
228  public String toString() {
229  return NbBundle.getMessage(this.getClass(), "AbstractAbstractFileNode.objectId");
230 
231  }
232  },
233  MIMETYPE {
234  @Override
235  public String toString() {
236  return NbBundle.getMessage(this.getClass(), "AbstractAbstractFileNode.mimeType");
237 
238  }
239  },
240  }
241 
249  public static void fillPropertyMap(Map<String, Object> map, AbstractFile content) {
250 
251  String path = "";
252  try {
253  path = content.getUniquePath();
254  } catch (TskCoreException ex) {
255  LOGGER.log(Level.SEVERE, "Except while calling Content.getUniquePath() on {0}", content); //NON-NLS
256  }
257 
258  map.put(AbstractFilePropertyType.NAME.toString(), AbstractAbstractFileNode.getContentDisplayName(content));
259  map.put(AbstractFilePropertyType.LOCATION.toString(), path);
260  map.put(AbstractFilePropertyType.MOD_TIME.toString(), ContentUtils.getStringTime(content.getMtime(), content));
261  map.put(AbstractFilePropertyType.CHANGED_TIME.toString(), ContentUtils.getStringTime(content.getCtime(), content));
262  map.put(AbstractFilePropertyType.ACCESS_TIME.toString(), ContentUtils.getStringTime(content.getAtime(), content));
263  map.put(AbstractFilePropertyType.CREATED_TIME.toString(), ContentUtils.getStringTime(content.getCrtime(), content));
264  map.put(AbstractFilePropertyType.SIZE.toString(), content.getSize());
265  map.put(AbstractFilePropertyType.FLAGS_DIR.toString(), content.getDirFlagAsString());
266  map.put(AbstractFilePropertyType.FLAGS_META.toString(), content.getMetaFlagsAsString());
267  map.put(AbstractFilePropertyType.MODE.toString(), content.getModesAsString());
268  map.put(AbstractFilePropertyType.USER_ID.toString(), content.getUid());
269  map.put(AbstractFilePropertyType.GROUP_ID.toString(), content.getGid());
270  map.put(AbstractFilePropertyType.META_ADDR.toString(), content.getMetaAddr());
271  map.put(AbstractFilePropertyType.ATTR_ADDR.toString(), Long.toString(content.getAttrType().getValue()) + "-" + Long.toString(content.getAttrId()));
272  map.put(AbstractFilePropertyType.TYPE_DIR.toString(), content.getDirType().getLabel());
273  map.put(AbstractFilePropertyType.TYPE_META.toString(), content.getMetaType().toString());
274  map.put(AbstractFilePropertyType.KNOWN.toString(), content.getKnown().getName());
275  map.put(AbstractFilePropertyType.HASHSETS.toString(), getHashSetHitsForFile(content));
276  map.put(AbstractFilePropertyType.MD5HASH.toString(), content.getMd5Hash() == null ? "" : content.getMd5Hash());
277  map.put(AbstractFilePropertyType.ObjectID.toString(), content.getId());
278  map.put(AbstractFilePropertyType.MIMETYPE.toString(), content.getMIMEType() == null ? "" : content.getMIMEType());
279  }
280 
281  static String getContentDisplayName(AbstractFile file) {
282  String name = file.getName();
283  switch (name) {
284  case "..":
285  return DirectoryNode.DOTDOTDIR;
286 
287  case ".":
288  return DirectoryNode.DOTDIR;
289  default:
290  return name;
291  }
292  }
293 
294  @SuppressWarnings("deprecation")
295  private static String getHashSetHitsForFile(AbstractFile content) {
296  try {
297  return StringUtils.join(content.getHashSetNames(), ", ");
298  } catch (TskCoreException tskCoreException) {
299  LOGGER.log(Level.WARNING, "Error getting hashset hits: ", tskCoreException); //NON-NLS
300  return "";
301  }
302  }
303 }
void removeIngestModuleEventListener(final PropertyChangeListener listener)
static String getStringTime(long epochSeconds, TimeZone tzone)
static synchronized IngestManager getInstance()
static void fillPropertyMap(Map< String, Object > map, AbstractFile content)
static synchronized void removePropertyChangeListener(PropertyChangeListener listener)
Definition: Case.java:1305
void addIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized void addPropertyChangeListener(PropertyChangeListener listener)
Definition: Case.java:1292
synchronized static Logger getLogger(String name)
Definition: Logger.java:166

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.