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

Copyright © 2012-2018 Basis Technology. Generated on: Fri Mar 22 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.