Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ExportContainerInfo.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 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.util.Arrays;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.stream.Collectors;
25 import java.util.stream.Stream;
26 import org.apache.commons.lang.StringUtils;
27 import org.openide.util.NbBundle.Messages;
37 import org.sleuthkit.datamodel.DataSource;
38 
42 class ExportContainerInfo {
43 
44  private final ContainerSummary containerSummary;
45 
49  ExportContainerInfo() {
50  containerSummary = new ContainerSummary();
51  }
52 
62  private static List<? extends ExcelItemExportable> getAcquisitionDetails(String acquisitionDetails) {
63  if (StringUtils.isBlank(acquisitionDetails)) {
64  return Collections.emptyList();
65  } else {
66  return Stream.of(acquisitionDetails.split("\\r?\\n"))
67  .map((line) -> (StringUtils.isBlank(line)) ? null : new SingleCellExportable(line))
68  .filter(item -> item != null)
69  .collect(Collectors.toList());
70  }
71  }
72 
73  @Messages({
74  "ExportContainerInfo_setFieldsForNonImageDataSource_na=N/A",
75  "ExportContainerInfo_tabName=Container",
76  "ExportContainerInfo_export_displayName=Display Name:",
77  "ExportContainerInfo_export_originalName=Name:",
78  "ExportContainerInfo_export_deviceId=Device ID:",
79  "ExportContainerInfo_export_timeZone=Time Zone:",
80  "ExportContainerInfo_export_acquisitionDetails=Acquisition Details:",
81  "ExportContainerInfo_export_imageType=Image Type:",
82  "ExportContainerInfo_export_size=Size:",
83  "ExportContainerInfo_export_sectorSize=Sector Size:",
84  "ExportContainerInfo_export_md5=MD5:",
85  "ExportContainerInfo_export_sha1=SHA1:",
86  "ExportContainerInfo_export_sha256=SHA256:",
87  "ExportContainerInfo_export_unallocatedSize=Unallocated Space:",
88  "ExportContainerInfo_export_filePaths=File Paths:",})
89  List<ExcelSheetExport> getExports(DataSource ds) {
90  DataFetcher<DataSource, ContainerDetails> containerDataFetcher = (dataSource) -> containerSummary.getContainerDetails(dataSource);
91  ContainerDetails containerDetails = ExcelExportAction.getFetchResult(containerDataFetcher, "Container sheets", ds);
92  if (ds == null || containerDetails == null) {
93  return Collections.emptyList();
94  }
95 
96  String NA = Bundle.ExportContainerInfo_setFieldsForNonImageDataSource_na();
97  DefaultCellModel<?> NACell = new DefaultCellModel<>(NA);
98 
99  ImageDetails imageDetails = containerDetails.getImageDetails();
100  boolean hasImage = imageDetails != null;
101 
102  DefaultCellModel<?> timeZone = hasImage ? new DefaultCellModel<>(imageDetails.getTimeZone()) : NACell;
103  DefaultCellModel<?> imageType = hasImage ? new DefaultCellModel<>(imageDetails.getImageType()) : NACell;
104  DefaultCellModel<?> size = hasImage ? SizeRepresentationUtil.getBytesCell(imageDetails.getSize()) : NACell;
105  DefaultCellModel<?> sectorSize = hasImage ? SizeRepresentationUtil.getBytesCell(imageDetails.getSectorSize()) : NACell;
106  DefaultCellModel<?> md5 = hasImage ? new DefaultCellModel<>(imageDetails.getMd5Hash()) : NACell;
107  DefaultCellModel<?> sha1 = hasImage ? new DefaultCellModel<>(imageDetails.getSha1Hash()) : NACell;
108  DefaultCellModel<?> sha256 = hasImage ? new DefaultCellModel<>(imageDetails.getSha256Hash()) : NACell;
109 
110  DefaultCellModel<?> unallocatedSize;
111  if (hasImage) {
112  Long unallocatedSizeVal = imageDetails.getUnallocatedSize();
113  if (unallocatedSizeVal != null) {
114  unallocatedSize = SizeRepresentationUtil.getBytesCell(unallocatedSizeVal);
115  } else {
116  unallocatedSize = NACell;
117  }
118  } else {
119  unallocatedSize = NACell;
120  }
121 
122  List<String> paths = containerDetails.getImageDetails() == null ? Collections.singletonList(NA) : containerDetails.getImageDetails().getPaths();
123  List<SingleCellExportable> cellPaths = paths.stream()
124  .map(SingleCellExportable::new)
125  .collect(Collectors.toList());
126 
127  return Arrays.asList(new ExcelSpecialFormatExport(Bundle.ExportContainerInfo_tabName(), Arrays.asList(new KeyValueItemExportable(Bundle.ExportContainerInfo_export_displayName(), new DefaultCellModel<>(containerDetails.getDisplayName())),
128  new KeyValueItemExportable(Bundle.ExportContainerInfo_export_originalName(), new DefaultCellModel<>(containerDetails.getOriginalName())),
129  new KeyValueItemExportable(Bundle.ExportContainerInfo_export_deviceId(), new DefaultCellModel<>(containerDetails.getDeviceId())),
130  new KeyValueItemExportable(Bundle.ExportContainerInfo_export_timeZone(), timeZone),
131  new TitledExportable(Bundle.ExportContainerInfo_export_acquisitionDetails(), getAcquisitionDetails(containerDetails.getAcquisitionDetails())),
132  new KeyValueItemExportable(Bundle.ExportContainerInfo_export_imageType(), imageType),
133  new KeyValueItemExportable(Bundle.ExportContainerInfo_export_size(), size),
134  new KeyValueItemExportable(Bundle.ExportContainerInfo_export_sectorSize(), sectorSize),
135  new KeyValueItemExportable(Bundle.ExportContainerInfo_export_md5(), md5),
136  new KeyValueItemExportable(Bundle.ExportContainerInfo_export_sha1(), sha1),
137  new KeyValueItemExportable(Bundle.ExportContainerInfo_export_sha256(), sha256),
138  new KeyValueItemExportable(Bundle.ExportContainerInfo_export_unallocatedSize(), unallocatedSize),
139  new TitledExportable(Bundle.ExportContainerInfo_export_filePaths(), cellPaths)
140  )));
141 
142  }
143 }

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