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

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