Autopsy  4.11.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddLogicalImageTask.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-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.logicalimager.dsp;
20 
21 import java.io.File;
22 import java.io.IOException;
23 import java.nio.file.Path;
24 import java.nio.file.Paths;
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.logging.Level;
28 import org.apache.commons.io.FileUtils;
29 import org.openide.util.NbBundle.Messages;
35 import org.sleuthkit.datamodel.Content;
36 import org.sleuthkit.datamodel.TskCoreException;
37 
44 final class AddLogicalImageTask extends AddMultipleImageTask {
45 
46  private final static Logger logger = Logger.getLogger(AddLogicalImageTask.class.getName());
47  private final static String ALERT_TXT = "alert.txt"; //NON-NLS
48  private final static String USERS_TXT = "users.txt"; //NON-NLS
49  private final File src;
50  private final File dest;
51  private final DataSourceProcessorCallback callback;
52  private final DataSourceProcessorProgressMonitor progressMonitor;
53 
54  AddLogicalImageTask(String deviceId,
55  List<String> imagePaths,
56  String timeZone,
57  File src, File dest,
58  DataSourceProcessorProgressMonitor progressMonitor,
60  ) throws NoCurrentCaseException {
61  super(deviceId, imagePaths, timeZone, progressMonitor, callback);
62  this.src = src;
63  this.dest = dest;
64  this.progressMonitor = progressMonitor;
65  this.callback = callback;
66  }
67 
73  @Messages({
74  "# {0} - src", "# {1} - dest", "AddLogicalImageTask.copyingImageFromTo=Copying image from {0} to {1}",
75  "AddLogicalImageTask.doneCopying=Done copying",
76  "# {0} - src", "# {1} - dest", "AddLogicalImageTask.failedToCopyDirectory=Failed to copy directory {0} to {1}",
77  "# {0} - file", "AddLogicalImageTask.addingToReport=Adding {0} to report",
78  "# {0} - file", "AddLogicalImageTask.doneAddingToReport=Done adding {0} to report"
79  })
80  @Override
81  public void run() {
82  List<String> errorList = new ArrayList<>();
83  List<Content> emptyDataSources = new ArrayList<>();
84 
85  try {
86  progressMonitor.setProgressText(Bundle.AddLogicalImageTask_copyingImageFromTo(src.toString(), dest.toString()));
87  FileUtils.copyDirectory(src, dest);
88  progressMonitor.setProgressText(Bundle.AddLogicalImageTask_doneCopying());
89  } catch (IOException ex) {
90  // Copy directory failed
91  String msg = Bundle.AddLogicalImageTask_failedToCopyDirectory(src.toString(), dest.toString());
92  errorList.add(msg);
93  logger.log(Level.SEVERE, String.format("Failed to copy directory {0} to {1}", src.toString(), dest.toString()));
94  callback.done(DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS, errorList, emptyDataSources);
95  return;
96  }
97 
98  // Add the alert.txt and users.txt to the case report
99  progressMonitor.setProgressText(Bundle.AddLogicalImageTask_addingToReport(ALERT_TXT));
100  String status = addReport(Paths.get(dest.toString(), ALERT_TXT), ALERT_TXT + " " + src.getName());
101  if (status != null) {
102  errorList.add(status);
103  callback.done(DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS, errorList, emptyDataSources);
104  return;
105  }
106  progressMonitor.setProgressText(Bundle.AddLogicalImageTask_doneAddingToReport(ALERT_TXT));
107 
108  progressMonitor.setProgressText(Bundle.AddLogicalImageTask_addingToReport(USERS_TXT));
109  status = addReport(Paths.get(dest.toString(), USERS_TXT), USERS_TXT + " " + src.getName());
110  if (status != null) {
111  errorList.add(status);
112  callback.done(DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS, errorList, emptyDataSources);
113  return;
114  }
115  progressMonitor.setProgressText(Bundle.AddLogicalImageTask_doneAddingToReport(USERS_TXT));
116 
117  super.run();
118  }
119 
128  @Messages({
129  "# {0} - file", "# {1} - exception message", "AddLogicalImageTask.failedToAddReport=Failed to add report {0}. Reason= {1}"
130  })
131  private String addReport(Path reportPath, String reportName) {
132  if (!reportPath.toFile().exists()) {
133  return null; // if the reportPath doesn't exist, just ignore it.
134  }
135  try {
136  Case.getCurrentCase().addReport(reportPath.toString(), "LogicalImager", reportName); //NON-NLS
137  return null;
138  } catch (TskCoreException ex) {
139  String msg = Bundle.AddLogicalImageTask_failedToAddReport(reportPath.toString(), ex.getMessage());
140  logger.log(Level.SEVERE, String.format("Failed to add report {0}. Reason= {1}", reportPath.toString(), ex.getMessage()));
141  return msg;
142  }
143  }
144 }
void addReport(String localPath, String srcModuleName, String reportName)
Definition: Case.java:1534
void done(DataSourceProcessorResult result, List< String > errList, List< Content > newDataSources)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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