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 volatile Host host = null;
 
   47         private final String deviceId, timezone;
 
   48         private String md5, sha1, sha256;
 
   49         private static ResourceBundle bundle = ResourceBundle.getBundle(
"org.sleuthkit.datamodel.Bundle");
 
   51         private static final Logger LOGGER = Logger.getLogger(
Image.class.
getName());
 
   73                 super(db, obj_id, name);
 
   78                 this.timezone = timezone;
 
  101         Image(
SleuthkitCase db, 
long obj_id, 
long type, String deviceId, 
long ssize, String name, String[] paths, String timezone, 
 
  102                         String md5, String sha1, String sha256, 
long size) 
throws TskCoreException {
 
  103                 super(db, obj_id, name);
 
  104                 this.deviceId = deviceId;
 
  108                 this.timezone = timezone;
 
  112                 this.sha256 = sha256;
 
  123                 if (paths.length == 0) {
 
  124                         throw new TskCoreException(
"Image has no associated paths");
 
  127                 if (imageHandle == 0) {
 
  134         synchronized void setImageHandle(
long imageHandle) {
 
  135                 this.imageHandle = imageHandle;
 
  148         @SuppressWarnings(
"deprecation")
 
  152                         if (imageHandle != 0) {
 
  164                 if (paths.length == 0) {
 
  176                                 if (paths.length > 0) {
 
  181                                 Logger.getLogger(
Image.class.
getName()).log(Level.SEVERE, 
"Could not find image size, image: " + 
this.getId(), ex); 
 
  228                 List<VolumeSystem> vs = 
new ArrayList<VolumeSystem>();
 
  229                 for (
Content child : children) {
 
  231                                 vs.add((VolumeSystem) child);
 
  246                 List<Volume> volumes = 
new ArrayList<Volume>();
 
  247                 for (
Content child : children) {
 
  248                         if (child instanceof 
Volume) {
 
  249                                 volumes.add((Volume) child);
 
  264                 List<FileSystem> fs = 
new ArrayList<>();
 
  281                 return v.
visit(
this);
 
  285         public <T> T accept(ContentVisitor<T> v) {
 
  286                 return v.visit(
this);
 
  301                 return super.toString(preserveState) + 
"Image [\t" + 
"\t" + 
"paths " + Arrays.toString(paths) + 
"\t" + 
"size " + size + 
"\t" + 
"ssize " + ssize + 
"\t" + 
"timezone " + timezone + 
"\t" + 
"type " + type + 
"]\t"; 
 
  311                 if (paths.length > 0) {
 
  312                         File imageFile = 
new File(paths[0]);
 
  313                         return imageFile.
exists();
 
  327                 Logger logger1 = Logger.getLogger(
"verifyImageSizes"); 
 
  328                 String errorString = 
"";
 
  332                                 List<Volume> volumes = vs.getVolumes();
 
  333                                 for (
Volume v : volumes) {
 
  334                                         byte[] buf = 
new byte[512];
 
  335                                         long endOffset = (v.getStart() + v.getLength()) * 512 - 512;
 
  337                                                 int readBytes = 
read(buf, endOffset, 512);
 
  339                                                         logger1.log(Level.WARNING, 
"Possible Incomplete Image: Error reading volume at offset {0}", endOffset); 
 
  340                                                         errorString = MessageFormat.format(bundle.getString(
"Image.verifyImageSize.errStr1.text"), endOffset);
 
  343                                                 logger1.log(Level.WARNING, 
"Possible Incomplete Image: Error reading volume at offset {0}: {1}", 
new Object[]{endOffset, ex.getLocalizedMessage()}); 
 
  344                                                 errorString = MessageFormat.format(bundle.getString(
"Image.verifyImageSize.errStr2.text"), endOffset);
 
  351                                 long block_size = fs.getBlock_size();
 
  352                                 long endOffset = fs.getImageOffset() + fs.getSize() - block_size;
 
  354                                         byte[] buf = 
new byte[(int) block_size];
 
  355                                         int readBytes = 
read(buf, endOffset, block_size);
 
  357                                                 logger1.log(Level.WARNING, 
"Possible Incomplete Image: Error reading file system at offset {0}", endOffset); 
 
  358                                                 errorString = MessageFormat.format(bundle.getString(
"Image.verifyImageSize.errStr3.text"), endOffset);
 
  361                                         logger1.log(Level.WARNING, 
"Possible Incomplete Image: Error reading file system at offset {0}: {1}", 
new Object[]{endOffset, ex.getLocalizedMessage()}); 
 
  362                                         errorString = MessageFormat.format(bundle.getString(
"Image.verifyImageSize.errStr4.text"), endOffset);
 
  379                 if (md5 == null || md5.isEmpty()) {
 
  393                 if (sha1 == null || sha1.isEmpty()) {
 
  407                 if (sha256 == null || sha256.isEmpty()) {
 
  420                 if (
getMd5().isEmpty() == 
false) {
 
  434                 if (
getSha1().isEmpty() == 
false) {
 
  452                 this.sha256 = sha256;
 
  497                 Statement statement = null;
 
  498                 ResultSet resultSet = null;
 
  499                 long contentSize = 0;
 
  501                 connection = sleuthkitCase.getConnection();
 
  504                         statement = connection.createStatement();
 
  505                         resultSet = connection.executeQuery(statement, 
"SELECT SUM (size) FROM tsk_image_info WHERE tsk_image_info.obj_id = " + 
getId());
 
  506                         if (resultSet.next()) {
 
  507                                 contentSize = resultSet.getLong(
"sum");
 
  509                 } 
catch (SQLException ex) {
 
  510                         throw new TskCoreException(String.format(
"There was a problem while querying the database for size data for object ID %d.", 
getId()), ex);
 
  512                         closeResultSet(resultSet);
 
  513                         closeStatement(statement);
 
  544                 getSleuthkitCase().setAcquisitionToolDetails(
this, name, version, settings);
 
  555                 return getSleuthkitCase().getDataSourceInfoString(
this, 
"acquisition_tool_settings");
 
  566                 return getSleuthkitCase().getDataSourceInfoString(
this, 
"acquisition_tool_name");
 
  577                 return getSleuthkitCase().getDataSourceInfoString(
this, 
"acquisition_tool_version");
 
  633         public void setSizes(
long totalSize, 
long sectorSize) 
throws TskCoreException {
 
  642         private static void closeResultSet(ResultSet resultSet) {
 
  643                 if (resultSet != null) {
 
  646                         } 
catch (SQLException ex) {
 
  647                                 LOGGER.log(Level.SEVERE, 
"Error closing ResultSet", ex); 
 
  657         private static void closeStatement(Statement statement) {
 
  658                 if (statement != null) {
 
  661                         } 
catch (SQLException ex) {
 
  662                                 LOGGER.log(Level.SEVERE, 
"Error closing Statement", ex); 
 
static int readImg(long imgHandle, byte[] readBuffer, long offset, long len)
 
Host getHostByDataSource(DataSource dataSource)
 
List< Volume > getVolumes()
 
List< FileSystem > getFileSystems()
 
void setAcquisitionToolDetails(String name, String version, String settings)
 
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 getAcquisitionToolVersion()
 
String getAcquisitionDetails()
 
void setSizes(long totalSize, long sectorSize)
 
static long findDeviceSize(String devPath)
 
HostManager getHostManager()
 
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 getAcquisitionToolSettings()
 
String toString(boolean preserveState)
 
String getAcquisitionToolName()
 
long getContentSize(SleuthkitCase sleuthkitCase)
 
synchronized long getImageHandle()