Autopsy  4.15.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
FileSearchData.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 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.discovery;
20 
21 import com.google.common.collect.ImmutableSet;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.Collection;
25 import java.util.Collections;
26 import java.util.List;
27 import org.openide.util.NbBundle;
29 
33 final class FileSearchData {
34 
35  private final static long BYTES_PER_MB = 1000000;
36 
40  @NbBundle.Messages({
41  "FileSearchData.Frequency.unique.displayName=Unique (1)",
42  "FileSearchData.Frequency.rare.displayName=Rare (2-10)",
43  "FileSearchData.Frequency.common.displayName=Common (11 - 100)",
44  "FileSearchData.Frequency.verycommon.displayName=Very Common (100+)",
45  "FileSearchData.Frequency.known.displayName=Known (NSRL)",
46  "FileSearchData.Frequency.unknown.displayName=Unknown",})
47  enum Frequency {
48  UNIQUE(0, 1, Bundle.FileSearchData_Frequency_unique_displayName()),
49  RARE(1, 10, Bundle.FileSearchData_Frequency_rare_displayName()),
50  COMMON(2, 100, Bundle.FileSearchData_Frequency_common_displayName()),
51  VERY_COMMON(3, 0, Bundle.FileSearchData_Frequency_verycommon_displayName()),
52  KNOWN(4, 0, Bundle.FileSearchData_Frequency_known_displayName()),
53  UNKNOWN(5, 0, Bundle.FileSearchData_Frequency_unknown_displayName());
54 
55  private final int ranking;
56  private final String displayName;
57  private final int maxOccur;
58 
59  Frequency(int ranking, int maxOccur, String displayName) {
60  this.ranking = ranking;
61  this.maxOccur = maxOccur;
62  this.displayName = displayName;
63  }
64 
70  int getRanking() {
71  return ranking;
72  }
73 
81  static Frequency fromCount(long count) {
82  if (count <= UNIQUE.getMaxOccur()) {
83  return UNIQUE;
84  } else if (count <= RARE.getMaxOccur()) {
85  return RARE;
86  } else if (count <= COMMON.getMaxOccur()) {
87  return COMMON;
88  }
89  return VERY_COMMON;
90  }
91 
98  static List<Frequency> getOptionsForFilteringWithCr() {
99  return Arrays.asList(UNIQUE, RARE, COMMON, VERY_COMMON, KNOWN);
100  }
101 
108  static List<Frequency> getOptionsForFilteringWithoutCr() {
109  return Arrays.asList(KNOWN, UNKNOWN);
110  }
111 
112  @Override
113  public String toString() {
114  return displayName;
115  }
116 
120  int getMaxOccur() {
121  return maxOccur;
122  }
123  }
124 
128  @NbBundle.Messages({
129  "FileSearchData.FileSize.XXLARGE.displayName=XXLarge",
130  "FileSearchData.FileSize.XLARGE.displayName=XLarge",
131  "FileSearchData.FileSize.LARGE.displayName=Large",
132  "FileSearchData.FileSize.MEDIUM.displayName=Medium",
133  "FileSearchData.FileSize.SMALL.displayName=Small",
134  "FileSearchData.FileSize.XSMALL.displayName=XSmall",
135  "FileSearchData.FileSize.10PlusGb=: 10GB+",
136  "FileSearchData.FileSize.5gbto10gb=: 5-10GB",
137  "FileSearchData.FileSize.1gbto5gb=: 1-5GB",
138  "FileSearchData.FileSize.100mbto1gb=: 100MB-1GB",
139  "FileSearchData.FileSize.200PlusMb=: 200MB+",
140  "FileSearchData.FileSize.50mbto200mb=: 50-200MB",
141  "FileSearchData.FileSize.500kbto100mb=: 500KB-100MB",
142  "FileSearchData.FileSize.1mbto50mb=: 1-50MB",
143  "FileSearchData.FileSize.100kbto1mb=: 100KB-1MB",
144  "FileSearchData.FileSize.16kbto100kb=: 16-100KB",
145  "FileSearchData.FileSize.upTo500kb=: 0-500KB",
146  "FileSearchData.FileSize.upTo16kb=: 0-16KB",})
147  enum FileSize {
148  XXLARGE_VIDEO(0, 10000 * BYTES_PER_MB, -1, Bundle.FileSearchData_FileSize_XXLARGE_displayName(), Bundle.FileSearchData_FileSize_10PlusGb()),
149  XLARGE_VIDEO(1, 5000 * BYTES_PER_MB, 10000 * BYTES_PER_MB, Bundle.FileSearchData_FileSize_XLARGE_displayName(), Bundle.FileSearchData_FileSize_5gbto10gb()),
150  LARGE_VIDEO(2, 1000 * BYTES_PER_MB, 5000 * BYTES_PER_MB, Bundle.FileSearchData_FileSize_LARGE_displayName(), Bundle.FileSearchData_FileSize_1gbto5gb()),
151  MEDIUM_VIDEO(3, 100 * BYTES_PER_MB, 1000 * BYTES_PER_MB, Bundle.FileSearchData_FileSize_MEDIUM_displayName(), Bundle.FileSearchData_FileSize_100mbto1gb()),
152  SMALL_VIDEO(4, 500000, 100 * BYTES_PER_MB, Bundle.FileSearchData_FileSize_SMALL_displayName(), Bundle.FileSearchData_FileSize_500kbto100mb()),
153  XSMALL_VIDEO(5, 0, 500000, Bundle.FileSearchData_FileSize_XSMALL_displayName(), Bundle.FileSearchData_FileSize_upTo500kb()),
154  XXLARGE_IMAGE(6, 200 * BYTES_PER_MB, -1, Bundle.FileSearchData_FileSize_XXLARGE_displayName(), Bundle.FileSearchData_FileSize_200PlusMb()),
155  XLARGE_IMAGE(7, 50 * BYTES_PER_MB, 200 * BYTES_PER_MB, Bundle.FileSearchData_FileSize_XLARGE_displayName(), Bundle.FileSearchData_FileSize_50mbto200mb()),
156  LARGE_IMAGE(8, 1 * BYTES_PER_MB, 50 * BYTES_PER_MB, Bundle.FileSearchData_FileSize_LARGE_displayName(), Bundle.FileSearchData_FileSize_1mbto50mb()),
157  MEDIUM_IMAGE(9, 100000, 1 * BYTES_PER_MB, Bundle.FileSearchData_FileSize_MEDIUM_displayName(), Bundle.FileSearchData_FileSize_100kbto1mb()),
158  SMALL_IMAGE(10, 16000, 100000, Bundle.FileSearchData_FileSize_SMALL_displayName(), Bundle.FileSearchData_FileSize_16kbto100kb()),
159  XSMALL_IMAGE(11, 0, 16000, Bundle.FileSearchData_FileSize_XSMALL_displayName(), Bundle.FileSearchData_FileSize_upTo16kb());
160 
161  private final int ranking; // Must be unique for each value
162  private final long minBytes; // Note that the size must be strictly greater than this to match
163  private final long maxBytes;
164  private final String sizeGroup;
165  private final String displaySize;
166  final static long NO_MAXIMUM = -1;
167 
168  FileSize(int ranking, long minB, long maxB, String displayName, String displaySize) {
169  this.ranking = ranking;
170  this.minBytes = minB;
171  if (maxB >= 0) {
172  this.maxBytes = maxB;
173  } else {
174  this.maxBytes = NO_MAXIMUM;
175  }
176  this.sizeGroup = displayName;
177  this.displaySize = displaySize;
178  }
179 
188  static FileSize fromImageSize(long size) {
189  if (size > XXLARGE_IMAGE.getMinBytes()) {
190  return XXLARGE_IMAGE;
191  } else if (size > XLARGE_IMAGE.getMinBytes()) {
192  return XLARGE_IMAGE;
193  } else if (size > LARGE_IMAGE.getMinBytes()) {
194  return LARGE_IMAGE;
195  } else if (size > MEDIUM_IMAGE.getMinBytes()) {
196  return MEDIUM_IMAGE;
197  } else if (size > SMALL_IMAGE.getMinBytes()) {
198  return SMALL_IMAGE;
199  } else {
200  return XSMALL_IMAGE;
201  }
202  }
203 
212  static FileSize fromVideoSize(long size) {
213  if (size > XXLARGE_VIDEO.getMinBytes()) {
214  return XXLARGE_VIDEO;
215  } else if (size > XLARGE_VIDEO.getMinBytes()) {
216  return XLARGE_VIDEO;
217  } else if (size > LARGE_VIDEO.getMinBytes()) {
218  return LARGE_VIDEO;
219  } else if (size > MEDIUM_VIDEO.getMinBytes()) {
220  return MEDIUM_VIDEO;
221  } else if (size > SMALL_VIDEO.getMinBytes()) {
222  return SMALL_VIDEO;
223  } else {
224  return XSMALL_VIDEO;
225  }
226  }
227 
233  long getMaxBytes() {
234  return maxBytes;
235  }
236 
242  long getMinBytes() {
243  return minBytes;
244  }
245 
251  int getRanking() {
252  return ranking;
253  }
254 
255  @Override
256  public String toString() {
257  return sizeGroup + displaySize;
258  }
259 
260  String getSizeGroup(){
261  return sizeGroup;
262  }
263 
270  static List<FileSize> getDefaultSizeOptions() {
271  return Arrays.asList(XXLARGE_IMAGE, XLARGE_IMAGE, LARGE_IMAGE, MEDIUM_IMAGE, SMALL_IMAGE, XSMALL_IMAGE);
272  }
273 
279  static List<FileSize> getOptionsForVideos() {
280  return Arrays.asList(XXLARGE_VIDEO, XLARGE_VIDEO, LARGE_VIDEO, MEDIUM_VIDEO, SMALL_VIDEO, XSMALL_VIDEO);
281  }
282  }
283 
284  //Discovery uses a different list of document mime types than FileTypeUtils.FileTypeCategory.DOCUMENTS
285  private static final ImmutableSet<String> DOCUMENT_MIME_TYPES
286  = new ImmutableSet.Builder<String>()
287  .add("text/html", //NON-NLS
288  "text/csv", //NON-NLS
289  "application/rtf", //NON-NLS
290  "application/pdf", //NON-NLS
291  "application/xhtml+xml", //NON-NLS
292  "application/x-msoffice", //NON-NLS
293  "application/msword", //NON-NLS
294  "application/msword2", //NON-NLS
295  "application/vnd.wordperfect", //NON-NLS
296  "application/vnd.openxmlformats-officedocument.wordprocessingml.document", //NON-NLS
297  "application/vnd.ms-powerpoint", //NON-NLS
298  "application/vnd.openxmlformats-officedocument.presentationml.presentation", //NON-NLS
299  "application/vnd.ms-excel", //NON-NLS
300  "application/vnd.ms-excel.sheet.4", //NON-NLS
301  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", //NON-NLS
302  "application/vnd.oasis.opendocument.presentation", //NON-NLS
303  "application/vnd.oasis.opendocument.spreadsheet", //NON-NLS
304  "application/vnd.oasis.opendocument.text" //NON-NLS
305  ).build();
306 
307  private static final ImmutableSet<String> IMAGE_UNSUPPORTED_DOC_TYPES
308  = new ImmutableSet.Builder<String>()
309  .add("application/pdf", //NON-NLS
310  "application/xhtml+xml").build(); //NON-NLS
311 
312  static Collection<String> getDocTypesWithoutImageExtraction() {
313  return Collections.unmodifiableCollection(IMAGE_UNSUPPORTED_DOC_TYPES);
314  }
315 
322  @NbBundle.Messages({
323  "FileSearchData.FileType.Audio.displayName=Audio",
324  "FileSearchData.FileType.Video.displayName=Video",
325  "FileSearchData.FileType.Image.displayName=Image",
326  "FileSearchData.FileType.Documents.displayName=Documents",
327  "FileSearchData.FileType.Executables.displayName=Executables",
328  "FileSearchData.FileType.Other.displayName=Other/Unknown"})
329  enum FileType {
330 
331  IMAGE(0, Bundle.FileSearchData_FileType_Image_displayName(), FileTypeUtils.FileTypeCategory.IMAGE.getMediaTypes()),
332  AUDIO(1, Bundle.FileSearchData_FileType_Audio_displayName(), FileTypeUtils.FileTypeCategory.AUDIO.getMediaTypes()),
333  VIDEO(2, Bundle.FileSearchData_FileType_Video_displayName(), FileTypeUtils.FileTypeCategory.VIDEO.getMediaTypes()),
334  EXECUTABLE(3, Bundle.FileSearchData_FileType_Executables_displayName(), FileTypeUtils.FileTypeCategory.EXECUTABLE.getMediaTypes()),
335  DOCUMENTS(4, Bundle.FileSearchData_FileType_Documents_displayName(), DOCUMENT_MIME_TYPES),
336  OTHER(5, Bundle.FileSearchData_FileType_Other_displayName(), new ArrayList<>());
337 
338  private final int ranking; // For ordering in the UI
339  private final String displayName;
340  private final Collection<String> mediaTypes;
341 
342  FileType(int value, String displayName, Collection<String> mediaTypes) {
343  this.ranking = value;
344  this.displayName = displayName;
345  this.mediaTypes = mediaTypes;
346  }
347 
353  Collection<String> getMediaTypes() {
354  return Collections.unmodifiableCollection(mediaTypes);
355  }
356 
357  @Override
358  public String toString() {
359  return displayName;
360  }
361 
367  int getRanking() {
368  return ranking;
369  }
370 
378  static FileType fromMIMEtype(String mimeType) {
379  for (FileType type : FileType.values()) {
380  if (type.getMediaTypes().contains(mimeType)) {
381  return type;
382  }
383  }
384  return OTHER;
385  }
386 
392  static List<FileType> getOptionsForFiltering() {
393  return Arrays.asList(IMAGE, VIDEO);
394  }
395  }
396 
400  @NbBundle.Messages({
401  "FileSearchData.Score.notable.displayName=Notable",
402  "FileSearchData.Score.interesting.displayName=Interesting",
403  "FileSearchData.Score.unknown.displayName=Unknown",})
404  enum Score {
405  NOTABLE(0, Bundle.FileSearchData_Score_notable_displayName()),
406  INTERESTING(1, Bundle.FileSearchData_Score_interesting_displayName()),
407  UNKNOWN(2, Bundle.FileSearchData_Score_unknown_displayName());
408 
409  private final int ranking;
410  private final String displayName;
411 
412  Score(int ranking, String displayName) {
413  this.ranking = ranking;
414  this.displayName = displayName;
415  }
416 
422  int getRanking() {
423  return ranking;
424  }
425 
431  static List<Score> getOptionsForFiltering() {
432  return Arrays.asList(NOTABLE, INTERESTING);
433  }
434 
435  @Override
436  public String toString() {
437  return displayName;
438  }
439  }
440 
441  private FileSearchData() {
442  // Class should not be instantiated
443  }
444 }

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