1 /*
2 * Autopsy Forensic Browser
3 *
4 * Copyright 2011-2013 Basis Technology Corp.
5 * Contact: carrier <at> sleuthkit <dot> org
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19 package org.sleuthkit.datamodel;
20
21 import java.text.MessageFormat;
22 import java.util.ResourceBundle;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.List;
26 import java.util.logging.Level;
27 import java.util.logging.Logger;
28 import java.io.File;
29
37 //data about image
38
39 private long type, ssize, size;
43 private static ResourceBundle
bundle = ResourceBundle.getBundle(
"org.sleuthkit.datamodel.Bundle");
44
60 this.ssize = ssize;
63 this.size = 0;
64 this.md5 = md5;
65 }
66
73 if (imageHandle == 0) {
75 }
76
78 }
79
80 @Override
82 return this;
83 }
84
85 @Override
87 //frees nothing, as we are caching image handles
88 }
89
90 @Override
92 try {
93 if (imageHandle != 0) {
95 imageHandle = 0;
96 }
97 } finally {
98 super.finalize();
99 }
100 }
101
102 @Override
104 // read from the image
106 }
107
108 @Override
110 if (size == 0) {
111 try {
112 if (paths.length > 0) {
113 //should always had at least one path
115 }
117 Logger.getLogger(
Image.class.
getName()).log(Level.SEVERE,
"Could not find image size, image: " +
this.getId(), ex);
//NON-NLS
118 }
119 }
120 return size;
121 }
122
123 //Methods for retrieval of meta-data attributes
131 }
132
139 return ssize;
140 }
141
142 @Override
144 return "/img_" +
getName();
//NON-NLS
145 }
146
154 }
155
162
164 List<VolumeSystem> vs = new ArrayList<VolumeSystem>();
165 for (
Content child : children) {
167 vs.add((VolumeSystem) child);
168 }
169 }
170
171 return vs;
172 }
173
180
182 List<Volume> volumes = new ArrayList<Volume>();
183 for (
Content child : children) {
184 if (child instanceof
Volume) {
185 volumes.add((Volume) child);
186 }
187 }
188
189 return volumes;
190 }
191
200 List<FileSystem> fs = new ArrayList<FileSystem>();
202 return fs;
203 }
204
212 }
213
214 @Override
216 return v.
visit(
this);
217 }
218
219 @Override
220 public <T> T accept(ContentVisitor<T> v) {
221 return v.visit(this);
222 }
223
224 @Override
227 }
228
229 @Override
232 }
233
234 @Override
236 return super.toString(preserveState) + "Image [\t" + "\t" + "paths " + Arrays.toString(paths) + "\t" + "size " + size + "\t" + "ssize " + ssize + "\t" + "timezone " + timezone + "\t" + "type " + type + "]\t"; //NON-NLS
237 }
238
246 if (paths.length > 0) {
247 File imageFile =
new File(paths[0]);
248 return imageFile.
exists();
249 }
250
251 return false;
252 }
253
262 Logger logger1 = Logger.getLogger("verifyImageSizes"); //NON-NLS
263 String errorString = "";
264 try {
267 List<Volume> volumes = vs.getVolumes();
268 for (
Volume v : volumes) {
269 byte[] buf = new byte[512];
270 long endOffset = (v.getStart() + v.getLength()) * 512 - 512;
271 try {
272 int readBytes =
read(buf, endOffset, 512);
273 if (readBytes < 0) {
274 logger1.warning("Possible Incomplete Image: Error reading volume at offset " + endOffset); //NON-NLS
275 errorString = MessageFormat.format(bundle.getString("Image.verifyImageSize.errStr1.text"), endOffset);
276 }
278 logger1.warning("Possible Incomplete Image: Error reading volume at offset " + endOffset + ": " + ex.getLocalizedMessage()); //NON-NLS
279 errorString = MessageFormat.format(bundle.getString("Image.verifyImageSize.errStr2.text"), endOffset);
280 }
281 }
282 }
283
286 long block_size = fs.getBlock_size();
287 long endOffset = fs.getImageOffset() + fs.getSize() - block_size;
288 try {
289 byte[] buf = new byte[(int) block_size];
290 int readBytes =
read(buf, endOffset, block_size);
291 if (readBytes < 0) {
292 logger1.warning("Possible Incomplete Image: Error reading file system at offset " + endOffset); //NON-NLS
293 errorString = MessageFormat.format(bundle.getString("Image.verifyImageSize.errStr3.text"), endOffset);
294 }
296 logger1.warning("Possible Incomplete Image: Error reading file system at offset " + endOffset + ": " + ex.getLocalizedMessage()); //NON-NLS
297 errorString = MessageFormat.format(bundle.getString("Image.verifyImageSize.errStr4.text"), endOffset);
298 }
299 }
301 // do nothing if we got an exception from trying to get file systems and volume systems
302 }
303 return errorString;
304 }
305
312 return md5;
313 }
314 }
static int readImg(long imgHandle, byte[] readBuffer, long offset, long len)
List< Volume > getVolumes()
List< FileSystem > getFileSystems()
Boolean imageFileExists()
Image(SleuthkitCase db, long obj_id, long type, long ssize, String name, String[] paths, String timezone, String md5)
TskData.TSK_IMG_TYPE_ENUM getType()
List< Long > getChildrenIds()
int read(byte[] buf, long offset, long len)
volatile long imageHandle
static long openImage(String[] imageFiles)
static long findDeviceSize(String devPath)
static ResourceBundle bundle
static void closeImg(long imgHandle)
SleuthkitCase getSleuthkitCase()
List< Content > getChildren()
List< VolumeSystem > getVolumeSystems()
static TSK_IMG_TYPE_ENUM valueOf(long imgType)
String toString(boolean preserveState)
synchronized long getImageHandle()