Autopsy  4.14.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.filequery;
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_IMAGE.displayName=XXLarge: 200MB+",
130  "FileSearchData.FileSize.XLARGE_IMAGE.displayName=XLarge: 50-200MB",
131  "FileSearchData.FileSize.LARGE_IMAGE.displayName=Large: 1-50MB",
132  "FileSearchData.FileSize.MEDIUM_IMAGE.displayName=Medium: 100KB-1MB",
133  "FileSearchData.FileSize.SMALL_IMAGE.displayName=Small: 16-100KB",
134  "FileSearchData.FileSize.XSMALL_IMAGE.displayName=XSmall: 0-16KB",
135  "FileSearchData.FileSize.XXLARGE_VIDEO.displayName=XXLarge: 10GB+",
136  "FileSearchData.FileSize.XLARGE_VIDEO.displayName=XLarge: 5-10GB",
137  "FileSearchData.FileSize.LARGE_VIDEO.displayName=Large: 1-5GB",
138  "FileSearchData.FileSize.MEDIUM_VIDEO.displayName=Medium: 100MB-1GB",
139  "FileSearchData.FileSize.SMALL_VIDEO.displayName=Small: 500KB-100MB",
140  "FileSearchData.FileSize.XSMALL_VIDEO.displayName=XSmall: 0-500KB",})
141  enum FileSize {
142  XXLARGE_VIDEO(0, 10000 * BYTES_PER_MB, -1, Bundle.FileSearchData_FileSize_XXLARGE_VIDEO_displayName()),
143  XLARGE_VIDEO(1, 5000 * BYTES_PER_MB, 10000 * BYTES_PER_MB, Bundle.FileSearchData_FileSize_XLARGE_VIDEO_displayName()),
144  LARGE_VIDEO(2, 1000 * BYTES_PER_MB, 5000 * BYTES_PER_MB, Bundle.FileSearchData_FileSize_LARGE_VIDEO_displayName()),
145  MEDIUM_VIDEO(3, 100 * BYTES_PER_MB, 1000 * BYTES_PER_MB, Bundle.FileSearchData_FileSize_MEDIUM_VIDEO_displayName()),
146  SMALL_VIDEO(4, 500000, 100 * BYTES_PER_MB, Bundle.FileSearchData_FileSize_SMALL_VIDEO_displayName()),
147  XSMALL_VIDEO(5, 0, 500000, Bundle.FileSearchData_FileSize_XSMALL_VIDEO_displayName()),
148  XXLARGE_IMAGE(6, 200 * BYTES_PER_MB, -1, Bundle.FileSearchData_FileSize_XXLARGE_IMAGE_displayName()),
149  XLARGE_IMAGE(7, 50 * BYTES_PER_MB, 200 * BYTES_PER_MB, Bundle.FileSearchData_FileSize_XLARGE_IMAGE_displayName()),
150  LARGE_IMAGE(8, 1 * BYTES_PER_MB, 50 * BYTES_PER_MB, Bundle.FileSearchData_FileSize_LARGE_IMAGE_displayName()),
151  MEDIUM_IMAGE(9, 100000, 1 * BYTES_PER_MB, Bundle.FileSearchData_FileSize_MEDIUM_IMAGE_displayName()),
152  SMALL_IMAGE(10, 16000, 100000, Bundle.FileSearchData_FileSize_SMALL_IMAGE_displayName()),
153  XSMALL_IMAGE(11, 0, 16000, Bundle.FileSearchData_FileSize_XSMALL_IMAGE_displayName());
154 
155  private final int ranking; // Must be unique for each value
156  private final long minBytes; // Note that the size must be strictly greater than this to match
157  private final long maxBytes;
158  private final String displayName;
159  final static long NO_MAXIMUM = -1;
160 
161  FileSize(int ranking, long minB, long maxB, String displayName) {
162  this.ranking = ranking;
163  this.minBytes = minB;
164  if (maxB >= 0) {
165  this.maxBytes = maxB;
166  } else {
167  this.maxBytes = NO_MAXIMUM;
168  }
169  this.displayName = displayName;
170  }
171 
180  static FileSize fromImageSize(long size) {
181  if (size > XXLARGE_IMAGE.getMinBytes()) {
182  return XXLARGE_IMAGE;
183  } else if (size > XLARGE_IMAGE.getMinBytes()) {
184  return XLARGE_IMAGE;
185  } else if (size > LARGE_IMAGE.getMinBytes()) {
186  return LARGE_IMAGE;
187  } else if (size > MEDIUM_IMAGE.getMinBytes()) {
188  return MEDIUM_IMAGE;
189  } else if (size > SMALL_IMAGE.getMinBytes()) {
190  return SMALL_IMAGE;
191  } else {
192  return XSMALL_IMAGE;
193  }
194  }
195 
204  static FileSize fromVideoSize(long size) {
205  if (size > XXLARGE_VIDEO.getMinBytes()) {
206  return XXLARGE_VIDEO;
207  } else if (size > XLARGE_VIDEO.getMinBytes()) {
208  return XLARGE_VIDEO;
209  } else if (size > LARGE_VIDEO.getMinBytes()) {
210  return LARGE_VIDEO;
211  } else if (size > MEDIUM_VIDEO.getMinBytes()) {
212  return MEDIUM_VIDEO;
213  } else if (size > SMALL_VIDEO.getMinBytes()) {
214  return SMALL_VIDEO;
215  } else {
216  return XSMALL_VIDEO;
217  }
218  }
219 
225  long getMaxBytes() {
226  return maxBytes;
227  }
228 
234  long getMinBytes() {
235  return minBytes;
236  }
237 
243  int getRanking() {
244  return ranking;
245  }
246 
247  @Override
248  public String toString() {
249  return displayName;
250  }
251 
257  static List<FileSize> getOptionsForImages() {
258  return Arrays.asList(XXLARGE_IMAGE, XLARGE_IMAGE, LARGE_IMAGE, MEDIUM_IMAGE, SMALL_IMAGE, XSMALL_IMAGE);
259  }
260 
266  static List<FileSize> getOptionsForVideos() {
267  return Arrays.asList(XXLARGE_VIDEO, XLARGE_VIDEO, LARGE_VIDEO, MEDIUM_VIDEO, SMALL_VIDEO, XSMALL_VIDEO);
268  }
269  }
270 
271  //File discovery uses a different list of document mime types than FileTypeUtils.FileTypeCategory.DOCUMENTS
272  private static final ImmutableSet<String> DOCUMENT_MIME_TYPES
273  = new ImmutableSet.Builder<String>()
274  .add("text/html", //NON-NLS
275  "text/csv", //NON-NLS
276  "application/rtf", //NON-NLS
277  "application/pdf", //NON-NLS
278  "application/xhtml+xml", //NON-NLS
279  "application/x-msoffice", //NON-NLS
280  "application/msword", //NON-NLS
281  "application/msword2", //NON-NLS
282  "application/vnd.wordperfect", //NON-NLS
283  "application/vnd.openxmlformats-officedocument.wordprocessingml.document", //NON-NLS
284  "application/vnd.ms-powerpoint", //NON-NLS
285  "application/vnd.openxmlformats-officedocument.presentationml.presentation", //NON-NLS
286  "application/vnd.ms-excel", //NON-NLS
287  "application/vnd.ms-excel.sheet.4", //NON-NLS
288  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", //NON-NLS
289  "application/vnd.oasis.opendocument.presentation", //NON-NLS
290  "application/vnd.oasis.opendocument.spreadsheet", //NON-NLS
291  "application/vnd.oasis.opendocument.text" //NON-NLS
292  ).build();
293 
294  private static final ImmutableSet<String> IMAGE_UNSUPPORTED_DOC_TYPES
295  = new ImmutableSet.Builder<String>()
296  .add("application/pdf", //NON-NLS
297  "application/xhtml+xml").build(); //NON-NLS
298 
299  static Collection<String> getDocTypesWithoutImageExtraction(){
300  return Collections.unmodifiableCollection(IMAGE_UNSUPPORTED_DOC_TYPES);
301  }
308  @NbBundle.Messages({
309  "FileSearchData.FileType.Audio.displayName=Audio",
310  "FileSearchData.FileType.Video.displayName=Video",
311  "FileSearchData.FileType.Image.displayName=Image",
312  "FileSearchData.FileType.Documents.displayName=Documents",
313  "FileSearchData.FileType.Executables.displayName=Executables",
314  "FileSearchData.FileType.Other.displayName=Other/Unknown"})
315  enum FileType {
316 
317  IMAGE(0, Bundle.FileSearchData_FileType_Image_displayName(), FileTypeUtils.FileTypeCategory.IMAGE.getMediaTypes()),
318  AUDIO(1, Bundle.FileSearchData_FileType_Audio_displayName(), FileTypeUtils.FileTypeCategory.AUDIO.getMediaTypes()),
319  VIDEO(2, Bundle.FileSearchData_FileType_Video_displayName(), FileTypeUtils.FileTypeCategory.VIDEO.getMediaTypes()),
320  EXECUTABLE(3, Bundle.FileSearchData_FileType_Executables_displayName(), FileTypeUtils.FileTypeCategory.EXECUTABLE.getMediaTypes()),
321  DOCUMENTS(4, Bundle.FileSearchData_FileType_Documents_displayName(), DOCUMENT_MIME_TYPES),
322  OTHER(5, Bundle.FileSearchData_FileType_Other_displayName(), new ArrayList<>());
323 
324  private final int ranking; // For ordering in the UI
325  private final String displayName;
326  private final Collection<String> mediaTypes;
327 
328  FileType(int value, String displayName, Collection<String> mediaTypes) {
329  this.ranking = value;
330  this.displayName = displayName;
331  this.mediaTypes = mediaTypes;
332  }
333 
339  Collection<String> getMediaTypes() {
340  return Collections.unmodifiableCollection(mediaTypes);
341  }
342 
343  @Override
344  public String toString() {
345  return displayName;
346  }
347 
353  int getRanking() {
354  return ranking;
355  }
356 
364  static FileType fromMIMEtype(String mimeType) {
365  for (FileType type : FileType.values()) {
366  if (type.getMediaTypes().contains(mimeType)) {
367  return type;
368  }
369  }
370  return OTHER;
371  }
372 
378  static List<FileType> getOptionsForFiltering() {
379  return Arrays.asList(IMAGE, VIDEO);
380  }
381  }
382 
386  @NbBundle.Messages({
387  "FileSearchData.Score.notable.displayName=Notable",
388  "FileSearchData.Score.interesting.displayName=Interesting",
389  "FileSearchData.Score.unknown.displayName=Unknown",})
390  enum Score {
391  NOTABLE(0, Bundle.FileSearchData_Score_notable_displayName()),
392  INTERESTING(1, Bundle.FileSearchData_Score_interesting_displayName()),
393  UNKNOWN(2, Bundle.FileSearchData_Score_unknown_displayName());
394 
395  private final int ranking;
396  private final String displayName;
397 
398  Score(int ranking, String displayName) {
399  this.ranking = ranking;
400  this.displayName = displayName;
401  }
402 
408  int getRanking() {
409  return ranking;
410  }
411 
417  static List<Score> getOptionsForFiltering() {
418  return Arrays.asList(NOTABLE, INTERESTING);
419  }
420 
421  @Override
422  public String toString() {
423  return displayName;
424  }
425  }
426 
427  private FileSearchData() {
428  // Class should not be instantiated
429  }
430 }

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