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) {
133 synchronized void setImageHandle(
long imageHandle) {
134 this.imageHandle = imageHandle;
150 if (imageHandle != 0) {
162 if (paths.length == 0) {
174 if (paths.length > 0) {
179 Logger.getLogger(
Image.class.
getName()).log(Level.SEVERE,
"Could not find image size, image: " +
this.getId(), ex);
226 List<VolumeSystem> vs =
new ArrayList<VolumeSystem>();
227 for (
Content child : children) {
229 vs.add((VolumeSystem) child);
244 List<Volume> volumes =
new ArrayList<Volume>();
245 for (
Content child : children) {
246 if (child instanceof
Volume) {
247 volumes.add((Volume) child);
262 List<FileSystem> fs =
new ArrayList<>();
279 return v.
visit(
this);
283 public <T> T accept(ContentVisitor<T> v) {
284 return v.visit(
this);
299 return super.toString(preserveState) +
"Image [\t" +
"\t" +
"paths " + Arrays.toString(paths) +
"\t" +
"size " + size +
"\t" +
"ssize " + ssize +
"\t" +
"timezone " + timezone +
"\t" +
"type " + type +
"]\t";
309 if (paths.length > 0) {
310 File imageFile =
new File(paths[0]);
311 return imageFile.
exists();
325 Logger logger1 = Logger.getLogger(
"verifyImageSizes");
326 String errorString =
"";
330 List<Volume> volumes = vs.getVolumes();
331 for (
Volume v : volumes) {
332 byte[] buf =
new byte[512];
333 long endOffset = (v.getStart() + v.getLength()) * 512 - 512;
335 int readBytes =
read(buf, endOffset, 512);
337 logger1.log(Level.WARNING,
"Possible Incomplete Image: Error reading volume at offset {0}", endOffset);
338 errorString = MessageFormat.format(bundle.getString(
"Image.verifyImageSize.errStr1.text"), endOffset);
341 logger1.log(Level.WARNING,
"Possible Incomplete Image: Error reading volume at offset {0}: {1}",
new Object[]{endOffset, ex.getLocalizedMessage()});
342 errorString = MessageFormat.format(bundle.getString(
"Image.verifyImageSize.errStr2.text"), endOffset);
349 long block_size = fs.getBlock_size();
350 long endOffset = fs.getImageOffset() + fs.getSize() - block_size;
352 byte[] buf =
new byte[(int) block_size];
353 int readBytes =
read(buf, endOffset, block_size);
355 logger1.log(Level.WARNING,
"Possible Incomplete Image: Error reading file system at offset {0}", endOffset);
356 errorString = MessageFormat.format(bundle.getString(
"Image.verifyImageSize.errStr3.text"), endOffset);
359 logger1.log(Level.WARNING,
"Possible Incomplete Image: Error reading file system at offset {0}: {1}",
new Object[]{endOffset, ex.getLocalizedMessage()});
360 errorString = MessageFormat.format(bundle.getString(
"Image.verifyImageSize.errStr4.text"), endOffset);
377 if (md5 == null || md5.isEmpty()) {
391 if (sha1 == null || sha1.isEmpty()) {
405 if (sha256 == null || sha256.isEmpty()) {
418 if (
getMd5().isEmpty() ==
false) {
432 if (
getSha1().isEmpty() ==
false) {
450 this.sha256 = sha256;
495 Statement statement = null;
496 ResultSet resultSet = null;
497 long contentSize = 0;
499 connection = sleuthkitCase.getConnection();
502 statement = connection.createStatement();
503 resultSet = connection.executeQuery(statement,
"SELECT SUM (size) FROM tsk_image_info WHERE tsk_image_info.obj_id = " +
getId());
504 if (resultSet.next()) {
505 contentSize = resultSet.getLong(
"sum");
507 }
catch (SQLException ex) {
508 throw new TskCoreException(String.format(
"There was a problem while querying the database for size data for object ID %d.",
getId()), ex);
510 closeResultSet(resultSet);
511 closeStatement(statement);
547 private static void closeResultSet(ResultSet resultSet) {
548 if (resultSet != null) {
551 }
catch (SQLException ex) {
552 LOGGER.log(Level.SEVERE,
"Error closing ResultSet", ex);
562 private static void closeStatement(Statement statement) {
563 if (statement != null) {
566 }
catch (SQLException ex) {
567 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()