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;
37 import org.openide.util.NbBundle.Messages;
43 final class AddRawImageTask
implements Runnable {
46 private final String deviceId;
47 private final String imageFilePath;
48 private final String timeZone;
49 private final long chunkSize;
52 private boolean criticalErrorOccurred;
53 private static final long TWO_GB = 2000000000L;
72 this.deviceId = deviceId;
73 this.imageFilePath = imageFilePath;
74 this.timeZone = timeZone;
75 this.chunkSize = chunkSize;
76 this.callback = callback;
77 this.progressMonitor = progressMonitor;
90 List<Content> newDataSources =
new ArrayList<>();
91 List<String> errorMessages =
new ArrayList<>();
92 addImageToCase(newDataSources, errorMessages);
100 if (criticalErrorOccurred) {
102 }
else if (!errorMessages.isEmpty()) {
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;
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);
150 caseDatabase.acquireSingleUserCaseWriteLock();
154 Image dataSource = caseDatabase.addImageInfo(0, imageFilePaths, timeZone);
155 dataSources.add(dataSource);
156 List<TskFileRange> fileRanges =
new ArrayList<>();
162 String verificationError = dataSource.verifyImageSize();
163 if (!verificationError.isEmpty()) {
164 errorMessages.add(Bundle.AddRawImageTask_image_noncritical_error_adding() + imageFilePaths + Bundle.AddRawImageTask_for_device() + deviceId +
":" + verificationError);
167 long imageSize = dataSource.getSize();
171 if (chunkSize > 0 && imageSize >= TWO_GB) {
172 for (
double size = TWO_GB; size < dataSource.getSize(); size += TWO_GB) {
173 fileRanges.add(
new TskFileRange(start, TWO_GB, sequence));
179 double leftoverSize = imageSize - sequence * TWO_GB;
180 fileRanges.add(
new TskFileRange(start, (
long)leftoverSize, sequence));
183 caseDatabase.addLayoutFiles(dataSource, fileRanges);
185 }
catch (TskCoreException ex) {
186 String errorMessage = Bundle.AddRawImageTask_image_critical_error_adding() + imageFilePaths + Bundle.AddRawImageTask_for_device() + deviceId +
":" + ex.getLocalizedMessage();
187 errorMessages.add(errorMessage);
188 logger.log(Level.SEVERE, errorMessage, ex);
189 criticalErrorOccurred =
true;
191 caseDatabase.releaseSingleUserCaseWriteLock();
void setProgressText(String text)
void setProgress(int progress)
void setIndeterminate(boolean indeterminate)
void done(DataSourceProcessorResult result, List< String > errList, List< Content > newDataSources)
SleuthkitCase getSleuthkitCase()
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()