Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddRawImageTask.java
Go to the documentation of this file.
1package org.sleuthkit.autopsy.datasourceprocessors;
2
3/*
4 * Autopsy Forensic Browser
5 *
6 * Copyright 2011-2018 Basis Technology Corp.
7 * Contact: carrier <at> sleuthkit <dot> org
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
22
23import java.io.File;
24import java.nio.file.Paths;
25import java.util.ArrayList;
26import java.util.List;
27import java.util.logging.Level;
28import org.openide.util.NbBundle.Messages;
29import org.sleuthkit.autopsy.casemodule.Case;
30import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
31import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessorCallback;
32import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessorProgressMonitor;
33import org.sleuthkit.autopsy.coreutils.Logger;
34import org.sleuthkit.datamodel.Content;
35import org.sleuthkit.datamodel.Host;
36import org.sleuthkit.datamodel.Image;
37import org.sleuthkit.datamodel.SleuthkitCase;
38import org.sleuthkit.datamodel.SleuthkitJNI;
39import org.sleuthkit.datamodel.TskCoreException;
40import org.sleuthkit.datamodel.TskFileRange;
41
42/*
43 * A runnable that adds a raw data source to a case database.
44 */
45final class AddRawImageTask implements Runnable {
46
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;
57
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;
79 this.host = host;
80 this.callback = callback;
81 this.progressMonitor = progressMonitor;
82 }
83
87 @Override
88 public void run() {
89 /*
90 * Process the input image file.
91 */
92 progressMonitor.setIndeterminate(true);
93 progressMonitor.setProgress(0);
94 List<Content> newDataSources = new ArrayList<>();
95 List<String> errorMessages = new ArrayList<>();
96 addImageToCase(newDataSources, errorMessages);
97
98 progressMonitor.setProgress(100);
99
103 DataSourceProcessorCallback.DataSourceProcessorResult result;
104 if (criticalErrorOccurred) {
105 result = DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS;
106 } else if (!errorMessages.isEmpty()) {
107 result = DataSourceProcessorCallback.DataSourceProcessorResult.NONCRITICAL_ERRORS;
108 } else {
109 result = DataSourceProcessorCallback.DataSourceProcessorResult.NO_ERRORS;
110 }
111 callback.done(result, errorMessages, newDataSources);
112 criticalErrorOccurred = false;
113 }
114
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;
133 try {
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;
139 return;
140 }
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;
150 return;
151 }
152 imageFilePaths.add(imageFilePath);
153 try {
154 /*
155 * Get Image that will be added to case
156 */
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<>();
160
161 /*
162 * Verify the size of the new image. Note that it may not be what is
163 * expected, but at least part of it was added to the case.
164 */
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);
168 }
169
170 long imageSize = dataSource.getSize();
171 int sequence = 0;
172 //start byte and end byte
173 long start = 0;
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));
177 start += TWO_GB;
178 sequence++;
179 }
180
181 }
182 double leftoverSize = imageSize - sequence * TWO_GB;
183 fileRanges.add(new TskFileRange(start, (long)leftoverSize, sequence));
184
185
186 caseDatabase.addLayoutFiles(dataSource, fileRanges);
187
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;
193 }
194 }
195}

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.