1 package org.sleuthkit.autopsy.datasourceprocessors;
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.openide.util.NbBundle.Messages;
43 final class AddRawImageTask
implements Runnable {
45 private static final Logger logger = Logger.getLogger(AddRawImageTask.class.getName());
46 private final String deviceId;
47 private final String imageFilePath;
48 private final String timeZone;
49 private final long chunkSize;
50 private final DataSourceProcessorProgressMonitor progressMonitor;
51 private final DataSourceProcessorCallback callback;
52 private boolean criticalErrorOccurred;
53 private static final long TWO_GB = 2000000000L;
71 AddRawImageTask(String deviceId, String imageFilePath, String timeZone,
long chunkSize, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
72 this.deviceId = deviceId;
73 this.imageFilePath = imageFilePath;
74 this.timeZone = timeZone;
75 this.chunkSize = chunkSize;
76 this.callback = callback;
77 this.progressMonitor = progressMonitor;
88 progressMonitor.setIndeterminate(
true);
89 progressMonitor.setProgress(0);
90 List<Content> newDataSources =
new ArrayList<>();
91 List<String> errorMessages =
new ArrayList<>();
92 addImageToCase(newDataSources, errorMessages);
94 progressMonitor.setProgress(100);
99 DataSourceProcessorCallback.DataSourceProcessorResult result;
100 if (criticalErrorOccurred) {
101 result = DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS;
102 }
else if (!errorMessages.isEmpty()) {
103 result = DataSourceProcessorCallback.DataSourceProcessorResult.NONCRITICAL_ERRORS;
105 result = DataSourceProcessorCallback.DataSourceProcessorResult.NO_ERRORS;
107 callback.done(result, errorMessages, newDataSources);
108 criticalErrorOccurred =
false;
121 @Messages({
"AddRawImageTask.progress.add.text=Adding raw image: ",
122 "AddRawImageTask.image.critical.error.adding=Critical error adding ",
123 "AddRawImageTask.for.device=for device ",
124 "AddRawImageTask.image.notExisting=is not existing.",
125 "AddRawImageTask.image.noncritical.error.adding=Non-critical error adding ",
126 "AddRawImageTask.noOpenCase.errMsg=No open case available."})
127 private void addImageToCase(List<Content> dataSources, List<String> errorMessages) {
128 SleuthkitCase caseDatabase;
130 caseDatabase = Case.getCurrentCaseThrows().getSleuthkitCase();
131 }
catch (NoCurrentCaseException ex) {
132 errorMessages.add(Bundle.AddRawImageTask_noOpenCase_errMsg());
133 logger.log(Level.SEVERE, Bundle.AddRawImageTask_noOpenCase_errMsg(), ex);
134 criticalErrorOccurred =
true;
137 progressMonitor.setProgressText(Bundle.AddRawImageTask_progress_add_text() + imageFilePath);
138 List<String> imageFilePaths =
new ArrayList<>();
139 File imageFile = Paths.get(imageFilePath).toFile();
140 if (!imageFile.exists()) {
141 String errorMessage = Bundle.AddRawImageTask_image_critical_error_adding() + imageFilePath + Bundle.AddRawImageTask_for_device()
142 + deviceId + Bundle.AddRawImageTask_image_notExisting();
143 errorMessages.add(errorMessage);
144 logger.log(Level.SEVERE, errorMessage);
145 criticalErrorOccurred =
true;
148 imageFilePaths.add(imageFilePath);
153 Image dataSource = caseDatabase.addImageInfo(0, imageFilePaths, timeZone);
154 dataSources.add(dataSource);
155 List<TskFileRange> fileRanges =
new ArrayList<>();
161 String verificationError = dataSource.verifyImageSize();
162 if (!verificationError.isEmpty()) {
163 errorMessages.add(Bundle.AddRawImageTask_image_noncritical_error_adding() + imageFilePaths + Bundle.AddRawImageTask_for_device() + deviceId +
":" + verificationError);
166 long imageSize = dataSource.getSize();
170 if (chunkSize > 0 && imageSize >= TWO_GB) {
171 for (
double size = TWO_GB; size < dataSource.getSize(); size += TWO_GB) {
172 fileRanges.add(
new TskFileRange(start, TWO_GB, sequence));
178 double leftoverSize = imageSize - sequence * TWO_GB;
179 fileRanges.add(
new TskFileRange(start, (
long)leftoverSize, sequence));
182 caseDatabase.addLayoutFiles(dataSource, fileRanges);
184 }
catch (TskCoreException ex) {
185 String errorMessage = Bundle.AddRawImageTask_image_critical_error_adding() + imageFilePaths + Bundle.AddRawImageTask_for_device() + deviceId +
":" + ex.getLocalizedMessage();
186 errorMessages.add(errorMessage);
187 logger.log(Level.SEVERE, errorMessage, ex);
188 criticalErrorOccurred =
true;