Autopsy  4.4
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddRawImageTask.java
Go to the documentation of this file.
1 package org.sleuthkit.autopsy.datasourceprocessors;
2 
3 /*
4  * Autopsy Forensic Browser
5  *
6  * Copyright 2011-2016 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 
23 import java.io.File;
24 import java.nio.file.Paths;
25 import java.util.ArrayList;
26 import java.util.List;
31 import org.sleuthkit.datamodel.Content;
32 import org.sleuthkit.datamodel.Image;
33 import org.sleuthkit.datamodel.SleuthkitCase;
34 import org.sleuthkit.datamodel.TskCoreException;
35 import org.sleuthkit.datamodel.TskFileRange;
36 import org.openide.util.NbBundle.Messages;
37 
38 /*
39  * A runnable that adds a raw data source to a case database.
40  */
41 final class AddRawImageTask implements Runnable {
42 
43  private static final Logger logger = Logger.getLogger(AddRawImageTask.class.getName());
44  private final String deviceId;
45  private final String imageFilePath;
46  private final String timeZone;
47  private final long chunkSize;
48  private final DataSourceProcessorProgressMonitor progressMonitor;
49  private final DataSourceProcessorCallback callback;
50  private boolean criticalErrorOccurred;
51  private static final long TWO_GB = 2000000000L;
52 
69  AddRawImageTask(String deviceId, String imageFilePath, String timeZone, long chunkSize, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
70  this.deviceId = deviceId;
71  this.imageFilePath = imageFilePath;
72  this.timeZone = timeZone;
73  this.chunkSize = chunkSize;
74  this.callback = callback;
75  this.progressMonitor = progressMonitor;
76  }
77 
81  @Override
82  public void run() {
83  /*
84  * Process the input image file.
85  */
86  progressMonitor.setIndeterminate(true);
87  progressMonitor.setProgress(0);
88  List<Content> newDataSources = new ArrayList<>();
89  List<String> errorMessages = new ArrayList<>();
90  addImageToCase(newDataSources, errorMessages);
91 
92  progressMonitor.setProgress(100);
93 
98  if (criticalErrorOccurred) {
100  } else if (!errorMessages.isEmpty()) {
102  } else {
104  }
105  callback.done(result, errorMessages, newDataSources);
106  criticalErrorOccurred = false;
107  }
108 
119  @Messages({"AddRawImageTask.progress.add.text=Adding raw image: ",
120  "AddRawImageTask.image.critical.error.adding=Critical error adding ",
121  "AddRawImageTask.for.device=for device ",
122  "AddRawImageTask.image.notExisting=is not existing.",
123  "AddRawImageTask.image.noncritical.error.adding=Non-critical error adding "})
124  private void addImageToCase(List<Content> dataSources, List<String> errorMessages) {
125  progressMonitor.setProgressText(Bundle.AddRawImageTask_progress_add_text() + imageFilePath);
126  List<String> imageFilePaths = new ArrayList<>();
127  SleuthkitCase caseDatabase = Case.getCurrentCase().getSleuthkitCase();
128  caseDatabase.acquireExclusiveLock();
129 
130  File imageFile = Paths.get(imageFilePath).toFile();
131  if (!imageFile.exists()) {
132  errorMessages.add(Bundle.AddRawImageTask_image_critical_error_adding() + imageFilePath + Bundle.AddRawImageTask_for_device()
133  + deviceId + Bundle.AddRawImageTask_image_notExisting());
134  criticalErrorOccurred = true;
135  return;
136  }
137 
138  imageFilePaths.add(imageFilePath);
139 
140  try {
141  /*
142  * Get Image that will be added to case
143  */
144  Image dataSource = caseDatabase.addImageInfo(0, imageFilePaths, timeZone); //TODO: change hard coded deviceId.
145  dataSources.add(dataSource);
146  List<TskFileRange> fileRanges = new ArrayList<>();
147 
148  /*
149  * Verify the size of the new image. Note that it may not be what is
150  * expected, but at least part of it was added to the case.
151  */
152  String verificationError = dataSource.verifyImageSize();
153  if (!verificationError.isEmpty()) {
154  errorMessages.add(Bundle.AddRawImageTask_image_noncritical_error_adding() + imageFilePaths + Bundle.AddRawImageTask_for_device() + deviceId + ":" + verificationError);
155  }
156 
157  long imageSize = dataSource.getSize();
158  int sequence = 0;
159  //start byte and end byte
160  long start = 0;
161  if (chunkSize > 0 && imageSize >= TWO_GB) {
162  for (double size = TWO_GB; size < dataSource.getSize(); size += TWO_GB) {
163  fileRanges.add(new TskFileRange(start, TWO_GB, sequence));
164  start += TWO_GB;
165  sequence++;
166  }
167 
168  }
169  double leftoverSize = imageSize - sequence * TWO_GB;
170  fileRanges.add(new TskFileRange(start, (long)leftoverSize, sequence));
171 
172 
173  caseDatabase.addLayoutFiles(dataSource, fileRanges);
174 
175  } catch (TskCoreException ex) {
176  errorMessages.add(Bundle.AddRawImageTask_image_critical_error_adding() + imageFilePaths + Bundle.AddRawImageTask_for_device() + deviceId + ":" + ex.getLocalizedMessage());
177  criticalErrorOccurred = true;
178  } finally {
179  caseDatabase.releaseExclusiveLock();
180  }
181 
182  }
183 }
void done(DataSourceProcessorResult result, List< String > errList, List< Content > newDataSources)
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

Copyright © 2012-2016 Basis Technology. Generated on: Tue Jun 13 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.