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;
47 private String md5, sha1, sha256;
48 private static ResourceBundle bundle = ResourceBundle.getBundle(
"org.sleuthkit.datamodel.Bundle");
50 private static final Logger LOGGER = Logger.getLogger(
Image.class.
getName());
72 super(db, obj_id, name);
77 this.timezone = timezone;
100 Image(
SleuthkitCase db,
long obj_id,
long type, String deviceId,
long ssize, String name, String[] paths, String timezone,
101 String md5, String sha1, String sha256,
long size)
throws TskCoreException {
102 super(db, obj_id, name);
103 this.deviceId = deviceId;
107 this.timezone = timezone;
111 this.sha256 = sha256;
122 if (paths.length == 0) {
123 throw new TskCoreException(
"Image has no associated paths");
126 if (imageHandle == 0) {
146 if (imageHandle != 0) {
158 if (paths.length == 0) {
170 if (paths.length > 0) {
175 Logger.getLogger(
Image.class.
getName()).log(Level.SEVERE,
"Could not find image size, image: " +
this.getId(), ex);
222 List<VolumeSystem> vs =
new ArrayList<VolumeSystem>();
223 for (
Content child : children) {
225 vs.add((VolumeSystem) child);
240 List<Volume> volumes =
new ArrayList<Volume>();
241 for (
Content child : children) {
242 if (child instanceof
Volume) {
243 volumes.add((Volume) child);
258 List<FileSystem> fs =
new ArrayList<FileSystem>();
275 return v.
visit(
this);
279 public <T> T accept(ContentVisitor<T> v) {
280 return v.visit(
this);
295 return super.toString(preserveState) +
"Image [\t" +
"\t" +
"paths " + Arrays.toString(paths) +
"\t" +
"size " + size +
"\t" +
"ssize " + ssize +
"\t" +
"timezone " + timezone +
"\t" +
"type " + type +
"]\t";
305 if (paths.length > 0) {
306 File imageFile =
new File(paths[0]);
307 return imageFile.
exists();
321 Logger logger1 = Logger.getLogger(
"verifyImageSizes");
322 String errorString =
"";
326 List<Volume> volumes = vs.getVolumes();
327 for (
Volume v : volumes) {
328 byte[] buf =
new byte[512];
329 long endOffset = (v.getStart() + v.getLength()) * 512 - 512;
331 int readBytes =
read(buf, endOffset, 512);
333 logger1.log(Level.WARNING,
"Possible Incomplete Image: Error reading volume at offset {0}", endOffset);
334 errorString = MessageFormat.format(bundle.getString(
"Image.verifyImageSize.errStr1.text"), endOffset);
337 logger1.log(Level.WARNING,
"Possible Incomplete Image: Error reading volume at offset {0}: {1}",
new Object[]{endOffset, ex.getLocalizedMessage()});
338 errorString = MessageFormat.format(bundle.getString(
"Image.verifyImageSize.errStr2.text"), endOffset);
345 long block_size = fs.getBlock_size();
346 long endOffset = fs.getImageOffset() + fs.getSize() - block_size;
348 byte[] buf =
new byte[(int) block_size];
349 int readBytes =
read(buf, endOffset, block_size);
351 logger1.log(Level.WARNING,
"Possible Incomplete Image: Error reading file system at offset {0}", endOffset);
352 errorString = MessageFormat.format(bundle.getString(
"Image.verifyImageSize.errStr3.text"), endOffset);
355 logger1.log(Level.WARNING,
"Possible Incomplete Image: Error reading file system at offset {0}: {1}",
new Object[]{endOffset, ex.getLocalizedMessage()});
356 errorString = MessageFormat.format(bundle.getString(
"Image.verifyImageSize.errStr4.text"), endOffset);
373 if (md5 == null || md5.isEmpty()) {
387 if (sha1 == null || sha1.isEmpty()) {
401 if (sha256 == null || sha256.isEmpty()) {
414 if (
getMd5().isEmpty() ==
false) {
428 if (
getSha1().isEmpty() ==
false) {
446 this.sha256 = sha256;
491 Statement statement = null;
492 ResultSet resultSet = null;
493 long contentSize = 0;
495 connection = sleuthkitCase.getConnection();
498 statement = connection.createStatement();
499 resultSet = connection.executeQuery(statement,
"SELECT SUM (size) FROM tsk_image_info WHERE tsk_image_info.obj_id = " +
getId());
500 if (resultSet.next()) {
501 contentSize = resultSet.getLong(
"sum");
503 }
catch (SQLException ex) {
504 throw new TskCoreException(String.format(
"There was a problem while querying the database for size data for object ID %d.",
getId()), ex);
506 closeResultSet(resultSet);
507 closeStatement(statement);
543 private static void closeResultSet(ResultSet resultSet) {
544 if (resultSet != null) {
547 }
catch (SQLException ex) {
548 LOGGER.log(Level.SEVERE,
"Error closing ResultSet", ex);
558 private static void closeStatement(Statement statement) {
559 if (statement != null) {
562 }
catch (SQLException ex) {
563 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()
void setAcquisitionDetails(String details)
Boolean imageFileExists()
Image(SleuthkitCase db, long obj_id, long type, long ssize, String name, String[] paths, String timezone, String md5)
void setSha1(String sha1)
static long openImage(String[] imageFiles, SleuthkitCase skCase)
TskData.TSK_IMG_TYPE_ENUM getType()
List< Long > getChildrenIds()
int read(byte[] buf, long offset, long len)
String getAcquisitionDetails()
static long findDeviceSize(String devPath)
SleuthkitCase getSleuthkitCase()
void setDisplayName(String newName)
List< Content > getChildren()
List< VolumeSystem > getVolumeSystems()
void setSha256(String sha256)
static TSK_IMG_TYPE_ENUM valueOf(long imgType)
String toString(boolean preserveState)
long getContentSize(SleuthkitCase sleuthkitCase)
synchronized long getImageHandle()