Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
ExportTypes.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2019-2021 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.report.modules.datasourcesummaryexport;
20 
21 import java.awt.Color;
22 import java.sql.SQLException;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.Collections;
26 import java.util.HashSet;
27 import java.util.List;
28 import java.util.stream.Collectors;
29 import java.util.stream.Stream;
30 import org.openide.util.NbBundle.Messages;
41 import org.sleuthkit.datamodel.DataSource;
42 import org.sleuthkit.datamodel.TskCoreException;
43 
48 @Messages({
49  "ExportTypes_artifactsTypesPieChart_title=Artifact Types",
50  "ExportTypes_filesByCategoryTable_allocatedRow_title=Allocated Files",
51  "ExportTypes_filesByCategoryTable_unallocatedRow_title=Unallocated Files",
52  "ExportTypes_filesByCategoryTable_slackRow_title=Slack Files",
53  "ExportTypes_filesByCategoryTable_directoryRow_title=Directories",
54  "ExportTypes_fileMimeTypesChart_title=File Types",
55  "ExportTypes_fileMimeTypesChart_valueLabel=Count",
56  "ExportTypes_fileMimeTypesChart_audio_title=Audio",
57  "ExportTypes_fileMimeTypesChart_documents_title=Documents",
58  "ExportTypes_fileMimeTypesChart_executables_title=Executables",
59  "ExportTypes_fileMimeTypesChart_images_title=Images",
60  "ExportTypes_fileMimeTypesChart_videos_title=Videos",
61  "ExportTypes_fileMimeTypesChart_other_title=Other",
62  "ExportTypes_fileMimeTypesChart_unknown_title=Unknown",
63  "ExportTypes_fileMimeTypesChart_notAnalyzed_title=Not Analyzed",
64  "ExportTypes_usageLabel_title=Usage",
65  "ExportTypes_osLabel_title=OS",
66  "ExportTypes_sizeLabel_title=Size",
67  "ExportTypes_excelTabName=Types"})
68 class ExportTypes {
69 
73  private static class TypesPieChartData {
74 
75  private final List<PieChartItem> pieSlices;
76  private final boolean usefulContent;
77 
85  TypesPieChartData(List<PieChartItem> pieSlices, boolean usefulContent) {
86  this.pieSlices = pieSlices;
87  this.usefulContent = usefulContent;
88  }
89 
93  List<PieChartItem> getPieSlices() {
94  return pieSlices;
95  }
96 
100  boolean isUsefulContent() {
101  return usefulContent;
102  }
103  }
104 
105  private final MimeTypeSummary mimeTypeSummary;
106  private final ContainerSummary containerSummary;
107  private final TypesSummary typesSummary;
108  private final SleuthkitCaseProvider provider;
109 
110  private static final Color IMAGES_COLOR = new Color(156, 39, 176);
111  private static final Color VIDEOS_COLOR = Color.YELLOW;
112  private static final Color AUDIO_COLOR = Color.BLUE;
113  private static final Color DOCUMENTS_COLOR = Color.GREEN;
114  private static final Color EXECUTABLES_COLOR = new Color(0, 188, 212);
115  private static final Color UNKNOWN_COLOR = Color.ORANGE;
116  private static final Color OTHER_COLOR = new Color(78, 52, 46);
117  private static final Color NOT_ANALYZED_COLOR = Color.WHITE;
118 
119  // All file type categories.
120  private static final List<FileTypeCategoryData> FILE_MIME_TYPE_CATEGORIES = Arrays.asList(
121  new FileTypeCategoryData(Bundle.ExportTypes_fileMimeTypesChart_images_title(), FileTypeCategory.IMAGE.getMediaTypes(), IMAGES_COLOR),
122  new FileTypeCategoryData(Bundle.ExportTypes_fileMimeTypesChart_videos_title(), FileTypeCategory.VIDEO.getMediaTypes(), VIDEOS_COLOR),
123  new FileTypeCategoryData(Bundle.ExportTypes_fileMimeTypesChart_audio_title(), FileTypeCategory.AUDIO.getMediaTypes(), AUDIO_COLOR),
124  new FileTypeCategoryData(Bundle.ExportTypes_fileMimeTypesChart_documents_title(), FileTypeCategory.DOCUMENTS.getMediaTypes(), DOCUMENTS_COLOR),
125  new FileTypeCategoryData(Bundle.ExportTypes_fileMimeTypesChart_executables_title(), FileTypeCategory.EXECUTABLE.getMediaTypes(), EXECUTABLES_COLOR),
126  new FileTypeCategoryData(Bundle.ExportTypes_fileMimeTypesChart_unknown_title(), new HashSet<>(Arrays.asList("application/octet-stream")), UNKNOWN_COLOR)
127  );
128 
129  ExportTypes() {
130  this.provider = SleuthkitCaseProvider.DEFAULT;
131  containerSummary = new ContainerSummary();
132  typesSummary = new TypesSummary();
133  mimeTypeSummary = new MimeTypeSummary();
134  }
135 
144  private TypesPieChartData getMimeTypeCategoriesModel(DataSource dataSource)
145  throws SQLException, TskCoreException, SleuthkitCaseProvider.SleuthkitCaseProviderException {
146 
147  if (dataSource == null) {
148  return null;
149  }
150 
151  // for each category of file types, get the counts of files
152  List<PieChartItem> fileCategoryItems = new ArrayList<>();
153  long categoryTotalCount = 0;
154 
155  for (FileTypeCategoryData cat : FILE_MIME_TYPE_CATEGORIES) {
156  long thisValue = DataSourceInfoUtilities.getLongOrZero(mimeTypeSummary.getCountOfFilesForMimeTypes(dataSource, cat.getMimeTypes()));
157  categoryTotalCount += thisValue;
158 
159  fileCategoryItems.add(new PieChartItem(
160  cat.getLabel(),
161  thisValue,
162  cat.getColor()));
163  }
164 
165  // get a count of all files with no mime type
166  long noMimeTypeCount = DataSourceInfoUtilities.getLongOrZero(mimeTypeSummary.getCountOfFilesWithNoMimeType(dataSource));
167 
168  // get a count of all regular files
169  long allRegularFiles = DataSourceInfoUtilities.getLongOrZero(DataSourceInfoUtilities.getCountOfRegNonSlackFiles(provider.get(), dataSource, null));
170 
171  // create entry for mime types in other category
172  long otherCount = allRegularFiles - (categoryTotalCount + noMimeTypeCount);
173  PieChartItem otherPieItem = new PieChartItem(Bundle.ExportTypes_fileMimeTypesChart_other_title(),
174  otherCount, OTHER_COLOR);
175 
176  // check at this point to see if these are all 0; if so, we don't have useful content.
177  boolean usefulContent = categoryTotalCount > 0 || otherCount > 0;
178 
179  // create entry for not analyzed mime types category
180  PieChartItem notAnalyzedItem = new PieChartItem(Bundle.ExportTypes_fileMimeTypesChart_notAnalyzed_title(),
181  noMimeTypeCount, NOT_ANALYZED_COLOR);
182 
183  // combine categories with 'other' and 'not analyzed'
184  List<PieChartItem> items = Stream.concat(
185  fileCategoryItems.stream(),
186  Stream.of(otherPieItem, notAnalyzedItem))
187  // remove items that have no value
188  .filter(slice -> slice.getValue() > 0)
189  .collect(Collectors.toList());
190 
191  return new TypesPieChartData(items, usefulContent);
192  }
193 
203  private static KeyValueItemExportable getStrExportable(DataFetcher<DataSource, String> fetcher, String key, DataSource dataSource) {
204  String result = ExcelExportAction.getFetchResult(fetcher, "Types", dataSource);
205  return (result == null) ? null : new KeyValueItemExportable(key, new DefaultCellModel<>(result));
206  }
207 
218  private static KeyValueItemExportable getCountExportable(DataFetcher<DataSource, Long> fetcher, String key, DataSource dataSource) {
219  Long count = ExcelExportAction.getFetchResult(fetcher, "Types", dataSource);
220  return (count == null) ? null : new KeyValueItemExportable(key,
221  new DefaultCellModel<Long>(count, DataSourceInfoUtilities.COMMA_FORMATTER::format, DataSourceInfoUtilities.COMMA_FORMAT_STR));
222  }
223 
224  List<ExcelExport.ExcelSheetExport> getExports(DataSource dataSource) {
225  if (dataSource == null) {
226  return Collections.emptyList();
227  }
228 
229  DataFetcher<DataSource, String> usageFetcher = (ds) -> containerSummary.getDataSourceType(ds);
230  DataFetcher<DataSource, String> osFetcher = (ds) -> containerSummary.getOperatingSystems(ds);
231  DataFetcher<DataSource, Long> sizeFetcher = (ds) -> ds == null ? null : ds.getSize();
232 
233  DataFetcher<DataSource, TypesPieChartData> typesFetcher = (ds) -> getMimeTypeCategoriesModel(ds);
234 
235  DataFetcher<DataSource, Long> allocatedFetcher = (ds) -> typesSummary.getCountOfAllocatedFiles(ds);
236  DataFetcher<DataSource, Long> unallocatedFetcher = (ds) -> typesSummary.getCountOfUnallocatedFiles(ds);
237  DataFetcher<DataSource, Long> slackFetcher = (ds) -> typesSummary.getCountOfSlackFiles(ds);
238  DataFetcher<DataSource, Long> directoriesFetcher = (ds) -> typesSummary.getCountOfDirectories(ds);
239 
240  // Retrieve data to create the types pie chart
241  TypesPieChartData typesData = ExcelExportAction.getFetchResult(typesFetcher, "Types", dataSource);
242  PieChartExport typesChart = (typesData == null || !typesData.isUsefulContent()) ? null
243  : new PieChartExport(
244  Bundle.ExportTypes_fileMimeTypesChart_title(),
245  Bundle.ExportTypes_fileMimeTypesChart_valueLabel(),
246  "#,###",
247  Bundle.ExportTypes_fileMimeTypesChart_title(),
248  typesData.getPieSlices());
249 
250  return Arrays.asList(new ExcelSpecialFormatExport(Bundle.ExportTypes_excelTabName(),
251  Stream.of(
252  getStrExportable(usageFetcher, Bundle.ExportTypes_usageLabel_title(), dataSource),
253  getStrExportable(osFetcher, Bundle.ExportTypes_osLabel_title(), dataSource),
254  new KeyValueItemExportable(Bundle.ExportTypes_sizeLabel_title(),
255  SizeRepresentationUtil.getBytesCell(ExcelExportAction.getFetchResult(sizeFetcher, "Types", dataSource))),
256  typesChart,
257  getCountExportable(allocatedFetcher, Bundle.ExportTypes_filesByCategoryTable_allocatedRow_title(), dataSource),
258  getCountExportable(unallocatedFetcher, Bundle.ExportTypes_filesByCategoryTable_unallocatedRow_title(), dataSource),
259  getCountExportable(slackFetcher, Bundle.ExportTypes_filesByCategoryTable_slackRow_title(), dataSource),
260  getCountExportable(directoriesFetcher, Bundle.ExportTypes_filesByCategoryTable_directoryRow_title(), dataSource))
261  .filter(sheet -> sheet != null)
262  .collect(Collectors.toList())
263  ));
264  }
265 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Oct 4 2022
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.