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

Copyright © 2012-2021 Basis Technology. Generated on: Thu Jul 8 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.