19 package org.sleuthkit.datamodel;
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;
29 import java.sql.ResultSet;
30 import java.sql.SQLException;
31 import java.sql.Statement;
42 private final long type, ssize;
44 private final String[] paths;
45 private volatile long imageHandle = 0;
46 private final String deviceId, timezone, md5;
47 private static ResourceBundle bundle = ResourceBundle.getBundle(
"org.sleuthkit.datamodel.Bundle");
49 private static final Logger LOGGER = Logger.getLogger(
Image.class.
getName());
71 super(db, obj_id, name);
76 this.timezone = timezone;
97 Image(
SleuthkitCase db,
long obj_id,
long type, String deviceId,
long ssize, String name, String[] paths, String timezone, String md5,
long size)
throws TskCoreException {
98 super(db, obj_id, name);
99 this.deviceId = deviceId;
103 this.timezone = timezone;
116 if (imageHandle == 0) {
136 if (imageHandle != 0) {
155 if (paths.length > 0) {
160 Logger.getLogger(
Image.class.
getName()).log(Level.SEVERE,
"Could not find image size, image: " +
this.getId(), ex);
207 List<VolumeSystem> vs =
new ArrayList<VolumeSystem>();
208 for (
Content child : children) {
210 vs.add((VolumeSystem) child);
225 List<Volume> volumes =
new ArrayList<Volume>();
226 for (
Content child : children) {
227 if (child instanceof
Volume) {
228 volumes.add((Volume) child);
243 List<FileSystem> fs =
new ArrayList<FileSystem>();
260 return v.
visit(
this);
264 public <T> T accept(ContentVisitor<T> v) {
265 return v.visit(
this);
280 return super.toString(preserveState) +
"Image [\t" +
"\t" +
"paths " + Arrays.toString(paths) +
"\t" +
"size " + size +
"\t" +
"ssize " + ssize +
"\t" +
"timezone " + timezone +
"\t" +
"type " + type +
"]\t";
290 if (paths.length > 0) {
291 File imageFile =
new File(paths[0]);
292 return imageFile.
exists();
306 Logger logger1 = Logger.getLogger(
"verifyImageSizes");
307 String errorString =
"";
311 List<Volume> volumes = vs.getVolumes();
312 for (
Volume v : volumes) {
313 byte[] buf =
new byte[512];
314 long endOffset = (v.getStart() + v.getLength()) * 512 - 512;
316 int readBytes =
read(buf, endOffset, 512);
318 logger1.log(Level.WARNING,
"Possible Incomplete Image: Error reading volume at offset {0}", endOffset);
319 errorString = MessageFormat.format(bundle.getString(
"Image.verifyImageSize.errStr1.text"), endOffset);
322 logger1.log(Level.WARNING,
"Possible Incomplete Image: Error reading volume at offset {0}: {1}",
new Object[]{endOffset, ex.getLocalizedMessage()});
323 errorString = MessageFormat.format(bundle.getString(
"Image.verifyImageSize.errStr2.text"), endOffset);
330 long block_size = fs.getBlock_size();
331 long endOffset = fs.getImageOffset() + fs.getSize() - block_size;
333 byte[] buf =
new byte[(int) block_size];
334 int readBytes =
read(buf, endOffset, block_size);
336 logger1.log(Level.WARNING,
"Possible Incomplete Image: Error reading file system at offset {0}", endOffset);
337 errorString = MessageFormat.format(bundle.getString(
"Image.verifyImageSize.errStr3.text"), endOffset);
340 logger1.log(Level.WARNING,
"Possible Incomplete Image: Error reading file system at offset {0}: {1}",
new Object[]{endOffset, ex.getLocalizedMessage()});
341 errorString = MessageFormat.format(bundle.getString(
"Image.verifyImageSize.errStr4.text"), endOffset);
389 Statement statement = null;
390 ResultSet resultSet = null;
391 long contentSize = 0;
393 connection = sleuthkitCase.getConnection();
396 statement = connection.createStatement();
397 resultSet = connection.executeQuery(statement,
"SELECT SUM (size) FROM tsk_image_info WHERE tsk_image_info.obj_id = " +
getId());
398 if (resultSet.next()) {
399 contentSize = resultSet.getLong(
"sum");
401 }
catch (SQLException ex) {
402 throw new TskCoreException(String.format(
"There was a problem while querying the database for size data for object ID %d.",
getId()), ex);
404 closeResultSet(resultSet);
405 closeStatement(statement);
417 private static void closeResultSet(ResultSet resultSet) {
418 if (resultSet != null) {
421 }
catch (SQLException ex) {
422 LOGGER.log(Level.SEVERE,
"Error closing ResultSet", ex);
432 private static void closeStatement(Statement statement) {
433 if (statement != null) {
436 }
catch (SQLException ex) {
437 LOGGER.log(Level.SEVERE,
"Error closing Statement", ex);
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)
static long openImage(String[] imageFiles)
static long findDeviceSize(String devPath)
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)
long getContentSize(SleuthkitCase sleuthkitCase)
synchronized long getImageHandle()