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;
45 final class AddRawImageTask
implements Runnable {
47 private static final Logger logger = Logger.getLogger(AddRawImageTask.class.getName());
48 private final String deviceId;
49 private final String imageFilePath;
50 private final String timeZone;
51 private final long chunkSize;
52 private final Host host;
53 private final DataSourceProcessorProgressMonitor progressMonitor;
54 private final DataSourceProcessorCallback callback;
55 private boolean criticalErrorOccurred;
56 private static final long TWO_GB = 2000000000L;
74 AddRawImageTask(String deviceId, String imageFilePath, String timeZone,
long chunkSize, Host host, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
75 this.deviceId = deviceId;
76 this.imageFilePath = imageFilePath;
77 this.timeZone = timeZone;
78 this.chunkSize = chunkSize;
80 this.callback = callback;
81 this.progressMonitor = progressMonitor;
92 progressMonitor.setIndeterminate(
true);
93 progressMonitor.setProgress(0);
94 List<Content> newDataSources =
new ArrayList<>();
95 List<String> errorMessages =
new ArrayList<>();
96 addImageToCase(newDataSources, errorMessages);
98 progressMonitor.setProgress(100);
103 DataSourceProcessorCallback.DataSourceProcessorResult result;
104 if (criticalErrorOccurred) {
105 result = DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS;
106 }
else if (!errorMessages.isEmpty()) {
107 result = DataSourceProcessorCallback.DataSourceProcessorResult.NONCRITICAL_ERRORS;
109 result = DataSourceProcessorCallback.DataSourceProcessorResult.NO_ERRORS;
111 callback.done(result, errorMessages, newDataSources);
112 criticalErrorOccurred =
false;
125 @Messages({
"AddRawImageTask.progress.add.text=Adding raw image: ",
126 "AddRawImageTask.image.critical.error.adding=Critical error adding ",
127 "AddRawImageTask.for.device=for device ",
128 "AddRawImageTask.image.notExisting=is not existing.",
129 "AddRawImageTask.image.noncritical.error.adding=Non-critical error adding ",
130 "AddRawImageTask.noOpenCase.errMsg=No open case available."})
131 private void addImageToCase(List<Content> dataSources, List<String> errorMessages) {
132 SleuthkitCase caseDatabase;
134 caseDatabase = Case.getCurrentCaseThrows().getSleuthkitCase();
135 }
catch (NoCurrentCaseException ex) {
136 errorMessages.add(Bundle.AddRawImageTask_noOpenCase_errMsg());
137 logger.log(Level.SEVERE, Bundle.AddRawImageTask_noOpenCase_errMsg(), ex);
138 criticalErrorOccurred =
true;
141 progressMonitor.setProgressText(Bundle.AddRawImageTask_progress_add_text() + imageFilePath);
142 List<String> imageFilePaths =
new ArrayList<>();
143 File imageFile = Paths.get(imageFilePath).toFile();
144 if (!imageFile.exists()) {
145 String errorMessage = Bundle.AddRawImageTask_image_critical_error_adding() + imageFilePath + Bundle.AddRawImageTask_for_device()
146 + deviceId + Bundle.AddRawImageTask_image_notExisting();
147 errorMessages.add(errorMessage);
148 logger.log(Level.SEVERE, errorMessage);
149 criticalErrorOccurred =
true;
152 imageFilePaths.add(imageFilePath);
157 Image dataSource = SleuthkitJNI.addImageToDatabase(caseDatabase, imageFilePaths.stream().toArray(String[]::
new), 0, timeZone, null, null, null, deviceId);
158 dataSources.add(dataSource);
159 List<TskFileRange> fileRanges =
new ArrayList<>();
165 String verificationError = dataSource.verifyImageSize();
166 if (!verificationError.isEmpty()) {
167 errorMessages.add(Bundle.AddRawImageTask_image_noncritical_error_adding() + imageFilePaths + Bundle.AddRawImageTask_for_device() + deviceId +
":" + verificationError);
170 long imageSize = dataSource.getSize();
174 if (chunkSize > 0 && imageSize >= TWO_GB) {
175 for (
double size = TWO_GB; size < dataSource.getSize(); size += TWO_GB) {
176 fileRanges.add(
new TskFileRange(start, TWO_GB, sequence));
182 double leftoverSize = imageSize - sequence * TWO_GB;
183 fileRanges.add(
new TskFileRange(start, (
long)leftoverSize, sequence));
186 caseDatabase.addLayoutFiles(dataSource, fileRanges);
188 }
catch (TskCoreException ex) {
189 String errorMessage = Bundle.AddRawImageTask_image_critical_error_adding() + imageFilePaths + Bundle.AddRawImageTask_for_device() + deviceId +
":" + ex.getLocalizedMessage();
190 errorMessages.add(errorMessage);
191 logger.log(Level.SEVERE, errorMessage, ex);
192 criticalErrorOccurred =
true;