Autopsy  4.14.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 
64  public CommSnapShotReportWriter(Case currentCase, Path reportFolderPath, String reportName, Date generationDate, BufferedImage snapshot, CommunicationsFilter filter) {
65 
66  super(currentCase, reportFolderPath, reportName, generationDate);
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 }
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-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.