Autopsy  4.9.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
FileTypes.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.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.List;
24 import java.util.Observable;
25 import java.util.Observer;
26 import java.util.Set;
27 import java.util.concurrent.ExecutionException;
28 import java.util.logging.Level;
29 import javax.swing.SwingWorker;
30 import org.openide.nodes.AbstractNode;
31 import org.openide.nodes.Children;
32 import org.openide.nodes.Sheet;
33 import org.openide.util.Lookup;
34 import org.openide.util.NbBundle;
35 import org.openide.util.lookup.Lookups;
37 import org.sleuthkit.datamodel.BlackboardArtifact;
38 import org.sleuthkit.datamodel.BlackboardAttribute;
39 import org.sleuthkit.datamodel.Content;
40 import org.sleuthkit.datamodel.ContentVisitor;
41 import org.sleuthkit.datamodel.DerivedFile;
42 import org.sleuthkit.datamodel.Directory;
43 import org.sleuthkit.datamodel.File;
44 import org.sleuthkit.datamodel.LayoutFile;
45 import org.sleuthkit.datamodel.LocalFile;
46 import org.sleuthkit.datamodel.SlackFile;
47 import org.sleuthkit.datamodel.SleuthkitCase;
48 import org.sleuthkit.datamodel.SleuthkitItemVisitor;
49 import org.sleuthkit.datamodel.TskCoreException;
50 
54 public final class FileTypes implements AutopsyVisitableItem {
55 
56  private static final Logger logger = Logger.getLogger(FileTypes.class.getName());
57  @NbBundle.Messages("FileTypes.name.text=File Types")
58  private static final String NAME = Bundle.FileTypes_name_text();
65  private static final int NODE_COUNT_FILE_TABLE_THRESHOLD = 1_000_000;
71  private boolean showCounts = true;
72 
73  private final SleuthkitCase skCase;
74 
75  private final long datasourceObjId;
76 
77  FileTypes(SleuthkitCase skCase) {
78  this(skCase, 0);
79  }
80 
81  FileTypes(SleuthkitCase skCase, long dsObjId) {
82  this.skCase = skCase;
83  this.datasourceObjId = dsObjId;
84  updateShowCounts();
85  }
86 
87  @Override
88  public <T> T accept(AutopsyItemVisitor<T> visitor) {
89  return visitor.visit(this);
90  }
91 
92  SleuthkitCase getSleuthkitCase() {
93  return skCase;
94  }
95 
96  long filteringDataSourceObjId() {
97  return this.datasourceObjId;
98  }
102  void updateShowCounts() {
103  /*
104  * once we have passed the threshold, we don't need to keep checking the
105  * number of rows in tsk_files
106  */
107  if (showCounts) {
108  try {
109  if (skCase.countFilesWhere("1=1") > NODE_COUNT_FILE_TABLE_THRESHOLD) { //NON-NLS
110  showCounts = false;
111  }
112  } catch (TskCoreException tskCoreException) {
113  showCounts = false;
114  logger.log(Level.SEVERE, "Error counting files.", tskCoreException); //NON-NLS
115  }
116  }
117  }
118 
122  public final class FileTypesNode extends DisplayableItemNode {
123 
124  FileTypesNode() {
125  super(new RootContentChildren(Arrays.asList(
127  new FileTypesByMimeType(FileTypes.this))),
128  Lookups.singleton(NAME));
129  this.setName(NAME);
130  this.setDisplayName(NAME);
131  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/file_types.png"); //NON-NLS
132  }
133 
134  @Override
135  public boolean isLeafTypeNode() {
136  return false;
137  }
138 
139  @Override
140  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
141  return visitor.visit(this);
142  }
143 
144  @Override
145  @NbBundle.Messages({
146  "FileTypes.createSheet.name.name=Name",
147  "FileTypes.createSheet.name.displayName=Name",
148  "FileTypes.createSheet.name.desc=no description"})
149  protected Sheet createSheet() {
150  Sheet sheet = super.createSheet();
151  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
152  if (sheetSet == null) {
153  sheetSet = Sheet.createPropertiesSet();
154  sheet.put(sheetSet);
155  }
156 
157  sheetSet.put(new NodeProperty<>(Bundle.FileTypes_createSheet_name_name(),
158  Bundle.FileTypes_createSheet_name_displayName(),
159  Bundle.FileTypes_createSheet_name_desc(),
160  NAME
161  ));
162  return sheet;
163  }
164 
165  @Override
166  public String getItemType() {
167  return getClass().getName();
168  }
169 
170  }
171 
172  static class FileNodeCreationVisitor extends ContentVisitor.Default<AbstractNode> {
173 
174  FileNodeCreationVisitor() {
175  }
176 
177  @Override
178  public FileNode visit(File f) {
179  return new FileNode(f, false);
180  }
181 
182  @Override
183  public DirectoryNode visit(Directory d) {
184  return new DirectoryNode(d);
185  }
186 
187  @Override
188  public LayoutFileNode visit(LayoutFile lf) {
189  return new LayoutFileNode(lf);
190  }
191 
192  @Override
193  public LocalFileNode visit(DerivedFile df) {
194  return new LocalFileNode(df);
195  }
196 
197  @Override
198  public LocalFileNode visit(LocalFile lf) {
199  return new LocalFileNode(lf);
200  }
201 
202  @Override
203  public SlackFileNode visit(SlackFile sf) {
204  return new SlackFileNode(sf, false);
205  }
206 
207  @Override
208  protected AbstractNode defaultVisit(Content di) {
209  throw new UnsupportedOperationException(NbBundle.getMessage(this.getClass(), "FileTypeChildren.exception.notSupported.msg", di.toString()));
210  }
211  }
212 
213  static abstract class BGCountUpdatingNode extends DisplayableItemNode implements Observer {
214 
215  private long childCount = -1;
216  private FileTypes typesRoot;
217 
218  BGCountUpdatingNode(FileTypes typesRoot, Children children) {
219  this(typesRoot, children, null);
220  }
221 
222  BGCountUpdatingNode(FileTypes typesRoot, Children children, Lookup lookup) {
223  super(children, lookup);
224  this.typesRoot = typesRoot;
225  }
226 
227  @Override
228  public void update(Observable o, Object arg) {
229  updateDisplayName();
230  }
231 
232  abstract String getDisplayNameBase();
233 
241  abstract long calculateChildCount() throws TskCoreException;
242 
247  @NbBundle.Messages("FileTypes.bgCounting.placeholder= (counting...)")
248  void updateDisplayName() {
249  if (typesRoot.showCounts) {
250  //only show "(counting...)" the first time, otherwise it is distracting.
251  setDisplayName(getDisplayNameBase() + ((childCount < 0) ? Bundle.FileTypes_bgCounting_placeholder()
252  : (" (" + childCount + ")"))); //NON-NLS
253  new SwingWorker<Long, Void>() {
254  @Override
255  protected Long doInBackground() throws Exception {
256  return calculateChildCount();
257  }
258 
259  @Override
260  protected void done() {
261  try {
262  childCount = get();
263  setDisplayName(getDisplayNameBase() + " (" + childCount + ")"); //NON-NLS
264  } catch (InterruptedException | ExecutionException ex) {
265  setDisplayName(getDisplayNameBase());
266  logger.log(Level.WARNING, "Failed to get count of files for " + getDisplayNameBase(), ex); //NON-NLS
267  }
268  }
269  }.execute();
270  } else {
271  setDisplayName(getDisplayNameBase() + ((childCount < 0) ? "" : (" (" + childCount + "+)"))); //NON-NLS
272  }
273  }
274  }
275 
285  static class FileTypesKey implements Content {
286 
287  private final Content content;
288 
289  public FileTypesKey(Content content) {
290  this.content = content;
291  }
292 
293  @Override
294  public boolean equals(Object obj) {
295  if (obj == null) {
296  return false;
297  }
298  if (getClass() != obj.getClass()) {
299  return false;
300  }
301  final FileTypesKey other = (FileTypesKey) obj;
302 
303  return this.content.getId() == other.content.getId();
304  }
305 
306  @Override
307  public int hashCode() {
308  int hash = 7;
309  hash = 101 * hash + (int)(this.content.getId() ^ (this.content.getId() >>> 32));
310  return hash;
311  }
312 
313  @Override
314  public <T> T accept(SleuthkitItemVisitor<T> v) {
315  return content.accept(v);
316  }
317 
318  @Override
319  public int read(byte[] buf, long offset, long len) throws TskCoreException {
320  return content.read(buf, offset, len);
321  }
322 
323  @Override
324  public void close() {
325  content.close();
326  }
327 
328  @Override
329  public long getSize() {
330  return content.getSize();
331  }
332 
333  @Override
334  public <T> T accept(ContentVisitor<T> v) {
335  return content.accept(v);
336  }
337 
338  @Override
339  public String getName() {
340  return content.getName();
341  }
342 
343  @Override
344  public String getUniquePath() throws TskCoreException {
345  return content.getUniquePath();
346  }
347 
348  @Override
349  public long getId() {
350  return content.getId();
351  }
352 
353  @Override
354  public Content getDataSource() throws TskCoreException {
355  return content.getDataSource();
356  }
357 
358  @Override
359  public List<Content> getChildren() throws TskCoreException {
360  return content.getChildren();
361  }
362 
363  @Override
364  public boolean hasChildren() throws TskCoreException {
365  return content.hasChildren();
366  }
367 
368  @Override
369  public int getChildrenCount() throws TskCoreException {
370  return content.getChildrenCount();
371  }
372 
373  @Override
374  public Content getParent() throws TskCoreException {
375  return content.getParent();
376  }
377 
378  @Override
379  public List<Long> getChildrenIds() throws TskCoreException {
380  return content.getChildrenIds();
381  }
382 
383  @Override
384  public BlackboardArtifact newArtifact(int artifactTypeID) throws TskCoreException {
385  return content.newArtifact(artifactTypeID);
386  }
387 
388  @Override
389  public BlackboardArtifact newArtifact(BlackboardArtifact.ARTIFACT_TYPE type) throws TskCoreException {
390  return content.newArtifact(type);
391  }
392 
393  @Override
394  public ArrayList<BlackboardArtifact> getArtifacts(String artifactTypeName) throws TskCoreException {
395  return content.getArtifacts(artifactTypeName);
396  }
397 
398  @Override
399  public BlackboardArtifact getGenInfoArtifact() throws TskCoreException {
400  return content.getGenInfoArtifact();
401  }
402 
403  @Override
404  public BlackboardArtifact getGenInfoArtifact(boolean create) throws TskCoreException {
405  return content.getGenInfoArtifact(create);
406  }
407 
408  @Override
409  public ArrayList<BlackboardAttribute> getGenInfoAttributes(BlackboardAttribute.ATTRIBUTE_TYPE attr_type) throws TskCoreException {
410  return content.getGenInfoAttributes(attr_type);
411  }
412 
413  @Override
414  public ArrayList<BlackboardArtifact> getArtifacts(int artifactTypeID) throws TskCoreException {
415  return content.getArtifacts(artifactTypeID);
416  }
417 
418  @Override
419  public ArrayList<BlackboardArtifact> getArtifacts(BlackboardArtifact.ARTIFACT_TYPE type) throws TskCoreException {
420  return content.getArtifacts(type);
421  }
422 
423  @Override
424  public ArrayList<BlackboardArtifact> getAllArtifacts() throws TskCoreException {
425  return content.getAllArtifacts();
426  }
427 
428  @Override
429  public Set<String> getHashSetNames() throws TskCoreException {
430  return content.getHashSetNames();
431  }
432 
433  @Override
434  public long getArtifactsCount(String artifactTypeName) throws TskCoreException {
435  return content.getArtifactsCount(artifactTypeName);
436  }
437 
438  @Override
439  public long getArtifactsCount(int artifactTypeID) throws TskCoreException {
440  return content.getArtifactsCount(artifactTypeID);
441  }
442 
443  @Override
444  public long getArtifactsCount(BlackboardArtifact.ARTIFACT_TYPE type) throws TskCoreException {
445  return content.getArtifactsCount(type);
446  }
447 
448  @Override
449  public long getAllArtifactsCount() throws TskCoreException {
450  return content.getAllArtifactsCount();
451  }
452  }
453 }
static final int NODE_COUNT_FILE_TABLE_THRESHOLD
Definition: FileTypes.java:65
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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.