Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
CommSnapShotReportWriter.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 */
19package org.sleuthkit.autopsy.communications.snapshot;
20
21import java.util.List;
22import java.awt.image.BufferedImage;
23import java.io.IOException;
24import java.nio.file.Path;
25import java.text.SimpleDateFormat;
26import java.time.Instant;
27import java.util.ArrayList;
28import java.util.Collection;
29import java.util.Date;
30import java.util.HashMap;
31import java.util.Set;
32import javax.imageio.ImageIO;
33import org.sleuthkit.autopsy.casemodule.Case;
34import org.sleuthkit.autopsy.report.uisnapshot.UiSnapShotReportWriter;
35import org.sleuthkit.datamodel.Account;
36import org.sleuthkit.datamodel.CommunicationsFilter;
37import org.sleuthkit.datamodel.CommunicationsFilter.AccountTypeFilter;
38import org.sleuthkit.datamodel.CommunicationsFilter.DateRangeFilter;
39import org.sleuthkit.datamodel.CommunicationsFilter.DeviceFilter;
40import org.sleuthkit.datamodel.CommunicationsFilter.SubFilter;
41import org.sleuthkit.datamodel.DataSource;
42import org.sleuthkit.datamodel.SleuthkitCase;
43import org.sleuthkit.datamodel.TskCoreException;
44
49
50 private final BufferedImage image;
51 private final CommunicationsFilter filter;
52
64 public CommSnapShotReportWriter(Case currentCase, Path reportFolderPath, String reportName, Date generationDate, BufferedImage snapshot, CommunicationsFilter filter) {
65
67
68 this.image = snapshot;
69 this.filter = filter;
70
71 }
72
79 @Override
80 protected void writeSnapShotHTMLFile() throws IOException {
81 SimpleDateFormat formatter = new SimpleDateFormat("MMMMM dd, yyyy"); //NON-NLS
82
83 ImageIO.write(image, "png", getReportFolderPath().resolve("snapshot.png").toFile()); //NON-NLS
84
85 //make a map of context objects to resolve template paramaters against
86 HashMap<String, Object> snapShotContext = new HashMap<>();
87 snapShotContext.put("reportTitle", getReportName()); //NON-NLS
88
89 List<SubFilter> filters = filter.getAndFilters();
90
91 for (SubFilter filter : filters) {
92 if (filter instanceof DateRangeFilter) {
93 long startDate = ((DateRangeFilter) filter).getStartDate();
94 long endDate = ((DateRangeFilter) filter).getEndDate();
95
96 if (startDate > 0) {
97
98 snapShotContext.put("startTime", formatter.format(new Date((Instant.ofEpochSecond(startDate)).toEpochMilli()))); //NON-NLS
99 }
100
101 if (endDate > 0) {
102 snapShotContext.put("endTime", formatter.format(new Date((Instant.ofEpochSecond(endDate)).toEpochMilli()))); //NON-NLS
103 }
104 } else if (filter instanceof AccountTypeFilter) {
105
106 Set<Account.Type> selectedAccounts = ((AccountTypeFilter) filter).getAccountTypes();
107 ArrayList<ReportWriterHelper> fullAccountList = new ArrayList<>();
108 for (Account.Type type : Account.Type.PREDEFINED_ACCOUNT_TYPES) {
109 if (type == Account.Type.CREDIT_CARD) {
110 continue;
111 }
112
113 fullAccountList.add(new ReportWriterHelper(type.getDisplayName(), selectedAccounts.contains(type)));
114 }
115
116 snapShotContext.put("accounts", fullAccountList);
117 } else if (filter instanceof DeviceFilter) {
118 Collection<String> ids = ((DeviceFilter) filter).getDevices();
119 ArrayList<ReportWriterHelper> list = new ArrayList<>();
120 try {
121 final SleuthkitCase sleuthkitCase = getCurrentCase().getSleuthkitCase();
122 for (DataSource dataSource : sleuthkitCase.getDataSources()) {
123 boolean selected = ids.contains(dataSource.getDeviceId());
124 String dsName = sleuthkitCase.getContentById(dataSource.getId()).getName();
125 list.add(new ReportWriterHelper(dsName, selected));
126 }
127 } catch (TskCoreException ex) {
128
129 }
130
131 snapShotContext.put("devices", list);
132 }
133 }
134
135 fillTemplateAndWrite("/org/sleuthkit/autopsy/communications/snapshot/comm_snapshot_template.html", "Snapshot", snapShotContext, getReportFolderPath().resolve("snapshot.html")); //NON-NLS
136 }
137
141 private final class ReportWriterHelper {
142
143 private final String label;
144 private final boolean selected;
145
152 ReportWriterHelper(String label, boolean selected) {
153 this.label = label;
154 this.selected = selected;
155 }
156
162 public String getLabel(){
163 return label;
164 }
165
171 public boolean isSelected(){
172 return selected;
173 }
174 }
175
176}
CommSnapShotReportWriter(Case currentCase, Path reportFolderPath, String reportName, Date generationDate, BufferedImage snapshot, CommunicationsFilter filter)
UiSnapShotReportWriter(Case currentCase, Path reportFolderPath, String reportName, Date generationDate)
void fillTemplateAndWrite(final String templateLocation, final String templateName, Object context, final Path outPutFile)

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.